Adding ability to edit sameAs from profile page VIVO-111

This commit is contained in:
Brian Caruso 2013-09-05 12:53:30 -04:00
parent 7ff02342e4
commit 7d01b546a9
5 changed files with 94 additions and 28 deletions

View file

@ -831,7 +831,7 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
*/
protected static final List<String> EXCLUDED_NAMESPACES = Arrays.asList(
"http://www.w3.org/2002/07/owl#"
//"http://www.w3.org/2002/07/owl#"
);
/*
* This is a hack to throw out properties in the vitro, rdf, rdfs, and owl namespaces.

View file

@ -2,6 +2,7 @@
package edu.cornell.mannlib.vitro.webapp.dao.jena;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@ -10,6 +11,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -34,6 +36,7 @@ import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.shared.Lock;
import com.hp.hpl.jena.util.iterator.ClosableIterator;
import com.hp.hpl.jena.vocabulary.OWL;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
@ -347,7 +350,7 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
return null;
}
Model constructedModel = ModelFactory.createDefaultModel();
Model constructedModel = ModelFactory.createDefaultModel();
for (String queryString : constructQueries) {
@ -402,13 +405,24 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
w.close();
}
} else {
constructedModel.read(
rdfService.sparqlConstructQuery(
queryString, RDFService.ModelSerializationFormat.N3), null, "N3");
String parseFormat = "N3";
RDFService.ModelSerializationFormat resultFormat = RDFService.ModelSerializationFormat.N3;
/* If the test ObjectPropertyStatementDaoJenaTest.testN3WithSameAs() fails
* this code can be removed: */
if( OWL.sameAs.getURI().equals( propertyUri )){
// VIVO-111: owl:sameAs can be represented as = in n3 but Jena's parser does not recognize it.
// Switch to rdf/xml only for sameAs since it seems like n3 would be faster the rest of the time.
parseFormat = "RDF/XML";
resultFormat = RDFService.ModelSerializationFormat.RDFXML;
}
/* end of removal */
InputStream is = rdfService.sparqlConstructQuery(queryString, resultFormat);
constructedModel.read( is, null, parseFormat);
}
} catch (Exception e) {
log.error("Error getting constructed model for subject " + subjectUri + " and property " + propertyUri);
} catch (Exception e) {
log.error("Error getting constructed model for subject " + subjectUri + " and property " + propertyUri, e);
}
}

View file

@ -22,10 +22,13 @@ public class PropertyGroupTemplateModel extends BaseTemplateModel {
private final String name;
private final List<PropertyTemplateModel> properties;
PropertyGroupTemplateModel(VitroRequest vreq, PropertyGroup group,
Individual subject, boolean editing,
List<DataProperty> populatedDataPropertyList, List<ObjectProperty> populatedObjectPropertyList) {
List<DataProperty> populatedDataPropertyList,
List<ObjectProperty> populatedObjectPropertyList) {
this.name = group.getName();
@ -49,6 +52,17 @@ public class PropertyGroupTemplateModel extends BaseTemplateModel {
properties.remove(ptm);
}
public String toString(){
String ptmStr ="";
for( int i=0; i < properties.size() ; i ++ ){
PropertyTemplateModel ptm = properties.get(i);
String spacer = "\n ";
if( ptm != null )
ptmStr = ptmStr + spacer + ptm.toString();
}
return String.format("\nPropertyGroupTemplateModel %s[%s] ",name, ptmStr );
}
/* Accessor methods for templates */
// Add this so it's included in dumps for debugging. The templates will want to display
@ -58,18 +72,14 @@ public class PropertyGroupTemplateModel extends BaseTemplateModel {
}
public String getName(String otherGroupName) {
String displayName = name;
if (displayName == null) {
displayName = "";
} else if (displayName.isEmpty()) {
displayName = otherGroupName;
}
return displayName;
if (name == null || name.isEmpty()) {
return otherGroupName;
} else {
return name;
}
}
public List<PropertyTemplateModel> getProperties() {
return properties;
}
}
}

View file

@ -36,12 +36,13 @@ public abstract class PropertyTemplateModel extends BaseTemplateModel {
private String name;
PropertyTemplateModel(Property property, Individual subject, VitroRequest vreq) {
this.vreq = vreq;
subjectUri = subject.getURI();
propertyUri = property.getURI();
localName = property.getLocalName();
log.debug("Local name for property " + propertyUri + ": " + localName);
localName = property.getLocalName();
setVerboseDisplayValues(property);
addUrl = "";
@ -53,14 +54,18 @@ public abstract class PropertyTemplateModel extends BaseTemplateModel {
protected void setVerboseDisplayValues(Property property) {
// No verbose display for vitro and vitro public properties.
// This models previous behavior. In theory the verbose display can be provided, but we may not want
// to give anyone access to these properties, since the application is dependent on them.
// This models previous behavior. In theory the verbose display can be provided,
// but we may not want to give anyone access to these properties, since the
// application is dependent on them.
String namespace = property.getNamespace();
if (VitroVocabulary.vitroURI.equals(namespace) || VitroVocabulary.VITRO_PUBLIC.equals(namespace)) {
if (VitroVocabulary.vitroURI.equals(namespace)
|| VitroVocabulary.VITRO_PUBLIC.equals(namespace)) {
return;
}
Boolean verboseDisplayValue = (Boolean) vreq.getSession().getAttribute("verbosePropertyDisplay");
Boolean verboseDisplayValue =
(Boolean) vreq.getSession().getAttribute("verbosePropertyDisplay");
if ( ! Boolean.TRUE.equals(verboseDisplayValue)) {
return;
}
@ -94,6 +99,12 @@ public abstract class PropertyTemplateModel extends BaseTemplateModel {
this.name = name;
}
public String toString() {
return String.format("%s on %s",
propertyUri != null ? propertyUri : "null Prop URI",
subjectUri != null ? subjectUri : "null Sub URI" );
}
/* Template properties */
public abstract String getType();
@ -117,6 +128,5 @@ public abstract class PropertyTemplateModel extends BaseTemplateModel {
public Map<String, Object> getVerboseDisplay() {
return verboseDisplay;
}
}
}

View file

@ -0,0 +1,32 @@
package edu.cornell.mannlib.vitro.webapp.dao.jena;
import static org.junit.Assert.*;
import org.junit.Test;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
public class ObjectPropertyStatementDaoJenaTest {
/**
* Test if jena lib can parse N3 that it generates.
* owl:sameAs has been a problem when it is represetned
* in N3 with the character =
*/
@Test
public void testN3WithSameAs() {
String n3WithSameAs = " <http://example.com/bob> = <http://example.com/robert> .";
try{
Model m = ModelFactory.createDefaultModel();
m.read(n3WithSameAs, null, "N3");
fail( "If this test fails it means that jena now correctly parses = when reading N3.");
}catch(Exception ex ){
}
}
}