NIHVIVO-143 Front end editing of moniker
This commit is contained in:
parent
1af92dc350
commit
1de471536a
9 changed files with 87 additions and 54 deletions
|
@ -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]");
|
||||
|
@ -511,6 +515,14 @@ public class EditConfiguration {
|
|||
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
|
||||
*/
|
||||
|
|
|
@ -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<DataPropertyStatement> statements = ind.getDataPropertyStatements();
|
||||
if( statements == null ) return null;
|
||||
for( DataPropertyStatement dps : statements){
|
||||
|
@ -93,10 +107,14 @@ 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;
|
||||
|
|
|
@ -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 "";
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,7 +126,6 @@
|
|||
</c:set>
|
||||
|
||||
<%
|
||||
System.out.println(request.getAttribute("editjson"));
|
||||
if( log.isDebugEnabled()) log.debug(request.getAttribute("editjson"));
|
||||
|
||||
EditConfiguration editConfig = new EditConfiguration((String)vreq.getAttribute("editjson"));
|
||||
|
|
|
@ -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="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.
|
||||
NOTE the pattern of punctuation (a period after the prefix URI and after the ?field) --%>
|
||||
<v:jsonset var="dataAssertion" >
|
||||
?subject <${predicate}> ?label .
|
||||
?subject <${predicate}> ?${propertyName} .
|
||||
</v:jsonset>
|
||||
|
||||
<%-- RY This will be the default, but base it on propertyName --%>
|
||||
<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">
|
||||
{
|
||||
"formUrl" : "${formUrl}",
|
||||
"editKey" : "${editKey}",
|
||||
"datapropKey" : "<%= datapropKeyStr == null ? "" : datapropKeyStr %>",
|
||||
"urlPatternToReturnTo" : "/entity",
|
||||
"isVitroNsProp" : "true",
|
||||
|
||||
"subject" : ["subject", "${subjectUriJson}" ],
|
||||
"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}" },
|
||||
"sparqlForExistingUris" : { },
|
||||
"fields" : {
|
||||
"label" : {
|
||||
"${propertyName}" : {
|
||||
"newResource" : "false",
|
||||
"validators" : [ "nonempty" ],
|
||||
"validators" : [ <c:if test="${!empty validator}">"${validator}"</c:if> ],
|
||||
"optionsType" : "UNDEFINED",
|
||||
"literalOptions" : [ ],
|
||||
"predicateUri" : "",
|
||||
|
@ -106,10 +107,14 @@ Also change hard-coded predicate to ?predicate, so it will be picked up from the
|
|||
</c:set>
|
||||
|
||||
<%
|
||||
|
||||
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
|
|||
|
||||
<h2>${title}</h2>
|
||||
<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>
|
||||
</form>
|
||||
|
||||
|
|
|
@ -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<String> 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();
|
||||
}
|
||||
%>
|
||||
|
||||
<jsp:forward page="postEditCleanUp.jsp"/>
|
||||
<jsp:forward page="../postEditCleanUp.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)) {
|
||||
%><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);
|
||||
}
|
||||
|
||||
boolean backButtonProblems = checkForBackButtonConfusion( submission, editConfig, subject, wdf);
|
||||
boolean backButtonProblems = checkForBackButtonConfusion(application, submission, editConfig, subject, wdf);
|
||||
if( backButtonProblems ){
|
||||
%><jsp:forward page="/edit/messages/datapropertyBackButtonProblems.jsp"/><%
|
||||
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(
|
||||
|
|
|
@ -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="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="anchorEditLinks"><edLnk:editLinks item="${vitroNsUri}anchor" data="${entity.anchor}" icons="false"/></c:set>
|
||||
</c:if>
|
||||
|
||||
<c:set var='themeDir'><c:out value='${portalBean.themeDir}' /></c:set>
|
||||
|
|
Loading…
Add table
Reference in a new issue