NIHVIVO-149 An individual's name can now be edited from the front end.

This commit is contained in:
rjy7 2010-03-15 15:35:35 +00:00
parent e06c6d0cba
commit f8726e8356
13 changed files with 287 additions and 94 deletions

View file

@ -1,5 +1,6 @@
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
<%@ page import="com.hp.hpl.jena.rdf.model.Model" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataProperty" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
@ -33,7 +34,8 @@
final String DEFAULT_DATA_FORM = "defaultDatapropForm.jsp";
final String DEFAULT_ERROR_FORM = "error.jsp";
final String DEFAULT_VITRO_NS_FORM = "defaultVitroNsPropForm.jsp";
if (!VitroRequestPrep.isSelfEditing(request) && !LoginFormBean.loggedIn(request, LoginFormBean.NON_EDITOR)) {
%> <c:redirect url="<%= Controllers.LOGIN %>" /> <%
}
@ -49,6 +51,7 @@
String predicateUri = vreq.getParameter("predicateUri");
String formParam = vreq.getParameter("editForm");
String command = vreq.getParameter("cmd");
boolean isVitroNsProp = vreq.getParameter("vitroNsProp").equals("true") ? true : false;
if( subjectUri == null || subjectUri.trim().length() == 0 ) {
log.error("required subjectUri parameter missing");
@ -76,9 +79,8 @@
DataProperty dataproperty = wdf.getDataPropertyDao().getDataPropertyByURI( predicateUri );
if( dataproperty == null) {
// We must have either a dataproperty or a custom form
// A custom form is used for a vitro namespace property
if (formParam == null) {
// No dataproperty will be returned for a vitro ns prop
if (!isVitroNsProp) {
log.error("Could not find data property '"+predicateUri+"' in model");
throw new Error("editDatapropStmtRequest.jsp: Could not find DataProperty in model: " + predicateUri);
}
@ -103,9 +105,19 @@
}
DataPropertyStatement dps = null;
// We don't need a dataprop statement in the request if we're using a custom form
// RY But we need the dps to call the edit config's prepareForDataPropUpdate.
// So we can either create the dps here, or in the custom form, or change
// prepareForDataPropUpdate to use the datahash to get the dps
if( dataHash != 0) {
dps = RdfLiteralHash.getDataPropertyStmtByHash(subject, dataHash);
if (isVitroNsProp) {
Model model = (Model)application.getAttribute("jenaOntModel");
dps = RdfLiteralHash.getVitroNsPropertyStmtByHash(subject, model, dataHash);
}
else {
dps = RdfLiteralHash.getDataPropertyStmtByHash(subject, dataHash);
}
if (dps==null) {
log.error("No match to existing data property \""+predicateUri+"\" statement for subject \""+subjectUri+"\" via key "+datapropKeyStr);
%><jsp:forward page="/edit/messages/dataPropertyStatementMissing.jsp"></jsp:forward> <%

View file

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

View file

@ -0,0 +1,128 @@
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
<%@ page import="com.hp.hpl.jena.rdf.model.Literal"%>
<%@ page import="com.hp.hpl.jena.rdf.model.Model"%>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual"%>
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary"%>
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration"%>
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory"%>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest"%>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
<%
org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger("edu.cornell.mannlib.vitro.jsp.edit.forms.vitroNsEditLabelForm.jsp");
log.debug("Starting vitroNsEditLabelForm.jsp");
VitroRequest vreq = new VitroRequest(request);
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
vreq.setAttribute("defaultNamespace", wdf.getDefaultNamespace());
String subjectUri = vreq.getParameter("subjectUri");
String predicateUri = vreq.getParameter("predicateUri");
DataPropertyStatement dps = (DataPropertyStatement)vreq.getAttribute("dataprop");
String datapropKeyStr = vreq.getParameter("datapropKey");
Individual subject = (Individual)vreq.getAttribute("subject");
if( subject == null ) {
throw new Error("In vitroNsEditLabelForm.jsp, could not find subject " + subjectUri);
}
%>
<%-- 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 --%>
<%-- Then enter a SPARQL query for the field, by convention concatenating the field id with "Existing"
to convey that the expression is used to retrieve any existing value for the field in an existing individual.
This must then be referenced in the sparqlForExistingLiterals section of the JSON block below
and in the literalsOnForm --%>
<v:jsonset var="labelExisting">
SELECT ?labelExisting WHERE {
?subject <http://www.w3.org/2000/01/rdf-schema#label> ?labelExisting }
</v:jsonset>
<%-- Pair the "existing" query with the skeleton of what will be asserted for a new statement involving this field.
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="labelAssertion" >
?subject <http://www.w3.org/2000/01/rdf-schema#label> ?label .
</v:jsonset>
<c:set var="editjson" scope="request">
{
"formUrl" : "${formUrl}",
"editKey" : "${editKey}",
"datapropKey" : "<%=datapropKeyStr==null?"":datapropKeyStr%>",
"urlPatternToReturnTo" : "/entity",
"subject" : ["subject", "${subjectUriJson}" ],
"predicate" : ["predicate", "${predicateUriJson}" ],
"object" : ["label", "", "DATAPROPHASH" ],
"n3required" : [ "${labelAssertion}" ],
"n3optional" : [ ],
"newResources" : { },
"urisInScope" : { },
"literalsInScope": { },
"urisOnForm" : [ ],
"literalsOnForm" : [ "label" ],
"filesOnForm" : [ ],
"sparqlForLiterals" : { },
"sparqlForUris" : { },
"sparqlForExistingLiterals" : { "label" : "${labelExisting}" },
"sparqlForExistingUris" : { },
"fields" : {
"label" : {
"newResource" : "false",
"validators" : [ "nonempty" ],
"optionsType" : "UNDEFINED",
"literalOptions" : [ ],
"predicateUri" : "",
"objectClassUri" : "",
"rangeDatatypeUri" : "http://www.w3.org/2001/XMLSchema#string",
"rangeLang" : "",
"assertions" : [ "${labelAssertion}" ]
}
}
}
</c:set>
<%
EditConfiguration editConfig = EditConfiguration.getConfigFromSession(session,request);
if (editConfig == null) {
editConfig = new EditConfiguration((String)vreq.getAttribute("editjson"));
EditConfiguration.putConfigInSession(editConfig, session);
}
if ( datapropKeyStr != null && datapropKeyStr.trim().length() > 0 ) {
Model model = (Model)application.getAttribute("jenaOntModel");
editConfig.prepareForDataPropUpdate(model,dps);
}
/* prepare the <title> and text for the submit button */
// RY Generalize this if we use the same form for all vitro ns props
String submitLabel = "Edit name";
request.setAttribute("title", "Edit the name of " + subject.getName() + ":");
%>
<jsp:include page="${preForm}"/>
<h2>${title}</h2>
<form action="<c:url value="/edit/processDatapropRdfForm.jsp"/>" >
<v:input type="text" id="label" size="30" />
<p class="submit"><v:input type="submit" id="submit" value="<%=submitLabel%>" cancel="${param.subjectUri}"/></p>
</form>
<jsp:include page="${postForm}"/>

View file

@ -1 +0,0 @@
In vitroNsLabelForm

View file

@ -92,7 +92,7 @@ and set a flag in the request to indicate "back button confusion"
EditSubmission submission = new EditSubmission(vreq.getParameterMap(), editConfig);
Map<String,String> errors = submission.getValidationErrors();
EditSubmission.putEditSubmissionInSession(session,submission);
EditSubmission.putEditSubmissionInSession(session,submission);
if( errors != null && ! errors.isEmpty() ){
String form = editConfig.getFormUrl();