NIHVIVO-195 Working on custom activity forms. Markup is screwed up and form doesn't submit yet.

This commit is contained in:
rjy7 2010-04-05 14:30:49 +00:00
parent 5a1abfdb5e
commit 2d9a10ccea

View file

@ -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()));
%>
<c:set var="vivoCore" value="http://vivoweb.org/ontology/core#" />
<c:set var="rdfs" value="<%= VitroVocabulary.RDFS %>" />
<c:set var="label" value="${rdfs}label" />
<c:set var="researchActivityUri" value="${vivoCore}hasResearchActivity" />
<c:set var="teachingActivityUri" value="${vivoCore}hasTeachingActivity" />
<c:set var="serviceActivityUri" value="${vivoCore}professionalServiceActivity" />
<c:set var="outreachActivityUri" value="${vivoCore}hasOutreachActivity" />
<c:choose>
<c:when test="${predicateUri == researchActivityUri}">
<c:set var="inverseUri" value="${vivoCore}researchActivityBy" scope="page" />
</c:when>
<c:when test="${predicateUri == teachingActivityUri}">
<c:set var="inverseUri" value="${vivoCore}teachingActivityBy" scope="page" />
</c:when>
<c:when test="${predicateUri == serviceActivityUri}">
<c:set var="inverseUri" value="${vivoCore}professionalServiceActivityBy" scope="page" />
</c:when>
<c:when test="${predicateUri == outreachActivityUri}">
<c:set var="inverseUri" value="${vivoCore}outreachActivityBy" scope="page" />
</c:when>
</c:choose>
<c:set var="activityUri" value="${vivoCore}hasActivity" />
<c:set var="inverseActivityUri" value="${vivoCore}activityBy" />
<%-- 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 --%>
<v:jsonset var="labelExisting" >
SELECT ?existingLabel WHERE {
?activityUri <${label}> ?existingLabel }
</v:jsonset>
<%-- 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) --%>
<v:jsonset var="labelAssertion" >
?activityUri <${label}> ?label .
</v:jsonset>
<c:set var="descriptionUri" value="${vivoCore}description" />
<v:jsonset var="descriptionExisting" >
SELECT ?existingDescription WHERE {
?activityUri <${descriptionUri}> ?existingDescription }
</v:jsonset>
<v:jsonset var="descriptionAssertion" >
?activityUri <${descriptionUri}> ?description .
</v:jsonset>
<c:set var="roleUri" value="${vivoCore}role" />
<v:jsonset var="roleExisting" >
SELECT ?existingRole WHERE {
?activityUri <${roleUri}> ?existingRole }
</v:jsonset>
<v:jsonset var="roleAssertion" >
?activityUri <${roleUri}> ?role .
</v:jsonset>
<c:set var="startYearMonthUri" value="${vivoCore}startYearMonth" />
<v:jsonset var="startYearMonthExisting" >
SELECT ?existingStartYearMonth WHERE {
?activityUri <${startYearMonthUri}> ?existingStartYearMonth }
</v:jsonset>
<v:jsonset var="startYearMonthAssertion" >
?activityUri <${startYearMonthUri}> ?startYearMonth .
</v:jsonset>
<c:set var="endYearMonthUri" value="${vivoCore}endYearMonth" />
<v:jsonset var="endYearMonthExisting">
SELECT ?existingEndYearMonth WHERE {
?activityUri <${endYearMonthUri}> ?existingEndYearMonth }
</v:jsonset>
<v:jsonset var="endYearMonthAssertion" >
?activityUri <${endYearMonthUri}> ?endYearMonth .
</v:jsonset>
<v:jsonset var="n3ForStmtToPerson">
?activityUri <${label}> ?label ;
a <${predicateUri}> ;
a <${activityUri} ;
a <${flagUri} ;
<${inverseUri}> ?person ;
<${inverseActivityUri}> ?person .
?person <${predicateUri}> ?activityUri ;
<${activityUri}> ?activityUri .
s
</v:jsonset>
<c:set var="editjson" scope="request">
{
"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}"]
}
}
}
</c:set>
<%
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();
%>
<c:set var="subjectName" value="<%= subjectName %>" />
<h1></h1>
<c:choose>
<c:when test="${predicateUri == researchActivityUri}">
<c:set var="propertyName" value="research focus and activity" scope="request" />
</c:when>
<c:when test="${predicateUri == teachingActivityUri}">
<c:set var="propertyName" value="teaching focus and activity" scope="request" />
</c:when>
<c:when test="${predicateUri == serviceActivityUri}">
<c:set var="propertyName" value="professional service" scope="request" />
</c:when>
<c:when test="${predicateUri == outreachActivityUri}">
<c:set var="propertyName" value="outreach and community service" scope="request" />
</c:when>
</c:choose>
<%
// 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
%>
<c:set var="title" value="Edit ${propertyName} entry for ${subjectName}" />
<c:set var="submitLabel" value="Save Changes" />
<%
} else { // adding new entry
%>
<c:set var="title" value="Create a new ${propertyName} entry for ${subjectName}" />
<c:set var="submitLabel" value="Create New ${submitPropertyName}" />
<% }
List<String> customCss = new ArrayList<String>(Arrays.asList("forms/css/customForm.css"
));
request.setAttribute("customCss", customCss);
%>
<c:set var="requiredHint" value="<span class='requiredHint'> *</span>" />
<c:set var="yearMonthHint" value="<span class='hint'>(YYYY-MM)</span>" />
<jsp:include page="${preForm}"/>
<h2>${title}</h2>
<form action="<c:url value="/edit/processRdfForm2.jsp"/>" >
<v:input type="text" label="Name ${requiredHint}" id="label" size="30" />
<v:input type="textarea" label="Description ${requiredHint}" id="description" rows="5" cols="30" />
<v:input type="text" label="Role ${requiredHint}" id="role" size="30" />
<v:input type="text" label="Start Year and Month ${yearMonthHint}" id="startYearMonth" size="7"/>
<v:input type="text" label="End Year and Month ${yearMonthHint}" id="endYearMonth" size="7"/>
<p class="submit"><v:input type="submit" id="submit" value="${submitLabel}" cancel="${param.subjectUri}"/></p>
<p id="requiredLegend" class="requiredHint">* required fields</p>
</form>
<jsp:include page="${postForm}"/>