<%-- $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.beans.ObjectProperty"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Css" %> <%@ 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"%> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%> <%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %> <%-- This form is for the object property between Organizations and Positions. --%> <% VitroRequest vreq = new VitroRequest(request); WebappDaoFactory wdf = vreq.getWebappDaoFactory(); vreq.setAttribute("defaultNamespace", ""); //empty string triggers default new URI behavior %> <%-- Define predicates used in n3 assertions and sparql queries --%> http://xmlns.com/foaf/0.1/Person <%-- 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 <${label}> ?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 <${label}> ?title. <%-- 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 ?existingPersonUri WHERE { ?positionUri <${positionForPerson}> ?existingPersonUri } ?positionUri <${positionForPerson}> ?personUri . ?personUri <${personInPosition}> ?positionUri . ?organizationUri <${orgForPositionPred}> ?positionUri . ?positionUri <${positionInOrgPred}> ?organizationUri . ?positionUri <${type}> <${positionType}> . ?positionUri <${positionToInterval}> ?intervalNode . ?intervalNode <${type}> <${intervalType}> . ?intervalNode <${intervalToStart}> ?startNode . ?startNode <${type}> <${dateTimeValueType}> . ?startNode <${dateTimeValue}> ?startField.value . ?startNode <${dateTimePrecision}> ?startField.precision . ?positionUri <${positionToInterval}> ?intervalNode . ?intervalNode <${type}> <${intervalType}> . ?intervalNode <${intervalToEnd}> ?endNode . ?endNode <${type}> <${dateTimeValueType}> . ?endNode <${dateTimeValue}> ?endField.value . ?endNode <${dateTimePrecision}> ?endField.precision . SELECT ?existingIntervalNode WHERE { ?positionUri <${positionToInterval}> ?existingIntervalNode . ?existingIntervalNode <${type}> <${intervalType}> . } SELECT ?existingStartNode WHERE { ?positionUri <${positionToInterval}> ?intervalNode . ?intervalNode <${type}> <${intervalType}> . ?intervalNode <${intervalToStart}> ?existingStartNode . ?existingStartNode <${type}> <${dateTimeValueType}> .} SELECT ?existingDateStart WHERE { ?positionUri <${positionToInterval}> ?intervalNode . ?intervalNode <${type}> <${intervalType}> . ?intervalNode <${intervalToStart}> ?startNode . ?startNode <${type}> <${dateTimeValueType}> . ?startNode <${dateTimeValue}> ?existingDateStart . } SELECT ?existingStartPrecision WHERE { ?positionUri <${positionToInterval}> ?intervalNode . ?intervalNode <${type}> <${intervalType}> . ?intervalNode <${intervalToStart}> ?startNode . ?startNode <${type}> <${dateTimeValueType}> . ?startNode <${dateTimePrecision}> ?existingStartPrecision . } SELECT ?existingEndNode WHERE { ?positionUri <${positionToInterval}> ?intervalNode . ?intervalNode <${type}> <${intervalType}> . ?intervalNode <${intervalToEnd}> ?existingEndNode . ?existingEndNode <${type}> <${dateTimeValueType}> .} SELECT ?existingEndDate WHERE { ?positionUri <${positionToInterval}> ?intervalNode . ?intervalNode <${type}> <${intervalType}> . ?intervalNode <${intervalToEnd}> ?endNode . ?endNode <${type}> <${dateTimeValueType}> . ?endNode <${dateTimeValue}> ?existingEndDate . } SELECT ?existingEndPrecision WHERE { ?positionUri <${positionToInterval}> ?intervalNode . ?intervalNode <${type}> <${intervalType}> . ?intervalNode <${intervalToEnd}> ?endNode . ?endNode <${type}> <${dateTimeValueType}> . ?endNode <${dateTimePrecision}> ?existingEndPrecision . } { "formUrl" : "${formUrl}", "editKey" : "${editKey}", "urlPatternToReturnTo" : "/entity", "subject" : ["organizationUri", "${subjectUriJson}" ], "predicate" : ["predicate", "${predicateUriJson}" ], "object" : ["positionUri", "${objectUriJson}", "URI" ], "n3required" : [ "${n3ForStmtToOrg}", "${titleAssertion}" , "${personUriAssertion}"], "n3optional" : [ "${n3ForStart}" , "${n3ForEnd}" ], "newResources" : { "positionUri" : "${defaultNamespace}", "intervalNode" : "${defaultNamespace}", "startNode" : "${defaultNamespace}", "endNode" : "${defaultNamespace}" }, "urisInScope" : { }, "literalsInScope": { }, "urisOnForm" : [ "personUri" ], "literalsOnForm" : [ "title", "startYear", "endYear" ], "filesOnForm" : [ ], "sparqlForLiterals" : { }, "sparqlForUris" : { }, "sparqlForExistingLiterals" : { "title" : "${titleExisting}", "startField.value" : "${existingStartDateQuery}", "endField.value" : "${existingEndDateQuery}" }, "sparqlForExistingUris" : { "personUri" : "${personUriExisting}", "intervalNode" : "${existingIntervalNodeQuery}", "startNode" : "${existingStartNodeQuery}", "endNode" : "${existingEndNodeQuery}", "startField.precision": "${existingStartPrecisionQuery}", "endField.precision" : "${existingEndPrecisionQuery}" }, "fields" : { "title" : { "newResource" : "false", "validators" : [ "nonempty" ], "optionsType" : "UNDEFINED", "literalOptions" : [ ], "predicateUri" : "", "objectClassUri" : "", "rangeDatatypeUri" : "", "rangeLang" : "", "assertions" : [ "${titleAssertion}" ] }, "personUri" : { "newResource" : "false", "validators" : [ "nonempty" ], "optionsType" : "INDIVIDUALS_VIA_VCLASS", "literalOptions" : [ ], "predicateUri" : "", "objectClassUri" : "${personClassUri}", "rangeDatatypeUri" : "", "rangeLang" : "", "assertions" : [ "${personUriAssertion}" ] }, "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); } else { editConfig.prepareForNonUpdate(model); } List customCss = new ArrayList(Arrays.asList(Css.CUSTOM_FORM.path() )); request.setAttribute("customCss", customCss); /* prepare the and text for the submit button */ Individual subject = (Individual) request.getAttribute("subject"); String submitLabel = ""; if (objectUri != null) { request.setAttribute("title","Edit position history entry for "+ subject.getName()); submitLabel = "Save changes"; } else { request.setAttribute("title","Create position history entry for " + subject.getName()); submitLabel = "Create position history entry"; } %> <jsp:include page="${preForm}"/> <h2>${title}</h2> <form class="customForm" action="<c:url value="/edit/processRdfForm2.jsp"/>" > <v:input type="text" label="title" id="title" size="30"/> <v:input type="select" label="person" id="personUri" /> <v:input id="startField" label="Start Year <span class='hint'>(YYYY)</span>" /> <v:input id="endField" label="End Year <span class='hint'>(YYYY)</span>" /> <p class="submit"><v:input type="submit" id="submit" value="<%=submitLabel%>" cancel="true"/></p> </form> <jsp:include page="${postForm}"/>