From 221a38eca72d3a97d7ea852ede1d7c35ed7ef5a5 Mon Sep 17 00:00:00 2001 From: briancaruso Date: Tue, 15 Nov 2011 22:05:53 +0000 Subject: [PATCH] Working on default data process form --- .../VTwo/EditConfigurationUtils.java | 23 +-- .../n3editing/VTwo/EditConfigurationVTwo.java | 54 ++--- .../n3editing/VTwo/JspToGeneratorMapping.java | 59 ++++++ .../edit/n3editing/VTwo/N3EditUtils.java | 12 +- .../BaseEditConfigurationGenerator.java | 2 +- .../DefaultDataPropertyFormGenerator.java | 195 +++++++++--------- .../generators/DefaultDeleteGenerator.java | 18 +- .../DefaultObjectPropertyFormGenerator.java | 30 +-- .../generators/MenuEditingFormGenerator.java | 18 +- .../generators/RDFSLabelGenerator.java | 18 +- .../EditRequestDispatchController.java | 65 +++--- .../controller/ProcessRdfFormController.java | 13 +- .../n3editing/processEdit/RdfLiteralHash.java | 154 +++++++++----- .../edit/EditConfigurationTemplateModel.java | 37 ++-- .../{ => processEdit}/RdfLiteralHashTest.java | 184 +++++++++-------- webapp/web/edit/editRequestDispatch.jsp | 48 +---- .../edit/forms/defaultDataPropertyForm.ftl | 2 +- 17 files changed, 496 insertions(+), 436 deletions(-) create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/JspToGeneratorMapping.java rename webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/{ => processEdit}/RdfLiteralHashTest.java (55%) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationUtils.java index bd2f14c0c..a594136a9 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationUtils.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationUtils.java @@ -152,9 +152,10 @@ public class EditConfigurationUtils { return (dataProp != null); } - public static String getDataPropKey(VitroRequest vreq) { - return vreq.getParameter("datapropKey"); + protected static String getDataPropKey(VitroRequest vreq) { + return vreq.getParameter("datapropKey"); } + //is object property public static boolean isObjectProperty(String predicateUri, VitroRequest vreq) { if(predicateUri == null) { @@ -171,25 +172,21 @@ public class EditConfigurationUtils { 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; if( dataHash != 0) { Model model = (Model)session.getServletContext().getAttribute("jenaOntModel"); - dps = RdfLiteralHash.getPropertyStmtByHash(EditConfigurationUtils.getSubjectIndividual(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; - } - + dps = RdfLiteralHash.getPropertyStmtByHash(EditConfigurationUtils.getSubjectUri(vreq), predicateUri, dataHash, model); } return dps; } //TODO: Include get object property statement - public static int getDataHash(VitroRequest vreq) { - int dataHash = 0; + public static Integer getDataHash(VitroRequest vreq) { + Integer dataHash = null; String datapropKey = EditConfigurationUtils.getDataPropKey(vreq); if (datapropKey!=null && datapropKey.trim().length()>0) { try { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationVTwo.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationVTwo.java index 2e08d0bb5..d73c5969b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationVTwo.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationVTwo.java @@ -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.ResourceFactory; -import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; 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.StandardModelSelector; 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.generators.DefaultDataPropertyFormGenerator; 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.search.beans.ProhibitedFromSearch; @@ -98,7 +98,7 @@ public class EditConfigurationVTwo { String object; String varNameForObject; - String datapropKey; + Integer datapropKey=null; String datapropValue; @@ -299,29 +299,22 @@ public class EditConfigurationVTwo { + varNameForObject + " and object is " + object); } } - - //TODO: Check if require + /** - * Make a copy of this EditConfiguration, prepare for a DataProperty update - * and return it. - * - * 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. + * Prepare an EditConfiguration for a DataProperty update. + * This should only be used when editing a existing data property statement. */ - 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( isObjectResource() ){ throw new Error("This request does not seems to be a DataPropStmt update"); } 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(); - //TODO: Check if multiple statements might affect this implementation? - List dataPropLiterals = new ArrayList(); - dataPropLiterals.add(new EditLiteral(dpStmt.getData(),dpStmt.getDatatypeURI(), dpStmt.getLanguage())); - literalsInScope.put(varNameForObject, dataPropLiterals); + DefaultDataPropertyFormGenerator.prepareForDataPropUpdate(model, this,dataPropertyDao ); // run SPARQL, sub in values SparqlEvaluateVTwo sparqlEval = new SparqlEvaluateVTwo(model); @@ -332,13 +325,13 @@ public class EditConfigurationVTwo { } /** - * Make a copy of this EditConfiguration, prepare for a ObjectProperty update - * and return it. + * Prepare for a ObjectProperty update. Run SPARQL for existing values. + * This can be used for an object property or a direct form. */ public void prepareForObjPropUpdate( Model model ){ if( model == null ) { 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() ) { 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."); @@ -358,9 +351,12 @@ public class EditConfigurationVTwo { 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 ){ - if( model == null ) throw new Error("EditConfiguration.prepareForNonUpdate() needs a Model"); + if( model == null ) throw new Error("prepareForNonUpdate() needs a non-null Model"); basicPrepare(); @@ -675,18 +671,18 @@ public class EditConfigurationVTwo { boolean dataKeyFound = false; if( object != null && ! object.trim().isEmpty() ) objectFound = true; - if( getDatapropKey() != null && ! getDatapropKey().isEmpty() ) + if( getDatapropKey() != null ) dataKeyFound = true; if( dataKeyFound && objectFound ) throw new Error("Bad configuration: both datapropKey and object are defined."); return objectFound; } - public String getDatapropKey() { + public Integer getDatapropKey() { return datapropKey; } - public void setDatapropKey(String datapropKey) { + public void setDatapropKey(Integer datapropKey) { this.datapropKey = datapropKey; } @@ -893,7 +889,7 @@ public class EditConfigurationVTwo { } 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 @@ -974,5 +970,13 @@ public class EditConfigurationVTwo { private static final String INDIVIDUAL_CONTROLLER = "/individual"; + public EditConfigurationVTwo addLiteralInScope(String key, Literal ... values) { + if( literalsInScope == null ){ + literalsInScope = new HashMap>(); + } + literalsInScope.put(key, Arrays.asList(values)); + return this; + } + } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/JspToGeneratorMapping.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/JspToGeneratorMapping.java new file mode 100644 index 000000000..dc8563b1b --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/JspToGeneratorMapping.java @@ -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 jspsToGenerators; + + static{ + jspsToGenerators = new HashMap(); + Map 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 vivoJspsToGenerators = (Map) object; + if( vivoJspsToGenerators != null ) + map.putAll( vivoJspsToGenerators ); + + } catch (Throwable th){ + log.error( "could not load VIVO jsp mappings",th ); + } + } +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/N3EditUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/N3EditUtils.java index 36f8687e9..792b38c24 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/N3EditUtils.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/N3EditUtils.java @@ -2,7 +2,9 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import com.hp.hpl.jena.ontology.OntModel; 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.DataPropertyStatementImpl; 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.processEdit.RdfLiteralHash; @@ -109,12 +113,14 @@ public class N3EditUtils { dps.setLanguage( submittedLiteral.getLanguage() ); dps.setData( submittedLiteral.getLexicalForm() ); - copy.prepareForDataPropUpdate(writeModel, dps); - copy.setDatapropKey( Integer.toString(RdfLiteralHash.makeRdfLiteralHash(dps)) ); + copy.prepareForDataPropUpdate(writeModel, vreq.getWebappDaoFactory().getDataPropertyDao()); + copy.setDatapropKey( RdfLiteralHash.makeRdfLiteralHash(dps)); } EditConfigurationVTwo.putConfigInSession(copy,vreq.getSession()); } } - } + } + + } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/BaseEditConfigurationGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/BaseEditConfigurationGenerator.java index 70f262abc..ffd4bce15 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/BaseEditConfigurationGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/BaseEditConfigurationGenerator.java @@ -52,7 +52,7 @@ public abstract class BaseEditConfigurationGenerator implements EditConfiguratio * Method to turn Strings or multiple List to List. * Only accepts String and List as multi args. */ - List list( Object ... objs){ + static List list( Object ... objs){ List rv = new ArrayList(); for( Object obj: objs){ if( obj instanceof String) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultDataPropertyFormGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultDataPropertyFormGenerator.java index 4256f29cd..6e7295feb 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultDataPropertyFormGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultDataPropertyFormGenerator.java @@ -2,134 +2,135 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators; -import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; -import java.util.List; import javax.servlet.http.HttpSession; import org.apache.commons.logging.Log; 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.DataPropertyStatement; import edu.cornell.mannlib.vitro.webapp.beans.Individual; 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.FieldVTwo; 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 HashMap defaultsForXSDtypes; - - static { - defaultsForXSDtypes = new HashMap(); - //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"); - } + private static Log log = LogFactory.getLog(DefaultDataPropertyFormGenerator.class); + static String literalVar = "literal"; + static String literalPlaceholder = "?"+literalVar; + @Override - public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, - HttpSession session) { + public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, 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 subjectUriJson = (String)vreq.getAttribute("subjectUriJson"); - String predicateUriJson = (String)vreq.getAttribute("predicateUriJson"); - String objectUriJson = (String)vreq.getAttribute("objectUriJson"); - - DataPropertyStatement dps = (DataPropertyStatement)vreq.getAttribute("dataprop"); - - String datapropKeyStr = vreq.getParameter("datapropKey"); - int dataHash=0; - - 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) + '"' ); + WebappDaoFactory unfilteredWdf = vreq.getUnfilteredWebappDaoFactory(); + DataProperty dataproperty = unfilteredWdf.getDataPropertyDao().getDataPropertyByURI( predicateUri ); + if( dataproperty == null) { + // No dataproperty will be returned for rdfs:label, but we shouldn't throw an error. + // This is controlled by the Jena layer, so we can't change the behavior. + if (! predicateUri.equals(VitroVocabulary.LABEL)) { + log.error("Could not find data property '"+predicateUri+"' in model"); + throw new Error("editDatapropStmtRequest.jsp: Could not find DataProperty in model: " + predicateUri); } } + 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(); - String dataLiteral = localName + "Edited"; - String formUrl = (String)vreq.getAttribute("formUrl"); - String editKey = (String)vreq.getAttribute("editKey"); - - EditConfigurationVTwo editConfiguration = new EditConfigurationVTwo(); - - List n3ForEdit = new ArrayList(); - 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.setN3Required(Arrays.asList( "?subject ?predicate " + literalPlaceholder + " . ")); + + editConfiguration.setDatapropKey( EditConfigurationUtils.getDataHash(vreq) ); editConfiguration.setVarNameForSubject("subject"); - editConfiguration.setSubjectUri(subjectUriJson); + editConfiguration.setSubjectUri(subjectUri); + editConfiguration.setEntityToReturnTo( subjectUri ); 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 editConfiguration.addModelChangePreprocessor( new DefaultDataPropEmptyField() ); - return editConfiguration; - } - - private EditConfigurationVTwo doHelp(VitroRequest vreq, String string) { - // TODO Auto-generated method stub - return null; + return editConfiguration; } + + 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"); + } + + + } + } + + + + } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultDeleteGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultDeleteGenerator.java index 0b72b901a..9f2a777e2 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultDeleteGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultDeleteGenerator.java @@ -48,9 +48,8 @@ public class DefaultDeleteGenerator implements EditConfigurationGenerator { private Log log = LogFactory.getLog(DefaultObjectPropertyFormGenerator.class); private String subjectUri = null; private String predicateUri = null; - private String objectUri = null; - private String datapropKeyStr= null; - private int dataHash = 0; + private String objectUri = null; + private Integer dataHash = 0; private DataPropertyStatement dps = null; private String dataLiteral = null; private String template = "confirmDeletePropertyForm.ftl"; @@ -107,14 +106,9 @@ public class DefaultDeleteGenerator implements EditConfigurationGenerator { } private void initDataParameters(VitroRequest vreq, HttpSession session) { - 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"); - } + dataHash = EditConfigurationUtils.getDataHash(vreq); + if( dataHash != null ){ + log.debug("Found a datapropKey in parameters and parsed it to int: " + dataHash); } dps = EditConfigurationUtils.getDataPropertyStatement(vreq, session, dataHash, predicateUri); } @@ -135,7 +129,7 @@ public class DefaultDeleteGenerator implements EditConfigurationGenerator { private void processDataPropForm(VitroRequest vreq, EditConfigurationVTwo editConfiguration) { //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 editConfiguration.setDatapropValue(""); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java index 2745252e6..0d63985a2 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java @@ -42,7 +42,7 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene private String objectUri = null; private String datapropKeyStr= null; private int dataHash = 0; - private DataPropertyStatement dps = null; + private String dataLiteral = null; private String objectPropertyTemplate = "defaultPropertyForm.ftl"; private String dataPropertyTemplate = "defaultDataPropertyForm.ftl"; @@ -161,25 +161,9 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene this.processObjectPropForm(vreq, editConfiguration); } else { this.isObjectPropForm = false; - this.initDataParameters(vreq, session); 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) { @@ -450,15 +434,7 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene editConfiguration.prepareForNonUpdate( model ); } } else { - //TODO: why is this checking for data prop keys? - if(datapropKeyStr != null && datapropKeyStr.trim().length() > 0 ) { - DataPropertyStatement dps = EditConfigurationUtils.getDataPropertyStatement(vreq, - session, - dataHash, - EditConfigurationUtils.getPredicateUri(vreq)); - - editConfiguration.prepareForDataPropUpdate(model, dps); - } + throw new Error("DefaultObjectPropertyForm does not handle data properties."); } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/MenuEditingFormGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/MenuEditingFormGenerator.java index 8b2189638..c070b31c7 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/MenuEditingFormGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/MenuEditingFormGenerator.java @@ -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.dao.DisplayVocabulary; 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.FieldVTwo; 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) { - String datapropKeyStr = vreq.getParameter("datapropKey"); - int dataHash=0; - DataPropertyStatement dps = (DataPropertyStatement)vreq.getAttribute("dataprop"); + Integer dataHash = EditConfigurationUtils.getDataHash(vreq); + DataPropertyStatement dps = (DataPropertyStatement)vreq.getAttribute("dataprop"); //ObjectUriJson is null, so should include data prop info here //Use dataprop key info here instead @@ -194,14 +194,8 @@ public class MenuEditingFormGenerator implements EditConfigurationGenerator { 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+"'"); - } + if( dps != null ){ + log.debug("dataHash is " + dataHash); String rangeDatatype = dps.getDatatypeURI(); if( rangeDatatype == null ){ @@ -229,7 +223,7 @@ public class MenuEditingFormGenerator implements EditConfigurationGenerator { vreq.setAttribute("rangeDefaultJson", '"' + MiscWebUtils.escape(defaultVal) + '"' ); } } - editConfiguration.setDatapropKey((datapropKeyStr==null)?"":datapropKeyStr); + editConfiguration.setDatapropKey(dataHash); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/RDFSLabelGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/RDFSLabelGenerator.java index 77050bf41..26bdb72c4 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/RDFSLabelGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/RDFSLabelGenerator.java @@ -145,25 +145,13 @@ public class RDFSLabelGenerator implements EditConfigurationGenerator { private void initDataParameters(VitroRequest vreq, HttpSession session) { - 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"); - } - } + dataHash = EditConfigurationUtils.getDataHash(vreq); dps = EditConfigurationUtils.getDataPropertyStatement(vreq, session, dataHash, predicateUri); } - - - - private void processDataPropForm(VitroRequest vreq, EditConfigurationVTwo editConfiguration) { //set data prop value, data prop key str, - editConfiguration.setDatapropKey((datapropKeyStr==null)?"":datapropKeyStr); + editConfiguration.setDatapropKey( EditConfigurationUtils.getDataHash(vreq) ); editConfiguration.setVarNameForObject(literalName); //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 Model model = (Model) session.getServletContext().getAttribute("jenaOntModel"); if(datapropKeyStr != null && datapropKeyStr.trim().length() > 0 ) { - editConfiguration.prepareForDataPropUpdate(model, dps); + editConfiguration.prepareForDataPropUpdate(model, vreq.getWebappDaoFactory().getDataPropertyDao()); } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatchController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatchController.java index 800bc9f7c..47ce89cb9 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatchController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatchController.java @@ -15,6 +15,7 @@ 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.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Property; 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 ***/ EditConfigurationVTwo editConfig = setupEditConfiguration(editConfGeneratorName, vreq); - + log.debug("editConfiguration:\n" + editConfig ); //what template? String template = editConfig.getTemplate(); @@ -139,14 +140,15 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet { editConfig.setPredicateUri( EditConfigurationUtils.getPredicateUri(vreq)); String objectUri = EditConfigurationUtils.getObjectUri(vreq); - String dataKey = EditConfigurationUtils.getDataPropKey(vreq); + Integer dataKey = EditConfigurationUtils.getDataHash(vreq); if (objectUri != null && ! objectUri.trim().isEmpty()) { // editing existing object if( editConfig.getObject() == null) editConfig.setObject( EditConfigurationUtils.getObjectUri(vreq)); 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 + editConfig.prepareForDataPropUpdate(model, vreq.getWebappDaoFactory().getDataPropertyDao()); } else{ //this might be a create new or a form editConfig.prepareForNonUpdate(model); @@ -168,37 +170,43 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet { //e.g. default add individual form etc. and additional scenarios //TODO: Check if additional scenarios should be checked here private String processEditConfGeneratorName(VitroRequest vreq) { - WebappDaoFactory wdf = vreq.getWebappDaoFactory(); //use default object property form if nothing else works 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)) { - editConfGeneratorName = DEFAULT_DELETE_FORM; - } + return DEFAULT_DELETE_FORM; + } + // *** 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 - //in order to test - //else if( predicateUri == null && ( formParam != null && !formParam.isEmpty()) ){ - else if( formParam != null && !formParam.isEmpty() ){ + String formParam = getFormParam(vreq); + if( formParam != null && !formParam.isEmpty() ){ //form parameter must be a fully qualified java class name of a EditConfigurationVTwoGenerator implementation. - editConfGeneratorName = formParam; - } else if(isVitroLabel(predicateUri)) { //in case of data property - editConfGeneratorName = RDFS_LABEL_FORM; + return formParam; + } + + 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{ - String customForm = getCustomForm(predicateUri, wdf); - if(customForm != null && !customForm.isEmpty()) { + String customForm = prop.getCustomEntryForm(); + if(customForm != null && !customForm.trim().isEmpty()) { editConfGeneratorName = customForm; } } + + log.debug("generator name is " + editConfGeneratorName); return editConfGeneratorName; } - - - - private String getCustomForm(String predicateUri, WebappDaoFactory wdf) { + private String getCustomForm(String predicateUri, WebappDaoFactory wdf) { Property prop = getPropertyByUri(predicateUri, wdf); return prop.getCustomEntryForm(); } @@ -212,11 +220,22 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet { return p; } - private boolean isVitroLabel(String predicateUri) { 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 private boolean isSkipEditForm(VitroRequest vreq) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfFormController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfFormController.java index c5a8eb398..15556c342 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfFormController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfFormController.java @@ -131,17 +131,18 @@ public class ProcessRdfFormController extends FreemarkerHttpServlet{ if(EditConfigurationUtils.isObjectProperty(editConfig.getPredicateUri(), vreq)) { return false; } - Individual subject = EditConfigurationUtils.getSubjectIndividual(vreq); + WebappDaoFactory wdf = vreq.getWebappDaoFactory(); - if (editConfig.getDatapropKey() == null - || editConfig.getDatapropKey().length() == 0) + if ( ! editConfig.isDataPropertyUpdate()) return false; - int dpropHash = Integer.parseInt(editConfig.getDatapropKey()); - DataPropertyStatement dps = RdfLiteralHash.getPropertyStmtByHash(subject, editConfig.getPredicateUri(), dpropHash, model); - + Integer dpropHash = editConfig.getDatapropKey(); + DataPropertyStatement dps = + RdfLiteralHash.getPropertyStmtByHash(editConfig.getSubjectUri(), + editConfig.getPredicateUri(), dpropHash, model); if (dps != null) return false; + DataProperty dp = wdf.getDataPropertyDao().getDataPropertyByURI( editConfig.getPredicateUri()); if (dp != null) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/RdfLiteralHash.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/RdfLiteralHash.java index e46aab8b2..46a90e24b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/RdfLiteralHash.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/RdfLiteralHash.java @@ -78,69 +78,131 @@ public class RdfLiteralHash { /** * Forward to either getDataPropertyStmtByHash or getRdfsLabelStatementByHash, depending on the property. - * @param ind + * @param subjectUri, + * @param predicateUri, * @param hash - * @param model + * @param model, may not be null * @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; - - // 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 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.enterCriticalSection(false); + StmtIterator stmts = model.listStatements(model.createResource(subjectUri), model.getProperty(predicateUri), - (RDFNode)null); + (RDFNode)null); try { while (stmts.hasNext()) { Statement stmt = stmts.nextStatement(); RDFNode node = stmt.getObject(); if ( node.isLiteral() ){ - dps = makeDataPropertyStatementFromStatement(stmt, node); + DataPropertyStatement dps = + makeDataPropertyStatementFromStatement(stmt, node); if (doesStmtMatchHash(dps, hash)) { return dps; } } } - //} catch { - - } finally{ - stmts.close(); - } 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 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 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) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/edit/EditConfigurationTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/edit/EditConfigurationTemplateModel.java index 57acb91d5..b3c90b271 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/edit/EditConfigurationTemplateModel.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/edit/EditConfigurationTemplateModel.java @@ -160,17 +160,15 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel { } private void setDataFormTitle() { - String formTitle = ""; - String datapropKeyStr = editConfig.getDatapropKey(); - DataProperty prop = EditConfigurationUtils.getDataProperty(vreq); - if(prop != null) { - if( datapropKeyStr != null && datapropKeyStr.trim().length() > 0 ) { - formTitle = "Change text for: "+prop.getPublicName()+""; - - } else { - formTitle ="Add new entry for: "+prop.getPublicName()+""; - } - } + String formTitle = ""; + DataProperty prop = EditConfigurationUtils.getDataProperty(vreq); + if(prop != null) { + if( editConfig.isDataPropertyUpdate() ) { + formTitle = "Change text for: "+prop.getPublicName()+""; + } else { + formTitle ="Add new entry for: "+prop.getPublicName()+""; + } + } pageData.put("formTitle", formTitle); } @@ -578,7 +576,10 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel { } public String getDatapropKey() { - return editConfig.getDatapropKey(); + if( editConfig.getDatapropKey() == null ) + return null; + else + return editConfig.getDatapropKey().toString(); } public DataPropertyStatement getDataPropertyStatement() { @@ -592,14 +593,12 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel { //Check whether deletion form should be included for default object property public boolean getIncludeDeletionForm() { - if(isDeleteProhibited()) + if( isDeleteProhibited() ) return false; - if(isObjectProperty()) { - return (getObjectUri() != null && !getObjectUri().isEmpty()); - } - else { - String datapropKey = editConfig.getDatapropKey(); - return (datapropKey != null && !datapropKey.isEmpty()); + if( isObjectProperty() ) { + return editConfig.isObjectPropertyUpdate(); + } else { + return editConfig.isDataPropertyUpdate(); } } diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/RdfLiteralHashTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/RdfLiteralHashTest.java similarity index 55% rename from webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/RdfLiteralHashTest.java rename to webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/RdfLiteralHashTest.java index 180a6bfcc..e7116ca33 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/RdfLiteralHashTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/RdfLiteralHashTest.java @@ -1,6 +1,8 @@ /* $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.util.ArrayList; @@ -125,95 +127,95 @@ public class RdfLiteralHashTest { Assert.assertTrue( ! RdfLiteralHash.doesStmtMatchHash(null, expectedHash) ); } - @Test - public void testGetDataPropertyStmtByHash() { - DataPropertyStatement stmtA = new DataPropertyStatementImpl(); - IndividualImpl ind = new IndividualImpl(); - List stmts = new ArrayList(); - - int expectedHash = 0; - - //test to see if the same subURI, predURI and Value can be distinguished by LANG/datatype - stmtA.setData(TEST_VALUE); - stmtA.setDatapropURI(TEST_DATA_PROP_URI); - stmtA.setIndividualURI(TEST_INDIVIDUAL_URI); - stmts.add(stmtA); - int expectedHashForSimpleStmt = RdfLiteralHash.makeRdfLiteralHash(stmtA); - - stmtA = new DataPropertyStatementImpl(); - stmtA.setData(TEST_VALUE ); - stmtA.setDatapropURI(TEST_DATA_PROP_URI); - stmtA.setIndividualURI(TEST_INDIVIDUAL_URI); - stmtA.setDatatypeURI(TEST_DATA_TYPE_URI); - int expectedHashForDatatypeStmt = RdfLiteralHash.makeRdfLiteralHash(stmtA); - stmts.add(stmtA); - - stmtA = new DataPropertyStatementImpl(); - stmtA.setData(TEST_VALUE ); - stmtA.setDatapropURI(TEST_DATA_PROP_URI); - stmtA.setIndividualURI(TEST_INDIVIDUAL_URI); - stmtA.setLanguage(TEST_LANG); - int expectedHashForLangStmt = RdfLiteralHash.makeRdfLiteralHash(stmtA); - stmts.add(stmtA); - - ind.setDataPropertyStatements(stmts); - - DataPropertyStatement stmt = RdfLiteralHash.getDataPropertyStmtByHash(ind, expectedHashForLangStmt); - Assert.assertNotNull(stmt); - Assert.assertEquals(TEST_DATA_PROP_URI, stmt.getDatapropURI() ); - Assert.assertEquals(TEST_INDIVIDUAL_URI, stmt.getIndividualURI() ); - Assert.assertEquals(TEST_LANG, stmt.getLanguage() ); - Assert.assertEquals(TEST_VALUE, stmt.getData() ); - Assert.assertNull(stmt.getDatatypeURI()); - - stmt = RdfLiteralHash.getDataPropertyStmtByHash(ind, expectedHashForSimpleStmt); - Assert.assertNotNull(stmt); - Assert.assertEquals(TEST_DATA_PROP_URI, stmt.getDatapropURI() ); - Assert.assertEquals(TEST_INDIVIDUAL_URI, stmt.getIndividualURI() ); - Assert.assertEquals(TEST_VALUE, stmt.getData() ); - Assert.assertNull(stmt.getDatatypeURI()); - Assert.assertNull(stmt.getLanguage()); - - stmt = RdfLiteralHash.getDataPropertyStmtByHash(ind, expectedHashForDatatypeStmt); - Assert.assertNotNull(stmt); - Assert.assertEquals(TEST_DATA_PROP_URI, stmt.getDatapropURI() ); - Assert.assertEquals(TEST_INDIVIDUAL_URI, stmt.getIndividualURI() ); - Assert.assertEquals(TEST_VALUE, stmt.getData() ); - Assert.assertEquals(TEST_DATA_TYPE_URI, stmt.getDatatypeURI() ); - Assert.assertNull(stmt.getLanguage()); - - - stmt = RdfLiteralHash.getDataPropertyStmtByHash(ind, 111111); - Assert.assertNull(stmt); - - } +// @Test +// public void testGetDataPropertyStmtByHash() { +// DataPropertyStatement stmtA = new DataPropertyStatementImpl(); +// IndividualImpl ind = new IndividualImpl(); +// List stmts = new ArrayList(); +// +// int expectedHash = 0; +// +// //test to see if the same subURI, predURI and Value can be distinguished by LANG/datatype +// stmtA.setData(TEST_VALUE); +// stmtA.setDatapropURI(TEST_DATA_PROP_URI); +// stmtA.setIndividualURI(TEST_INDIVIDUAL_URI); +// stmts.add(stmtA); +// int expectedHashForSimpleStmt = RdfLiteralHash.makeRdfLiteralHash(stmtA); +// +// stmtA = new DataPropertyStatementImpl(); +// stmtA.setData(TEST_VALUE ); +// stmtA.setDatapropURI(TEST_DATA_PROP_URI); +// stmtA.setIndividualURI(TEST_INDIVIDUAL_URI); +// stmtA.setDatatypeURI(TEST_DATA_TYPE_URI); +// int expectedHashForDatatypeStmt = RdfLiteralHash.makeRdfLiteralHash(stmtA); +// stmts.add(stmtA); +// +// stmtA = new DataPropertyStatementImpl(); +// stmtA.setData(TEST_VALUE ); +// stmtA.setDatapropURI(TEST_DATA_PROP_URI); +// stmtA.setIndividualURI(TEST_INDIVIDUAL_URI); +// stmtA.setLanguage(TEST_LANG); +// int expectedHashForLangStmt = RdfLiteralHash.makeRdfLiteralHash(stmtA); +// stmts.add(stmtA); +// +// ind.setDataPropertyStatements(stmts); +// +// DataPropertyStatement stmt = RdfLiteralHash.getDataPropertyStmtByHash(ind, expectedHashForLangStmt); +// Assert.assertNotNull(stmt); +// Assert.assertEquals(TEST_DATA_PROP_URI, stmt.getDatapropURI() ); +// Assert.assertEquals(TEST_INDIVIDUAL_URI, stmt.getIndividualURI() ); +// Assert.assertEquals(TEST_LANG, stmt.getLanguage() ); +// Assert.assertEquals(TEST_VALUE, stmt.getData() ); +// Assert.assertNull(stmt.getDatatypeURI()); +// +// stmt = RdfLiteralHash.getDataPropertyStmtByHash(ind.getURI(), expectedHashForSimpleStmt); +// Assert.assertNotNull(stmt); +// Assert.assertEquals(TEST_DATA_PROP_URI, stmt.getDatapropURI() ); +// Assert.assertEquals(TEST_INDIVIDUAL_URI, stmt.getIndividualURI() ); +// Assert.assertEquals(TEST_VALUE, stmt.getData() ); +// Assert.assertNull(stmt.getDatatypeURI()); +// Assert.assertNull(stmt.getLanguage()); +// +// stmt = RdfLiteralHash.getDataPropertyStmtByHash(ind, expectedHashForDatatypeStmt); +// Assert.assertNotNull(stmt); +// Assert.assertEquals(TEST_DATA_PROP_URI, stmt.getDatapropURI() ); +// Assert.assertEquals(TEST_INDIVIDUAL_URI, stmt.getIndividualURI() ); +// Assert.assertEquals(TEST_VALUE, stmt.getData() ); +// Assert.assertEquals(TEST_DATA_TYPE_URI, stmt.getDatatypeURI() ); +// Assert.assertNull(stmt.getLanguage()); +// +// +// stmt = RdfLiteralHash.getDataPropertyStmtByHash(ind, 111111); +// Assert.assertNull(stmt); +// +// } - @Test - public void testGetRdfsLabelStatementByHash(){ - - String n3 = - "@prefix ex: . \n" + - "@prefix rdf: . \n"+ - "@prefix rdfs: .\n"+ - " ex:bob rdfs:label \"Smith, Bob\"^^<"+XSD.xstring.getURI()+"> ." ; - - Model model = (ModelFactory.createDefaultModel()).read(new StringReader(n3), "", "N3"); - - Individual bob = new IndividualImpl(); - bob.setURI("http://example.com/bob"); - - int hash = RdfLiteralHash.makeRdfsLabelLiteralHash(bob, "Smith, Bob", model); - DataPropertyStatement stmt = RdfLiteralHash.getRdfsLabelStatementByHash(bob, model, hash); - - String data = stmt.getData(); - String datatypeUri = stmt.getDatatypeURI(); - String predicateUri = stmt.getDatapropURI(); - String subjectUri = stmt.getIndividualURI(); - - Assert.assertEquals("Smith, Bob", data); - Assert.assertEquals(XSD.xstring.getURI(), datatypeUri); - Assert.assertEquals(VitroVocabulary.LABEL, predicateUri); - Assert.assertEquals("http://example.com/bob", subjectUri); - - } +// @Test +// public void testGetRdfsLabelStatementByHash(){ +// +// String n3 = +// "@prefix ex: . \n" + +// "@prefix rdf: . \n"+ +// "@prefix rdfs: .\n"+ +// " ex:bob rdfs:label \"Smith, Bob\"^^<"+XSD.xstring.getURI()+"> ." ; +// +// Model model = (ModelFactory.createDefaultModel()).read(new StringReader(n3), "", "N3"); +// +// Individual bob = new IndividualImpl(); +// bob.setURI("http://example.com/bob"); +// +// int hash = RdfLiteralHash.makeRdfsLabelLiteralHash(bob, "Smith, Bob", model); +// DataPropertyStatement stmt = RdfLiteralHash.getRdfsLabelStatementByHash(bob.getURI(), model, hash); +// +// String data = stmt.getData(); +// String datatypeUri = stmt.getDatatypeURI(); +// String predicateUri = stmt.getDatapropURI(); +// String subjectUri = stmt.getIndividualURI(); +// +// Assert.assertEquals("Smith, Bob", data); +// Assert.assertEquals(XSD.xstring.getURI(), datatypeUri); +// Assert.assertEquals(VitroVocabulary.LABEL, predicateUri); +// Assert.assertEquals("http://example.com/bob", subjectUri); +// +// } } diff --git a/webapp/web/edit/editRequestDispatch.jsp b/webapp/web/edit/editRequestDispatch.jsp index f33d55a65..b418adf1a 100644 --- a/webapp/web/edit/editRequestDispatch.jsp +++ b/webapp/web/edit/editRequestDispatch.jsp @@ -1,5 +1,7 @@ <%-- $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.ObjectProperty" %> <%@ 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. <% - HashMap jspFormToGenerator = new HashMap(); - HashMap 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"); + Map jspFormToGenerator = JspToGeneratorMapping.jspsToGenerators; //Check if special model, in which case forward if(request.getParameter("switchToDisplayModel") != null) { diff --git a/webapp/web/templates/freemarker/edit/forms/defaultDataPropertyForm.ftl b/webapp/web/templates/freemarker/edit/forms/defaultDataPropertyForm.ftl index a1532a684..29d5d2208 100644 --- a/webapp/web/templates/freemarker/edit/forms/defaultDataPropertyForm.ftl +++ b/webapp/web/templates/freemarker/edit/forms/defaultDataPropertyForm.ftl @@ -11,7 +11,7 @@ - +
<#--The submit label should be set within the template itself, right now