diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditConfiguration.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditConfiguration.java index b5a3801fb..1db55a168 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditConfiguration.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditConfiguration.java @@ -87,6 +87,7 @@ public class EditConfiguration { String entityToReturnTo; String formUrl; String editKey; + boolean isVitroNsProp; EditN3Generator n3generator; private String originalJson; @@ -169,6 +170,9 @@ public class EditConfiguration { urlPatternToReturnTo = obj.getString("urlPatternToReturnTo"); + String vitroNsPropParam = obj.getString("isVitroNsProp"); + isVitroNsProp = vitroNsPropParam != null && vitroNsPropParam.equalsIgnoreCase("true"); + JSONArray predicate = obj.getJSONArray("predicate"); if( predicate.length() != 2 ) throw new Error("EditConfiguration predicate field must be an array with two items: [varnameForPredicate, predicateUri]"); @@ -510,6 +514,14 @@ public class EditConfiguration { public void setUrlPatternToReturnTo(String s) { urlPatternToReturnTo = s; } + + public boolean isVitroNsProp() { + return isVitroNsProp; + } + + public void setIsVitroNsProp(boolean b) { + isVitroNsProp = b; + } /** return a copy of the value so that the configuration is not modified by external code. * @return diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/RdfLiteralHash.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/RdfLiteralHash.java index 18e0be0fc..917df7855 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/RdfLiteralHash.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/RdfLiteralHash.java @@ -56,7 +56,6 @@ public class RdfLiteralHash { } /** - * * @param stmt * @param hash * @return @@ -75,15 +74,30 @@ public class RdfLiteralHash { return stmtHash == hash; } - /** - * - * @param ind, may be null and getDataPropertyStatements() may return null. + * Forward to either getDataPropertyStmtByHash or getVitroNsPropByHash, depending on the type of property. + * @param ind * @param hash + * @param model + * @param isVitroNsProp * @return a DataPropertyStatement if found or null if not found */ + // RY Instead of a code fork here, we should have a method of Individual getAllDataPropertyStatements() which + // doesn't filter out the vitro ns property statements. This would also simplify the front end editing of the vitro ns + // properties, because they wouldn't have to be a special case. + public static DataPropertyStatement getPropertyStmtByHash(Individual ind, int hash, Model model, boolean isVitroNsProp) { + + if (ind == null) return null; + + DataPropertyStatement dps = isVitroNsProp ? RdfLiteralHash.getVitroNsPropertyStmtByHash(ind, model, hash) : + RdfLiteralHash.getDataPropertyStmtByHash(ind, hash); + + return dps; + } + + public static DataPropertyStatement getDataPropertyStmtByHash( Individual ind, int hash){ - if( ind == null ) return null; + List statements = ind.getDataPropertyStatements(); if( statements == null ) return null; for( DataPropertyStatement dps : statements){ @@ -92,11 +106,15 @@ public class RdfLiteralHash { } return null; } - + + /** + * + * @param ind, may be null and getDataPropertyStatements() may return null. + * @param hash + * @return a DataPropertyStatement if found or null if not found + */ public static DataPropertyStatement getVitroNsPropertyStmtByHash(Individual ind, Model model, int hash) { - if (ind == null || model == null || hash == 0) { - return null; - } + DataPropertyStatement dps = null; StmtIterator stmts = model.listStatements(model.createResource(ind.getURI()), null, (RDFNode)null); try { @@ -113,6 +131,7 @@ public class RdfLiteralHash { dps.setLanguage(lang); dps.setData(value); dps.setDatapropURI(stmt.getPredicate().toString()); + dps.setIndividualURI(ind.getURI()); if (doesStmtMatchHash(dps, hash)) { break; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/InputElementFormattingTag.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/InputElementFormattingTag.java index ce34f7181..d8f748cf8 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/InputElementFormattingTag.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/InputElementFormattingTag.java @@ -235,13 +235,6 @@ public class InputElementFormattingTag extends TagSupport { log.debug("doValue():", ex); } - //here we are looking for defaults since everything else failed -// Field field = editConfig.getField( getId() ); -// if( field == null ) -// log.debug("doValue(): when looking for default value, could not find Field object in EditConfig"); -// else -// return field.getDefault(); - log.debug("doValue(): No existing or default value for key '"+getId()+"' found from in editConfig or" +" or editSub"); return ""; diff --git a/webapp/web/edit/editDatapropStmtRequestDispatch.jsp b/webapp/web/edit/editDatapropStmtRequestDispatch.jsp index c2bdba6af..c3b232431 100644 --- a/webapp/web/edit/editDatapropStmtRequestDispatch.jsp +++ b/webapp/web/edit/editDatapropStmtRequestDispatch.jsp @@ -14,9 +14,11 @@ <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Portal" %> <%@ page import="java.util.HashMap" %> +<%@ page import="org.apache.commons.logging.Log" %> +<%@ page import="org.apache.commons.logging.LogFactory" %> <% - org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.editDatapropStmtRequestDispatch"); - //Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.editDatapropStmtRequestDispatch"); + //org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.editDatapropStmtRequestDispatch.jsp"); + final Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.editDatapropStmtRequestDispatch.jsp"); %> <% // Decide which form to forward to, set subjectUri, subjectUriJson, predicateUri, predicateUriJson in request @@ -107,13 +109,9 @@ DataPropertyStatement dps = null; if( dataHash != 0) { - if (isVitroNsProp) { - Model model = (Model)application.getAttribute("jenaOntModel"); - dps = RdfLiteralHash.getVitroNsPropertyStmtByHash(subject, model, dataHash); - } - else { - dps = RdfLiteralHash.getDataPropertyStmtByHash(subject, dataHash); - } + Model model = (Model)application.getAttribute("jenaOntModel"); + dps = RdfLiteralHash.getPropertyStmtByHash(subject, dataHash, model, isVitroNsProp); + if (dps==null) { log.error("No match to existing data property \""+predicateUri+"\" statement for subject \""+subjectUri+"\" via key "+datapropKeyStr); @@ -124,7 +122,9 @@ } if( log.isDebugEnabled() ){ - log.debug("predicate for DataProperty from request is " + dataproperty.getURI() + " with rangeDatatypeUri of '" + dataproperty.getRangeDatatypeURI() + "'"); + if (dataproperty != null) { + log.debug("predicate for DataProperty from request is " + dataproperty.getURI() + " with rangeDatatypeUri of '" + dataproperty.getRangeDatatypeURI() + "'"); + } if( dps == null ) log.debug("no existng DataPropertyStatement statement was found, making a new statemet"); else{ @@ -134,7 +134,9 @@ msg += " prop uri: <"+dps.getDatapropURI() + ">\n"; msg += " prop data: \"" + dps.getData() + "\"\n"; msg += " datatype: <" + dps.getDatatypeURI() + ">\n"; - msg += " hash of this stmt: " + RdfLiteralHash.makeRdfLiteralHash(dps); + //if (!isVitroNsProp) { + msg += " hash of this stmt: " + RdfLiteralHash.makeRdfLiteralHash(dps); + //} log.debug(msg); } } diff --git a/webapp/web/edit/forms/defaultDatapropForm.jsp b/webapp/web/edit/forms/defaultDatapropForm.jsp index dfe4d0daa..aa7d81453 100644 --- a/webapp/web/edit/forms/defaultDatapropForm.jsp +++ b/webapp/web/edit/forms/defaultDatapropForm.jsp @@ -126,7 +126,6 @@ <% -System.out.println(request.getAttribute("editjson")); if( log.isDebugEnabled()) log.debug(request.getAttribute("editjson")); EditConfiguration editConfig = new EditConfiguration((String)vreq.getAttribute("editjson")); diff --git a/webapp/web/edit/forms/defaultVitroNsPropForm.jsp b/webapp/web/edit/forms/defaultVitroNsPropForm.jsp index 670bf70cf..459c5bb51 100644 --- a/webapp/web/edit/forms/defaultVitroNsPropForm.jsp +++ b/webapp/web/edit/forms/defaultVitroNsPropForm.jsp @@ -36,14 +36,6 @@ %> -<%-- RY Once this is working, change to just one vitroNsEditForm for all vitro ns props, by parameterizing the predicate. -The title and submit button text will need to be customized. -Not sure sparqlForExistingLiterals is needed: see defaultDatapropForm - doesn't use it. - --%> -<%-- RY Change labelExisting, label, and labelAssertion to variables once this is working, -so it can be more easily copied to another form. -Also change hard-coded predicate to ?predicate, so it will be picked up from the editConfig predicate --%> - @@ -60,19 +52,28 @@ Also change hard-coded predicate to ?predicate, so it will be picked up from the The actual assertion inserted in the model will be created via string substitution into the ? variables. NOTE the pattern of punctuation (a period after the prefix URI and after the ?field) --%> - ?subject <${predicate}> ?label . + ?subject <${predicate}> ?${propertyName} . <%-- RY This will be the default, but base it on propertyName --%> +<%-- RY Add other validation cases here. --%> + + + + + + + { "formUrl" : "${formUrl}", "editKey" : "${editKey}", "datapropKey" : "<%= datapropKeyStr == null ? "" : datapropKeyStr %>", "urlPatternToReturnTo" : "/entity", - + "isVitroNsProp" : "true", + "subject" : ["subject", "${subjectUriJson}" ], "predicate" : ["predicate", "${predicateUriJson}" ], "object" : ["${propertyName}", "", "DATAPROPHASH" ], @@ -90,9 +91,9 @@ Also change hard-coded predicate to ?predicate, so it will be picked up from the "sparqlForExistingLiterals" : { "${propertyName}" : "${dataExisting}" }, "sparqlForExistingUris" : { }, "fields" : { - "label" : { + "${propertyName}" : { "newResource" : "false", - "validators" : [ "nonempty" ], + "validators" : [ "${validator}" ], "optionsType" : "UNDEFINED", "literalOptions" : [ ], "predicateUri" : "", @@ -106,10 +107,14 @@ Also change hard-coded predicate to ?predicate, so it will be picked up from the <% + EditConfiguration editConfig = EditConfiguration.getConfigFromSession(session,request); if (editConfig == null) { + log.debug("No editConfig in session. Making new editConfig."); + log.debug(vreq.getAttribute("editjson")); editConfig = new EditConfiguration((String)vreq.getAttribute("editjson")); EditConfiguration.putConfigInSession(editConfig, session); + } if ( datapropKeyStr != null && datapropKeyStr.trim().length() > 0 ) { @@ -127,7 +132,7 @@ Also change hard-coded predicate to ?predicate, so it will be picked up from the

${title}

" > - +

diff --git a/webapp/web/edit/messages/datapropertyBackButtonProblems.jsp b/webapp/web/edit/messages/datapropertyBackButtonProblems.jsp index 69282d6a6..7b7231e84 100644 --- a/webapp/web/edit/messages/datapropertyBackButtonProblems.jsp +++ b/webapp/web/edit/messages/datapropertyBackButtonProblems.jsp @@ -39,7 +39,7 @@ and set a flag in the request to indicate "back button confusion" public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.datapropertyBackButtonProblems.jsp"); %> <% - +System.out.println("IN BACK BUTTON JSP"); log.debug("Starting datapropertyBackButtonProblems.jsp"); if( session == null) @@ -57,7 +57,7 @@ and set a flag in the request to indicate "back button confusion" VitroRequest vreq = new VitroRequest(request); EditConfiguration editConfig = EditConfiguration.getConfigFromSession(session,vreq); - EditSubmission submission = new EditSubmission(vreq, vreq.getParameterMap(), editConfig); + EditSubmission submission = new EditSubmission(vreq.getParameterMap(), editConfig); EditN3Generator n3Subber = editConfig.getN3Generator(); List n3Required = editConfig.getN3Required(); @@ -182,13 +182,13 @@ and set a flag in the request to indicate "back button confusion" jenaOntModel.remove( model ); } }catch(Throwable t){ - errorMessages.add("In processDatapropRdfForm.jsp, error adding edit change n3required model to in memory model \n"+ t.getMessage() ); + errorMessages.add("In datapropertyBackButtonProblems.jsp, error adding edit change n3required model to in memory model \n"+ t.getMessage() ); }finally{ lock.leaveCriticalSection(); } %> - + <%! diff --git a/webapp/web/edit/processDatapropRdfForm.jsp b/webapp/web/edit/processDatapropRdfForm.jsp index 5c70d83b1..17f28c75b 100644 --- a/webapp/web/edit/processDatapropRdfForm.jsp +++ b/webapp/web/edit/processDatapropRdfForm.jsp @@ -62,15 +62,15 @@ and set a flag in the request to indicate "back button confusion" --%> <%! - public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.processDatapropRdfForm.jsp"); + + final Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.processDatapropRdfForm.jsp"); %> <% log.debug("Starting processDatapropRdfForm.jsp"); if( session == null) throw new Error("need to have session"); -%> -<% + boolean selfEditing = VitroRequestPrep.isSelfEditing(request); if (!selfEditing && !LoginFormBean.loggedIn(request, LoginFormBean.NON_EDITOR)) { %><% @@ -132,7 +132,7 @@ and set a flag in the request to indicate "back button confusion" throw new Error("In processDatapropRdfForm.jsp, could not find subject Individual via uri " + subjectUri); } - boolean backButtonProblems = checkForBackButtonConfusion( submission, editConfig, subject, wdf); + boolean backButtonProblems = checkForBackButtonConfusion(application, submission, editConfig, subject, wdf); if( backButtonProblems ){ %><% return; @@ -369,14 +369,18 @@ and set a flag in the request to indicate "back button confusion" return fieldChanged; } - private boolean checkForBackButtonConfusion(EditSubmission submission, + private boolean checkForBackButtonConfusion(ServletContext application, EditSubmission submission, EditConfiguration editConfig, Individual subject, WebappDaoFactory wdf) { if (editConfig.getDatapropKey() == null || editConfig.getDatapropKey().length() == 0) return false; - DataPropertyStatement dps = RdfLiteralHash.getDataPropertyStmtByHash( - subject, Integer.parseInt(editConfig.getDatapropKey())); + + Model model = (Model)application.getAttribute("jenaOntModel"); + int dpropHash = Integer.parseInt(editConfig.getDatapropKey()); + boolean isVitroNsProp = editConfig.isVitroNsProp(); + DataPropertyStatement dps = RdfLiteralHash.getPropertyStmtByHash(subject, dpropHash, model, isVitroNsProp); + if (dps != null) return false; DataProperty dp = wdf.getDataPropertyDao().getDataPropertyByURI( diff --git a/webapp/web/templates/entity/entityBasic.jsp b/webapp/web/templates/entity/entityBasic.jsp index c0c18f666..9ea606e93 100644 --- a/webapp/web/templates/entity/entityBasic.jsp +++ b/webapp/web/templates/entity/entityBasic.jsp @@ -89,8 +89,7 @@ if (VitroRequestPrep.isSelfEditing(request) || LoginFormBean.loggedIn(request, L - - +