From a109868f34d63c1d0d188f2ae6b7c95a5a38ec8c Mon Sep 17 00:00:00 2001 From: hjkhjk54 Date: Tue, 29 Nov 2011 16:35:05 +0000 Subject: [PATCH] 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. --- .../n3editing/VTwo/EditN3GeneratorVTwo.java | 2 +- .../edit/n3editing/VTwo/ProcessRdfForm.java | 4 +- ...aultAddMissingIndividualFormGenerator.java | 11 +- webapp/web/edit/editRequestDispatch.jsp | 56 +++----- webapp/web/edit/forms/admin/mayEditAs.jsp | 128 ------------------ 5 files changed, 30 insertions(+), 171 deletions(-) delete mode 100644 webapp/web/edit/forms/admin/mayEditAs.jsp diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditN3GeneratorVTwo.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditN3GeneratorVTwo.java index e23669813..847f9206c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditN3GeneratorVTwo.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditN3GeneratorVTwo.java @@ -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); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/ProcessRdfForm.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/ProcessRdfForm.java index c26cd7d2f..dd933444f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/ProcessRdfForm.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/ProcessRdfForm.java @@ -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"); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultAddMissingIndividualFormGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultAddMissingIndividualFormGenerator.java index 64da0feeb..f113c1782 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultAddMissingIndividualFormGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultAddMissingIndividualFormGenerator.java @@ -123,9 +123,8 @@ public class DefaultAddMissingIndividualFormGenerator implements EditConfigurati private Map generateNewResources(VitroRequest vreq) { HashMap newResources = new HashMap(); - //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" diff --git a/webapp/web/edit/editRequestDispatch.jsp b/webapp/web/edit/editRequestDispatch.jsp index 4281b2c62..6d0801699 100644 --- a/webapp/web/edit/editRequestDispatch.jsp +++ b/webapp/web/edit/editRequestDispatch.jsp @@ -34,15 +34,17 @@ public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp. //Instead of edit request which is what we'll do later, here we'll forward to Menu Management Controller 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,34 +246,16 @@ 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 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 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); %> diff --git a/webapp/web/edit/forms/admin/mayEditAs.jsp b/webapp/web/edit/forms/admin/mayEditAs.jsp deleted file mode 100644 index 8563a83c7..000000000 --- a/webapp/web/edit/forms/admin/mayEditAs.jsp +++ /dev/null @@ -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"))); -%> - - - ?subject ?predicate ?objectVar. - - - - { - "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}"] - } - } - } - - -<% /* 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"; - } -%> - - -

<%=formTitle%>

-
" method="post"> - - - - - -
" method="post"> - - - - - - - -
- -