From 7f3ba682908cae89f99ea52deea091a071a7e223 Mon Sep 17 00:00:00 2001 From: rjy7 Date: Wed, 24 Mar 2010 21:41:33 +0000 Subject: [PATCH] NIHVIVO-144 Enable adding new primary or additional link from front end --- .../webapp/utils/FrontEndEditingUtils.java | 24 +- .../webapp/web/jsptags/PropertyEditLinks.java | 222 ++++++++++++------ .../edit/editDatapropStmtRequestDispatch.jsp | 2 +- webapp/web/edit/editRequestDispatch.jsp | 3 +- webapp/web/edit/forms/defaultLinkForm.jsp | 47 ++-- webapp/web/edit/forms/defaultLinkForm.new.jsp | 176 ++++++++++++++ ...orm.jsp => defaultVitroNsDataPropForm.jsp} | 0 webapp/web/templates/entity/entityBasic.jsp | 14 +- 8 files changed, 386 insertions(+), 102 deletions(-) create mode 100644 webapp/web/edit/forms/defaultLinkForm.new.jsp rename webapp/web/edit/forms/{defaultVitroNsPropForm.jsp => defaultVitroNsDataPropForm.jsp} (100%) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/FrontEndEditingUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/FrontEndEditingUtils.java index 01aa2cfcd..e81d86382 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/FrontEndEditingUtils.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/FrontEndEditingUtils.java @@ -12,16 +12,20 @@ import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; public class FrontEndEditingUtils { - public static final List VITRO_NS_PROPS_FOR_FRONT_END_EDITING = Arrays.asList(VitroVocabulary.BLURB, - VitroVocabulary.CITATION, - VitroVocabulary.DESCRIPTION, - VitroVocabulary.IMAGETHUMB, - VitroVocabulary.LABEL, - VitroVocabulary.LINK_ANCHOR, - VitroVocabulary.MONIKER, - VitroVocabulary.PRIMARY_LINK - //, RDF_TYPE, TIMEKEY - ); + public static final List VITRO_NS_DATAPROPS = Arrays.asList(VitroVocabulary.BLURB, + VitroVocabulary.CITATION, + VitroVocabulary.DESCRIPTION, + VitroVocabulary.IMAGETHUMB, + VitroVocabulary.LABEL, + VitroVocabulary.MONIKER + // VitroVocabulary.RDF_TYPE, + // VitroVocabulary.TIMEKEY + ); + + public static final List VITRO_NS_OBJECT_PROPS = Arrays.asList(VitroVocabulary.ADDITIONAL_LINK, + VitroVocabulary.PRIMARY_LINK + ); + public static String getVitroNsPropDatatypeUri(String propName) { //Resource datatype = propName == TIMEKEY ? XSD.dateTime : XSD.xstring; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/PropertyEditLinks.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/PropertyEditLinks.java index bd716ad7f..5556c0a5d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/PropertyEditLinks.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/PropertyEditLinks.java @@ -107,7 +107,6 @@ public class PropertyEditLinks extends TagSupport{ Individual entity = (Individual)pageContext.getRequest().getAttribute("entity"); LinkStruct[] links = null; - String themeDir = (String)pageContext.getAttribute("themeDir"); //get context prefix needs to end with a slash like "/vivo/" or "/" String contextPath = ((HttpServletRequest)pageContext.getRequest()).getContextPath(); @@ -118,27 +117,45 @@ public class PropertyEditLinks extends TagSupport{ if( item instanceof ObjectPropertyStatement ){ ObjectPropertyStatement prop = (ObjectPropertyStatement)item; - links = doObjPropStmt( prop, themeDir, policyToAccess(ids, policy, prop), contextPath ); + links = doObjPropStmt( prop, policyToAccess(ids, policy, prop), contextPath ); } else if( item instanceof DataPropertyStatement ){ DataPropertyStatement prop = (DataPropertyStatement)item; - links = doDataPropStmt( prop, themeDir, policyToAccess(ids, policy, prop), contextPath ); + links = doDataPropStmt( prop, policyToAccess(ids, policy, prop), contextPath ); } else if (entity == null) { log.error("unable to find an Individual in request using var name 'entity'"); return SKIP_BODY; } else if( item instanceof ObjectProperty ){ ObjectProperty prop = (ObjectProperty)item; - links = doObjProp( prop, entity, themeDir, policyToAccess(ids, policy, entity.getURI(), prop), contextPath ); + links = doObjProp( prop, entity, policyToAccess(ids, policy, entity.getURI(), prop), contextPath ); } else if( item instanceof DataProperty ){ DataProperty prop = (DataProperty)item; // a DataProperty populated for this subject individual - links = doDataProp( prop, entity, themeDir,policyToAccess(ids, policy, entity.getURI(), prop), contextPath ) ; - } else if (item instanceof String && isVitroNsProp((String) item)) { + links = doDataProp( prop, entity, policyToAccess(ids, policy, entity.getURI(), prop),contextPath ); + + // Vitro namespace property + } else if (item instanceof String) { + String predicateUri = (String) item; String subjectUri = entity.getURI(); - if (data != null) { // links to edit or delete an existing value - DataPropertyStatement dps = (DataPropertyStatement) new DataPropertyStatementImpl(subjectUri, (String)item, data); - links = doVitroNamespacePropStmt( dps, entity, themeDir, policyToAccess(ids, policy, dps), contextPath ); - } else { // link to add a new value - links = doVitroNsProp( subjectUri, (String)item, themeDir, policyToAccess(ids, policy, subjectUri, (String)item), contextPath ) ; + if (isVitroNsDataProp(predicateUri)) { + if (data == null) { // link to add a new value + links = doVitroNsDataProp( subjectUri, predicateUri, policyToAccess(ids, policy, subjectUri, predicateUri), contextPath ); + } else { // links to edit or delete an existing value + DataPropertyStatement dps = (DataPropertyStatement) new DataPropertyStatementImpl(subjectUri, predicateUri, data); + links = doVitroNsDataPropStmt( dps, entity, policyToAccess(ids, policy, dps), contextPath ); + } + } else if (isVitroNsObjectProp(predicateUri)) { + if (data == null) { // link to add a new value + links = doObjProp( subjectUri, predicateUri, policyToAccess(ids, policy, subjectUri, predicateUri), contextPath ); + } else { // links to edit or delete an existing value + DataPropertyStatement dps = (DataPropertyStatement) new DataPropertyStatementImpl(subjectUri, predicateUri, data); + //links = doVitroNsObjPropStmt( dps, entity, policyToAccess(ids, policy, dps), contextPath ); + } } + else { + log.error("PropertyEditLinks cannot make links for an object of type " + predicateUri); + return SKIP_BODY; + } + + } else { log.error("PropertyEditLinks cannot make links for an object of type "+item.getClass().getName()); return SKIP_BODY; @@ -164,7 +181,7 @@ public class PropertyEditLinks extends TagSupport{ return SKIP_BODY; } - protected LinkStruct[] doDataProp(DataProperty dprop, Individual entity, String themeDir, EditLinkAccess[] allowedAccessTypeArray, String contextPath) { + protected LinkStruct[] doDataProp(DataProperty dprop, Individual entity, EditLinkAccess[] allowedAccessTypeArray, String contextPath) { if( allowedAccessTypeArray == null || dprop == null || allowedAccessTypeArray.length == 0 ) { log.debug("null or empty access type array in doDataProp for dprop "+dprop.getPublicName()+"; most likely just a property prohibited from editing"); return empty_array; @@ -191,7 +208,7 @@ public class PropertyEditLinks extends TagSupport{ return links; } - protected LinkStruct[] doVitroNsProp(String subjectUri, String propertyUri, String themeDir, EditLinkAccess[] allowedAccessTypeArray, String contextPath) { + protected LinkStruct[] doVitroNsDataProp(String subjectUri, String propertyUri, EditLinkAccess[] allowedAccessTypeArray, String contextPath) { if( allowedAccessTypeArray == null || subjectUri == null || allowedAccessTypeArray.length == 0 ) { log.debug("null or empty access type array in doDataProp for vitro namespace property " + propertyUri + "; most likely just a property prohibited from editing"); return empty_array; @@ -229,18 +246,29 @@ public class PropertyEditLinks extends TagSupport{ return links; } - - protected LinkStruct[] doObjProp(ObjectProperty oprop, Individual entity, String themeDir, EditLinkAccess[] allowedAccessTypeArray, String contextPath) { + // Used for ontology object properties + protected LinkStruct[] doObjProp(ObjectProperty oprop, Individual entity, EditLinkAccess[] allowedAccessTypeArray, String contextPath) { if( allowedAccessTypeArray == null || oprop == null || allowedAccessTypeArray.length == 0 ) { log.debug("null or empty access type array in doObjProp for oprop "+oprop.getDomainPublic()+"; most likely just a property prohibited from editing"); return empty_array; } + + return doObjProp(entity.getURI(), oprop.getURI(), allowedAccessTypeArray, contextPath); + } + + // Used for Vitro namespace object properties + protected LinkStruct[] doObjProp(String subjectUri, String predicateUri, EditLinkAccess[] allowedAccessTypeArray, String contextPath) { + if( allowedAccessTypeArray == null || subjectUri == null || allowedAccessTypeArray.length == 0 ) { + log.debug("null or empty access type array in doObjProp for oprop "+ predicateUri +"; most likely just a property prohibited from editing"); + return empty_array; + } LinkStruct[] links = new LinkStruct[1]; if( contains( allowedAccessTypeArray, EditLinkAccess.ADDNEW )){ + String url= makeRelativeHref(contextPath + "edit/editRequestDispatch.jsp", - "subjectUri", entity.getURI(), - "predicateUri", oprop.getURI()); + "subjectUri", subjectUri, + "predicateUri", predicateUri); LinkStruct ls = new LinkStruct(); ls.setHref( url ); ls.setType("add"); @@ -250,7 +278,7 @@ public class PropertyEditLinks extends TagSupport{ return links; } - protected LinkStruct[] doDataPropStmt(DataPropertyStatement dpropStmt, String themeDir, EditLinkAccess[] allowedAccessTypeArray, String contextPath) { + protected LinkStruct[] doDataPropStmt(DataPropertyStatement dpropStmt, EditLinkAccess[] allowedAccessTypeArray, String contextPath) { if( allowedAccessTypeArray == null || dpropStmt == null || allowedAccessTypeArray.length == 0 ) { log.info("null or empty access type array in doDataPropStmt for "+dpropStmt.getDatapropURI()); return empty_array; @@ -300,57 +328,8 @@ public class PropertyEditLinks extends TagSupport{ return links; } - protected LinkStruct[] doObjPropStmt(ObjectPropertyStatement opropStmt, String themeDir2, EditLinkAccess[] allowedAccessTypeArray, String contextPath) { - if( allowedAccessTypeArray == null || opropStmt == null || allowedAccessTypeArray.length == 0 ) { - log.info("null or empty access type array in doObjPropStmt for "+opropStmt.getPropertyURI()); - return empty_array; - } - LinkStruct[] links = new LinkStruct[2]; - int index=0; + protected LinkStruct[] doVitroNsDataPropStmt(DataPropertyStatement dpropStmt, Individual subject, EditLinkAccess[] allowedAccessTypeArray, String contextPath) { - if( contains( allowedAccessTypeArray, EditLinkAccess.MODIFY ) ){ - log.debug("permission found to UPDATE object property statement "+opropStmt.getPropertyURI()+" so icon created"); - String url = ( contains( allowedAccessTypeArray, EditLinkAccess.DELETE ) ) - ? makeRelativeHref(contextPath + "edit/editRequestDispatch.jsp", - "subjectUri", opropStmt.getSubjectURI(), - "predicateUri", opropStmt.getPropertyURI(), - "objectUri", opropStmt.getObjectURI()) - : makeRelativeHref(contextPath + "edit/editRequestDispatch.jsp", - "subjectUri", opropStmt.getSubjectURI(), - "predicateUri", opropStmt.getPropertyURI(), - "objectUri", opropStmt.getObjectURI(), - "deleteProhibited", "prohibited"); - - LinkStruct ls = new LinkStruct(); - ls.setHref( url ); - ls.setType("edit"); - ls.setMouseoverText("change this relationship"); - links[index] = ls; index++; - - } else { - log.debug("NO permission to UPDATE this object property statement ("+opropStmt.getPropertyURI()+") found in policy"); - } - if( contains( allowedAccessTypeArray, EditLinkAccess.DELETE ) ){ - log.debug("permission found to DELETE object property statement "+opropStmt.getPropertyURI()+" so icon created"); - String url = makeRelativeHref(contextPath + "edit/editRequestDispatch.jsp", - "subjectUri", opropStmt.getSubjectURI(), - "predicateUri", opropStmt.getPropertyURI(), - "objectUri", opropStmt.getObjectURI(), - "cmd", "delete"); - LinkStruct ls = new LinkStruct(); - ls.setHref( url ); - ls.setType("delete"); - ls.setMouseoverText("delete this relationship"); - links[index] = ls; index++; - - } else { - log.debug("NO permission to DELETE this object property statement ("+opropStmt.getPropertyURI()+") found in policy"); - } - return links; - } - - protected LinkStruct[] doVitroNamespacePropStmt(DataPropertyStatement dpropStmt, Individual subject, String themeDir, EditLinkAccess[] allowedAccessTypeArray, String contextPath) { - if( allowedAccessTypeArray == null || dpropStmt == null || allowedAccessTypeArray.length == 0 ) { log.debug("Null or empty access type array for vitro namespace property " + dpropStmt.getDatapropURI()); return empty_array; @@ -432,6 +411,105 @@ public class PropertyEditLinks extends TagSupport{ return links; } + protected LinkStruct[] doObjPropStmt(ObjectPropertyStatement opropStmt, EditLinkAccess[] allowedAccessTypeArray, String contextPath) { + if( allowedAccessTypeArray == null || opropStmt == null || allowedAccessTypeArray.length == 0 ) { + log.info("null or empty access type array in doObjPropStmt for "+opropStmt.getPropertyURI()); + return empty_array; + } + LinkStruct[] links = new LinkStruct[2]; + int index=0; + + if( contains( allowedAccessTypeArray, EditLinkAccess.MODIFY ) ){ + log.debug("permission found to UPDATE object property statement "+opropStmt.getPropertyURI()+" so icon created"); + String url = ( contains( allowedAccessTypeArray, EditLinkAccess.DELETE ) ) + ? makeRelativeHref(contextPath + "edit/editRequestDispatch.jsp", + "subjectUri", opropStmt.getSubjectURI(), + "predicateUri", opropStmt.getPropertyURI(), + "objectUri", opropStmt.getObjectURI()) + : makeRelativeHref(contextPath + "edit/editRequestDispatch.jsp", + "subjectUri", opropStmt.getSubjectURI(), + "predicateUri", opropStmt.getPropertyURI(), + "objectUri", opropStmt.getObjectURI(), + "deleteProhibited", "prohibited"); + + LinkStruct ls = new LinkStruct(); + ls.setHref( url ); + ls.setType("edit"); + ls.setMouseoverText("change this relationship"); + links[index] = ls; index++; + + } else { + log.debug("NO permission to UPDATE this object property statement ("+opropStmt.getPropertyURI()+") found in policy"); + } + if( contains( allowedAccessTypeArray, EditLinkAccess.DELETE ) ){ + log.debug("permission found to DELETE object property statement "+opropStmt.getPropertyURI()+" so icon created"); + String url = makeRelativeHref(contextPath + "edit/editRequestDispatch.jsp", + "subjectUri", opropStmt.getSubjectURI(), + "predicateUri", opropStmt.getPropertyURI(), + "objectUri", opropStmt.getObjectURI(), + "cmd", "delete"); + LinkStruct ls = new LinkStruct(); + ls.setHref( url ); + ls.setType("delete"); + ls.setMouseoverText("delete this relationship"); + links[index] = ls; index++; + + } else { + log.debug("NO permission to DELETE this object property statement ("+opropStmt.getPropertyURI()+") found in policy"); + } + return links; + } + +// protected LinkStruct[] doObjPropStmt(ObjectPropertyStatement opropStmt, EditLinkAccess[] allowedAccessTypeArray, String contextPath) { +// if( allowedAccessTypeArray == null || opropStmt == null || allowedAccessTypeArray.length == 0 ) { +// log.info("null or empty access type array in doObjPropStmt for "+opropStmt.getPropertyURI()); +// return empty_array; +// } +// LinkStruct[] links = new LinkStruct[2]; +// int index=0; +// +// if( contains( allowedAccessTypeArray, EditLinkAccess.MODIFY ) ){ +// log.debug("permission found to UPDATE object property statement "+opropStmt.getPropertyURI()+" so icon created"); +// String url = ( contains( allowedAccessTypeArray, EditLinkAccess.DELETE ) ) +// ? makeRelativeHref(contextPath + "edit/editRequestDispatch.jsp", +// "subjectUri", opropStmt.getSubjectURI(), +// "predicateUri", opropStmt.getPropertyURI(), +// "objectUri", opropStmt.getObjectURI()) +// : makeRelativeHref(contextPath + "edit/editRequestDispatch.jsp", +// "subjectUri", opropStmt.getSubjectURI(), +// "predicateUri", opropStmt.getPropertyURI(), +// "objectUri", opropStmt.getObjectURI(), +// "deleteProhibited", "prohibited"); +// +// LinkStruct ls = new LinkStruct(); +// ls.setHref( url ); +// ls.setType("edit"); +// ls.setMouseoverText("change this relationship"); +// links[index] = ls; index++; +// +// } else { +// log.debug("NO permission to UPDATE this object property statement ("+opropStmt.getPropertyURI()+") found in policy"); +// } +// if( contains( allowedAccessTypeArray, EditLinkAccess.DELETE ) ){ +// log.debug("permission found to DELETE object property statement "+opropStmt.getPropertyURI()+" so icon created"); +// String url = makeRelativeHref(contextPath + "edit/editRequestDispatch.jsp", +// "subjectUri", opropStmt.getSubjectURI(), +// "predicateUri", opropStmt.getPropertyURI(), +// "objectUri", opropStmt.getObjectURI(), +// "cmd", "delete"); +// LinkStruct ls = new LinkStruct(); +// ls.setHref( url ); +// ls.setType("delete"); +// ls.setMouseoverText("delete this relationship"); +// links[index] = ls; index++; +// +// } else { +// log.debug("NO permission to DELETE this object property statement ("+opropStmt.getPropertyURI()+") found in policy"); +// } +// return links; +// } + + /* ********************* utility methods ********************************* */ protected static String makeRelativeHref( String baseUrl, String ... queries ) { String href = baseUrl; @@ -599,8 +677,12 @@ public class PropertyEditLinks extends TagSupport{ } - private boolean isVitroNsProp(String predicateUri) { - return FrontEndEditingUtils.VITRO_NS_PROPS_FOR_FRONT_END_EDITING.contains(predicateUri); + private boolean isVitroNsDataProp(String predicateUri) { + return FrontEndEditingUtils.VITRO_NS_DATAPROPS.contains(predicateUri); + } + + private boolean isVitroNsObjectProp(String predicateUri) { + return FrontEndEditingUtils.VITRO_NS_OBJECT_PROPS.contains(predicateUri); } } diff --git a/webapp/web/edit/editDatapropStmtRequestDispatch.jsp b/webapp/web/edit/editDatapropStmtRequestDispatch.jsp index b3e4fae8a..3ac3616f8 100644 --- a/webapp/web/edit/editDatapropStmtRequestDispatch.jsp +++ b/webapp/web/edit/editDatapropStmtRequestDispatch.jsp @@ -36,7 +36,7 @@ ************************************** */ final String DEFAULT_DATA_FORM = "defaultDatapropForm.jsp"; - final String DEFAULT_VITRO_NS_FORM = "defaultVitroNsPropForm.jsp"; + final String DEFAULT_VITRO_NS_FORM = "defaultVitroNsDataPropForm.jsp"; final String DEFAULT_ERROR_FORM = "error.jsp"; if (!VitroRequestPrep.isSelfEditing(request) && !LoginFormBean.loggedIn(request, LoginFormBean.NON_EDITOR)) { diff --git a/webapp/web/edit/editRequestDispatch.jsp b/webapp/web/edit/editRequestDispatch.jsp index ede52abc3..8bbf75d53 100644 --- a/webapp/web/edit/editRequestDispatch.jsp +++ b/webapp/web/edit/editRequestDispatch.jsp @@ -234,7 +234,8 @@ public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp. request.setAttribute("form", form); %> - + + <%! diff --git a/webapp/web/edit/forms/defaultLinkForm.jsp b/webapp/web/edit/forms/defaultLinkForm.jsp index 875646abf..f66c132d1 100644 --- a/webapp/web/edit/forms/defaultLinkForm.jsp +++ b/webapp/web/edit/forms/defaultLinkForm.jsp @@ -9,14 +9,25 @@ <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataProperty" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary"%> + <%@ page import="java.util.List" %> + <%@ page import="org.apache.commons.logging.Log" %> <%@ page import="org.apache.commons.logging.LogFactory" %> + <%@ 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.defaultLinkForm.jsp"); + public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.forms.defaultLinkForm.jsp"); %> +<% + String predicateUri = (String)request.getAttribute("predicateUri"); +%> + + + + <%-- Enter here any class names to be used for constructing INDIVIDUALS_VIA_VCLASS pick lists These are then referenced in the field's ObjectClassUri but not elsewhere. NOTE that this class may not exist in the model, in which the only choice of type @@ -28,7 +39,7 @@ public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp. Each of these must then be referenced in the sparqlForExistingLiterals section of the JSON block below and in the literalsOnForm --%> - PREFIX vitro: + PREFIX vitro: <${vitroUri}> . SELECT ?urlExisting WHERE { ?link vitro:linkURL ?urlExisting } @@ -36,17 +47,17 @@ public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp. 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) --%> - @prefix vitro: . + @prefix vitro: <${vitroUri}> . ?link vitro:linkURL ?url . - PREFIX vitro: + PREFIX vitro: <${vitroUri}> . SELECT ?anchorExisting WHERE { ?link vitro:linkAnchor ?anchorExisting } - @prefix vitro: . + @prefix vitro: <${vitroUri}> . ?link vitro:linkAnchor ?anchor . @@ -54,11 +65,10 @@ public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp. the SparqlForExistingUris --%> - @prefix rdf: . - @prefix rdfs: . - @prefix vitro: . + @prefix rdf: <${rdfUri}> . + @prefix vitro: <${vitroUri}> . - ?subject vitro:additionalLink ?link . + ?subject <${predicateUri}> ?link . ?link rdf:type vitro:Link . @@ -69,7 +79,7 @@ public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp. - @prefix rdf: . + @prefix rdf: <${rdfUri}> . ?link rdf:type ?type . @@ -126,6 +136,8 @@ public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp. } <% + log.debug(request.getAttribute("editjson")); + EditConfiguration editConfig = EditConfiguration.getConfigFromSession(session,request); if( editConfig == null ){ editConfig = new EditConfiguration((String)request.getAttribute("editjson")); @@ -143,13 +155,14 @@ public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp. /* get some data to make the form more useful */ Individual subject = (Individual)request.getAttribute("subject"); - String submitLabel=""; // don't put local variables into the request - /* title is used by pre and post form fragments */ + String submitLabel=""; + String title=""; + String linkType = predicateUri.equals(VitroVocabulary.PRIMARY_LINK) ? "primary" : "additional"; if (objectUri != null) { - request.setAttribute("title", "Edit link for " + subject.getName()); + title = "Edit " + linkType + " link for " + subject.getName(); submitLabel = "Save changes"; } else { - request.setAttribute("title","Create a new link for " + subject.getName()); + title = "Create a new " + linkType + " link for " + subject.getName(); submitLabel = "Create new link"; } @@ -157,11 +170,11 @@ public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp. -

${title}

+

<%= title %>

" > - - + +

diff --git a/webapp/web/edit/forms/defaultLinkForm.new.jsp b/webapp/web/edit/forms/defaultLinkForm.new.jsp new file mode 100644 index 000000000..565dfc729 --- /dev/null +++ b/webapp/web/edit/forms/defaultLinkForm.new.jsp @@ -0,0 +1,176 @@ +<%-- $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.beans.VClass" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %> +<%@ 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.beans.DataProperty" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary" %> + +<%@ page import="java.util.List" %> + +<%@ page import="org.apache.commons.logging.Log" %> +<%@ page import="org.apache.commons.logging.LogFactory" %> + +<%@ 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.defaultLinkForm.jsp"); +%> + + + + + +<%-- Enter here any class names to be used for constructing INDIVIDUALS_VIA_VCLASS pick lists + These are then referenced in the field's ObjectClassUri but not elsewhere. + NOTE that this class may not exist in the model, in which the only choice of type + that will show up is "web page", which will insert no new statements and just create + links of type vitro:Link --%> + +<%-- Then enter a SPARQL query for each 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. + Each of these must then be referenced in the sparqlForExistingLiterals section of the JSON block below + and in the literalsOnForm --%> + + SELECT ?urlExisting + WHERE { ?link <${predicateUri}> ?urlExisting } + +<%-- 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) --%> + + ?link <${predicateUri}> ?url . + + + + PREFIX vitro: <${vitroUri}> + SELECT ?anchorExisting + WHERE { ?link vitro:linkAnchor ?anchorExisting } + + + @prefix vitro: <${vitroUri}> . + ?link vitro:linkAnchor ?anchor . + + +<%-- When not retrieving a literal via a datatype property, put the SPARQL statement into + the SparqlForExistingUris --%> + + + @prefix rdf: <${rdfUri}> . + @prefix vitro: <${vitroUri}> . + + ?subject <${predicateUri}> ?link . + + ?link rdf:type vitro:Link . + + ?link + vitro:linkURL ?url ; + vitro:linkAnchor ?anchor . + + + + + @prefix rdf: <${rdfUri}> . + + ?link rdf:type ?type . + + + + { + "formUrl" : "${formUrl}", + "editKey" : "${editKey}", + "urlPatternToReturnTo" : "/entity", + + "subject" : ["subject", "${subjectUriJson}" ], + "predicate" : ["predicate", "${predicateUriJson}" ], + "object" : ["link", "${objectUriJson}", "URI" ], + + "n3required" : [ "${n3ForEdit}" ], + "n3optional" : [ "${n3Optional}" ], + "newResources" : { }, + "urisInScope" : { }, + "literalsInScope" : { }, + "urisOnForm" : [ ], + "literalsOnForm" : [ "url", "anchor" ], + "filesOnForm" : [ ], + "sparqlForLiterals" : { }, + "sparqlForUris" : { }, + "sparqlForExistingLiterals" : { + "url" : "${urlExisting}", + "anchor" : "${anchorExisting}" + }, + "sparqlForExistingUris" : { }, + "fields" : { + "url" : { + "newResource" : "false", + "validators" : [ "nonempty" ], + "optionsType" : "UNDEFINED", + "literalOptions" : [ ], + "predicateUri" : "", + "objectClassUri" : "", + "rangeDatatypeUri" : "", + "rangeLang" : "", + "assertions" : [ "${urlAssertion}" ] + }, + "anchor" : { + "newResource" : "false", + "validators" : [ "nonempty" ], + "optionsType" : "UNDEFINED", + "literalOptions" : [ ], + "predicateUri" : "", + "objectClassUri" : "", + "rangeDatatypeUri" : "", + "rangeLang" : "", + "assertions" : [ "${anchorAssertion}" ] + } + } + } + +<% + log.debug(request.getAttribute("editjson")); + + EditConfiguration editConfig = EditConfiguration.getConfigFromSession(session,request); + if( editConfig == null ){ + editConfig = new EditConfiguration((String)request.getAttribute("editjson")); + EditConfiguration.putConfigInSession(editConfig, session); + } + + + Model model = (Model)application.getAttribute("jenaOntModel"); + String objectUri = (String)request.getAttribute("objectUri"); + if( objectUri != null ){ + editConfig.prepareForObjPropUpdate(model); + }else{ + editConfig.prepareForNonUpdate(model); + } + + /* get some data to make the form more useful */ + Individual subject = (Individual)request.getAttribute("subject"); + + String submitLabel=""; + String title = ""; + if (objectUri != null) { + title = "Edit url for " + subject.getName(); + submitLabel = "Save changes"; + } else { + title = "Create a new url for " + subject.getName(); + submitLabel = "Create new url"; + } + +%> + + + +

<%= title %>

+
" > + +
+ + + + diff --git a/webapp/web/edit/forms/defaultVitroNsPropForm.jsp b/webapp/web/edit/forms/defaultVitroNsDataPropForm.jsp similarity index 100% rename from webapp/web/edit/forms/defaultVitroNsPropForm.jsp rename to webapp/web/edit/forms/defaultVitroNsDataPropForm.jsp diff --git a/webapp/web/templates/entity/entityBasic.jsp b/webapp/web/templates/entity/entityBasic.jsp index 449b6fce7..a6d9db8e7 100644 --- a/webapp/web/templates/entity/entityBasic.jsp +++ b/webapp/web/templates/entity/entityBasic.jsp @@ -149,11 +149,19 @@ RY Description not working - FIX <%-- Links --%> - -