NIHVIVO-143 Front end editing of moniker

This commit is contained in:
rjy7 2010-03-16 19:17:53 +00:00
parent 1af92dc350
commit 1de471536a
9 changed files with 87 additions and 54 deletions

View file

@ -87,6 +87,7 @@ public class EditConfiguration {
String entityToReturnTo; String entityToReturnTo;
String formUrl; String formUrl;
String editKey; String editKey;
boolean isVitroNsProp;
EditN3Generator n3generator; EditN3Generator n3generator;
private String originalJson; private String originalJson;
@ -169,6 +170,9 @@ public class EditConfiguration {
urlPatternToReturnTo = obj.getString("urlPatternToReturnTo"); urlPatternToReturnTo = obj.getString("urlPatternToReturnTo");
String vitroNsPropParam = obj.getString("isVitroNsProp");
isVitroNsProp = vitroNsPropParam != null && vitroNsPropParam.equalsIgnoreCase("true");
JSONArray predicate = obj.getJSONArray("predicate"); JSONArray predicate = obj.getJSONArray("predicate");
if( predicate.length() != 2 ) if( predicate.length() != 2 )
throw new Error("EditConfiguration predicate field must be an array with two items: [varnameForPredicate, predicateUri]"); throw new Error("EditConfiguration predicate field must be an array with two items: [varnameForPredicate, predicateUri]");
@ -511,6 +515,14 @@ public class EditConfiguration {
urlPatternToReturnTo = 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 a copy of the value so that the configuration is not modified by external code.
* @return * @return
*/ */

View file

@ -56,7 +56,6 @@ public class RdfLiteralHash {
} }
/** /**
*
* @param stmt * @param stmt
* @param hash * @param hash
* @return * @return
@ -75,15 +74,30 @@ public class RdfLiteralHash {
return stmtHash == hash; return stmtHash == hash;
} }
/** /**
* * Forward to either getDataPropertyStmtByHash or getVitroNsPropByHash, depending on the type of property.
* @param ind, may be null and getDataPropertyStatements() may return null. * @param ind
* @param hash * @param hash
* @param model
* @param isVitroNsProp
* @return a DataPropertyStatement if found or null if not found * @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){ public static DataPropertyStatement getDataPropertyStmtByHash( Individual ind, int hash){
if( ind == null ) return null;
List<DataPropertyStatement> statements = ind.getDataPropertyStatements(); List<DataPropertyStatement> statements = ind.getDataPropertyStatements();
if( statements == null ) return null; if( statements == null ) return null;
for( DataPropertyStatement dps : statements){ for( DataPropertyStatement dps : statements){
@ -93,10 +107,14 @@ public class RdfLiteralHash {
return null; 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) { public static DataPropertyStatement getVitroNsPropertyStmtByHash(Individual ind, Model model, int hash) {
if (ind == null || model == null || hash == 0) {
return null;
}
DataPropertyStatement dps = null; DataPropertyStatement dps = null;
StmtIterator stmts = model.listStatements(model.createResource(ind.getURI()), null, (RDFNode)null); StmtIterator stmts = model.listStatements(model.createResource(ind.getURI()), null, (RDFNode)null);
try { try {
@ -113,6 +131,7 @@ public class RdfLiteralHash {
dps.setLanguage(lang); dps.setLanguage(lang);
dps.setData(value); dps.setData(value);
dps.setDatapropURI(stmt.getPredicate().toString()); dps.setDatapropURI(stmt.getPredicate().toString());
dps.setIndividualURI(ind.getURI());
if (doesStmtMatchHash(dps, hash)) { if (doesStmtMatchHash(dps, hash)) {
break; break;

View file

@ -235,13 +235,6 @@ public class InputElementFormattingTag extends TagSupport {
log.debug("doValue():", ex); 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" log.debug("doValue(): No existing or default value for key '"+getId()+"' found from in editConfig or"
+" or editSub"); +" or editSub");
return ""; return "";

View file

@ -14,9 +14,11 @@
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Portal" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Portal" %>
<%@ page import="java.util.HashMap" %> <%@ 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"); //org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.editDatapropStmtRequestDispatch.jsp");
//Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.editDatapropStmtRequestDispatch"); 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 // Decide which form to forward to, set subjectUri, subjectUriJson, predicateUri, predicateUriJson in request
@ -107,13 +109,9 @@
DataPropertyStatement dps = null; DataPropertyStatement dps = null;
if( dataHash != 0) { if( dataHash != 0) {
if (isVitroNsProp) { Model model = (Model)application.getAttribute("jenaOntModel");
Model model = (Model)application.getAttribute("jenaOntModel"); dps = RdfLiteralHash.getPropertyStmtByHash(subject, dataHash, model, isVitroNsProp);
dps = RdfLiteralHash.getVitroNsPropertyStmtByHash(subject, model, dataHash);
}
else {
dps = RdfLiteralHash.getDataPropertyStmtByHash(subject, dataHash);
}
if (dps==null) { if (dps==null) {
log.error("No match to existing data property \""+predicateUri+"\" statement for subject \""+subjectUri+"\" via key "+datapropKeyStr); log.error("No match to existing data property \""+predicateUri+"\" statement for subject \""+subjectUri+"\" via key "+datapropKeyStr);
@ -124,7 +122,9 @@
} }
if( log.isDebugEnabled() ){ 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 ) if( dps == null )
log.debug("no existng DataPropertyStatement statement was found, making a new statemet"); log.debug("no existng DataPropertyStatement statement was found, making a new statemet");
else{ else{
@ -134,7 +134,9 @@
msg += " prop uri: <"+dps.getDatapropURI() + ">\n"; msg += " prop uri: <"+dps.getDatapropURI() + ">\n";
msg += " prop data: \"" + dps.getData() + "\"\n"; msg += " prop data: \"" + dps.getData() + "\"\n";
msg += " datatype: <" + dps.getDatatypeURI() + ">\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); log.debug(msg);
} }
} }

View file

@ -126,7 +126,6 @@
</c:set> </c:set>
<% <%
System.out.println(request.getAttribute("editjson"));
if( log.isDebugEnabled()) log.debug(request.getAttribute("editjson")); if( log.isDebugEnabled()) log.debug(request.getAttribute("editjson"));
EditConfiguration editConfig = new EditConfiguration((String)vreq.getAttribute("editjson")); EditConfiguration editConfig = new EditConfiguration((String)vreq.getAttribute("editjson"));

View file

@ -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 --%>
<c:set var="predicate" value="<%=predicateUri%>" /> <c:set var="predicate" value="<%=predicateUri%>" />
<c:set var="propertyName" value="${fn:substringAfter(predicate, '#')}" /> <c:set var="propertyName" value="${fn:substringAfter(predicate, '#')}" />
@ -60,18 +52,27 @@ 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. 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) --%> NOTE the pattern of punctuation (a period after the prefix URI and after the ?field) --%>
<v:jsonset var="dataAssertion" > <v:jsonset var="dataAssertion" >
?subject <${predicate}> ?label . ?subject <${predicate}> ?${propertyName} .
</v:jsonset> </v:jsonset>
<%-- RY This will be the default, but base it on propertyName --%> <%-- RY This will be the default, but base it on propertyName --%>
<c:set var="rangeDatatypeUri" value="http://www.w3.org/2001/XMLSchema#string" /> <c:set var="rangeDatatypeUri" value="http://www.w3.org/2001/XMLSchema#string" />
<%-- RY Add other validation cases here. --%>
<c:choose>
<c:when test="${propertyName == 'label' || propertyName == 'type'}">
<c:set var="validator" value="nonempty" />
</c:when>
</c:choose>
<c:set var="editjson" scope="request"> <c:set var="editjson" scope="request">
{ {
"formUrl" : "${formUrl}", "formUrl" : "${formUrl}",
"editKey" : "${editKey}", "editKey" : "${editKey}",
"datapropKey" : "<%= datapropKeyStr == null ? "" : datapropKeyStr %>", "datapropKey" : "<%= datapropKeyStr == null ? "" : datapropKeyStr %>",
"urlPatternToReturnTo" : "/entity", "urlPatternToReturnTo" : "/entity",
"isVitroNsProp" : "true",
"subject" : ["subject", "${subjectUriJson}" ], "subject" : ["subject", "${subjectUriJson}" ],
"predicate" : ["predicate", "${predicateUriJson}" ], "predicate" : ["predicate", "${predicateUriJson}" ],
@ -90,9 +91,9 @@ Also change hard-coded predicate to ?predicate, so it will be picked up from the
"sparqlForExistingLiterals" : { "${propertyName}" : "${dataExisting}" }, "sparqlForExistingLiterals" : { "${propertyName}" : "${dataExisting}" },
"sparqlForExistingUris" : { }, "sparqlForExistingUris" : { },
"fields" : { "fields" : {
"label" : { "${propertyName}" : {
"newResource" : "false", "newResource" : "false",
"validators" : [ "nonempty" ], "validators" : [ <c:if test="${!empty validator}">"${validator}"</c:if> ],
"optionsType" : "UNDEFINED", "optionsType" : "UNDEFINED",
"literalOptions" : [ ], "literalOptions" : [ ],
"predicateUri" : "", "predicateUri" : "",
@ -106,10 +107,14 @@ Also change hard-coded predicate to ?predicate, so it will be picked up from the
</c:set> </c:set>
<% <%
EditConfiguration editConfig = EditConfiguration.getConfigFromSession(session,request); EditConfiguration editConfig = EditConfiguration.getConfigFromSession(session,request);
if (editConfig == null) { if (editConfig == null) {
log.debug("No editConfig in session. Making new editConfig.");
log.debug(vreq.getAttribute("editjson"));
editConfig = new EditConfiguration((String)vreq.getAttribute("editjson")); editConfig = new EditConfiguration((String)vreq.getAttribute("editjson"));
EditConfiguration.putConfigInSession(editConfig, session); EditConfiguration.putConfigInSession(editConfig, session);
} }
if ( datapropKeyStr != null && datapropKeyStr.trim().length() > 0 ) { 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
<h2>${title}</h2> <h2>${title}</h2>
<form action="<c:url value="/edit/processDatapropRdfForm.jsp"/>" > <form action="<c:url value="/edit/processDatapropRdfForm.jsp"/>" >
<v:input type="text" id="label" size="30" /> <v:input type="text" id="${propertyName}" size="30" />
<p class="submit"><v:input type="submit" id="submit" value="${submitLabel}" cancel="${param.subjectUri}"/></p> <p class="submit"><v:input type="submit" id="submit" value="${submitLabel}" cancel="${param.subjectUri}"/></p>
</form> </form>

View file

@ -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"); 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"); log.debug("Starting datapropertyBackButtonProblems.jsp");
if( session == null) if( session == null)
@ -57,7 +57,7 @@ and set a flag in the request to indicate "back button confusion"
VitroRequest vreq = new VitroRequest(request); VitroRequest vreq = new VitroRequest(request);
EditConfiguration editConfig = EditConfiguration.getConfigFromSession(session,vreq); 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(); EditN3Generator n3Subber = editConfig.getN3Generator();
List<String> n3Required = editConfig.getN3Required(); List<String> n3Required = editConfig.getN3Required();
@ -182,13 +182,13 @@ and set a flag in the request to indicate "back button confusion"
jenaOntModel.remove( model ); jenaOntModel.remove( model );
} }
}catch(Throwable t){ }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{ }finally{
lock.leaveCriticalSection(); lock.leaveCriticalSection();
} }
%> %>
<jsp:forward page="postEditCleanUp.jsp"/> <jsp:forward page="../postEditCleanUp.jsp"/>
<%! <%!

View file

@ -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"); log.debug("Starting processDatapropRdfForm.jsp");
if( session == null) if( session == null)
throw new Error("need to have session"); throw new Error("need to have session");
%>
<%
boolean selfEditing = VitroRequestPrep.isSelfEditing(request); boolean selfEditing = VitroRequestPrep.isSelfEditing(request);
if (!selfEditing && !LoginFormBean.loggedIn(request, LoginFormBean.NON_EDITOR)) { if (!selfEditing && !LoginFormBean.loggedIn(request, LoginFormBean.NON_EDITOR)) {
%><c:redirect url="<%= Controllers.LOGIN %>" /><% %><c:redirect url="<%= Controllers.LOGIN %>" /><%
@ -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); 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 ){ if( backButtonProblems ){
%><jsp:forward page="/edit/messages/datapropertyBackButtonProblems.jsp"/><% %><jsp:forward page="/edit/messages/datapropertyBackButtonProblems.jsp"/><%
return; return;
@ -369,14 +369,18 @@ and set a flag in the request to indicate "back button confusion"
return fieldChanged; return fieldChanged;
} }
private boolean checkForBackButtonConfusion(EditSubmission submission, private boolean checkForBackButtonConfusion(ServletContext application, EditSubmission submission,
EditConfiguration editConfig, Individual subject, EditConfiguration editConfig, Individual subject,
WebappDaoFactory wdf) { WebappDaoFactory wdf) {
if (editConfig.getDatapropKey() == null if (editConfig.getDatapropKey() == null
|| editConfig.getDatapropKey().length() == 0) || editConfig.getDatapropKey().length() == 0)
return false; 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) if (dps != null)
return false; return false;
DataProperty dp = wdf.getDataPropertyDao().getDataPropertyByURI( DataProperty dp = wdf.getDataPropertyDao().getDataPropertyByURI(

View file

@ -90,7 +90,6 @@ if (VitroRequestPrep.isSelfEditing(request) || LoginFormBean.loggedIn(request, L
<c:set var="descriptionEditLinks"><edLnk:editLinks item="${vitroNsUri}description" data="${entity.description}" icons="false"/></c:set> <c:set var="descriptionEditLinks"><edLnk:editLinks item="${vitroNsUri}description" data="${entity.description}" icons="false"/></c:set>
<c:set var="timekeyEditLinks"><edLnk:editLinks item="${vitroNsUri}timekey" data="${entity.timekey}" icons="false"/></c:set> <c:set var="timekeyEditLinks"><edLnk:editLinks item="${vitroNsUri}timekey" data="${entity.timekey}" icons="false"/></c:set>
<c:set var="urlEditLinks"><edLnk:editLinks item="${vitroNsUri}url" data="${entity.url}" icons="false"/></c:set> <c:set var="urlEditLinks"><edLnk:editLinks item="${vitroNsUri}url" data="${entity.url}" icons="false"/></c:set>
<c:set var="anchorEditLinks"><edLnk:editLinks item="${vitroNsUri}anchor" data="${entity.anchor}" icons="false"/></c:set>
</c:if> </c:if>
<c:set var='themeDir'><c:out value='${portalBean.themeDir}' /></c:set> <c:set var='themeDir'><c:out value='${portalBean.themeDir}' /></c:set>