<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> <%@ page import="java.util.List" %> <%@ page import="java.util.ArrayList" %> <%@ page import="java.util.Arrays" %> <%@ page import="com.hp.hpl.jena.rdf.model.Literal"%> <%@ 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.edit.n3editing.StartYearBeforeEndYear"%> <%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.PersonHasPositionValidator"%> <%@ 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.personHasPositionHistory.jsp"); %> <% VitroRequest vreq = new VitroRequest(request); WebappDaoFactory wdf = vreq.getWebappDaoFactory(); vreq.setAttribute("defaultNamespace", ""); //empty string triggers default new URI behavior request.setAttribute("stringDatatypeUriJson", MiscWebUtils.escape(XSD.xstring.toString())); request.setAttribute("gYearDatatypeUriJson", MiscWebUtils.escape(XSD.gYear.toString())); %> <%-- 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 ?titleExisting WHERE { ?positionUri <${titlePred}> ?titleExisting } <%-- 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) --%> ?positionUri <${titlePred}> ?title ; <${label}> ?title. SELECT ?startYearExisting WHERE { ?positionUri <${startYearPred}> ?startYearExisting } ?positionUri <${startYearPred}> ?startYear . SELECT ?endYearExisting WHERE { ?positionUri <${endYearPred}> ?endYearExisting } ?positionUri <${endYearPred}> ?endYear . <%-- Note there is really no difference in how things are set up for an object property except below in the n3ForEdit section, in whether the ..Existing variable goes in SparqlForExistingLiterals or in the SparqlForExistingUris, as well as perhaps in how the options are prepared --%> SELECT ?existingOrgUri WHERE { ?positionUri <${positionInOrgPred}> ?existingOrgUri } ?positionUri <${positionInOrgPred}> ?organizationUri . ?organizationUri <${orgForPositionPred}> ?positionUri . SELECT ?existingPositionType WHERE { ?positionUri a ?existingPositionType } ?positionUri a ?positionType . ?newOrg <${label}> ?newOrgName . ?newOrg a ?newOrgType . @prefix core: <${vivoCore}> . ?person core:personInPosition ?positionUri . ?positionUri core:positionForPerson ?person ; a ?positionType . ?positionUri <${positionInOrgPred}> ?newOrg . ?newOrg <${label}> ?newOrgName ; a ?newOrgType ; <${orgForPositionPred}> ?positionUri . ${positionClass} ${orgClass} { "formUrl" : "${formUrl}", "editKey" : "${editKey}", "urlPatternToReturnTo" : "/entity", "subject" : ["person", "${subjectUriJson}" ], "predicate" : ["predicate", "${predicateUriJson}" ], "object" : ["positionUri", "${objectUriJson}", "URI" ], "n3required" : [ "${n3ForStmtToPerson}", "${titleAssertion}", "${startYearAssertion}" ], "n3optional" : [ "${organizationUriAssertion}", "${n3ForNewOrg}", "${newOrgNameAssertion}", "${newOrgTypeAssertion}", "${endYearAssertion}"], "newResources" : { "positionUri" : "${defaultNamespace}", "newOrg" : "${defaultNamespace}" }, "urisInScope" : { }, "literalsInScope": { }, "urisOnForm" : [ "organizationUri", "newOrgType", "positionType" ], "literalsOnForm" : [ "title", "newOrgName", "startYear", "endYear" ], "filesOnForm" : [ ], "sparqlForLiterals" : { }, "sparqlForUris" : { }, "sparqlForExistingLiterals" : { "title" : "${titleExisting}", "startYear" : "${startYearExisting}", "endYear" : "${endYearExisting}" }, "sparqlForExistingUris" : { "organizationUri" : "${organizationUriExisting}", "positionType" : "${positionTypeExisting}" }, "fields" : { "title" : { "newResource" : "false", "validators" : [ "nonempty" ], "optionsType" : "UNDEFINED", "literalOptions" : [ ], "predicateUri" : "", "objectClassUri" : "", "rangeDatatypeUri" : "${stringDatatypeUriJson}", "rangeLang" : "", "assertions" : [ "${titleAssertion}" ] }, "positionType" : { "newResource" : "false", "validators" : [ "nonempty" ], "optionsType" : "CHILD_VCLASSES_WITH_PARENT", "literalOptions" : [ "Select one" ], "predicateUri" : "", "objectClassUri" : "${positionClassUriJson}", "rangeDatatypeUri" : "", "rangeLang" : "", "assertions" : [ "${positionTypeAssertion}" ] }, "organizationUri" : { "newResource" : "false", "validators" : [ ], "optionsType" : "INDIVIDUALS_VIA_VCLASS", "literalOptions" : [ "Select one" ], "predicateUri" : "", "objectClassUri" : "${orgClassUriJson}", "rangeDatatypeUri" : "", "rangeLang" : "", "assertions" : [ "${organizationUriAssertion}" ] }, "newOrgName" : { "newResource" : "false", "validators" : [ ], "optionsType" : "UNDEFINED", "literalOptions" : [ ], "predicateUri" : "", "objectClassUri" : "", "rangeDatatypeUri" : "${stringDatatypeUriJson}", "rangeLang" : "", "assertions" : [ "${n3ForNewOrg}" ] }, "newOrgType" : { "newResource" : "false", "validators" : [ ], "optionsType" : "CHILD_VCLASSES", "literalOptions" : [ "Select one" ], "predicateUri" : "", "objectClassUri" : "${orgClassUriJson}", "rangeDatatypeUri" : "", "rangeLang" : "", "assertions" : [ "${newOrgTypeAssertion}" ] }, "startYear" : { "newResource" : "false", "validators" : [ "nonempty", "datatype:${gYearDatatypeUriJson}" ], "optionsType" : "UNDEFINED", "literalOptions" : [ ], "predicateUri" : "", "objectClassUri" : "", "rangeDatatypeUri" : "${gYearDatatypeUriJson}", "rangeLang" : "", "assertions" : ["${startYearAssertion}"] }, "endYear" : { "newResource" : "false", "validators" : [ "datatype:${gYearDatatypeUriJson}" ], "optionsType" : "UNDEFINED", "literalOptions" : [ ], "predicateUri" : "", "objectClassUri" : "", "rangeDatatypeUri" : "${gYearDatatypeUriJson}", "rangeLang" : "", "assertions" : ["${endYearAssertion}"] } } } <% 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); } editConfig.addValidator(new PersonHasPositionValidator() ); editConfig.addValidator(new StartYearBeforeEndYear("startYear","endYear") ); Model model = (Model) application.getAttribute("jenaOntModel"); String objectUri = (String) request.getAttribute("objectUri"); if (objectUri != null) { // editing existing editConfig.prepareForObjPropUpdate(model); } else { // adding new editConfig.prepareForNonUpdate(model); } String subjectName = ((Individual) request.getAttribute("subject")).getName(); %> <% if (objectUri != null) { // editing existing entry %> <%-- NB This will be the button text when Javascript is disabled. --%> <% } else { // adding new entry %> <%-- NB This will be the button text when Javascript is disabled. --%> <% } List customJs = new ArrayList(Arrays.asList("/js/utils.js", "/js/customFormUtils.js", "/edit/forms/js/customForm.js" //, "/edit/forms/js/customFormTwoStep.js" )); request.setAttribute("customJs", customJs); List customCss = new ArrayList(Arrays.asList("/edit/forms/css/customForm.css" , "/edit/forms/css/personHasPositionHistory.css" )); request.setAttribute("customCss", customCss); %>

${title}

" >
or
Add a New Organization

<%-- RY If set steps to 1 when editType == 'edit', may be able to combine the step 1 and edit cases in the Javascript. --%>

* required fields