%-- $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 being linked to
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="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.beans.DataPropertyStatement" %>
<%@ 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.utils.StringUtils" %>
<%@ 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.json.JSONObject" %>
<%@ 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
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. --%>
<%-- 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 a new and an existing person --%>
@prefix core: <${vivoCore}> .
?authorshipUri a core:Authorship ;
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 ;
<${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" : [ "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");
//for some reason we are comming from the add new and that is working
//but we also come from the edit, and that is not working.
editConfig.setObject(""); //this will force the edit config to always be an add, never an update
editConfig.prepareForNonUpdate(model); // we're only adding new, not editing existing
String subjectUri = vreq.getParameter("subjectUri");
String predicateUri = vreq.getParameter("predicateUri");
String vivoCore = "http://vivoweb.org/ontology/core#";
//Individual infoResource = vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI(subjectUri);
Individual infoResource = ((Individual) request.getAttribute("subject"));
vreq.setAttribute("infoResourceName", infoResource.getName());
List authorships = infoResource.getRelatedIndividuals(predicateUri);
List customJs = new ArrayList(Arrays.asList(JavaScript.JQUERY_UI.path(),
JavaScript.CUSTOM_FORM_UTILS.path(),
"/js/browserUtils.js",
"/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/autocomplete.css",
"/edit/forms/css/addAuthorsToInformationResource.css"
));
request.setAttribute("customCss", customCss);
String ulClass = "";
List ulClasses = new ArrayList();
if (authorships.size() > 1) {
// This class triggers application of dd styles. Don't wait for js to add
// the ui-sortable class, because then the page flashes as the styles are updated.
ulClasses.add("dd");
}
if (ulClasses.size() > 0) {
ulClass="class=\"" + StringUtils.join(ulClasses, " ") + "\"";
}
%>
<%-- DO NOT CHANGE IDS, CLASSES, OR HTML STRUCTURE ON THIS PAGE WITHOUT UNDERSTANDING THE IMPACT ON THE JAVASCRIPT! --%>
${title}
<%@ include file="unsupportedBrowserMessage.jsp" %>
Manage Authors
>
<%
String rankPredicateUri = vivoCore + "authorRank";
// RY We should use whatever is used on the individual profile page to list
// this property in rank order...
DataPropertyComparator comp = new DataPropertyComparator(rankPredicateUri);
Collections.sort(authorships, comp);
int maxRank = 0;
int authorshipCount = authorships.size();
// for ( ObjectPropertyStatement stmt : authorshipStmts) {
// Individual authorship = stmt.getObject();
%>
<%
for ( Individual authorship : authorships ) {
request.setAttribute("authorshipUri", authorship.getURI());
request.setAttribute("authorshipName", authorship.getName());
DataPropertyStatement rankStmt = authorship.getDataPropertyStatement(rankPredicateUri);
if (rankStmt != null) {
maxRank = Integer.parseInt(rankStmt.getData());
}
request.setAttribute("author", authorship.getRelatedIndividual(vivoCore + "linkedAuthor"));
%>
<%-- span.author will be used in the next phase, when we display a message that the author has been
removed. That text will replace the a.authorName, which will be removed. --%>
<%-- This span is here to assign a width to. We can't assign directly to the a.authorName,
for the case when it's followed by an em tag - we want the width to apply to the whole thing. --%>
${authorName}${authorshipName} (no linked author)Remove
<%-- Undo --%>
<%
}
// A new author will be ranked last when added.
// This value is now inserted by JavaScript, but leave it here as a safety net in case page
// load reordering returns an error.
request.setAttribute("newRank", maxRank + 1);
System.out.println("request rank: " + request.getAttribute("newRank"));
request.setAttribute("rankPredicate", rankPredicateUri);
%>
<% if (authorshipCount == 0) { %>
This publication currently has no authors specified.
<% } %>
<%-- DO NOT CHANGE IDS, CLASSES, OR HTML STRUCTURE IN THIS FORM WITHOUT UNDERSTANDING THE IMPACT ON THE JAVASCRIPT! --%>
" >
Add an Author
<%-- RY maybe make this a label and input field. See what looks best. --%>