NIHVIVO-1907 Add repair mode to publication form

This commit is contained in:
ryounes 2011-04-05 14:33:06 +00:00
parent eab8a2153b
commit 9d5383c6e0
3 changed files with 82 additions and 45 deletions

View file

@ -33,6 +33,8 @@ core:informationResourceInAuthorship (InformationResource : Authorship) - invers
<%@ page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.JavaScript" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.JavaScript" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Css" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Css" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils"%>
<%@ page import="edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils.EditMode"%>
<%@ page import="org.apache.commons.logging.Log" %> <%@ page import="org.apache.commons.logging.Log" %>
<%@ page import="org.apache.commons.logging.LogFactory" %> <%@ page import="org.apache.commons.logging.LogFactory" %>
@ -45,13 +47,52 @@ core:informationResourceInAuthorship (InformationResource : Authorship) - invers
public static String nodeToPubProp = "http://vivoweb.org/ontology/core#linkedInformationResource"; public static String nodeToPubProp = "http://vivoweb.org/ontology/core#linkedInformationResource";
%> %>
<% <%
VitroRequest vreq = new VitroRequest(request); VitroRequest vreq = new VitroRequest(request);
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
vreq.setAttribute("defaultNamespace", ""); //empty string triggers default new URI behavior
String subjectUri = vreq.getParameter("subjectUri"); String subjectUri = vreq.getParameter("subjectUri");
String predicateUri = vreq.getParameter("predicateUri"); String predicateUri = vreq.getParameter("predicateUri");
String subjectName = ((Individual) request.getAttribute("subject")).getName(); String objectUri = vreq.getParameter("objectUri");
Individual obj = (Individual) request.getAttribute("object");
EditMode mode = FrontEndEditingUtils.getEditMode(request, nodeToPubProp);
/*
There are 3 modes that this form can be in:
1. Add. There is a subject and a predicate but no position and nothing else.
2. Repair a bad role node. There is a subject, predicate and object but there is no individual on the
other end of the object's core:linkedInformationResource stmt. This should be similar to an add but the form should be expanded.
3. Really bad node. Multiple core:authorInAuthorship statements.
This form does not currently support normal edit mode where there is a subject, an object, and an individual on
the other end of the object's core:linkedInformationResource statement. We redirect to the publication profile
to edit the publication.
*/
if( mode == EditMode.ADD ) {
%> <c:set var="editMode" value="add"/><%
} else if(mode == EditMode.EDIT){
// Because it's edit mode, we already know there's one and only one statement
ObjectPropertyStatement ops = obj.getObjectPropertyStatements(nodeToPubProp).get(0);
String pubUri = ops.getObjectURI();
String forwardToIndividual = pubUri != null ? pubUri : objectUri;
%>
<jsp:forward page="/individual">
<jsp:param value="<%= forwardToIndividual %>" name="uri"/>
</jsp:forward>
<%
} else if(mode == EditMode.REPAIR){
%> <c:set var="editMode" value="repair"/><%
}
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
vreq.setAttribute("defaultNamespace", ""); //empty string triggers default new URI behavior
Individual subject = (Individual) request.getAttribute("subject");
String subjectName = subject.getName();
vreq.setAttribute("subjectUriJson", MiscWebUtils.escape(subjectUri)); vreq.setAttribute("subjectUriJson", MiscWebUtils.escape(subjectUri));
vreq.setAttribute("stringDatatypeUriJson", MiscWebUtils.escape(XSD.xstring.toString())); vreq.setAttribute("stringDatatypeUriJson", MiscWebUtils.escape(XSD.xstring.toString()));
@ -60,38 +101,6 @@ core:informationResourceInAuthorship (InformationResource : Authorship) - invers
vreq.setAttribute("intDatatypeUri", intDatatypeUri); vreq.setAttribute("intDatatypeUri", intDatatypeUri);
vreq.setAttribute("intDatatypeUriJson", MiscWebUtils.escape(intDatatypeUri)); vreq.setAttribute("intDatatypeUriJson", MiscWebUtils.escape(intDatatypeUri));
Individual subject = (Individual) request.getAttribute("subject");
Individual obj = (Individual) request.getAttribute("object");
// Check to see if this is an edit of existing, if yes redirect to pub
if( obj != null ){
List<ObjectPropertyStatement> stmts = obj.getObjectPropertyStatements( nodeToPubProp );
if( stmts != null && stmts.size() > 0 ){
ObjectPropertyStatement ops = stmts.get(0);
String pubUri = ops.getObjectURI();
if( pubUri != null ){
%>
<jsp:forward page="/individual">
<jsp:param value="<%= pubUri %>" name="uri"/>
</jsp:forward>
<%
}
}
}
/* This form is not prepared to deal with editing an existing relationship, so redirect
* to authorship page if no publication was found. This is not ideal, because you can't add
* a linked information resource from that page, but you can at least continue to the back end.
* May want to modify form in a future version to support repair mode.
*/
if (obj != null) {
String objectUri = obj.getURI();
%>
<jsp:forward page="/individual">
<jsp:param value="<%= objectUri %>" name="uri"/>
</jsp:forward>
<%
}
%> %>
<c:set var="vivoOnt" value="http://vivoweb.org/ontology" /> <c:set var="vivoOnt" value="http://vivoweb.org/ontology" />
@ -219,10 +228,16 @@ SPARQL queries for existing values. --%>
editConfig.addValidator(new PersonHasPublicationValidator()); editConfig.addValidator(new PersonHasPublicationValidator());
Model model = (Model) application.getAttribute("jenaOntModel"); Model model = (Model) application.getAttribute("jenaOntModel");
String objectUri = (String) request.getAttribute("objectUri");
editConfig.prepareForNonUpdate(model); // we're only adding new, not editing existing if (objectUri != null) { // editing existing (in this case, only repair is currently provided by the form)
editConfig.prepareForObjPropUpdate(model);
} else { // adding new
editConfig.prepareForNonUpdate(model);
}
// Return to person, not publication. See NIHVIVO-1464. // Return to person, not publication. See NIHVIVO-1464.
// editConfig.setEntityToReturnTo("?pubUri"); // editConfig.setEntityToReturnTo("?pubUri");
List<String> customJs = new ArrayList<String>(Arrays.asList(JavaScript.JQUERY_UI.path(), List<String> customJs = new ArrayList<String>(Arrays.asList(JavaScript.JQUERY_UI.path(),
JavaScript.CUSTOM_FORM_UTILS.path(), JavaScript.CUSTOM_FORM_UTILS.path(),
"/js/browserUtils.js", "/js/browserUtils.js",
@ -237,11 +252,28 @@ SPARQL queries for existing values. --%>
request.setAttribute("customCss", customCss); request.setAttribute("customCss", customCss);
%> %>
<%-- Configure add vs. edit --%>
<c:choose>
<c:when test='${editMode == "add"}'>
<c:set var="titleVerb" value="Create" />
<c:set var="submitButtonText" value="Publication" />
</c:when>
<c:otherwise>
<c:set var="titleVerb" value="Edit" />
<c:set var="submitButtonText" value="Edit Publication" />
</c:otherwise>
</c:choose>
<c:set var="requiredHint" value="<span class='requiredHint'> *</span>" /> <c:set var="requiredHint" value="<span class='requiredHint'> *</span>" />
<jsp:include page="${preForm}" /> <jsp:include page="${preForm}" />
<h2>Create publication entry for <%= subjectName %></h2> <% if( mode == EditMode.ERROR ){ %>
<div>This form is unable to handle the editing of this position because it is associated with
multiple Position individuals.</div>
<% }else{ %>
<h2>${titleVerb} publication entry for <%= subjectName %></h2>
<%@ include file="unsupportedBrowserMessage.jsp" %> <%@ include file="unsupportedBrowserMessage.jsp" %>
@ -261,7 +293,7 @@ SPARQL queries for existing values. --%>
</div> </div>
</div> </div>
<p class="submit"><v:input type="submit" id="submit" value="Publication" cancel="true" /></p> <p class="submit"><v:input type="submit" id="submit" value="${submitButtonText}" cancel="true" /></p>
<p id="requiredLegend" class="requiredHint">* required fields</p> <p id="requiredLegend" class="requiredHint">* required fields</p>
</form> </form>
@ -279,7 +311,12 @@ var customFormData = {
sparqlForAcFilter: '${sparqlForAcFilter}', sparqlForAcFilter: '${sparqlForAcFilter}',
sparqlQueryUrl: '${sparqlQueryUrl}', sparqlQueryUrl: '${sparqlQueryUrl}',
acUrl: '${acUrl}', acUrl: '${acUrl}',
submitButtonTextType: 'simple' submitButtonTextType: 'simple',
editMode: '${editMode}',
defaultTypeName: 'publication' // used in repair mode to generate button text
}; };
</script> </script>
<% } %>
<jsp:include page="${postForm}"/> <jsp:include page="${postForm}"/>

View file

@ -439,8 +439,9 @@ var customForm = {
// e.g., 'Create Grant & Principal Investigator' // e.g., 'Create Grant & Principal Investigator'
buttonText = 'Create ' + typeText + ' & ' + baseButtonText; buttonText = 'Create ' + typeText + ' & ' + baseButtonText;
} else { } else {
// e.g., 'Create Publication' // In repair mode, baseButtonText is "Edit X". Keep that for this case.
buttonText = 'Create ' + baseButtonText; // In add mode, baseButtonText is "X", so we get, e.g., "Create Publication"
buttonText = this.editMode == 'repair' ? baseButtonText : 'Create ' + baseButtonText;
} }
} }
// Using existing related individual // Using existing related individual

View file

@ -492,7 +492,6 @@ type is returned and we don't get a match to the select element options. --%>
</c:when> </c:when>
<c:otherwise> <c:otherwise>
<c:set var="titleVerb" value="Edit" /> <c:set var="titleVerb" value="Edit" />
<c:set var="title" value="Edit educational background entry for ${subjectName}" />
<c:set var="submitButtonText" value="Edit Education and Training" /> <c:set var="submitButtonText" value="Edit Education and Training" />
<c:set var="disabledVal">${editMode == "repair" ? "" : "disabled" }</c:set> <c:set var="disabledVal">${editMode == "repair" ? "" : "disabled" }</c:set>
</c:otherwise> </c:otherwise>
@ -513,7 +512,7 @@ This goes to an experimental FM based form:
multiple Position individuals.</div> multiple Position individuals.</div>
<% }else{ %> <% }else{ %>
<h2>${titleVerb} education and training entry for <%= subjectName %></h2> <h2>${titleVerb} education and training entry for ${subjectName}</h2>
<form class="customForm" action="<c:url value="/edit/processRdfForm2.jsp"/>" > <form class="customForm" action="<c:url value="/edit/processRdfForm2.jsp"/>" >