Fixing build, adding unit tests
This commit is contained in:
parent
1446b9c039
commit
107c64dbf8
10 changed files with 145 additions and 61 deletions
|
@ -5,10 +5,10 @@ package edu.cornell.mannlib.vitro.webapp.edit;
|
|||
import com.hp.hpl.jena.rdf.model.*;
|
||||
import com.hp.hpl.jena.datatypes.RDFDatatype;
|
||||
import com.hp.hpl.jena.graph.Node;/**
|
||||
* bdc34: I needed to have a representation of a rdf literal for
|
||||
* bdc34: I needed to have a representation of a RDF literal for
|
||||
* editing. Jena seems to have a Model associated with the literals and
|
||||
* has deprecated the creation of simple Literals as if they were data
|
||||
* structures. So this code was writen.
|
||||
* has depreciated the creation of simple Literals as if they were data
|
||||
* structures. So this code was written.
|
||||
*
|
||||
* THESE MAY NOT BE USED AS LITERALS WITH THE JENA LIBRARY
|
||||
*/
|
||||
|
|
|
@ -93,14 +93,17 @@ public class EditConfigurationVTwo {
|
|||
/** When this is a DataPropertyStmt edit, the object is not used, the
|
||||
* DataPropertyStatement is retrieved using the subject, predicate and the
|
||||
* datapropKey. When this edit is for a ObjectPropertyStmt,
|
||||
* object is the uri without the quoting < or >.
|
||||
* object is the URI, it has no quoting or < or >.
|
||||
*/
|
||||
String object;
|
||||
|
||||
/**
|
||||
* This can be the variable name for the object of a statement in
|
||||
* a object property or data property form.
|
||||
*/
|
||||
String varNameForObject;
|
||||
|
||||
Integer datapropKey=null;
|
||||
String datapropValue;
|
||||
|
||||
|
||||
/** urlPatternToReturnTo is the URL to use as the servlet to return to.
|
||||
* Usually it is "/individual" and entityToReturnTo will be added as a
|
||||
|
@ -194,8 +197,7 @@ public class EditConfigurationVTwo {
|
|||
editConfig.setVarNameForObject(this.getVarNameForObject());
|
||||
|
||||
editConfig.setDatapropKey(this.getDatapropKey());
|
||||
//original set datapropValue, which in this case would be empty string but no way here
|
||||
editConfig.setDatapropValue(this.datapropValue);
|
||||
|
||||
editConfig.setUrlPatternToReturnTo(this.getUrlPatternToReturnTo());
|
||||
|
||||
//n3 required
|
||||
|
@ -686,11 +688,6 @@ public class EditConfigurationVTwo {
|
|||
this.datapropKey = datapropKey;
|
||||
}
|
||||
|
||||
//to allow for external setting
|
||||
public void setDatapropValue(String datapropValue) {
|
||||
this.datapropValue = datapropValue;
|
||||
}
|
||||
|
||||
public String getSubjectUri() {
|
||||
return subjectUri;
|
||||
}
|
||||
|
|
|
@ -321,6 +321,7 @@ public class ProcessRdfForm {
|
|||
List<String> optionalAsserts, List<String> requiredRetracts,
|
||||
List<String> optionalRetracts) {
|
||||
if( !log.isDebugEnabled() ) return;
|
||||
log.debug(msg);
|
||||
logSubstitueN3( msg, requiredAsserts, "required assertions");
|
||||
logSubstitueN3( msg, optionalAsserts, "optional assertions");
|
||||
logSubstitueN3( msg, requiredRetracts, "required retractions");
|
||||
|
@ -328,7 +329,7 @@ public class ProcessRdfForm {
|
|||
}
|
||||
|
||||
private void logSubstitueN3(String msg, List<String> n3, String label){
|
||||
if( n3 == null) return;
|
||||
if( n3 == null || n3.size() == 0) return;
|
||||
String out = label + ":\n";
|
||||
for( String str : n3 ){
|
||||
out += " " + str + "\n";
|
||||
|
|
|
@ -91,10 +91,13 @@ public class DefaultDataPropertyFormGenerator extends BaseEditConfigurationGener
|
|||
|
||||
String subjectUri = editConfiguration.getSubjectUri();
|
||||
String predicateUri = editConfiguration.getPredicateUri();
|
||||
Integer dataHash = editConfiguration.getDatapropKey();
|
||||
Integer dataHash = editConfiguration.getDatapropKey();
|
||||
|
||||
if( predicateUri == null )
|
||||
throw new Error("predicateUri was null");
|
||||
|
||||
DataProperty dataproperty = dataPropertyDao.getDataPropertyByURI( predicateUri );
|
||||
if( dataproperty == null )
|
||||
if( dataproperty == null && ! VitroVocabulary.LABEL.equals( predicateUri ))
|
||||
throw new Error("could not get data property for " + predicateUri);
|
||||
|
||||
DataPropertyStatement dps = null;
|
||||
|
@ -105,32 +108,46 @@ public class DefaultDataPropertyFormGenerator extends BaseEditConfigurationGener
|
|||
if (dps==null){
|
||||
throw new Error("No match to existing data property \""+predicateUri+"\" statement for subject \""+subjectUri+"\" via key "+dataHash);
|
||||
}else{
|
||||
|
||||
//Put data property statement's literal in scope
|
||||
//TODO: Check if multiple statements might affect this implementation?
|
||||
editConfiguration.addLiteralInScope(literalVar, new EditLiteral(dps.getData(),dps.getDatatypeURI(), dps.getLanguage()) );
|
||||
|
||||
String statementDataType = null;
|
||||
String statementLang = null;
|
||||
|
||||
statementDataType = dps.getDatatypeURI();
|
||||
if( statementDataType == null ){
|
||||
log.debug("no range datatype uri set on data property statement when property's range datatype is "+dataproperty.getRangeDatatypeURI()+" in DefaultDataPropertyFormGenerator");
|
||||
} else {
|
||||
log.debug("range datatype uri of ["+statementDataType+"] on data property statement in DefaultDataPropertyFormGenerator");
|
||||
}
|
||||
statementLang = dps.getLanguage();
|
||||
if( statementLang == null ) {
|
||||
log.debug("no language attribute on data property statement in DefaultDataPropertyFormGenerator");
|
||||
}else{
|
||||
log.debug("language attribute of ["+statementLang+"] on data property statement in DefaultDataPropertyFormGenerator");
|
||||
}
|
||||
|
||||
|
||||
editConfiguration.addLiteralInScope(
|
||||
editConfiguration.getVarNameForObject(),
|
||||
new EditLiteral(dps.getData(),dps.getDatatypeURI(), dps.getLanguage()) );
|
||||
|
||||
dataTypeDebug( dps, dataproperty );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static void dataTypeDebug(DataPropertyStatement dps,
|
||||
DataProperty dataproperty) {
|
||||
if( dps == null )
|
||||
return;
|
||||
|
||||
String statementDataType = null;
|
||||
String statementLang = null;
|
||||
|
||||
statementLang = dps.getLanguage();
|
||||
if( statementLang == null ) {
|
||||
log.debug("no language attribute on data property statement in DefaultDataPropertyFormGenerator");
|
||||
}else{
|
||||
log.debug("language attribute of ["+statementLang+"] on data property statement in DefaultDataPropertyFormGenerator");
|
||||
}
|
||||
|
||||
if( dataproperty == null )
|
||||
return;
|
||||
|
||||
statementDataType = dps.getDatatypeURI();
|
||||
if( statementDataType == null ){
|
||||
log.debug("no range datatype uri set on data property statement when property's range datatype is "+dataproperty.getRangeDatatypeURI()+" in DefaultDataPropertyFormGenerator");
|
||||
} else {
|
||||
log.debug("range datatype uri of ["+statementDataType+"] on data property statement in DefaultDataPropertyFormGenerator");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -130,8 +130,6 @@ public class DefaultDeleteGenerator implements EditConfigurationGenerator {
|
|||
private void processDataPropForm(VitroRequest vreq, EditConfigurationVTwo editConfiguration) {
|
||||
//set data prop value, data prop key str,
|
||||
editConfiguration.setDatapropKey( EditConfigurationUtils.getDataHash(vreq) );
|
||||
//original set datapropValue, which in this case would be empty string but no way here
|
||||
editConfiguration.setDatapropValue("");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -47,19 +47,13 @@ public class RDFSLabelGenerator implements EditConfigurationGenerator {
|
|||
private Log log = LogFactory.getLog(DefaultObjectPropertyFormGenerator.class);
|
||||
|
||||
private String subjectUri = null;
|
||||
private String predicateUri = null;
|
||||
private String datapropKeyStr= null;
|
||||
private int dataHash = 0;
|
||||
private DataPropertyStatement dps = null;
|
||||
private String predicateUri = null;
|
||||
private Integer dataHash = null;
|
||||
|
||||
private String literalName = "label";
|
||||
|
||||
|
||||
private String template = "rdfsLabelForm.ftl";
|
||||
private static HashMap<String,String> defaultsForXSDtypes ;
|
||||
static {
|
||||
defaultsForXSDtypes = new HashMap<String,String>();
|
||||
//defaultsForXSDtypes.put("http://www.w3.org/2001/XMLSchema#dateTime","2001-01-01T12:00:00");
|
||||
defaultsForXSDtypes.put("http://www.w3.org/2001/XMLSchema#dateTime","#Unparseable datetime defaults to now");
|
||||
}
|
||||
|
||||
@Override
|
||||
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, HttpSession session) {
|
||||
//Check if an edit configuration exists and return that, otherwise create a new one
|
||||
|
@ -145,18 +139,13 @@ public class RDFSLabelGenerator implements EditConfigurationGenerator {
|
|||
|
||||
|
||||
private void initDataParameters(VitroRequest vreq, HttpSession session) {
|
||||
dataHash = EditConfigurationUtils.getDataHash(vreq);
|
||||
dps = EditConfigurationUtils.getDataPropertyStatement(vreq, session, dataHash, predicateUri);
|
||||
dataHash = EditConfigurationUtils.getDataHash(vreq);
|
||||
}
|
||||
|
||||
private void processDataPropForm(VitroRequest vreq, EditConfigurationVTwo editConfiguration) {
|
||||
//set data prop value, data prop key str,
|
||||
editConfiguration.setDatapropKey( EditConfigurationUtils.getDataHash(vreq) );
|
||||
editConfiguration.setVarNameForObject(literalName);
|
||||
|
||||
//original set datapropValue, which in this case would be empty string but no way here
|
||||
editConfiguration.setDatapropValue("");
|
||||
editConfiguration.setUrlPatternToReturnTo("/entity");
|
||||
editConfiguration.setVarNameForObject(literalName);
|
||||
}
|
||||
|
||||
//Get N3 required
|
||||
|
@ -333,10 +322,9 @@ public class RDFSLabelGenerator implements EditConfigurationGenerator {
|
|||
private void prepareForUpdate(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) {
|
||||
//Here, retrieve model from
|
||||
Model model = (Model) session.getServletContext().getAttribute("jenaOntModel");
|
||||
if(datapropKeyStr != null && datapropKeyStr.trim().length() > 0 ) {
|
||||
editConfiguration.prepareForDataPropUpdate(model, vreq.getWebappDaoFactory().getDataPropertyDao());
|
||||
if( editConfiguration.isDataPropertyUpdate() ){
|
||||
editConfiguration.prepareForDataPropUpdate(model, vreq.getWebappDaoFactory().getDataPropertyDao());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue