Updates for NIHVIVO-3354 (default add missing individual and substitution of empty strings in object variables). Also updating edit request dispatch to forward to new edit dispatch controller before any additional processing in case the "oldEdit" parameter is not passed. Also removing mayEditAs.jsp.

This commit is contained in:
hjkhjk54 2011-11-29 16:35:05 +00:00
parent a4f0f119c0
commit a109868f34
5 changed files with 30 additions and 171 deletions

View file

@ -86,7 +86,7 @@ public class EditN3GeneratorVTwo {
public String subInUris(String var, String value, String target) {
// empty URIs get skipped
if( var == null || var.isEmpty() || value == null || target == null)
if( var == null || var.isEmpty() || value == null || value.isEmpty() || target == null)
return target;
return subInNonBracketedURIS(var, "<" + value + ">", target);

View file

@ -355,9 +355,9 @@ public class ProcessRdfForm {
}else{
log.debug("no varNameForPredicate found in configuration");
}
String varNameForObj = configuration.getVarNameForObject();
if( varNameForObj != null && ! varNameForObj.isEmpty()){
if( varNameForObj != null
&& ! varNameForObj.isEmpty()){
varToValue.put( varNameForObj, configuration.getObject());
}else{
log.debug("no varNameForObject found in configuration");

View file

@ -123,9 +123,8 @@ public class DefaultAddMissingIndividualFormGenerator implements EditConfigurati
private Map<String, String> generateNewResources(VitroRequest vreq) {
HashMap<String, String> newResources = new HashMap<String, String>();
//TODO: Get default namespace
String defaultNamespace = vreq.getWebappDaoFactory().getDefaultNamespace();
newResources.put(objectVarName, defaultNamespace + "individual");
//Null triggers default namespace
newResources.put(objectVarName, null);
return newResources;
}
//Need to replace edit key
@ -183,7 +182,11 @@ public class DefaultAddMissingIndividualFormGenerator implements EditConfigurati
private void initObjectParameters(VitroRequest vreq) {
//in case of object property
objectUri = EditConfigurationUtils.getObjectUri(vreq);
String thisObjectUri = EditConfigurationUtils.getObjectUri(vreq);
if(thisObjectUri != null && !thisObjectUri.isEmpty()) {
objectUri = EditConfigurationUtils.getObjectUri(vreq);
}
//otherwise object uri will stay null - since don't want to set it to empty string
}
//this particular form uses a different var name for object "newIndividual"

View file

@ -35,14 +35,16 @@ public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.
response.sendRedirect(request.getContextPath() + "/editDisplayModel?" + queryString);
}
//This is our way fo being able to test the new edit configuration
//TODO: Remove this when testing done
if(request.getParameter("testEdit") != null) {
String queryString = request.getQueryString();
response.sendRedirect(request.getContextPath() + "/editRequestDispatch?" + queryString);
//If you find the parameter for testing the old edit, go ahead with the rest of the form
//otherwise forward immediately to the new edit request dispatch controller
String oldEdit = request.getParameter("oldEdit");
if(oldEdit == null) {
String queryString = request.getQueryString();
response.sendRedirect(
request.getContextPath() +
"/editRequestDispatch?" +
queryString);
}
/*
Decide which form to forward to, set subjectUri, subjectUriJson, predicateUri, and predicateUriJson in request.
Also get the Individual for the subjectUri and put it in the request scope.
@ -244,33 +246,15 @@ public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.
form = formParam;
}
String oldEdit = request.getParameter("oldEdit");
if( oldEdit == null){
//First check to see if the form is actually a jsp
//IF so use the custom form mapping
if(form.endsWith(".jsp")) {
//Get the java mapping
if(JspToGeneratorMapping.jspsToGenerators.containsKey(form)) {
form = JspToGeneratorMapping.jspsToGenerators.get(form);
}
}
String queryString = request.getQueryString();
response.sendRedirect(
request.getContextPath() +
"/editRequestDispatch?" +
queryString + "&editForm=" + form);
return;
} else {
//For testing the jsp when test parameter has value,
//Do a reverse mapping from generator to jsp where it exists
for (Map.Entry<String, String> entry: JspToGeneratorMapping.jspsToGenerators.entrySet()) {
if(form.equals(entry.getValue())) {
//Get the jsp corresponding to the Java generator
form = entry.getKey();
break;
}
}
}
//If doing old edit, which we must be b/c otherwise we wouldn't be here
//then get the other
for (Map.Entry<String, String> entry: JspToGeneratorMapping.jspsToGenerators.entrySet()) {
if(form.equals(entry.getValue())) {
//Get the jsp corresponding to the Java generator
form = entry.getKey();
break;
}
}
request.setAttribute("form", form);
%>

View file

@ -1,128 +0,0 @@
<%-- $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.Individual" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.ModelSelector" %>
<%@ page import="com.hp.hpl.jena.ontology.OntModel"%>
<%@ page import="org.apache.commons.logging.Log" %>
<%@ page import="org.apache.commons.logging.LogFactory" %>
<%@page import="edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
<%!
public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.forms.admin.mayEditAs.jsp");
public static String RANGE_CLASS = "http://xmlns.com/foaf/0.1/Person";
public static String PREDICATE = VitroVocabulary.MAY_EDIT_AS;
%>
<%
String subjectUri = (String)request.getAttribute("subjectUri");
VitroRequest vreq = new VitroRequest(request);
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
VClass rangeClass = wdf.getVClassDao().getVClassByURI( RANGE_CLASS );
if( rangeClass == null ) log.debug("Cannot find class for range for property."
+ " Looking for " + RANGE_CLASS);
request.setAttribute("rangeClassUriJson", MiscWebUtils.escape(RANGE_CLASS));
request.setAttribute("predicateUriJson", MiscWebUtils.escape(PREDICATE));
request.setAttribute("objectUriJson" , MiscWebUtils.escape((String)request.getAttribute("objectUri")));
%>
<v:jsonset var="n3ForEdit" >
?subject ?predicate ?objectVar.
</v:jsonset>
<c:set var="editjson" scope="request">
{
"formUrl" : "${formUrl}",
"editKey" : "${editKey}",
"urlPatternToReturnTo" : "/userEdit",
"subject" : [ "subject", "${subjectUriJson}" ] ,
"predicate" : [ "predicate", "${predicateUriJson}" ],
"object" : [ "objectVar" , "${objectUriJson}" , "URI"],
"n3required" : [ "${n3ForEdit}" ],
"n3optional" : [ ],
"newResources" : { },
"urisInScope" : { },
"literalsInScope" : { },
"urisOnForm" : ["objectVar"],
"literalsOnForm" : [ ],
"filesOnForm" : [ ],
"sparqlForLiterals" : { },
"sparqlForUris" : { },
"sparqlForExistingLiterals" : { },
"sparqlForExistingUris" : { },
"fields" : { "objectVar" : {
"newResource" : "false",
"queryForExisting" : { },
"validators" : [ ],
"optionsType" : "INDIVIDUALS_VIA_VCLASS",
"subjectUri" : "${subjectUriJson}",
"subjectClassUri" : "",
"predicateUri" : "",
"objectClassUri" : "${rangeClassUriJson}",
"rangeDatatypeUri" : "",
"rangeLang" : "",
"literalOptions" : [ ] ,
"assertions" : ["${n3ForEdit}"]
}
}
}
</c:set>
<% /* now put edit configuration Json object into session */
EditConfiguration editConfig = new EditConfiguration((String)request.getAttribute("editjson"));
EditConfiguration.putConfigInSession(editConfig, session);
String formTitle ="";
String submitLabel ="";
Model model = (Model)application.getAttribute("jenaOntModel");
editConfig.setWriteModelSelector( new ModelSelector(){
public OntModel getModel(HttpServletRequest request, ServletContext context){
return (OntModel)context.getAttribute("userAccountsOntModel");
}
});
if( request.getAttribute("object") != null ){//this block is for an edit of an existing object property statement
editConfig.prepareForObjPropUpdate( model );
formTitle = "Change person associated with this user account";
submitLabel = "Save Change";
} else {
editConfig.prepareForNonUpdate( model );
formTitle = "Select person to associate with this user account";
submitLabel = "Create Association";
}
%>
<jsp:include page="${preForm}"/>
<h2><%=formTitle%></h2>
<form class="editForm" action="<c:url value="/edit/processRdfForm2.jsp"/>" method="post">
<v:input type="select" id="objectVar" size="80" />
<v:input type="submit" id="submit" value="<%=submitLabel%>" cancel="${param.subjectUri}"/>
</form>
<c:if test="${!empty param.objectUri}" >
<form class="deleteForm" action="<c:url value="/edit/n3Delete.jsp"/>" method="post">
<label for="delete"><h3>Or remove this association?</h3></label>
<input type="hidden" name="subjectUri" value="${param.subjectUri}"/>
<input type="hidden" name="predicateUri" value="${param.predicateUri}"/>
<input type="hidden" name="objectVar" value="${param.objectUri}"/>
<input type="hidden" name="editform" value="edit/admin/mayEditAs.jsp"/>
<v:input type="submit" id="delete" value="Remove" cancel="" />
</form>
</c:if>
<jsp:include page="${postForm}"/>