From 2d9a10ccea7c62680aec3c41d729f2fec23ed28f Mon Sep 17 00:00:00 2001 From: rjy7 Date: Mon, 5 Apr 2010 14:30:49 +0000 Subject: [PATCH] NIHVIVO-195 Working on custom activity forms. Markup is screwed up and form doesn't submit yet. --- productMods/edit/forms/personHasActivity.jsp | 310 +++++++++++++++++++ 1 file changed, 310 insertions(+) create mode 100644 productMods/edit/forms/personHasActivity.jsp diff --git a/productMods/edit/forms/personHasActivity.jsp b/productMods/edit/forms/personHasActivity.jsp new file mode 100644 index 00000000..43922aaf --- /dev/null +++ b/productMods/edit/forms/personHasActivity.jsp @@ -0,0 +1,310 @@ +<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> + +<%-- Custom form for research, teaching, service, and outreach activities --%> + +<%@ 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.utils.TitleCase" %> + +<%@ 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 + + String flagURI = null; + if (vreq.getAppBean().isFlag1Active()) { + flagURI = VitroVocabulary.vitroURI+"Flag1Value"+vreq.getPortal().getPortalId()+"Thing"; + } else { + flagURI = wdf.getVClassDao().getTopConcept().getURI(); // fall back to owl:Thing if not portal filtering + } + vreq.setAttribute("flagURI",flagURI); + + request.setAttribute("stringDatatypeUriJson", MiscWebUtils.escape(XSD.xstring.toString())); + request.setAttribute("gYearMonthDatatypeUriJson", MiscWebUtils.escape(XSD.gYearMonth.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 ?existingLabel WHERE { + ?activityUri <${label}> ?existingLabel } + + +<%-- 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) --%> + + ?activityUri <${label}> ?label . + + + + + SELECT ?existingDescription WHERE { + ?activityUri <${descriptionUri}> ?existingDescription } + + + ?activityUri <${descriptionUri}> ?description . + + + + + SELECT ?existingRole WHERE { + ?activityUri <${roleUri}> ?existingRole } + + + ?activityUri <${roleUri}> ?role . + + + + + SELECT ?existingStartYearMonth WHERE { + ?activityUri <${startYearMonthUri}> ?existingStartYearMonth } + + + ?activityUri <${startYearMonthUri}> ?startYearMonth . + + + + + SELECT ?existingEndYearMonth WHERE { + ?activityUri <${endYearMonthUri}> ?existingEndYearMonth } + + + ?activityUri <${endYearMonthUri}> ?endYearMonth . + + + + + ?activityUri <${label}> ?label ; + a <${predicateUri}> ; + a <${activityUri} ; + a <${flagUri} ; + <${inverseUri}> ?person ; + <${inverseActivityUri}> ?person . + + ?person <${predicateUri}> ?activityUri ; + <${activityUri}> ?activityUri . + s + + + + { + "formUrl" : "${formUrl}", + "editKey" : "${editKey}", + "urlPatternToReturnTo" : "/entity", + + "subject" : ["person", "${subjectUriJson}" ], + "predicate" : ["predicate", "${predicateUriJson}" ], + "object" : ["activityUri", "${objectUriJson}", "URI" ], + + "n3required" : [ "${n3ForStmtToPerson}", "${labelAssertion}", "${descriptionAssertion}", "${roleAssertion}" ], + + "n3optional" : [ "${startYearMonthAssertion}", "${endYearMonthAssertion}" ], + + "newResources" : { "activityUri" : "${defaultNamespace}" }, + + "urisInScope" : { }, + "literalsInScope": { }, + "urisOnForm" : [ "activityUri"], + "literalsOnForm" : [ "name", "description", "role", "startYearMonth", "endYearMonth" ], + "filesOnForm" : [ ], + "sparqlForLiterals" : { }, + "sparqlForUris" : { }, + "sparqlForExistingLiterals" : { + "name" : "${labelExisting}", + "description" : "${descriptionExisting}", + "role" : "${roleExisting}", + "startYearMonth" : "${startYearMonthExisting}", + "endYearMonth" : "${endYearMonthExisting}", + }, + "sparqlForExistingUris" : { }, + + "fields" : { + "name" : { + "newResource" : "false", + "validators" : [ "nonempty" ], + "optionsType" : "UNDEFINED", + "literalOptions" : [ ], + "predicateUri" : "", + "objectClassUri" : "", + "rangeDatatypeUri" : "${stringDatatypeUriJson}", + "rangeLang" : "", + "assertions" : [ "${labelAssertion}" ] + }, + "description" : { + "newResource" : "false", + "validators" : [ "nonempty" ], + "optionsType" : "UNDEFINED", + "literalOptions" : [ ], + "predicateUri" : "", + "objectClassUri" : "", + "rangeDatatypeUri" : "${stringDatatypeUriJson}", + "rangeLang" : "", + "assertions" : [ "${descriptionAssertion}" ] + }, + "role" : { + "newResource" : "false", + "validators" : [ "nonempty" ], + "optionsType" : "UNDEFINED", + "literalOptions" : [ ], + "predicateUri" : "", + "objectClassUri" : "", + "rangeDatatypeUri" : "${stringDatatypeUriJson}", + "rangeLang" : "", + "assertions" : [ "${descriptionAssertion}" ] + }, + "startYearMonth" : { + "newResource" : "false", + "validators" : [ "datatype:${gYearMonthDatatypeUriJson}" ], + "optionsType" : "UNDEFINED", + "literalOptions" : [ ], + "predicateUri" : "", + "objectClassUri" : "", + "rangeDatatypeUri" : "${gYearMonthDatatypeUriJson}", + "rangeLang" : "", + "assertions" : ["${startYearMonthAssertion}"] + }, + "endYearMonth" : { + "newResource" : "false", + "validators" : [ "datatype:${gYearMonthDatatypeUriJson}" ], + "optionsType" : "UNDEFINED", + "literalOptions" : [ ], + "predicateUri" : "", + "objectClassUri" : "", + "rangeDatatypeUri" : "${gYearMonthDatatypeUriJson}", + "rangeLang" : "", + "assertions" : ["${endYearMonthAssertion}"] + } + } +} + +<% + 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) { // editing existing + editConfig.prepareForObjPropUpdate(model); + } else { // adding new + editConfig.prepareForNonUpdate(model); + } + + String subjectName = ((Individual) request.getAttribute("subject")).getName(); +%> + +

+ + + + + + + + + + + + + + +<% + // RY put propertyName in page context instead, and get a PageContext object + String propName = (String)request.getAttribute("propertyName"); + vreq.setAttribute("submitPropertyName", TitleCase.toTitleCase(propName)); + + if (objectUri != null) { // editing existing entry +%> + + +<% + } else { // adding new entry +%> + + +<% } + + + List customCss = new ArrayList(Arrays.asList("forms/css/customForm.css" + )); + request.setAttribute("customCss", customCss); +%> + + + + + + +

${title}

+ +
" > + + + + + + + + +

+ +

* required fields

+ + + +