<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> <%-- Custom form for adding authors to information resources Classes: core:InformationResource - the information resource being edited core:Authorship - primary new individual being created foaf:Person - new or existing individual Data properties of Authorship: core:authorRank Object properties (domain : range) core:informationResourceInAuthorship (InformationResource : Authorship) core:linkedInformationResource (Authorship : InformationResource) - inverse of informationResourceInAuthorship core:linkedAuthor (Authorship : Person) core:authorInAuthorship (Person : Authorship) - inverse of linkedAuthor --%> <%@ page import="java.util.List" %> <%@ page import="java.util.ArrayList" %> <%@ page import="java.util.Arrays" %> <%@ page import="java.util.Collections" %> <%@ page import="java.net.URLEncoder" %> <%@ 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.beans.DataPropertyComparator" %> <%@ 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.edit.n3editing.PublicationHasAuthorValidator" %> <%@ 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="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.addAuthorsToInformationResource.jsp"); %> <% VitroRequest vreq = new VitroRequest(request); WebappDaoFactory wdf = vreq.getWebappDaoFactory(); vreq.setAttribute("defaultNamespace", ""); //empty string triggers default new URI behavior String flagUri = null; if (wdf.getApplicationDao().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); vreq.setAttribute("stringDatatypeUriJson", MiscWebUtils.escape(XSD.xstring.toString())); String intDatatypeUri = XSD.xint.toString(); vreq.setAttribute("intDatatypeUri", intDatatypeUri); vreq.setAttribute("intDatatypeUriJson", MiscWebUtils.escape(intDatatypeUri)); %> <%-- Unlike other custom forms, this form does not allow edits of existing authors, so there are no SPARQL queries for existing values. --%> <%-- RY Is this claim correct, or do we need them to retrieve an existing individual? --%> <%-- Data properties --%> @prefix foaf: <${foaf}> . ?newPerson foaf:firstName ?firstName . @prefix core: <${vivoCore}> . ?newPerson core:middleName ?middleName . @prefix foaf: <${foaf}> . ?newPerson foaf:lastName ?lastName . @prefix core: <${vivoCore}> . ?authorshipUri core:authorRank ?rank . <%-- This applies to both new and existing person --%> @prefix core: <${vivoCore}> . ?authorshipUri a core:Authorship , <${flagUri}> ; core:linkedInformationResource ?infoResource ; core:authorRank ?rank . ?infoResource core:informationResourceInAuthorship ?authorshipUri . @prefix core: <${vivoCore}> . ?authorshipUri core:linkedAuthor ?personUri . ?personUri core:authorInAuthorship ?authorshipUri . @prefix foaf: <${foaf}> . @prefix core: <${vivoCore}> . ?newPerson a foaf:Person , <${flagUri}> ; <${label}> ?label . ?authorshipUri core:linkedAuthor ?newPerson . ?newPerson core:authorInAuthorship ?authorshipUri . ${personClassUri} { "formUrl" : "${formUrl}", "editKey" : "${editKey}", "urlPatternToReturnTo" : "${returnPathAfterSubmit}", "subject" : ["infoResource", "${subjectUriJson}" ], "predicate" : ["predicate", "${predicateUriJson}" ], "object" : ["authorshipUri", "${objectUriJson}", "URI" ], "n3required" : [ "${n3ForNewAuthorship}", "${authorshipRankAssertion}" ], "n3optional" : [ "${newPersonFirstNameAssertion}", "${newPersonMiddleNameAssertion}", "${newPersonLastNameAssertion}", "${n3ForNewPerson}", "${n3ForExistingPerson}" ], "newResources" : { "authorshipUri" : "${defaultNamespace}", "newPerson" : "${defaultNamespace}" }, "urisInScope" : { }, "literalsInScope": { }, "urisOnForm" : [ "authorshipUri", "personUri" ], "literalsOnForm" : [ "firstName", "middleName", "lastName", "rank", "label" ], "filesOnForm" : [ ], "sparqlForLiterals" : { }, "sparqlForUris" : { }, "sparqlForExistingLiterals" : { }, "sparqlForExistingUris" : { }, "fields" : { "label" : { "newResource" : "false", "validators" : [ "datatype:${stringDatatypeUriJson}" ], "optionsType" : "UNDEFINED", "literalOptions" : [ ], "predicateUri" : "", "objectClassUri" : "", "rangeDatatypeUri" : "${stringDatatypeUriJson}", "rangeLang" : "", "assertions" : [ "${n3ForNewPerson}" ] }, "firstName" : { "newResource" : "false", "validators" : [ "datatype:${stringDatatypeUriJson}" ], "optionsType" : "UNDEFINED", "literalOptions" : [ ], "predicateUri" : "", "objectClassUri" : "", "rangeDatatypeUri" : "${stringDatatypeUriJson}", "rangeLang" : "", "assertions" : [ "${newPersonFirstNameAssertion}" ] }, "middleName" : { "newResource" : "false", "validators" : [ "datatype:${stringDatatypeUriJson}" ], "optionsType" : "UNDEFINED", "literalOptions" : [ ], "predicateUri" : "", "objectClassUri" : "", "rangeDatatypeUri" : "${stringDatatypeUriJson}", "rangeLang" : "", "assertions" : [ "${newPersonMiddleNameAssertion}" ] }, "lastName" : { "newResource" : "false", "validators" : [ "datatype:${stringDatatypeUriJson}" ], "optionsType" : "UNDEFINED", "literalOptions" : [ ], "predicateUri" : "", "objectClassUri" : "", "rangeDatatypeUri" : "${stringDatatypeUriJson}", "rangeLang" : "", "assertions" : [ "${newPersonLastNameAssertion}" ] }, "rank" : { "newResource" : "false", "validators" : [ "nonempty" ], "optionsType" : "UNDEFINED", "literalOptions" : [ ], "predicateUri" : "", "objectClassUri" : "", "rangeDatatypeUri" : "${intDatatypeUriJson}", "rangeLang" : "", "assertions" : ["${authorshipRankAssertion}"] }, "personUri" : { "newResource" : "false", "validators" : [ ], "optionsType" : "UNDEFINED", "literalOptions" : [ ], "predicateUri" : "", "objectClassUri" : "${personClassUriJson}", "rangeDatatypeUri" : "", "rangeLang" : "", "assertions" : ["${n3ForExistingPerson}"] } } } <% 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 PublicationHasAuthorValidator()); Model model = (Model) application.getAttribute("jenaOntModel"); String objectUri = (String) request.getAttribute("objectUri"); editConfig.prepareForNonUpdate(model); // we're only adding new, not editing existing String subjectUri = vreq.getParameter("subjectUri"); String predicateUri = vreq.getParameter("predicateUri"); Individual infoResource = vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI(subjectUri); List authorships = infoResource.getRelatedIndividuals(predicateUri); String rankUri = "http://vivoweb.org/ontology/core#authorRank"; DataPropertyComparator comp = new DataPropertyComparator(rankUri); Collections.sort(authorships, comp); vreq.setAttribute("infoResourceName", infoResource.getName()); String linkedAuthorProperty = "http://vivoweb.org/ontology/core#linkedAuthor"; List customJs = new ArrayList(Arrays.asList(JavaScript.JQUERY_UI.path(), JavaScript.UTILS.path(), JavaScript.CUSTOM_FORM_UTILS.path(), "/edit/forms/js/addAuthorsToInformationResource.js" )); request.setAttribute("customJs", customJs); List customCss = new ArrayList(Arrays.asList(Css.JQUERY_UI.path(), Css.CUSTOM_FORM.path(), "/edit/forms/css/addAuthorsToInformationResource.css" )); request.setAttribute("customCss", customCss); %>

${title}

<% // Try this in order to get the new author hightlighted after page reload. // If we do an ajax submit, we won't need it. //String processedForm = (String) vreq.getAttribute("processedForm"); //String ulClass = ""; //if (processedForm != null && processedForm.equals("true")) { // ulClass = "class='processedSubmission'"; //} //System.out.println(vreq.getAttribute("entToReturnTo")); %>
    <% int rank = 0; for ( Individual authorship : authorships ) { int rank1 = Integer.valueOf(authorship.getDataValue(rankUri)); String rankValue = authorship.getDataValue(rankUri); // full value, including xsd type if present if (rankValue == null) { rankValue = ""; rank = 0; } else { rank = Integer.valueOf(rankValue); // just the integer value } Individual author = authorship.getRelatedIndividual(linkedAuthorProperty); if ( author != null ) { request.setAttribute("author", author); // Doesn't seem to need urlencoding to add as id attribute value //request.setAttribute("authorUri", URLEncoder.encode(author.getURI(), "UTF-8")); request.setAttribute("authorUri", author.getURI()); request.setAttribute("authorshipUri", authorship.getURI()); request.setAttribute("rank", rank); %> <%-- --%>
  • <%-- This span will be used in the next phase, when we display a message that the author has been removed. That text will replace the a.authorLink. --%> ${author.name} Remove <%-- Undo --%>
  • <% } } // A new author will be ranked last when added. // This wouldn't handle gaps in the ranking: vreq.setAttribute("rank", authorships.size()+1); vreq.setAttribute("newRank", rank + 1); vreq.setAttribute("rankPred", rankUri); %>
<% if (authorships.size() == 0) { %>

This publication currently has no authors specified.

<% } %>
" >

Add an Author

<%-- RY maybe make this a label and input field. See what looks best. --%>

" /> " />

* required fields