<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> <%-- Custom form for adding a grant to an person for the predicates hasCo-PrincipalInvestigatorRole and hasPrincipalInvestigatorRole. This is intended to create a set of statements like: ?person core:hasPrincipalInvestigatorRole ?newRole. ?newRole rdf:type core:PrincipalInvestigatorRole ; core:relatedRole ?someGrant . --%> <%@ page import="java.util.List" %> <%@ page import="java.util.ArrayList" %> <%@ page import="java.util.Arrays" %> <%@ page import="com.hp.hpl.jena.rdf.model.Model" %> <%@ page import="com.hp.hpl.jena.vocabulary.XSD" %> <%@ 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.web.MiscWebUtils" %> <%@ 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.edit.n3editing.StartYearBeforeEndYear"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils.EditMode"%> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%> <%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %> <% VitroRequest vreq = new VitroRequest(request); WebappDaoFactory wdf = vreq.getWebappDaoFactory(); vreq.setAttribute("defaultNamespace", ""); //empty string triggers default new URI behavior vreq.setAttribute("stringDatatypeUriJson", MiscWebUtils.escape(XSD.xstring.toString())); String intDatatypeUri = XSD.xint.toString(); vreq.setAttribute("intDatatypeUri", intDatatypeUri); vreq.setAttribute("intDatatypeUriJson", MiscWebUtils.escape(intDatatypeUri)); vreq.setAttribute("gYearDatatypeUriJson", MiscWebUtils.escape(XSD.gYear.toString())); String predicateUri = (String)request.getAttribute("predicateUri"); ObjectProperty op = wdf.getObjectPropertyDao().getObjectPropertyByURI( predicateUri ); if( op != null && op.getURIInverse() != null ){ %> <%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.Field"%> <%@page import="edu.cornell.mannlib.vitro.webapp.edit.elements.DateTimeWithPrecision"%> <%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.DateTimeIntervalValidation"%><%=op.getURIInverse()%> <% }else{ %> <% } /* There are 4 modes that this form can be in: 1. Add, there is a subject and a predicate but no role and nothing else. 2. normal edit where everything should already be filled out. There is a subject, a object and an individual on the other end of the object's core:roleIn stmt. 3. Repair a bad role node. There is a subject, prediate and object but there is no individual on the other end of the object's core:roleIn stmt. This should be similar to an add but the form should be expanded. 4. Really bad node. multiple core:roleIn statements. */ EditMode mode = FrontEndEditingUtils.getEditMode(request, "http://vivoweb.org/ontology/core#roleIn"); if( mode == EditMode.ADD ) { %> <% } else if(mode == EditMode.EDIT){ %> <% } else if(mode == EditMode.REPAIR){ %> <% } %> %> <%@page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty"%> <% // set role type based on predicate String subjectName = ((Individual) request.getAttribute("subject")).getName(); if ( ((String)request.getAttribute("predicateUri")).endsWith("hasPrincipalInvestigatorRole") ) { %> http://vivoweb.org/ontology/core#PrincipalInvestigatorRole Principal Investigator principal investigator entry for <%= subjectName %> <% }else if ( ((String)request.getAttribute("predicateUri")).endsWith("hasCo-PrincipalInvestigatorRole") ) { %> http://vivoweb.org/ontology/core#CoPrincipalInvestigatorRole Co-Principal Investigator co-principal investigator entry for <%= subjectName %> <% }else { %> http://vivoweb.org/ontology/core#InvestigatorRole Investigator investigator entry for <%= subjectName %> <% } %> <%-- Configure add vs. edit --%> <%-- editMode == "repair" --%> @prefix core: <${vivoCore}> . @prefix rdf: <${rdf}> . ?person ?rolePredicate ?role. ?role a ?roleType ; core:roleIn ?grant . ?grant a core:Grant ; core:relatedRole ?role . ?role ?inverseRolePredicate ?person. ?role <${roleToInterval}> ?intervalNode . ?intervalNode <${type}> <${intervalType}> . ?intervalNode <${intervalToStart}> ?startNode . ?startNode <${type}> <${dateTimeValueType}> . ?startNode <${dateTimeValue}> ?startField.value . ?startNode <${dateTimePrecision}> ?startField.precision . ?role <${roleToInterval}> ?intervalNode . ?intervalNode <${type}> <${intervalType}> . ?intervalNode <${intervalToEnd}> ?endNode . ?endNode <${type}> <${dateTimeValueType}> . ?endNode <${dateTimeValue}> ?endField.value . ?endNode <${dateTimePrecision}> ?endField.precision . @prefix rdfs: <${rdfs}> . ?grant rdfs:label ?grantLabel . PREFIX core: <${vivoCore}> PREFIX rdfs: <${rdfs}> SELECT ?existingGrantLabel WHERE { ?role core:roleIn ?existingGrant . ?existingGrant rdfs:label ?existingGrantLabel . } PREFIX core: <${vivoCore}> SELECT ?existingGrant WHERE { ?role core:roleIn ?existingGrant . } ${vivoOnt}#Grant SELECT ?existingIntervalNode WHERE { ?role <${roleToInterval}> ?existingIntervalNode . ?existingIntervalNode <${type}> <${intervalType}> . } SELECT ?existingStartNode WHERE { ?role <${roleToInterval}> ?intervalNode . ?intervalNode <${type}> <${intervalType}> . ?intervalNode <${intervalToStart}> ?existingStartNode . ?existingStartNode <${type}> <${dateTimeValueType}> .} SELECT ?existingDateStart WHERE { ?role <${roleToInterval}> ?intervalNode . ?intervalNode <${type}> <${intervalType}> . ?intervalNode <${intervalToStart}> ?startNode . ?startNode <${type}> <${dateTimeValueType}> . ?startNode <${dateTimeValue}> ?existingDateStart . } SELECT ?existingStartPrecision WHERE { ?role <${roleToInterval}> ?intervalNode . ?intervalNode <${type}> <${intervalType}> . ?intervalNode <${intervalToStart}> ?startNode . ?startNode <${type}> <${dateTimeValueType}> . ?startNode <${dateTimePrecision}> ?existingStartPrecision . } SELECT ?existingEndNode WHERE { ?role <${roleToInterval}> ?intervalNode . ?intervalNode <${type}> <${intervalType}> . ?intervalNode <${intervalToEnd}> ?existingEndNode . ?existingEndNode <${type}> <${dateTimeValueType}> .} SELECT ?existingEndDate WHERE { ?role <${roleToInterval}> ?intervalNode . ?intervalNode <${type}> <${intervalType}> . ?intervalNode <${intervalToEnd}> ?endNode . ?endNode <${type}> <${dateTimeValueType}> . ?endNode <${dateTimeValue}> ?existingEndDate . } SELECT ?existingEndPrecision WHERE { ?role <${roleToInterval}> ?intervalNode . ?intervalNode <${type}> <${intervalType}> . ?intervalNode <${intervalToEnd}> ?endNode . ?endNode <${type}> <${dateTimeValueType}> . ?endNode <${dateTimePrecision}> ?existingEndPrecision . } { "formUrl" : "${formUrl}", "editKey" : "${editKey}", "urlPatternToReturnTo" : "/individual", "subject" : ["person", "${subjectUriJson}" ], "predicate" : ["rolePredicate", "${predicateUriJson}" ], "object" : ["role", "${objectUriJson}", "URI" ], "n3required" : [ "${n3ForGrantRole}" ], "n3optional" : [ "${n3ForGrantLabel}", "${n3ForInverse}", "${n3ForStart}", "${n3ForEnd}" ], "newResources" : { "role" : "${defaultNamespace}", "grant" : "${defaultNamespace}", "intervalNode" : "${defaultNamespace}", "startNode" : "${defaultNamespace}", "endNode" : "${defaultNamespace}" }, "urisInScope" : { "roleType" : "${roleType}", "inverseRolePredicate" : "${inversePredicate}" }, "literalsInScope": { }, "urisOnForm" : [ "grant" ], "literalsOnForm" : [ "grantLabel", "existingGrantLabel" ], "filesOnForm" : [ ], "sparqlForLiterals" : { }, "sparqlForUris" : { }, "sparqlForExistingLiterals" : { "grantLabel":"${grantLabelQuery}" , "startField.value" : "${existingStartDateQuery}", "endField.value" : "${existingEndDateQuery}" }, "sparqlForExistingUris" : { "grant":"${grantQuery}", "intervalNode" : "${existingIntervalNodeQuery}", "startNode" : "${existingStartNodeQuery}", "endNode" : "${existingEndNodeQuery}", "startField.precision": "${existingStartPrecisionQuery}", "endField.precision" : "${existingEndPrecisionQuery}" }, "fields" : { "grant" : { "newResource" : "false", "validators" : [ ], "optionsType" : "UNDEFINED", "literalOptions" : [ ], "predicateUri" : "", "objectClassUri" : "${grantTypeUriJson}", "rangeDatatypeUri" : "", "rangeLang" : "", "assertions" : [ "${n3ForGrantRole}" ] }, "grantLabel" : { "newResource" : "false", "validators" : [ ${labelRequired} "datatype:${stringDatatypeUriJson}" ], "optionsType" : "UNDEFINED", "literalOptions" : [ ], "predicateUri" : "", "objectClassUri" : "", "rangeDatatypeUri" : "${stringDatatypeUriJson}", "rangeLang" : "", "assertions" : ["${n3ForGrantLabel}", "${n3ForGrantRole}" ] }, "existingGrantLabel" : { /* Needed iff we return from an invalid submission */ "newResource" : "false", "validators" : [ ], "optionsType" : "UNDEFINED", "literalOptions" : [ ], "predicateUri" : "", "objectClassUri" : "", "rangeDatatypeUri" : "", "rangeLang" : "", "assertions" : [ ] }, "startField" : { "newResource" : "false", "validators" : [ ], "optionsType" : "UNDEFINED", "literalOptions" : [ ], "predicateUri" : "", "objectClassUri" : "", "rangeDatatypeUri" : "", "rangeLang" : "", "assertions" : [ "${n3ForStart}" ] }, "endField" : { "newResource" : "false", "validators" : [ ], "optionsType" : "UNDEFINED", "literalOptions" : [ ], "predicateUri" : "", "objectClassUri" : "", "rangeDatatypeUri" : "", "rangeLang" : "", "assertions" : ["${n3ForEnd}" ] } } } <% EditConfiguration editConfig = EditConfiguration.getConfigFromSession(session,request); if (editConfig == null) { editConfig = new EditConfiguration((String) request.getAttribute("editjson")); EditConfiguration.putConfigInSession(editConfig,session); //setup date time edit elements Field startField = editConfig.getField("startField"); startField.setEditElement( new DateTimeWithPrecision(startField, VitroVocabulary.Precision.YEAR.uri(), VitroVocabulary.Precision.NONE.uri())); Field endField = editConfig.getField("endField"); endField.setEditElement( new DateTimeWithPrecision(endField, VitroVocabulary.Precision.YEAR.uri(), VitroVocabulary.Precision.NONE.uri())); editConfig.addValidator(new DateTimeIntervalValidation("startField","endField") ); } Model model = (Model) application.getAttribute("jenaOntModel"); String objectUri = (String) request.getAttribute("objectUri"); if (objectUri != null) { editConfig.prepareForObjPropUpdate(model); // Return browser to person individual after editing an existing role. } else { editConfig.prepareForNonUpdate(model); // NIHVIVO-1014 Return browser to person individual after editing an existing role. // Return the browser to the new activity entity after adding a new role. // editConfig.setEntityToReturnTo("?grant"); } String subjectUri = vreq.getParameter("subjectUri"); List customJs = new ArrayList(Arrays.asList(JavaScript.JQUERY_UI.path(), JavaScript.CUSTOM_FORM_UTILS.path(), "/js/browserUtils.js", "/edit/forms/js/customFormWithAutocomplete.js" )); request.setAttribute("customJs", customJs); List customCss = new ArrayList(Arrays.asList(Css.JQUERY_UI.path(), Css.CUSTOM_FORM.path(), "/edit/forms/css/customFormWithAutocomplete.css" )); request.setAttribute("customCss", customCss); %> <% if( mode == EditMode.ERROR ){ %>
This form is unable to handle the editing of this position because it is associated with multiple Position individuals.
<% }else{ %>

${formHeading}

<%@ include file="unsupportedBrowserMessage.jsp" %> <%-- DO NOT CHANGE IDS, CLASSES, OR HTML STRUCTURE IN THIS FORM WITHOUT UNDERSTANDING THE IMPACT ON THE JAVASCRIPT! --%>
" >

<%-- Store this value in a hidden field, because the displayed field is disabled and doesn't submit. This ensures that when returning from a validation error, we retain the value. --%>

(Verify this match)

<%-- Field value populated by JavaScript --%> <%-- Needed iff we return from an invalid submission --%>

Years of Participation in Grant

* required fields

<%-- Must be all one line for JavaScript. --%> PREFIX core: <${vivoCore}> SELECT ?grantUri WHERE {<${subjectUri}> <${predicateUri}> ?grantRole . ?grantRole core:roleIn ?grantUri .} <% } %>