Working on default data process form
This commit is contained in:
parent
3dbd67d5c2
commit
221a38eca7
17 changed files with 496 additions and 436 deletions
|
@ -152,9 +152,10 @@ public class EditConfigurationUtils {
|
||||||
return (dataProp != null);
|
return (dataProp != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getDataPropKey(VitroRequest vreq) {
|
protected static String getDataPropKey(VitroRequest vreq) {
|
||||||
return vreq.getParameter("datapropKey");
|
return vreq.getParameter("datapropKey");
|
||||||
}
|
}
|
||||||
|
|
||||||
//is object property
|
//is object property
|
||||||
public static boolean isObjectProperty(String predicateUri, VitroRequest vreq) {
|
public static boolean isObjectProperty(String predicateUri, VitroRequest vreq) {
|
||||||
if(predicateUri == null) {
|
if(predicateUri == null) {
|
||||||
|
@ -171,25 +172,21 @@ public class EditConfigurationUtils {
|
||||||
return predicateUri.equals(VitroVocabulary.LABEL);
|
return predicateUri.equals(VitroVocabulary.LABEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DataPropertyStatement getDataPropertyStatement(VitroRequest vreq, HttpSession session, int dataHash, String predicateUri) {
|
/**
|
||||||
|
* May return null if data property statement cannot be found.
|
||||||
|
*/
|
||||||
|
public static DataPropertyStatement getDataPropertyStatement(VitroRequest vreq, HttpSession session, Integer dataHash, String predicateUri) {
|
||||||
DataPropertyStatement dps = null;
|
DataPropertyStatement dps = null;
|
||||||
if( dataHash != 0) {
|
if( dataHash != 0) {
|
||||||
Model model = (Model)session.getServletContext().getAttribute("jenaOntModel");
|
Model model = (Model)session.getServletContext().getAttribute("jenaOntModel");
|
||||||
dps = RdfLiteralHash.getPropertyStmtByHash(EditConfigurationUtils.getSubjectIndividual(vreq), predicateUri, dataHash, model);
|
dps = RdfLiteralHash.getPropertyStmtByHash(EditConfigurationUtils.getSubjectUri(vreq), predicateUri, dataHash, model);
|
||||||
|
|
||||||
if (dps==null) {
|
|
||||||
//log.error("No match to existing data property \""+predicateUri+"\" statement for subject \""+subjectUri+"\" via key "+datapropKeyStr);
|
|
||||||
//TODO: Needs to forward to dataPropMissingStatement.jsp
|
|
||||||
//return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return dps;
|
return dps;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Include get object property statement
|
//TODO: Include get object property statement
|
||||||
public static int getDataHash(VitroRequest vreq) {
|
public static Integer getDataHash(VitroRequest vreq) {
|
||||||
int dataHash = 0;
|
Integer dataHash = null;
|
||||||
String datapropKey = EditConfigurationUtils.getDataPropKey(vreq);
|
String datapropKey = EditConfigurationUtils.getDataPropKey(vreq);
|
||||||
if (datapropKey!=null && datapropKey.trim().length()>0) {
|
if (datapropKey!=null && datapropKey.trim().length()>0) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -27,13 +27,13 @@ import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.ModelSelector;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.ModelSelector;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.StandardModelSelector;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.StandardModelSelector;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.StandardWDFSelector;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.StandardWDFSelector;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.WDFSelector;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.WDFSelector;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultDataPropertyFormGenerator;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ModelChangePreprocessor;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ModelChangePreprocessor;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
||||||
|
@ -98,7 +98,7 @@ public class EditConfigurationVTwo {
|
||||||
String object;
|
String object;
|
||||||
String varNameForObject;
|
String varNameForObject;
|
||||||
|
|
||||||
String datapropKey;
|
Integer datapropKey=null;
|
||||||
String datapropValue;
|
String datapropValue;
|
||||||
|
|
||||||
|
|
||||||
|
@ -299,29 +299,22 @@ public class EditConfigurationVTwo {
|
||||||
+ varNameForObject + " and object is " + object);
|
+ varNameForObject + " and object is " + object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Check if require
|
|
||||||
/**
|
/**
|
||||||
* Make a copy of this EditConfiguration, prepare for a DataProperty update
|
* Prepare an EditConfiguration for a DataProperty update.
|
||||||
* and return it.
|
* This should only be used when editing a existing data property statement.
|
||||||
*
|
|
||||||
* TODO: there is a good chance that this could be moved to the generator for
|
|
||||||
* the default data property form since that is the only place this is useful.
|
|
||||||
*/
|
*/
|
||||||
public void prepareForDataPropUpdate( Model model, DataPropertyStatement dpStmt){
|
public void prepareForDataPropUpdate( Model model, DataPropertyDao dataPropertyDao ){
|
||||||
if( model == null ) throw new Error("EditConfiguration.prepareForDataPropUpdate() needs a Model");
|
if( model == null ) throw new Error("EditConfiguration.prepareForDataPropUpdate() needs a Model");
|
||||||
if( isObjectResource() ){
|
if( isObjectResource() ){
|
||||||
throw new Error("This request does not seems to be a DataPropStmt update");
|
throw new Error("This request does not seems to be a DataPropStmt update");
|
||||||
} else if (datapropKey == null) {
|
} else if (datapropKey == null) {
|
||||||
throw new Error("This request does not appear to be for an update since it lacks a dataprop object or a dataProp hash key ");
|
throw new Error("This request does not appear to be for an update since it lacks a dataProp hash key ");
|
||||||
}
|
}
|
||||||
|
|
||||||
basicPrepare();
|
basicPrepare();
|
||||||
|
|
||||||
//TODO: Check if multiple statements might affect this implementation?
|
DefaultDataPropertyFormGenerator.prepareForDataPropUpdate(model, this,dataPropertyDao );
|
||||||
List<Literal> dataPropLiterals = new ArrayList<Literal>();
|
|
||||||
dataPropLiterals.add(new EditLiteral(dpStmt.getData(),dpStmt.getDatatypeURI(), dpStmt.getLanguage()));
|
|
||||||
literalsInScope.put(varNameForObject, dataPropLiterals);
|
|
||||||
|
|
||||||
// run SPARQL, sub in values
|
// run SPARQL, sub in values
|
||||||
SparqlEvaluateVTwo sparqlEval = new SparqlEvaluateVTwo(model);
|
SparqlEvaluateVTwo sparqlEval = new SparqlEvaluateVTwo(model);
|
||||||
|
@ -332,13 +325,13 @@ public class EditConfigurationVTwo {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a copy of this EditConfiguration, prepare for a ObjectProperty update
|
* Prepare for a ObjectProperty update. Run SPARQL for existing values.
|
||||||
* and return it.
|
* This can be used for an object property or a direct form.
|
||||||
*/
|
*/
|
||||||
public void prepareForObjPropUpdate( Model model ){
|
public void prepareForObjPropUpdate( Model model ){
|
||||||
if( model == null ) {
|
if( model == null ) {
|
||||||
log.debug("Model is null and will be throwing an error");
|
log.debug("Model is null and will be throwing an error");
|
||||||
throw new Error("EditConfiguration.prepareForObjPropUpdate() needs a Model");}
|
throw new Error("EditConfiguration.prepareForObjPropUpdate() needs a non-null Model");}
|
||||||
if( !isObjectResource() ) {
|
if( !isObjectResource() ) {
|
||||||
log.debug("This does not seem to be an object property update. Lacks object.");
|
log.debug("This does not seem to be an object property update. Lacks object.");
|
||||||
throw new Error("This request does not appear to be for a object property update.");
|
throw new Error("This request does not appear to be for a object property update.");
|
||||||
|
@ -358,9 +351,12 @@ public class EditConfigurationVTwo {
|
||||||
hasBeenPreparedForUpdate = true;
|
hasBeenPreparedForUpdate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run SPARQL for Additional values. This can be used for
|
||||||
|
* a data property, an object property or a direct form.
|
||||||
|
*/
|
||||||
public void prepareForNonUpdate( Model model ){
|
public void prepareForNonUpdate( Model model ){
|
||||||
if( model == null ) throw new Error("EditConfiguration.prepareForNonUpdate() needs a Model");
|
if( model == null ) throw new Error("prepareForNonUpdate() needs a non-null Model");
|
||||||
|
|
||||||
basicPrepare();
|
basicPrepare();
|
||||||
|
|
||||||
|
@ -675,18 +671,18 @@ public class EditConfigurationVTwo {
|
||||||
boolean dataKeyFound = false;
|
boolean dataKeyFound = false;
|
||||||
if( object != null && ! object.trim().isEmpty() )
|
if( object != null && ! object.trim().isEmpty() )
|
||||||
objectFound = true;
|
objectFound = true;
|
||||||
if( getDatapropKey() != null && ! getDatapropKey().isEmpty() )
|
if( getDatapropKey() != null )
|
||||||
dataKeyFound = true;
|
dataKeyFound = true;
|
||||||
if( dataKeyFound && objectFound )
|
if( dataKeyFound && objectFound )
|
||||||
throw new Error("Bad configuration: both datapropKey and object are defined.");
|
throw new Error("Bad configuration: both datapropKey and object are defined.");
|
||||||
return objectFound;
|
return objectFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDatapropKey() {
|
public Integer getDatapropKey() {
|
||||||
return datapropKey;
|
return datapropKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDatapropKey(String datapropKey) {
|
public void setDatapropKey(Integer datapropKey) {
|
||||||
this.datapropKey = datapropKey;
|
this.datapropKey = datapropKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -893,7 +889,7 @@ public class EditConfigurationVTwo {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDataPropertyUpdate() {
|
public boolean isDataPropertyUpdate() {
|
||||||
return this.getDatapropKey() != null && this.getDatapropKey().length() > 0;
|
return this.getDatapropKey() != null ;
|
||||||
}
|
}
|
||||||
|
|
||||||
//This is for specific data for a form that will be set by the generator
|
//This is for specific data for a form that will be set by the generator
|
||||||
|
@ -974,5 +970,13 @@ public class EditConfigurationVTwo {
|
||||||
|
|
||||||
private static final String INDIVIDUAL_CONTROLLER = "/individual";
|
private static final String INDIVIDUAL_CONTROLLER = "/individual";
|
||||||
|
|
||||||
|
public EditConfigurationVTwo addLiteralInScope(String key, Literal ... values) {
|
||||||
|
if( literalsInScope == null ){
|
||||||
|
literalsInScope = new HashMap<String, List<Literal>>();
|
||||||
|
}
|
||||||
|
literalsInScope.put(key, Arrays.asList(values));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.RDFSLabelGenerator;
|
||||||
|
|
||||||
|
public class JspToGeneratorMapping {
|
||||||
|
static Log log = LogFactory.getLog( JspToGeneratorMapping.class );
|
||||||
|
|
||||||
|
public static Map<String,String> jspsToGenerators;
|
||||||
|
|
||||||
|
static{
|
||||||
|
jspsToGenerators = new HashMap<String,String>();
|
||||||
|
Map<String, String> map = jspsToGenerators;
|
||||||
|
|
||||||
|
// vitro forms:
|
||||||
|
// map.put("autoCompleteDatapropForm.jsp",
|
||||||
|
// edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AutoCompleteDatapropFormGenerator.class.getName());
|
||||||
|
// map.put("autoCompleteObjPropForm.jsp",
|
||||||
|
// edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AutoCompleteObjPropFormGenerator.class.getName());
|
||||||
|
map.put("datapropStmtDelete.jsp",
|
||||||
|
edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultDeleteGenerator.class.getName());
|
||||||
|
// map.put("dateTimeIntervalForm.jsp",
|
||||||
|
// edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DateTimeIntervalFormGenerator.class.getName());
|
||||||
|
// map.put("dateTimeValueForm.jsp",
|
||||||
|
// edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DateTimeValueFormGenerator.class.getName());
|
||||||
|
map.put("defaultAddMissingIndividualForm.jsp",
|
||||||
|
edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultAddMissingIndividualFormGenerator.class.getName());
|
||||||
|
map.put("defaultDatapropForm.jsp",
|
||||||
|
edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultDataPropertyFormGenerator.class.getName());
|
||||||
|
map.put("defaultObjPropForm.jsp",
|
||||||
|
edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultObjectPropertyFormGenerator.class.getName());
|
||||||
|
map.put("newIndividualForm.jsp",
|
||||||
|
edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.NewIndividualFormGenerator.class.getName());
|
||||||
|
map.put("propDelete.jsp",
|
||||||
|
edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultDeleteGenerator.class.getName());
|
||||||
|
map.put("rdfsLabelForm.jsp",
|
||||||
|
RDFSLabelGenerator.class.getName());
|
||||||
|
|
||||||
|
//add in the vivo mappings if they exist
|
||||||
|
Object object = null;
|
||||||
|
try {
|
||||||
|
Class classDefinition =
|
||||||
|
Class.forName("edu.cornell.mannlib.vitro.webapp.edit.n3editing.N3TransitionToV2Mapping");
|
||||||
|
object = classDefinition.newInstance();
|
||||||
|
Map<String,String> vivoJspsToGenerators = (Map) object;
|
||||||
|
if( vivoJspsToGenerators != null )
|
||||||
|
map.putAll( vivoJspsToGenerators );
|
||||||
|
|
||||||
|
} catch (Throwable th){
|
||||||
|
log.error( "could not load VIVO jsp mappings",th );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,7 +2,9 @@
|
||||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo;
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
import com.hp.hpl.jena.rdf.model.Literal;
|
import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
|
@ -10,6 +12,8 @@ import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.EditConfigurationGenerator;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.RDFSLabelGenerator;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ModelChangePreprocessor;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ModelChangePreprocessor;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
||||||
|
|
||||||
|
@ -109,12 +113,14 @@ public class N3EditUtils {
|
||||||
dps.setLanguage( submittedLiteral.getLanguage() );
|
dps.setLanguage( submittedLiteral.getLanguage() );
|
||||||
dps.setData( submittedLiteral.getLexicalForm() );
|
dps.setData( submittedLiteral.getLexicalForm() );
|
||||||
|
|
||||||
copy.prepareForDataPropUpdate(writeModel, dps);
|
copy.prepareForDataPropUpdate(writeModel, vreq.getWebappDaoFactory().getDataPropertyDao());
|
||||||
copy.setDatapropKey( Integer.toString(RdfLiteralHash.makeRdfLiteralHash(dps)) );
|
copy.setDatapropKey( RdfLiteralHash.makeRdfLiteralHash(dps));
|
||||||
}
|
}
|
||||||
EditConfigurationVTwo.putConfigInSession(copy,vreq.getSession());
|
EditConfigurationVTwo.putConfigInSession(copy,vreq.getSession());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ public abstract class BaseEditConfigurationGenerator implements EditConfiguratio
|
||||||
* Method to turn Strings or multiple List<String> to List<String>.
|
* Method to turn Strings or multiple List<String> to List<String>.
|
||||||
* Only accepts String and List<String> as multi args.
|
* Only accepts String and List<String> as multi args.
|
||||||
*/
|
*/
|
||||||
List<String> list( Object ... objs){
|
static List<String> list( Object ... objs){
|
||||||
List<String> rv = new ArrayList<String>();
|
List<String> rv = new ArrayList<String>();
|
||||||
for( Object obj: objs){
|
for( Object obj: objs){
|
||||||
if( obj instanceof String)
|
if( obj instanceof String)
|
||||||
|
|
|
@ -2,134 +2,135 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators;
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.DefaultDataPropEmptyField;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.DefaultDataPropEmptyField;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
||||||
|
|
||||||
public class DefaultDataPropertyFormGenerator implements EditConfigurationGenerator {
|
public class DefaultDataPropertyFormGenerator extends BaseEditConfigurationGenerator implements EditConfigurationGenerator {
|
||||||
|
|
||||||
private Log log = LogFactory.getLog(DefaultDataPropertyFormGenerator.class);
|
private static Log log = LogFactory.getLog(DefaultDataPropertyFormGenerator.class);
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
static String literalVar = "literal";
|
||||||
|
static String literalPlaceholder = "?"+literalVar;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq,
|
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, HttpSession session) {
|
||||||
HttpSession session) {
|
String command = vreq.getParameter("cmd");
|
||||||
|
|
||||||
String subjectUri = vreq.getParameter("subjectUri");
|
String subjectUri = vreq.getParameter("subjectUri");
|
||||||
|
Individual subject = vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI(subjectUri);
|
||||||
|
if( subject == null )
|
||||||
|
throw new Error("In DefaultDataPropertyFormGenerator, could not find individual for URI " + subjectUri);
|
||||||
|
|
||||||
String predicateUri = vreq.getParameter("predicateUri");
|
String predicateUri = vreq.getParameter("predicateUri");
|
||||||
String subjectUriJson = (String)vreq.getAttribute("subjectUriJson");
|
WebappDaoFactory unfilteredWdf = vreq.getUnfilteredWebappDaoFactory();
|
||||||
String predicateUriJson = (String)vreq.getAttribute("predicateUriJson");
|
DataProperty dataproperty = unfilteredWdf.getDataPropertyDao().getDataPropertyByURI( predicateUri );
|
||||||
String objectUriJson = (String)vreq.getAttribute("objectUriJson");
|
if( dataproperty == null) {
|
||||||
|
// No dataproperty will be returned for rdfs:label, but we shouldn't throw an error.
|
||||||
DataPropertyStatement dps = (DataPropertyStatement)vreq.getAttribute("dataprop");
|
// This is controlled by the Jena layer, so we can't change the behavior.
|
||||||
|
if (! predicateUri.equals(VitroVocabulary.LABEL)) {
|
||||||
String datapropKeyStr = vreq.getParameter("datapropKey");
|
log.error("Could not find data property '"+predicateUri+"' in model");
|
||||||
int dataHash=0;
|
throw new Error("editDatapropStmtRequest.jsp: Could not find DataProperty in model: " + predicateUri);
|
||||||
|
|
||||||
DataProperty prop = (DataProperty)vreq.getAttribute("predicate");
|
|
||||||
//if( prop == null ) return doHelp(vreq, "In DefaultDataPropertyFormGenerator, could not find predicate " + predicateUri);
|
|
||||||
vreq.setAttribute("propertyName",prop.getPublicName());
|
|
||||||
|
|
||||||
Individual subject = (Individual)vreq.getAttribute("subject");
|
|
||||||
//if( subject == null ) return doHelp(vreq,"In DefaultDataPropertyFormGenerator, could not find subject " + subjectUri);
|
|
||||||
vreq.setAttribute("subjectName",subject.getName());
|
|
||||||
|
|
||||||
String rangeDatatypeUri = vreq.getWebappDaoFactory().getDataPropertyDao().getRequiredDatatypeURI(subject, prop);
|
|
||||||
//String rangeDatatypeUri = prop.getRangeDatatypeURI();
|
|
||||||
vreq.setAttribute("rangeDatatypeUriJson", MiscWebUtils.escape(rangeDatatypeUri));
|
|
||||||
|
|
||||||
|
|
||||||
if( dps != null ){
|
|
||||||
try {
|
|
||||||
dataHash = Integer.parseInt(datapropKeyStr);
|
|
||||||
log.debug("dataHash is " + dataHash);
|
|
||||||
} catch (NumberFormatException ex) {
|
|
||||||
log.debug("could not parse dataprop hash "+
|
|
||||||
"but there was a dataproperty; hash: '"+datapropKeyStr+"'");
|
|
||||||
}
|
|
||||||
|
|
||||||
String rangeDatatype = dps.getDatatypeURI();
|
|
||||||
if( rangeDatatype == null ){
|
|
||||||
log.debug("no range datatype uri set on data property statement when property's range datatype is "+prop.getRangeDatatypeURI()+" in DefaultDataPropertyFormGenerator");
|
|
||||||
vreq.setAttribute("rangeDatatypeUriJson","");
|
|
||||||
} else {
|
|
||||||
log.debug("range datatype uri of ["+rangeDatatype+"] on data property statement in DefaultDataPropertyFormGenerator");
|
|
||||||
vreq.setAttribute("rangeDatatypeUriJson",rangeDatatype);
|
|
||||||
}
|
|
||||||
String rangeLang = dps.getLanguage();
|
|
||||||
if( rangeLang == null ) {
|
|
||||||
log.debug("no language attribute on data property statement in DefaultDataPropertyFormGenerator");
|
|
||||||
vreq.setAttribute("rangeLangJson","");
|
|
||||||
}else{
|
|
||||||
log.debug("language attribute of ["+rangeLang+"] on data property statement in DefaultDataPropertyFormGenerator");
|
|
||||||
vreq.setAttribute("rangeLangJson", rangeLang);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.debug("No incoming dataproperty statement attribute for property "+prop.getPublicName()+"; adding a new statement");
|
|
||||||
if(rangeDatatypeUri != null && rangeDatatypeUri.length() > 0) {
|
|
||||||
String defaultVal = defaultsForXSDtypes.get(rangeDatatypeUri);
|
|
||||||
if( defaultVal == null )
|
|
||||||
vreq.setAttribute("rangeDefaultJson", "");
|
|
||||||
else
|
|
||||||
vreq.setAttribute("rangeDefaultJson", '"' + MiscWebUtils.escape(defaultVal) + '"' );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String rangeDatatypeUri = dataproperty.getRangeDatatypeURI();
|
||||||
|
if( rangeDatatypeUri == null || rangeDatatypeUri.trim().isEmpty() ){
|
||||||
|
rangeDatatypeUri = vreq.getWebappDaoFactory().getDataPropertyDao().getRequiredDatatypeURI(subject, dataproperty);
|
||||||
|
}
|
||||||
|
|
||||||
|
EditConfigurationVTwo editConfiguration = new EditConfigurationVTwo();
|
||||||
|
|
||||||
|
editConfiguration.setTemplate("defaultDataPropertyForm.ftl");
|
||||||
|
|
||||||
String localName = prop.getLocalName();
|
editConfiguration.setN3Required(Arrays.asList( "?subject ?predicate " + literalPlaceholder + " . "));
|
||||||
String dataLiteral = localName + "Edited";
|
|
||||||
String formUrl = (String)vreq.getAttribute("formUrl");
|
editConfiguration.setDatapropKey( EditConfigurationUtils.getDataHash(vreq) );
|
||||||
String editKey = (String)vreq.getAttribute("editKey");
|
|
||||||
|
|
||||||
EditConfigurationVTwo editConfiguration = new EditConfigurationVTwo();
|
|
||||||
|
|
||||||
List<String> n3ForEdit = new ArrayList<String>();
|
|
||||||
n3ForEdit.add("?subject");
|
|
||||||
n3ForEdit.add("?predicate");
|
|
||||||
n3ForEdit.add("?"+dataLiteral);
|
|
||||||
editConfiguration.setN3Required(n3ForEdit);
|
|
||||||
|
|
||||||
editConfiguration.setFormUrl(formUrl);
|
|
||||||
editConfiguration.setEditKey(editKey);
|
|
||||||
|
|
||||||
editConfiguration.setDatapropKey((datapropKeyStr==null)?"":datapropKeyStr);
|
|
||||||
editConfiguration.setUrlPatternToReturnTo("/individual");
|
|
||||||
|
|
||||||
editConfiguration.setVarNameForSubject("subject");
|
editConfiguration.setVarNameForSubject("subject");
|
||||||
editConfiguration.setSubjectUri(subjectUriJson);
|
editConfiguration.setSubjectUri(subjectUri);
|
||||||
|
editConfiguration.setEntityToReturnTo( subjectUri );
|
||||||
|
|
||||||
editConfiguration.setVarNameForPredicate("predicate");
|
editConfiguration.setVarNameForPredicate("predicate");
|
||||||
editConfiguration.setPredicateUri(predicateUriJson);
|
editConfiguration.setPredicateUri(predicateUri);
|
||||||
|
|
||||||
|
editConfiguration.setLiteralsOnForm( Arrays.asList( literalVar ));
|
||||||
|
|
||||||
|
editConfiguration.addField( new FieldVTwo()
|
||||||
|
.setName( literalVar )
|
||||||
|
.setPredicateUri(predicateUri)
|
||||||
|
.setRangeDatatypeUri(rangeDatatypeUri));
|
||||||
|
|
||||||
//deal with empty field
|
//deal with empty field
|
||||||
editConfiguration.addModelChangePreprocessor( new DefaultDataPropEmptyField() );
|
editConfiguration.addModelChangePreprocessor( new DefaultDataPropEmptyField() );
|
||||||
|
|
||||||
return editConfiguration;
|
return editConfiguration;
|
||||||
}
|
|
||||||
|
|
||||||
private EditConfigurationVTwo doHelp(VitroRequest vreq, String string) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void prepareForDataPropUpdate(Model model, EditConfigurationVTwo editConfiguration, DataPropertyDao dataPropertyDao){
|
||||||
|
|
||||||
|
String subjectUri = editConfiguration.getSubjectUri();
|
||||||
|
String predicateUri = editConfiguration.getPredicateUri();
|
||||||
|
Integer dataHash = editConfiguration.getDatapropKey();
|
||||||
|
|
||||||
|
DataProperty dataproperty = dataPropertyDao.getDataPropertyByURI( predicateUri );
|
||||||
|
if( dataproperty == null )
|
||||||
|
throw new Error("could not get data property for " + predicateUri);
|
||||||
|
|
||||||
|
DataPropertyStatement dps = null;
|
||||||
|
if( dataHash == null ){
|
||||||
|
throw new Error("prepareForDataPropUpdate() should not be called if the EditConfiguration is not a data property statement update ");
|
||||||
|
}else{
|
||||||
|
dps = RdfLiteralHash.getPropertyStmtByHash(subjectUri, predicateUri, dataHash, model);
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,9 +48,8 @@ public class DefaultDeleteGenerator implements EditConfigurationGenerator {
|
||||||
private Log log = LogFactory.getLog(DefaultObjectPropertyFormGenerator.class);
|
private Log log = LogFactory.getLog(DefaultObjectPropertyFormGenerator.class);
|
||||||
private String subjectUri = null;
|
private String subjectUri = null;
|
||||||
private String predicateUri = null;
|
private String predicateUri = null;
|
||||||
private String objectUri = null;
|
private String objectUri = null;
|
||||||
private String datapropKeyStr= null;
|
private Integer dataHash = 0;
|
||||||
private int dataHash = 0;
|
|
||||||
private DataPropertyStatement dps = null;
|
private DataPropertyStatement dps = null;
|
||||||
private String dataLiteral = null;
|
private String dataLiteral = null;
|
||||||
private String template = "confirmDeletePropertyForm.ftl";
|
private String template = "confirmDeletePropertyForm.ftl";
|
||||||
|
@ -107,14 +106,9 @@ public class DefaultDeleteGenerator implements EditConfigurationGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initDataParameters(VitroRequest vreq, HttpSession session) {
|
private void initDataParameters(VitroRequest vreq, HttpSession session) {
|
||||||
datapropKeyStr = EditConfigurationUtils.getDataPropKey(vreq);
|
dataHash = EditConfigurationUtils.getDataHash(vreq);
|
||||||
if( datapropKeyStr != null ){
|
if( dataHash != null ){
|
||||||
try {
|
log.debug("Found a datapropKey in parameters and parsed it to int: " + dataHash);
|
||||||
dataHash = Integer.parseInt(datapropKeyStr);
|
|
||||||
log.debug("Found a datapropKey in parameters and parsed it to int: " + dataHash);
|
|
||||||
} catch (NumberFormatException ex) {
|
|
||||||
//return doHelp(vreq, "Cannot decode incoming datapropKey value "+datapropKeyStr+" as an integer hash in EditDataPropStmtRequestDispatchController");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
dps = EditConfigurationUtils.getDataPropertyStatement(vreq, session, dataHash, predicateUri);
|
dps = EditConfigurationUtils.getDataPropertyStatement(vreq, session, dataHash, predicateUri);
|
||||||
}
|
}
|
||||||
|
@ -135,7 +129,7 @@ public class DefaultDeleteGenerator implements EditConfigurationGenerator {
|
||||||
|
|
||||||
private void processDataPropForm(VitroRequest vreq, EditConfigurationVTwo editConfiguration) {
|
private void processDataPropForm(VitroRequest vreq, EditConfigurationVTwo editConfiguration) {
|
||||||
//set data prop value, data prop key str,
|
//set data prop value, data prop key str,
|
||||||
editConfiguration.setDatapropKey((datapropKeyStr==null)?"":datapropKeyStr);
|
editConfiguration.setDatapropKey( EditConfigurationUtils.getDataHash(vreq) );
|
||||||
//original set datapropValue, which in this case would be empty string but no way here
|
//original set datapropValue, which in this case would be empty string but no way here
|
||||||
editConfiguration.setDatapropValue("");
|
editConfiguration.setDatapropValue("");
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene
|
||||||
private String objectUri = null;
|
private String objectUri = null;
|
||||||
private String datapropKeyStr= null;
|
private String datapropKeyStr= null;
|
||||||
private int dataHash = 0;
|
private int dataHash = 0;
|
||||||
private DataPropertyStatement dps = null;
|
|
||||||
private String dataLiteral = null;
|
private String dataLiteral = null;
|
||||||
private String objectPropertyTemplate = "defaultPropertyForm.ftl";
|
private String objectPropertyTemplate = "defaultPropertyForm.ftl";
|
||||||
private String dataPropertyTemplate = "defaultDataPropertyForm.ftl";
|
private String dataPropertyTemplate = "defaultDataPropertyForm.ftl";
|
||||||
|
@ -161,25 +161,9 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene
|
||||||
this.processObjectPropForm(vreq, editConfiguration);
|
this.processObjectPropForm(vreq, editConfiguration);
|
||||||
} else {
|
} else {
|
||||||
this.isObjectPropForm = false;
|
this.isObjectPropForm = false;
|
||||||
this.initDataParameters(vreq, session);
|
|
||||||
this.processDataPropForm(vreq, editConfiguration);
|
this.processDataPropForm(vreq, editConfiguration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initDataParameters(VitroRequest vreq, HttpSession session) {
|
|
||||||
dataLiteral = getDataLiteral(vreq);
|
|
||||||
datapropKeyStr = EditConfigurationUtils.getDataPropKey(vreq);
|
|
||||||
if( datapropKeyStr != null ){
|
|
||||||
try {
|
|
||||||
dataHash = Integer.parseInt(datapropKeyStr);
|
|
||||||
log.debug("Found a datapropKey in parameters and parsed it to int: " + dataHash);
|
|
||||||
} catch (NumberFormatException ex) {
|
|
||||||
//return doHelp(vreq, "Cannot decode incoming datapropKey value "+datapropKeyStr+" as an integer hash in EditDataPropStmtRequestDispatchController");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dps = EditConfigurationUtils.getDataPropertyStatement(vreq, session, dataHash, predicateUri);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void initObjectParameters(VitroRequest vreq) {
|
private void initObjectParameters(VitroRequest vreq) {
|
||||||
|
@ -450,15 +434,7 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene
|
||||||
editConfiguration.prepareForNonUpdate( model );
|
editConfiguration.prepareForNonUpdate( model );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//TODO: why is this checking for data prop keys?
|
throw new Error("DefaultObjectPropertyForm does not handle data properties.");
|
||||||
if(datapropKeyStr != null && datapropKeyStr.trim().length() > 0 ) {
|
|
||||||
DataPropertyStatement dps = EditConfigurationUtils.getDataPropertyStatement(vreq,
|
|
||||||
session,
|
|
||||||
dataHash,
|
|
||||||
EditConfigurationUtils.getPredicateUri(vreq));
|
|
||||||
|
|
||||||
editConfiguration.prepareForDataPropUpdate(model, dps);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.SelectListGeneratorVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.SelectListGeneratorVTwo;
|
||||||
|
@ -175,9 +176,8 @@ public class MenuEditingFormGenerator implements EditConfigurationGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processDataPropForm(VitroRequest vreq, EditConfigurationVTwo editConfiguration) {
|
private void processDataPropForm(VitroRequest vreq, EditConfigurationVTwo editConfiguration) {
|
||||||
String datapropKeyStr = vreq.getParameter("datapropKey");
|
Integer dataHash = EditConfigurationUtils.getDataHash(vreq);
|
||||||
int dataHash=0;
|
DataPropertyStatement dps = (DataPropertyStatement)vreq.getAttribute("dataprop");
|
||||||
DataPropertyStatement dps = (DataPropertyStatement)vreq.getAttribute("dataprop");
|
|
||||||
|
|
||||||
//ObjectUriJson is null, so should include data prop info here
|
//ObjectUriJson is null, so should include data prop info here
|
||||||
//Use dataprop key info here instead
|
//Use dataprop key info here instead
|
||||||
|
@ -194,14 +194,8 @@ public class MenuEditingFormGenerator implements EditConfigurationGenerator {
|
||||||
vreq.setAttribute("rangeDatatypeUriJson", MiscWebUtils.escape(rangeDatatypeUri));
|
vreq.setAttribute("rangeDatatypeUriJson", MiscWebUtils.escape(rangeDatatypeUri));
|
||||||
|
|
||||||
|
|
||||||
if( dps != null ){
|
if( dps != null ){
|
||||||
try {
|
log.debug("dataHash is " + dataHash);
|
||||||
dataHash = Integer.parseInt(datapropKeyStr);
|
|
||||||
log.debug("dataHash is " + dataHash);
|
|
||||||
} catch (NumberFormatException ex) {
|
|
||||||
log.debug("could not parse dataprop hash "+
|
|
||||||
"but there was a dataproperty; hash: '"+datapropKeyStr+"'");
|
|
||||||
}
|
|
||||||
|
|
||||||
String rangeDatatype = dps.getDatatypeURI();
|
String rangeDatatype = dps.getDatatypeURI();
|
||||||
if( rangeDatatype == null ){
|
if( rangeDatatype == null ){
|
||||||
|
@ -229,7 +223,7 @@ public class MenuEditingFormGenerator implements EditConfigurationGenerator {
|
||||||
vreq.setAttribute("rangeDefaultJson", '"' + MiscWebUtils.escape(defaultVal) + '"' );
|
vreq.setAttribute("rangeDefaultJson", '"' + MiscWebUtils.escape(defaultVal) + '"' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
editConfiguration.setDatapropKey((datapropKeyStr==null)?"":datapropKeyStr);
|
editConfiguration.setDatapropKey(dataHash);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -145,25 +145,13 @@ public class RDFSLabelGenerator implements EditConfigurationGenerator {
|
||||||
|
|
||||||
|
|
||||||
private void initDataParameters(VitroRequest vreq, HttpSession session) {
|
private void initDataParameters(VitroRequest vreq, HttpSession session) {
|
||||||
datapropKeyStr = EditConfigurationUtils.getDataPropKey(vreq);
|
dataHash = EditConfigurationUtils.getDataHash(vreq);
|
||||||
if( datapropKeyStr != null ){
|
|
||||||
try {
|
|
||||||
dataHash = Integer.parseInt(datapropKeyStr);
|
|
||||||
log.debug("Found a datapropKey in parameters and parsed it to int: " + dataHash);
|
|
||||||
} catch (NumberFormatException ex) {
|
|
||||||
//return doHelp(vreq, "Cannot decode incoming datapropKey value "+datapropKeyStr+" as an integer hash in EditDataPropStmtRequestDispatchController");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dps = EditConfigurationUtils.getDataPropertyStatement(vreq, session, dataHash, predicateUri);
|
dps = EditConfigurationUtils.getDataPropertyStatement(vreq, session, dataHash, predicateUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void processDataPropForm(VitroRequest vreq, EditConfigurationVTwo editConfiguration) {
|
private void processDataPropForm(VitroRequest vreq, EditConfigurationVTwo editConfiguration) {
|
||||||
//set data prop value, data prop key str,
|
//set data prop value, data prop key str,
|
||||||
editConfiguration.setDatapropKey((datapropKeyStr==null)?"":datapropKeyStr);
|
editConfiguration.setDatapropKey( EditConfigurationUtils.getDataHash(vreq) );
|
||||||
editConfiguration.setVarNameForObject(literalName);
|
editConfiguration.setVarNameForObject(literalName);
|
||||||
|
|
||||||
//original set datapropValue, which in this case would be empty string but no way here
|
//original set datapropValue, which in this case would be empty string but no way here
|
||||||
|
@ -346,7 +334,7 @@ public class RDFSLabelGenerator implements EditConfigurationGenerator {
|
||||||
//Here, retrieve model from
|
//Here, retrieve model from
|
||||||
Model model = (Model) session.getServletContext().getAttribute("jenaOntModel");
|
Model model = (Model) session.getServletContext().getAttribute("jenaOntModel");
|
||||||
if(datapropKeyStr != null && datapropKeyStr.trim().length() > 0 ) {
|
if(datapropKeyStr != null && datapropKeyStr.trim().length() > 0 ) {
|
||||||
editConfiguration.prepareForDataPropUpdate(model, dps);
|
editConfiguration.prepareForDataPropUpdate(model, vreq.getWebappDaoFactory().getDataPropertyDao());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
@ -78,7 +79,7 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
/**** make new or get an existing edit configuration ***/
|
/**** make new or get an existing edit configuration ***/
|
||||||
EditConfigurationVTwo editConfig = setupEditConfiguration(editConfGeneratorName, vreq);
|
EditConfigurationVTwo editConfig = setupEditConfiguration(editConfGeneratorName, vreq);
|
||||||
|
log.debug("editConfiguration:\n" + editConfig );
|
||||||
|
|
||||||
//what template?
|
//what template?
|
||||||
String template = editConfig.getTemplate();
|
String template = editConfig.getTemplate();
|
||||||
|
@ -139,14 +140,15 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
|
||||||
editConfig.setPredicateUri( EditConfigurationUtils.getPredicateUri(vreq));
|
editConfig.setPredicateUri( EditConfigurationUtils.getPredicateUri(vreq));
|
||||||
|
|
||||||
String objectUri = EditConfigurationUtils.getObjectUri(vreq);
|
String objectUri = EditConfigurationUtils.getObjectUri(vreq);
|
||||||
String dataKey = EditConfigurationUtils.getDataPropKey(vreq);
|
Integer dataKey = EditConfigurationUtils.getDataHash(vreq);
|
||||||
if (objectUri != null && ! objectUri.trim().isEmpty()) {
|
if (objectUri != null && ! objectUri.trim().isEmpty()) {
|
||||||
// editing existing object
|
// editing existing object
|
||||||
if( editConfig.getObject() == null)
|
if( editConfig.getObject() == null)
|
||||||
editConfig.setObject( EditConfigurationUtils.getObjectUri(vreq));
|
editConfig.setObject( EditConfigurationUtils.getObjectUri(vreq));
|
||||||
editConfig.prepareForObjPropUpdate(model);
|
editConfig.prepareForObjPropUpdate(model);
|
||||||
} else if( dataKey != null ) { // edit of a data prop
|
} else if( dataKey != null ) { // edit of a data prop statement
|
||||||
//do nothing since the data prop form generator must take care of it
|
//do nothing since the data prop form generator must take care of it
|
||||||
|
editConfig.prepareForDataPropUpdate(model, vreq.getWebappDaoFactory().getDataPropertyDao());
|
||||||
} else{
|
} else{
|
||||||
//this might be a create new or a form
|
//this might be a create new or a form
|
||||||
editConfig.prepareForNonUpdate(model);
|
editConfig.prepareForNonUpdate(model);
|
||||||
|
@ -168,37 +170,43 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
|
||||||
//e.g. default add individual form etc. and additional scenarios
|
//e.g. default add individual form etc. and additional scenarios
|
||||||
//TODO: Check if additional scenarios should be checked here
|
//TODO: Check if additional scenarios should be checked here
|
||||||
private String processEditConfGeneratorName(VitroRequest vreq) {
|
private String processEditConfGeneratorName(VitroRequest vreq) {
|
||||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
|
||||||
//use default object property form if nothing else works
|
//use default object property form if nothing else works
|
||||||
String editConfGeneratorName = DEFAULT_OBJ_FORM;
|
String editConfGeneratorName = DEFAULT_OBJ_FORM;
|
||||||
String predicateUri = getPredicateUri(vreq);
|
|
||||||
String formParam = getFormParam(vreq);
|
//Handle deletion before any of the other cases
|
||||||
//Handle deletion before any of the other cases
|
|
||||||
if(isDeleteForm(vreq)) {
|
if(isDeleteForm(vreq)) {
|
||||||
editConfGeneratorName = DEFAULT_DELETE_FORM;
|
return DEFAULT_DELETE_FORM;
|
||||||
}
|
}
|
||||||
|
|
||||||
// *** handle the case where the form is specified as a request parameter ***
|
// *** handle the case where the form is specified as a request parameter ***
|
||||||
//TODO: Substitute the original line in again which checks for null predicate, currently overriding
|
String formParam = getFormParam(vreq);
|
||||||
//in order to test
|
if( formParam != null && !formParam.isEmpty() ){
|
||||||
//else if( predicateUri == null && ( formParam != null && !formParam.isEmpty()) ){
|
|
||||||
else if( formParam != null && !formParam.isEmpty() ){
|
|
||||||
//form parameter must be a fully qualified java class name of a EditConfigurationVTwoGenerator implementation.
|
//form parameter must be a fully qualified java class name of a EditConfigurationVTwoGenerator implementation.
|
||||||
editConfGeneratorName = formParam;
|
return formParam;
|
||||||
} else if(isVitroLabel(predicateUri)) { //in case of data property
|
}
|
||||||
editConfGeneratorName = RDFS_LABEL_FORM;
|
|
||||||
|
String predicateUri = getPredicateUri(vreq);
|
||||||
|
if( isVitroLabel(predicateUri) ) { //in case of data property
|
||||||
|
return RDFS_LABEL_FORM;
|
||||||
|
}
|
||||||
|
|
||||||
|
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||||
|
Property prop = getPropertyByUri(predicateUri, wdf);
|
||||||
|
|
||||||
|
if(isDataProperty( prop , wdf )){
|
||||||
|
editConfGeneratorName = DEFAULT_DATA_FORM;
|
||||||
} else{
|
} else{
|
||||||
String customForm = getCustomForm(predicateUri, wdf);
|
String customForm = prop.getCustomEntryForm();
|
||||||
if(customForm != null && !customForm.isEmpty()) {
|
if(customForm != null && !customForm.trim().isEmpty()) {
|
||||||
editConfGeneratorName = customForm;
|
editConfGeneratorName = customForm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.debug("generator name is " + editConfGeneratorName);
|
||||||
return editConfGeneratorName;
|
return editConfGeneratorName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private String getCustomForm(String predicateUri, WebappDaoFactory wdf) {
|
private String getCustomForm(String predicateUri, WebappDaoFactory wdf) {
|
||||||
Property prop = getPropertyByUri(predicateUri, wdf);
|
Property prop = getPropertyByUri(predicateUri, wdf);
|
||||||
return prop.getCustomEntryForm();
|
return prop.getCustomEntryForm();
|
||||||
}
|
}
|
||||||
|
@ -212,11 +220,22 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean isVitroLabel(String predicateUri) {
|
private boolean isVitroLabel(String predicateUri) {
|
||||||
return predicateUri.equals(VitroVocabulary.LABEL);
|
return predicateUri.equals(VitroVocabulary.LABEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isDataProperty(Property prop, WebappDaoFactory wdf) {
|
||||||
|
if( prop != null && prop instanceof DataProperty ){
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
DataProperty dataProp = wdf.getDataPropertyDao().getDataPropertyByURI(prop.getURI());
|
||||||
|
if( dataProp != null )
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//if skip edit form
|
//if skip edit form
|
||||||
private boolean isSkipEditForm(VitroRequest vreq) {
|
private boolean isSkipEditForm(VitroRequest vreq) {
|
||||||
|
|
|
@ -131,17 +131,18 @@ public class ProcessRdfFormController extends FreemarkerHttpServlet{
|
||||||
if(EditConfigurationUtils.isObjectProperty(editConfig.getPredicateUri(), vreq)) {
|
if(EditConfigurationUtils.isObjectProperty(editConfig.getPredicateUri(), vreq)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Individual subject = EditConfigurationUtils.getSubjectIndividual(vreq);
|
|
||||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||||
if (editConfig.getDatapropKey() == null
|
if ( ! editConfig.isDataPropertyUpdate())
|
||||||
|| editConfig.getDatapropKey().length() == 0)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
int dpropHash = Integer.parseInt(editConfig.getDatapropKey());
|
Integer dpropHash = editConfig.getDatapropKey();
|
||||||
DataPropertyStatement dps = RdfLiteralHash.getPropertyStmtByHash(subject, editConfig.getPredicateUri(), dpropHash, model);
|
DataPropertyStatement dps =
|
||||||
|
RdfLiteralHash.getPropertyStmtByHash(editConfig.getSubjectUri(),
|
||||||
|
editConfig.getPredicateUri(), dpropHash, model);
|
||||||
if (dps != null)
|
if (dps != null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
DataProperty dp = wdf.getDataPropertyDao().getDataPropertyByURI(
|
DataProperty dp = wdf.getDataPropertyDao().getDataPropertyByURI(
|
||||||
editConfig.getPredicateUri());
|
editConfig.getPredicateUri());
|
||||||
if (dp != null) {
|
if (dp != null) {
|
||||||
|
|
|
@ -78,69 +78,131 @@ public class RdfLiteralHash {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forward to either getDataPropertyStmtByHash or getRdfsLabelStatementByHash, depending on the property.
|
* Forward to either getDataPropertyStmtByHash or getRdfsLabelStatementByHash, depending on the property.
|
||||||
* @param ind
|
* @param subjectUri,
|
||||||
|
* @param predicateUri,
|
||||||
* @param hash
|
* @param hash
|
||||||
* @param model
|
* @param model, may not be null
|
||||||
* @return a DataPropertyStatement if found or null if not found
|
* @return a DataPropertyStatement if found or null if not found
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static DataPropertyStatement getPropertyStmtByHash(Individual ind, String predicateUri, int hash, Model model) {
|
public static DataPropertyStatement getPropertyStmtByHash(String subjectUri, String predicateUri, int hash, Model model) {
|
||||||
|
if (subjectUri == null || predicateUri == null ) return null;
|
||||||
|
|
||||||
if (ind == null) return null;
|
model.enterCriticalSection(false);
|
||||||
|
StmtIterator stmts = model.listStatements(model.createResource(subjectUri),
|
||||||
// RY Instead of a code fork here, we should have a method of Individual getAllDataPropertyStatements() which
|
|
||||||
// doesn't filter out rdfs:label.
|
|
||||||
DataPropertyStatement dps = predicateUri.equals(VitroVocabulary.LABEL)
|
|
||||||
? getRdfsLabelStatementByHash(ind, model, hash)
|
|
||||||
: getDataPropertyStmtByHash(ind, hash);
|
|
||||||
|
|
||||||
return dps;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static DataPropertyStatement getDataPropertyStmtByHash( Individual ind, int hash){
|
|
||||||
|
|
||||||
List<DataPropertyStatement> statements = ind.getDataPropertyStatements();
|
|
||||||
if( statements == null ) return null;
|
|
||||||
for( DataPropertyStatement dps : statements){
|
|
||||||
if( doesStmtMatchHash(dps, hash) )
|
|
||||||
return dps;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param ind, may be null
|
|
||||||
* @param hash
|
|
||||||
* @return a DataPropertyStatement if found or null if not found
|
|
||||||
*/
|
|
||||||
public static DataPropertyStatement getRdfsLabelStatementByHash(Individual ind, Model model, int hash) {
|
|
||||||
|
|
||||||
String predicateUri = VitroVocabulary.LABEL;
|
|
||||||
|
|
||||||
DataPropertyStatement dps = null;
|
|
||||||
StmtIterator stmts = model.listStatements(model.createResource(ind.getURI()),
|
|
||||||
model.getProperty(predicateUri),
|
model.getProperty(predicateUri),
|
||||||
(RDFNode)null);
|
(RDFNode)null);
|
||||||
try {
|
try {
|
||||||
while (stmts.hasNext()) {
|
while (stmts.hasNext()) {
|
||||||
Statement stmt = stmts.nextStatement();
|
Statement stmt = stmts.nextStatement();
|
||||||
RDFNode node = stmt.getObject();
|
RDFNode node = stmt.getObject();
|
||||||
if ( node.isLiteral() ){
|
if ( node.isLiteral() ){
|
||||||
dps = makeDataPropertyStatementFromStatement(stmt, node);
|
DataPropertyStatement dps =
|
||||||
|
makeDataPropertyStatementFromStatement(stmt, node);
|
||||||
if (doesStmtMatchHash(dps, hash)) {
|
if (doesStmtMatchHash(dps, hash)) {
|
||||||
return dps;
|
return dps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//} catch {
|
|
||||||
|
|
||||||
} finally{
|
|
||||||
stmts.close();
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
} finally {
|
||||||
|
stmts.close();
|
||||||
|
model.leaveCriticalSection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Get data property for subject, predicate and hash. This does not use
|
||||||
|
// * filtering DAOs to avoid the problems when attempting to edit predicates that
|
||||||
|
// * are filtered out.
|
||||||
|
// *
|
||||||
|
// * @param ind, may be null
|
||||||
|
// * @param hash
|
||||||
|
// * @return a DataPropertyStatement if found or null if not found
|
||||||
|
// */
|
||||||
|
// protected static DataPropertyStatement getStatementByHash(String subjectUri, Model model, int hash) {
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// DataPropertyStatement dps = null;
|
||||||
|
//
|
||||||
|
// // Not using getAllDataPropertyStatements() because it filters out rdfs:labels
|
||||||
|
////
|
||||||
|
//// List<DataPropertyStatement> statements = ind.getDataPropertyStatements();
|
||||||
|
//// if( statements == null ) return null;
|
||||||
|
//// for( DataPropertyStatement dps : statements){
|
||||||
|
//// if( doesStmtMatchHash(dps, hash) )
|
||||||
|
//// return dps;
|
||||||
|
//// }
|
||||||
|
//// return null;
|
||||||
|
//
|
||||||
|
// StmtIterator stmts = model.listStatements(model.createResource(subjectUri),
|
||||||
|
// model.getProperty(predicateUri),
|
||||||
|
// (RDFNode)null);
|
||||||
|
// try {
|
||||||
|
// while (stmts.hasNext()) {
|
||||||
|
// Statement stmt = stmts.nextStatement();
|
||||||
|
// RDFNode node = stmt.getObject();
|
||||||
|
// if ( node.isLiteral() ){
|
||||||
|
// dps = makeDataPropertyStatementFromStatement(stmt, node);
|
||||||
|
// if (doesStmtMatchHash(dps, hash)) {
|
||||||
|
// return dps;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// //} catch {
|
||||||
|
//
|
||||||
|
// } finally{
|
||||||
|
// stmts.close();
|
||||||
|
// }
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get data property for subject, predicate and hash. This does not use
|
||||||
|
* filtering DAOs to avoid the problems when attempting to edit predicates that
|
||||||
|
* are filtered out.
|
||||||
|
*
|
||||||
|
* @param ind, may be null
|
||||||
|
* @param hash
|
||||||
|
* @return a DataPropertyStatement if found or null if not found
|
||||||
|
*/
|
||||||
|
// protected static DataPropertyStatement getStatementByHash(String subjectUri, String predicateUri, Model model, int hash) {
|
||||||
|
// // Not using getAllDataPropertyStatements() because it filters out rdfs:labels
|
||||||
|
////
|
||||||
|
//// List<DataPropertyStatement> statements = ind.getDataPropertyStatements();
|
||||||
|
//// if( statements == null ) return null;
|
||||||
|
//// for( DataPropertyStatement dps : statements){
|
||||||
|
//// if( doesStmtMatchHash(dps, hash) )
|
||||||
|
//// return dps;
|
||||||
|
//// }
|
||||||
|
//// return null;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// model.enterCriticalSection(false);
|
||||||
|
// StmtIterator stmts = model.listStatements(model.createResource(subjectUri),
|
||||||
|
// model.getProperty(predicateUri),
|
||||||
|
// (RDFNode)null);
|
||||||
|
// try {
|
||||||
|
// while (stmts.hasNext()) {
|
||||||
|
// Statement stmt = stmts.nextStatement();
|
||||||
|
// RDFNode node = stmt.getObject();
|
||||||
|
// if ( node.isLiteral() ){
|
||||||
|
// DataPropertyStatement dps =
|
||||||
|
// makeDataPropertyStatementFromStatement(stmt, node);
|
||||||
|
// if (doesStmtMatchHash(dps, hash)) {
|
||||||
|
// return dps;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return null;
|
||||||
|
// } finally {
|
||||||
|
// stmts.close();
|
||||||
|
// model.leaveCriticalSection();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
public static int makeRdfsLabelLiteralHash( Individual subject, String value, Model model) {
|
public static int makeRdfsLabelLiteralHash( Individual subject, String value, Model model) {
|
||||||
|
|
||||||
|
|
|
@ -160,17 +160,15 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDataFormTitle() {
|
private void setDataFormTitle() {
|
||||||
String formTitle = "";
|
String formTitle = "";
|
||||||
String datapropKeyStr = editConfig.getDatapropKey();
|
DataProperty prop = EditConfigurationUtils.getDataProperty(vreq);
|
||||||
DataProperty prop = EditConfigurationUtils.getDataProperty(vreq);
|
if(prop != null) {
|
||||||
if(prop != null) {
|
if( editConfig.isDataPropertyUpdate() ) {
|
||||||
if( datapropKeyStr != null && datapropKeyStr.trim().length() > 0 ) {
|
formTitle = "Change text for: <em>"+prop.getPublicName()+"</em>";
|
||||||
formTitle = "Change text for: <em>"+prop.getPublicName()+"</em>";
|
} else {
|
||||||
|
formTitle ="Add new entry for: <em>"+prop.getPublicName()+"</em>";
|
||||||
} else {
|
}
|
||||||
formTitle ="Add new entry for: <em>"+prop.getPublicName()+"</em>";
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
pageData.put("formTitle", formTitle);
|
pageData.put("formTitle", formTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -578,7 +576,10 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDatapropKey() {
|
public String getDatapropKey() {
|
||||||
return editConfig.getDatapropKey();
|
if( editConfig.getDatapropKey() == null )
|
||||||
|
return null;
|
||||||
|
else
|
||||||
|
return editConfig.getDatapropKey().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataPropertyStatement getDataPropertyStatement() {
|
public DataPropertyStatement getDataPropertyStatement() {
|
||||||
|
@ -592,14 +593,12 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
|
||||||
|
|
||||||
//Check whether deletion form should be included for default object property
|
//Check whether deletion form should be included for default object property
|
||||||
public boolean getIncludeDeletionForm() {
|
public boolean getIncludeDeletionForm() {
|
||||||
if(isDeleteProhibited())
|
if( isDeleteProhibited() )
|
||||||
return false;
|
return false;
|
||||||
if(isObjectProperty()) {
|
if( isObjectProperty() ) {
|
||||||
return (getObjectUri() != null && !getObjectUri().isEmpty());
|
return editConfig.isObjectPropertyUpdate();
|
||||||
}
|
} else {
|
||||||
else {
|
return editConfig.isDataPropertyUpdate();
|
||||||
String datapropKey = editConfig.getDatapropKey();
|
|
||||||
return (datapropKey != null && !datapropKey.isEmpty());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -125,95 +127,95 @@ public class RdfLiteralHashTest {
|
||||||
Assert.assertTrue( ! RdfLiteralHash.doesStmtMatchHash(null, expectedHash) );
|
Assert.assertTrue( ! RdfLiteralHash.doesStmtMatchHash(null, expectedHash) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void testGetDataPropertyStmtByHash() {
|
// public void testGetDataPropertyStmtByHash() {
|
||||||
DataPropertyStatement stmtA = new DataPropertyStatementImpl();
|
// DataPropertyStatement stmtA = new DataPropertyStatementImpl();
|
||||||
IndividualImpl ind = new IndividualImpl();
|
// IndividualImpl ind = new IndividualImpl();
|
||||||
List<DataPropertyStatement> stmts = new ArrayList<DataPropertyStatement>();
|
// List<DataPropertyStatement> stmts = new ArrayList<DataPropertyStatement>();
|
||||||
|
//
|
||||||
int expectedHash = 0;
|
// int expectedHash = 0;
|
||||||
|
//
|
||||||
//test to see if the same subURI, predURI and Value can be distinguished by LANG/datatype
|
// //test to see if the same subURI, predURI and Value can be distinguished by LANG/datatype
|
||||||
stmtA.setData(TEST_VALUE);
|
// stmtA.setData(TEST_VALUE);
|
||||||
stmtA.setDatapropURI(TEST_DATA_PROP_URI);
|
// stmtA.setDatapropURI(TEST_DATA_PROP_URI);
|
||||||
stmtA.setIndividualURI(TEST_INDIVIDUAL_URI);
|
// stmtA.setIndividualURI(TEST_INDIVIDUAL_URI);
|
||||||
stmts.add(stmtA);
|
// stmts.add(stmtA);
|
||||||
int expectedHashForSimpleStmt = RdfLiteralHash.makeRdfLiteralHash(stmtA);
|
// int expectedHashForSimpleStmt = RdfLiteralHash.makeRdfLiteralHash(stmtA);
|
||||||
|
//
|
||||||
stmtA = new DataPropertyStatementImpl();
|
// stmtA = new DataPropertyStatementImpl();
|
||||||
stmtA.setData(TEST_VALUE );
|
// stmtA.setData(TEST_VALUE );
|
||||||
stmtA.setDatapropURI(TEST_DATA_PROP_URI);
|
// stmtA.setDatapropURI(TEST_DATA_PROP_URI);
|
||||||
stmtA.setIndividualURI(TEST_INDIVIDUAL_URI);
|
// stmtA.setIndividualURI(TEST_INDIVIDUAL_URI);
|
||||||
stmtA.setDatatypeURI(TEST_DATA_TYPE_URI);
|
// stmtA.setDatatypeURI(TEST_DATA_TYPE_URI);
|
||||||
int expectedHashForDatatypeStmt = RdfLiteralHash.makeRdfLiteralHash(stmtA);
|
// int expectedHashForDatatypeStmt = RdfLiteralHash.makeRdfLiteralHash(stmtA);
|
||||||
stmts.add(stmtA);
|
// stmts.add(stmtA);
|
||||||
|
//
|
||||||
stmtA = new DataPropertyStatementImpl();
|
// stmtA = new DataPropertyStatementImpl();
|
||||||
stmtA.setData(TEST_VALUE );
|
// stmtA.setData(TEST_VALUE );
|
||||||
stmtA.setDatapropURI(TEST_DATA_PROP_URI);
|
// stmtA.setDatapropURI(TEST_DATA_PROP_URI);
|
||||||
stmtA.setIndividualURI(TEST_INDIVIDUAL_URI);
|
// stmtA.setIndividualURI(TEST_INDIVIDUAL_URI);
|
||||||
stmtA.setLanguage(TEST_LANG);
|
// stmtA.setLanguage(TEST_LANG);
|
||||||
int expectedHashForLangStmt = RdfLiteralHash.makeRdfLiteralHash(stmtA);
|
// int expectedHashForLangStmt = RdfLiteralHash.makeRdfLiteralHash(stmtA);
|
||||||
stmts.add(stmtA);
|
// stmts.add(stmtA);
|
||||||
|
//
|
||||||
ind.setDataPropertyStatements(stmts);
|
// ind.setDataPropertyStatements(stmts);
|
||||||
|
//
|
||||||
DataPropertyStatement stmt = RdfLiteralHash.getDataPropertyStmtByHash(ind, expectedHashForLangStmt);
|
// DataPropertyStatement stmt = RdfLiteralHash.getDataPropertyStmtByHash(ind, expectedHashForLangStmt);
|
||||||
Assert.assertNotNull(stmt);
|
// Assert.assertNotNull(stmt);
|
||||||
Assert.assertEquals(TEST_DATA_PROP_URI, stmt.getDatapropURI() );
|
// Assert.assertEquals(TEST_DATA_PROP_URI, stmt.getDatapropURI() );
|
||||||
Assert.assertEquals(TEST_INDIVIDUAL_URI, stmt.getIndividualURI() );
|
// Assert.assertEquals(TEST_INDIVIDUAL_URI, stmt.getIndividualURI() );
|
||||||
Assert.assertEquals(TEST_LANG, stmt.getLanguage() );
|
// Assert.assertEquals(TEST_LANG, stmt.getLanguage() );
|
||||||
Assert.assertEquals(TEST_VALUE, stmt.getData() );
|
// Assert.assertEquals(TEST_VALUE, stmt.getData() );
|
||||||
Assert.assertNull(stmt.getDatatypeURI());
|
// Assert.assertNull(stmt.getDatatypeURI());
|
||||||
|
//
|
||||||
stmt = RdfLiteralHash.getDataPropertyStmtByHash(ind, expectedHashForSimpleStmt);
|
// stmt = RdfLiteralHash.getDataPropertyStmtByHash(ind.getURI(), expectedHashForSimpleStmt);
|
||||||
Assert.assertNotNull(stmt);
|
// Assert.assertNotNull(stmt);
|
||||||
Assert.assertEquals(TEST_DATA_PROP_URI, stmt.getDatapropURI() );
|
// Assert.assertEquals(TEST_DATA_PROP_URI, stmt.getDatapropURI() );
|
||||||
Assert.assertEquals(TEST_INDIVIDUAL_URI, stmt.getIndividualURI() );
|
// Assert.assertEquals(TEST_INDIVIDUAL_URI, stmt.getIndividualURI() );
|
||||||
Assert.assertEquals(TEST_VALUE, stmt.getData() );
|
// Assert.assertEquals(TEST_VALUE, stmt.getData() );
|
||||||
Assert.assertNull(stmt.getDatatypeURI());
|
// Assert.assertNull(stmt.getDatatypeURI());
|
||||||
Assert.assertNull(stmt.getLanguage());
|
// Assert.assertNull(stmt.getLanguage());
|
||||||
|
//
|
||||||
stmt = RdfLiteralHash.getDataPropertyStmtByHash(ind, expectedHashForDatatypeStmt);
|
// stmt = RdfLiteralHash.getDataPropertyStmtByHash(ind, expectedHashForDatatypeStmt);
|
||||||
Assert.assertNotNull(stmt);
|
// Assert.assertNotNull(stmt);
|
||||||
Assert.assertEquals(TEST_DATA_PROP_URI, stmt.getDatapropURI() );
|
// Assert.assertEquals(TEST_DATA_PROP_URI, stmt.getDatapropURI() );
|
||||||
Assert.assertEquals(TEST_INDIVIDUAL_URI, stmt.getIndividualURI() );
|
// Assert.assertEquals(TEST_INDIVIDUAL_URI, stmt.getIndividualURI() );
|
||||||
Assert.assertEquals(TEST_VALUE, stmt.getData() );
|
// Assert.assertEquals(TEST_VALUE, stmt.getData() );
|
||||||
Assert.assertEquals(TEST_DATA_TYPE_URI, stmt.getDatatypeURI() );
|
// Assert.assertEquals(TEST_DATA_TYPE_URI, stmt.getDatatypeURI() );
|
||||||
Assert.assertNull(stmt.getLanguage());
|
// Assert.assertNull(stmt.getLanguage());
|
||||||
|
//
|
||||||
|
//
|
||||||
stmt = RdfLiteralHash.getDataPropertyStmtByHash(ind, 111111);
|
// stmt = RdfLiteralHash.getDataPropertyStmtByHash(ind, 111111);
|
||||||
Assert.assertNull(stmt);
|
// Assert.assertNull(stmt);
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void testGetRdfsLabelStatementByHash(){
|
// public void testGetRdfsLabelStatementByHash(){
|
||||||
|
//
|
||||||
String n3 =
|
// String n3 =
|
||||||
"@prefix ex: <http://example.com/> . \n" +
|
// "@prefix ex: <http://example.com/> . \n" +
|
||||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
// "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n"+
|
// "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n"+
|
||||||
" ex:bob rdfs:label \"Smith, Bob\"^^<"+XSD.xstring.getURI()+"> ." ;
|
// " ex:bob rdfs:label \"Smith, Bob\"^^<"+XSD.xstring.getURI()+"> ." ;
|
||||||
|
//
|
||||||
Model model = (ModelFactory.createDefaultModel()).read(new StringReader(n3), "", "N3");
|
// Model model = (ModelFactory.createDefaultModel()).read(new StringReader(n3), "", "N3");
|
||||||
|
//
|
||||||
Individual bob = new IndividualImpl();
|
// Individual bob = new IndividualImpl();
|
||||||
bob.setURI("http://example.com/bob");
|
// bob.setURI("http://example.com/bob");
|
||||||
|
//
|
||||||
int hash = RdfLiteralHash.makeRdfsLabelLiteralHash(bob, "Smith, Bob", model);
|
// int hash = RdfLiteralHash.makeRdfsLabelLiteralHash(bob, "Smith, Bob", model);
|
||||||
DataPropertyStatement stmt = RdfLiteralHash.getRdfsLabelStatementByHash(bob, model, hash);
|
// DataPropertyStatement stmt = RdfLiteralHash.getRdfsLabelStatementByHash(bob.getURI(), model, hash);
|
||||||
|
//
|
||||||
String data = stmt.getData();
|
// String data = stmt.getData();
|
||||||
String datatypeUri = stmt.getDatatypeURI();
|
// String datatypeUri = stmt.getDatatypeURI();
|
||||||
String predicateUri = stmt.getDatapropURI();
|
// String predicateUri = stmt.getDatapropURI();
|
||||||
String subjectUri = stmt.getIndividualURI();
|
// String subjectUri = stmt.getIndividualURI();
|
||||||
|
//
|
||||||
Assert.assertEquals("Smith, Bob", data);
|
// Assert.assertEquals("Smith, Bob", data);
|
||||||
Assert.assertEquals(XSD.xstring.getURI(), datatypeUri);
|
// Assert.assertEquals(XSD.xstring.getURI(), datatypeUri);
|
||||||
Assert.assertEquals(VitroVocabulary.LABEL, predicateUri);
|
// Assert.assertEquals(VitroVocabulary.LABEL, predicateUri);
|
||||||
Assert.assertEquals("http://example.com/bob", subjectUri);
|
// Assert.assertEquals("http://example.com/bob", subjectUri);
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
}
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
||||||
|
|
||||||
|
<%@page import="java.util.Map"%>
|
||||||
|
<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.JspToGeneratorMapping"%>
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
|
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty" %>
|
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty" %>
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %>
|
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %>
|
||||||
|
@ -24,51 +26,7 @@ public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.
|
||||||
<vitro:confirmAuthorization />
|
<vitro:confirmAuthorization />
|
||||||
|
|
||||||
<%
|
<%
|
||||||
HashMap<String,String> jspFormToGenerator = new HashMap<String,String>();
|
Map<String,String> jspFormToGenerator = JspToGeneratorMapping.jspsToGenerators;
|
||||||
HashMap<String,String> map = jspFormToGenerator;
|
|
||||||
//vitro forms:
|
|
||||||
map.put("autoCompleteDatapropForm.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AutoCompleteDatapropFormGenerator");
|
|
||||||
map.put("autoCompleteObjPropForm.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AutoCompleteObjPropFormGenerator");
|
|
||||||
map.put("datapropStmtDelete.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultDeleteGenerator");
|
|
||||||
map.put("dateTimeIntervalForm.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DateTimeIntervalFormGenerator");
|
|
||||||
map.put("dateTimeValueForm.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DateTimeValueFormGenerator");
|
|
||||||
map.put("defaultAddMissingIndividualForm.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultAddMissingIndividualFormGenerator");
|
|
||||||
map.put("defaultDatapropForm.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultDataPropertyFormGenerator");
|
|
||||||
map.put("defaultObjPropForm.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultObjectPropertyFormGenerator");
|
|
||||||
map.put("newIndividualForm.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.NewIndividualFormGenerator");
|
|
||||||
map.put("propDelete.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultDeleteGenerator");
|
|
||||||
map.put("rdfsLabelForm.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.RdfsLabelGenerator");
|
|
||||||
|
|
||||||
//vivo forms:
|
|
||||||
|
|
||||||
map.put("addAuthorsToInformationResource.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddAuthorsToInformationResourceGenerator");
|
|
||||||
map.put("manageWebpagesForIndividual.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.ManageWebpagesForIndividualGenerator");
|
|
||||||
map.put("newIndividualForm.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.NewIndividualFormGenerator");
|
|
||||||
map.put("organizationHasPositionHistory.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.OrganizationHasPositionHistoryGenerator");
|
|
||||||
map.put("personHasEducationalTraining.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.PersonHasEducationalTraining");
|
|
||||||
map.put("personHasPositionHistory.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.PersonHasPositionHistoryGenerator");
|
|
||||||
map.put("redirectToPublication.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.RedirectToPublicationGenerator");
|
|
||||||
map.put("terminologyAnnotation.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.TerminologyAnnotationGenerator");
|
|
||||||
map.put("unsupportedBrowserMessage.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.UnsupportedBrowserMessage");
|
|
||||||
map.put("addGrantRoleToPerson.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddGrantRoleToPersonGenerator");
|
|
||||||
map.put("addEditWebpageForm.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddEditWebpageFormGenerator");
|
|
||||||
|
|
||||||
//vivo 2 stage role forms:
|
|
||||||
|
|
||||||
map.put("addAttendeeRoleToPerson.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddAttendeeRoleToPersonGenerator");
|
|
||||||
map.put("addClinicalRoleToPerson.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddClinicalRoleToPersonGenerator");
|
|
||||||
map.put("addEditorRoleToPerson.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddEditorRoleToPersonGenerator");
|
|
||||||
map.put("addHeadOfRoleToPerson.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddHeadOfRoleToPersonGenerator");
|
|
||||||
map.put("addMemberRoleToPerson.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddMemberRoleToPersonGenerator");
|
|
||||||
map.put("addOrganizerRoleToPerson.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddOrganizerRoleToPersonGenerator");
|
|
||||||
map.put("addOutreachRoleToPerson.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddOutreachRoleToPersonGenerator");
|
|
||||||
map.put("addPresenterRoleToPerson.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddPresenterRoleToPersonGenerator");
|
|
||||||
map.put("addPublicationToPerson.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddPublicationToPersonGenerator");
|
|
||||||
map.put("addResearcherRoleToPerson.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddResearcherRoleToPersonGenerator");
|
|
||||||
map.put("addReviewerRoleToPerson.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddReviewerRoleToPersonGenerator");
|
|
||||||
map.put("addRoleToPersonTwoStage.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddRoleToPersonTwoStageGenerator");
|
|
||||||
map.put("addServiceProviderRoleToPerson.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddServiceProviderRoleToPersonGenerator");
|
|
||||||
map.put("addTeacherRoleToPerson.jsp", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddTeacherRoleToPersonGenerator");
|
|
||||||
|
|
||||||
//Check if special model, in which case forward
|
//Check if special model, in which case forward
|
||||||
if(request.getParameter("switchToDisplayModel") != null) {
|
if(request.getParameter("switchToDisplayModel") != null) {
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
</#if>
|
</#if>
|
||||||
|
|
||||||
|
|
||||||
<textarea rows="2" id="${editConfiguration.dataLiteral}" name="${editConfiguration.dataLiteral}" value="${literalValues}" class="useTinyMce" role="textarea">${literalValues}</textarea>
|
<textarea rows="2" id="literal" name="literal" value="${literalValues}" class="useTinyMce" role="textarea">${literalValues}</textarea>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
<#--The submit label should be set within the template itself, right now
|
<#--The submit label should be set within the template itself, right now
|
||||||
|
|
Loading…
Add table
Reference in a new issue