updates for various freemarker forms still in progress
This commit is contained in:
parent
a014f61127
commit
9084d52ec6
6 changed files with 663 additions and 67 deletions
|
@ -0,0 +1,66 @@
|
|||
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
<#import "lib-vivo-form.ftl" as lvf>
|
||||
|
||||
<#assign existingConcepts = editConfiguration.pageData.existingConcepts/>
|
||||
<#--If edit submission exists, then retrieve validation errors if they exist-->
|
||||
<#if editSubmission?has_content && editSubmission.submissionExists = true && editSubmission.validationErrors?has_content>
|
||||
<#assign submissionErrors = editSubmission.validationErrors/>
|
||||
</#if>
|
||||
|
||||
|
||||
|
||||
<h2>Manage Associated Concepts</h2>
|
||||
|
||||
<#--Display error messages if any-->
|
||||
|
||||
|
||||
<#if submissionErrors?has_content>
|
||||
<section id="error-alert" role="alert">
|
||||
<img src="${urls.images}/iconAlert.png" width="24" height="24" alert="Error alert icon" />
|
||||
<p>
|
||||
<#--below shows examples of both printing out all error messages and checking the error message for a specific field-->
|
||||
<#list submissionErrors?keys as errorFieldName>
|
||||
${errorFieldName} : ${submissionErrors[errorFieldName]}
|
||||
</#list>
|
||||
|
||||
|
||||
</p>
|
||||
</section>
|
||||
</#if>
|
||||
|
||||
|
||||
<section id="addAssociatedConcept" role="region">
|
||||
|
||||
|
||||
<ul id="existingTerms" >
|
||||
|
||||
<script type="text/javascript">
|
||||
var existingTermsData = [];
|
||||
</script>
|
||||
|
||||
<#list existingConcepts?keys as key>
|
||||
<#local existingConcept = existingConcepts[key] />
|
||||
<li class="existingTerm">
|
||||
|
||||
<span class="term">
|
||||
|
||||
<span class="termWrapper">
|
||||
<span class="termLabel">
|
||||
${existingConcept.conceptLabel}
|
||||
</span>
|
||||
</span>
|
||||
<a href="${urls.base}/edit/primitiveDelete" class="remove">Remove</a>
|
||||
</span>
|
||||
</li>
|
||||
|
||||
<script type="text/javascript">
|
||||
existingTermsData.push({
|
||||
"conceptNodeUri": "${existingConcept.conceptURI}",
|
||||
"conceptLabel": "${existingConcept.conceptLabel}"
|
||||
});
|
||||
</script>
|
||||
|
||||
</#list>
|
||||
|
||||
</ul>
|
||||
</section>
|
|
@ -4,7 +4,20 @@
|
|||
|
||||
<#import "lib-vivo-form.ftl" as lf>
|
||||
|
||||
<#assign title="<em>${infoResourceName}</em>" />
|
||||
<#--Retrieve certain page specific information information-->
|
||||
<#assign newRank = editConfiguration.pageData.newRank />
|
||||
<#assign existingAuthorInfo = editConfiguration.pageData.existingAuthorInfo />
|
||||
<#assign rankPredicate = editConfiguration.pageData.rankPredicate />
|
||||
|
||||
<#--Values from edit configuration to populate fields -->
|
||||
|
||||
<#--UL class based on size of existing authors-->
|
||||
<#assign urlClass = ""/>
|
||||
<#if (existingAuthorInfo?size > 0)>
|
||||
<#assign urlClass = "class='dd'"/>
|
||||
</#if>
|
||||
|
||||
<#assign title="<em>${editConfiguration.subjectName}</em>" />
|
||||
<#assign requiredHint="<span class='requiredHint'> *</span>" />
|
||||
<#assign initialHint="<span class='hint'>(initial okay)</span>" />
|
||||
|
||||
|
@ -18,41 +31,38 @@
|
|||
var authorshipData = [];
|
||||
</script>
|
||||
|
||||
<#list authors as author>
|
||||
<li class="authorship">
|
||||
<#-- 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. -->
|
||||
<span class="author">
|
||||
<#-- 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. -->
|
||||
<span class="authorNameWrapper">
|
||||
<#if author <#--<c:when test="${!empty author}">-->>
|
||||
<#assign authorUri=author.URI />
|
||||
<#assign authorName=author.name />
|
||||
<#assign authorHref="/individual" />
|
||||
<#-- I don't know how to "translate"" this in to freemarker <c:param name="uri" value="${authorUri}"/>-->
|
||||
<span class="authorName">${authorName}</span>
|
||||
<#else>
|
||||
<#assign authorUri="" />
|
||||
<#assign authorName="" />
|
||||
<#assign authorHref="/individual" />
|
||||
<#-- I don't know how to "translate" this in to freemarker <c:param name="uri" value="${authorshipUri}"/>-->
|
||||
<span class="authorName">${authorshipName}</span><em> (no linked author)</em>
|
||||
</#if>
|
||||
</span>
|
||||
|
||||
<#assign deleteAuthorshipHref="/edit/primitiveDelete" />
|
||||
<a href="${deleteAuthorshipHref}" class="remove">Remove</a>
|
||||
</span>
|
||||
</li>
|
||||
<#assign authorHref="/individual?uri=" />
|
||||
<#--This should be a list of java objects where URI and name can be retrieved-->
|
||||
<#list existingAuthorInfo as authorship>
|
||||
<#local authorUri = authorship.authorUri/>
|
||||
<#local authorName = authorship.authorName/>
|
||||
|
||||
<script type="text/javascript">
|
||||
authorshipData.push({
|
||||
"authorshipUri": "${authorshipUri}",
|
||||
"authorUri": "${authorUri}",
|
||||
"authorName": "${authorName}"
|
||||
});
|
||||
</script>
|
||||
<li class="authorship">
|
||||
<#-- 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. -->
|
||||
<span class="author">
|
||||
<#-- 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. -->
|
||||
<span class="authorNameWrapper">
|
||||
<#if (authorUri?length > 0)>
|
||||
<span class="authorName">${authorName}</span>
|
||||
<#else>
|
||||
<span class="authorName">${authorship.authorshipName}</span><em> (no linked author)</em>
|
||||
</#if>
|
||||
</span>
|
||||
|
||||
<a href="${urls.base}/edit/primitiveDelete" class="remove">Remove</a>
|
||||
</span>
|
||||
</li>
|
||||
|
||||
<script type="text/javascript">
|
||||
authorshipData.push({
|
||||
"authorshipUri": "${authorship.authorshipUri}",
|
||||
"authorUri": "${authorUri}",
|
||||
"authorName": "${authorName}"
|
||||
});
|
||||
</script>
|
||||
</#list>
|
||||
|
||||
<#--// A new author will be ranked last when added.
|
||||
|
@ -65,10 +75,10 @@
|
|||
|
||||
<section id="showAddForm" role="region">
|
||||
<input type="hidden" name = "editKey" value="${editKey}" />
|
||||
<input type="submit" id="showAddFormButton" value="${editConfiguration.submitLabel}" role="button" />
|
||||
<input type="submit" id="showAddFormButton" value="replace submit label" role="button" />
|
||||
|
||||
<span class="or"> or </span>
|
||||
<a class="cancel" href="${editConfiguration.cancelUrl}" title="Cancel">Return to Publication</a>
|
||||
<a class="cancel" href="${cancelUrl}" title="Cancel">Return to Publication</a>
|
||||
</section>
|
||||
|
||||
<form id="addAuthorForm" action ="${submitUrl}" class="customForm">
|
||||
|
@ -92,12 +102,12 @@
|
|||
<input type="hidden" name="rank" id="rank" value="${newRank}" role="input" />
|
||||
|
||||
<p class="submit">
|
||||
<input type="hidden" name = "editKey" value="${keyValue}" role="input" />
|
||||
<input type="submit" id="submit" value="${submitButtonText}" role="button" role="input" />
|
||||
<input type="hidden" name = "editKey" value="${editKey}" role="input" />
|
||||
<input type="submit" id="submit" value="Add Author" role="button" role="input" />
|
||||
|
||||
<span class="or"> or </span>
|
||||
|
||||
<a class="cancel" href="${editConfiguration.cancelUrl}" title="Cancel">Cancel</a>
|
||||
<a class="cancel" href="${cancelUrl}" title="Cancel">Cancel</a>
|
||||
</p>
|
||||
|
||||
<p id="requiredLegend" class="requiredHint">* required fields</p>
|
||||
|
@ -105,16 +115,19 @@
|
|||
|
||||
<script type="text/javascript">
|
||||
var customFormData = {
|
||||
rankPredicate: ${rankPredicate},
|
||||
acUrl: ${acUrl},
|
||||
reorderUrl: '/edit/reorder'
|
||||
rankPredicate: '${rankPredicate}',
|
||||
acUrl: '${urls.base}/autocomplete?tokenize=true',
|
||||
reorderUrl: '{urls.base}/edit/reorder'
|
||||
};
|
||||
</script>
|
||||
|
||||
${stylesheets.add('<link rel="stylesheet" href="${urls.base}/js/jquery-ui/css/smoothness/jquery-ui-1.8.9.custom.css" />')}
|
||||
${stylesheets.add('<link rel="stylesheet" href="${urls.base}/edit/forms/css/customForm.css" />',
|
||||
'<link rel="stylesheet" href="${urls.base}/edit/forms/css/autocomplete.css" />',
|
||||
'<link rel="stylesheet" href="${urls.base}/edit/forms/css/addAuthorsToInformationResource.css" />')}
|
||||
|
||||
${scripts.add('<script type="text/javascript" src="${urls.base}/js/utils.js"></script>',
|
||||
'<script type="text/javascript" src="${urls.base}/js/customFormUtils.js"></script>',
|
||||
'<script type="text/javascript" src="${urls.base}/edit/forms/js/customFormWithAutocomplete.js"></script>',
|
||||
|
||||
${scripts.add('<script type="text/javascript" src="${urls.base}/js/jquery-ui/js/jquery-ui-1.8.9.custom.min.js"></script>'),
|
||||
'<script type="text/javascript" src="${urls.base}/js/customFormUtils.js"></script>',
|
||||
'<script type="text/javascript" src="${urls.base}/js/browserUtils.js"></script>',
|
||||
'<script type="text/javascript" src="${urls.base}/edit/forms/js/addAuthorsToInformationResource.js"></script>')}
|
|
@ -124,9 +124,9 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
|||
|
||||
|
||||
private void setVarNames(EditConfigurationVTwo editConfiguration) {
|
||||
editConfiguration.setVarNameForSubject("person");
|
||||
editConfiguration.setVarNameForSubject("subject");
|
||||
editConfiguration.setVarNameForPredicate("predicate");
|
||||
editConfiguration.setVarNameForObject("edTraining");
|
||||
editConfiguration.setVarNameForObject("conceptNode");
|
||||
}
|
||||
|
||||
protected void setTemplate(EditConfigurationVTwo editConfiguration,
|
||||
|
@ -171,10 +171,8 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
|||
*/
|
||||
private Map<String, String> generateNewResources(VitroRequest vreq) {
|
||||
HashMap<String, String> newResources = new HashMap<String, String>();
|
||||
//TODO: Get default namespace
|
||||
String defaultNamespace = vreq.getWebappDaoFactory().getDefaultNamespace();
|
||||
newResources.put("conceptNode", defaultNamespace + "individual");
|
||||
//Only the node itself will be new for a newly created concept node
|
||||
//There are no new resources here, the concept node uri doesn't
|
||||
//get created but already exists, and vocab uri should already exist as well
|
||||
return newResources;
|
||||
}
|
||||
|
||||
|
@ -221,6 +219,7 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
|||
List<String> urisOnForm = new ArrayList<String>();
|
||||
List<String> literalsOnForm = new ArrayList<String>();
|
||||
//The URI of the node that defines the concept
|
||||
urisOnForm.add("conceptURI");
|
||||
urisOnForm.add("vocabURI");
|
||||
//Also need to add the label of the concept
|
||||
literalsOnForm.add("conceptLabel");
|
||||
|
@ -249,7 +248,7 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
|||
private HashMap<String, String> generateSparqlForExistingUris(VitroRequest vreq) {
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
//Existing uris here might include is defined by
|
||||
map.put("vocabURI", getExistingVocabURIQuery());
|
||||
//map.put("vocabURI", getExistingVocabURIQuery());
|
||||
return map;
|
||||
}
|
||||
|
||||
|
@ -290,11 +289,23 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
|||
*/
|
||||
|
||||
private void setFields(EditConfigurationVTwo editConfiguration, VitroRequest vreq, String predicateUri) {
|
||||
|
||||
setConceptNodeField(editConfiguration, vreq);
|
||||
setConceptLabelField(editConfiguration, vreq);
|
||||
setVocabURIField(editConfiguration, vreq);
|
||||
}
|
||||
|
||||
//this field will be hidden and include the concept node URI
|
||||
private void setConceptNodeField(EditConfigurationVTwo editConfiguration,
|
||||
VitroRequest vreq) {
|
||||
editConfiguration.addField(new FieldVTwo().
|
||||
setName("conceptNode").
|
||||
setValidators(new ArrayList<String>()).
|
||||
setOptionsType("UNDEFINED"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void setVocabURIField(EditConfigurationVTwo editConfiguration,
|
||||
VitroRequest vreq) {
|
||||
editConfiguration.addField(new FieldVTwo().
|
||||
|
|
|
@ -2,18 +2,386 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
import com.hp.hpl.jena.vocabulary.RDFS;
|
||||
import com.hp.hpl.jena.vocabulary.XSD;
|
||||
|
||||
public class AddAuthorsToInformationResourceGenerator extends BaseEditConfigurationGenerator implements EditConfigurationGenerator {
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyComparator;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeIntervalValidationVTwo;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
|
||||
|
||||
public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator implements EditConfigurationGenerator {
|
||||
|
||||
@Override
|
||||
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq,
|
||||
HttpSession session) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new Error(this.getClass().getName() + " is not yet implement");
|
||||
EditConfigurationVTwo editConfiguration = new EditConfigurationVTwo();
|
||||
initBasics(editConfiguration, vreq);
|
||||
initPropertyParameters(vreq, session, editConfiguration);
|
||||
initObjectPropForm(editConfiguration, vreq);
|
||||
//Overriding url to return to
|
||||
setUrlToReturnTo(editConfiguration, vreq);
|
||||
setVarNames(editConfiguration);
|
||||
|
||||
|
||||
// Required N3
|
||||
editConfiguration.setN3Required(generateN3Required());
|
||||
|
||||
// Optional N3
|
||||
editConfiguration.setN3Optional( generateN3Optional());
|
||||
|
||||
editConfiguration.setNewResources( generateNewResources(vreq) );
|
||||
|
||||
//In scope
|
||||
setUrisAndLiteralsInScope(editConfiguration, vreq);
|
||||
|
||||
//on Form
|
||||
setUrisAndLiteralsOnForm(editConfiguration, vreq);
|
||||
|
||||
//Sparql queries
|
||||
setSparqlQueries(editConfiguration, vreq);
|
||||
|
||||
//set fields
|
||||
setFields(editConfiguration, vreq, EditConfigurationUtils.getPredicateUri(vreq));
|
||||
|
||||
//template file
|
||||
editConfiguration.setTemplate("addAuthorsToInformationResource.ftl");
|
||||
//no validators or preprocessors
|
||||
|
||||
//Adding additional data, specifically edit mode
|
||||
addFormSpecificData(editConfiguration, vreq);
|
||||
return editConfiguration;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void setVarNames(EditConfigurationVTwo editConfiguration) {
|
||||
editConfiguration.setVarNameForSubject("infoResource");
|
||||
editConfiguration.setVarNameForPredicate("predicate");
|
||||
editConfiguration.setVarNameForObject("authorshipUri");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void setUrlToReturnTo(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
||||
editConfiguration.setUrlPatternToReturnTo(EditConfigurationUtils.getFormUrlWithoutContext(vreq));
|
||||
|
||||
}
|
||||
|
||||
/***N3 strings both required and optional***/
|
||||
|
||||
public String getN3PrefixString() {
|
||||
return "@prefix core: <" + vivoCore + "> ." +
|
||||
"@prefix foaf: <" + foaf + "> . " ;
|
||||
}
|
||||
|
||||
|
||||
//n3 for new authorship, authorship rank assertion
|
||||
private List<String> generateN3Required() {
|
||||
return list(getN3NewAuthorship(),
|
||||
getN3AuthorshipRank());
|
||||
}
|
||||
|
||||
private String getN3NewAuthorship() {
|
||||
return getN3PrefixString() +
|
||||
"?authorshipUri a core:Authorship ;" +
|
||||
" core:linkedInformationResource ?infoResource ;" +
|
||||
" core:authorRank ?rank . " +
|
||||
"?infoResource core:informationResourceInAuthorship ?authorshipUri . ";
|
||||
}
|
||||
|
||||
private String getN3AuthorshipRank() {
|
||||
return getN3PrefixString() +
|
||||
"?authorshipUri core:authorRank ?rank .";
|
||||
}
|
||||
|
||||
//first name, middle name, last name, and new perseon for new author being created, and n3 for existing person
|
||||
//if existing person selected as author
|
||||
private List<String> generateN3Optional() {
|
||||
return list(getN3NewPersonFirstName() ,
|
||||
getN3NewPersonMiddleName(),
|
||||
getN3NewPersonLastName(),
|
||||
getN3NewPerson(),
|
||||
getN3ForExistingPerson());
|
||||
|
||||
}
|
||||
|
||||
|
||||
private String getN3NewPersonFirstName() {
|
||||
return getN3PrefixString() +
|
||||
"?newPerson foaf:firstName ?firstName .";
|
||||
}
|
||||
|
||||
private String getN3NewPersonMiddleName() {
|
||||
return getN3PrefixString() +
|
||||
"?newPerson core:middleName ?middleName .";
|
||||
}
|
||||
|
||||
private String getN3NewPersonLastName() {
|
||||
return getN3PrefixString() +
|
||||
"?newPerson foaf:lastName ?lastName .";
|
||||
}
|
||||
|
||||
private String getN3NewPerson() {
|
||||
return getN3PrefixString() +
|
||||
"?newPerson a foaf:Person ;" +
|
||||
"<" + RDFS.label.getURI() + "> ?label ." +
|
||||
"?authorshipUri core:linkedAuthor ?newPerson ." +
|
||||
"?newPerson core:authorInAuthorship ?authorshipUri . ";
|
||||
}
|
||||
|
||||
private String getN3ForExistingPerson() {
|
||||
return getN3PrefixString() +
|
||||
"?authorshipUri core:linkedAuthor ?personUri ." +
|
||||
"?personUri core:authorInAuthorship ?authorshipUri .";
|
||||
}
|
||||
|
||||
/** Get new resources */
|
||||
//A new authorship uri will always be created when an author is added
|
||||
//A new person may be added if a person not in the system will be added as author
|
||||
private Map<String, String> generateNewResources(VitroRequest vreq) {
|
||||
String DEFAULT_NS_TOKEN=null; //null forces the default NS
|
||||
|
||||
HashMap<String, String> newResources = new HashMap<String, String>();
|
||||
newResources.put("authorshipUri", DEFAULT_NS_TOKEN);
|
||||
newResources.put("newPerson", DEFAULT_NS_TOKEN);
|
||||
return newResources;
|
||||
}
|
||||
|
||||
/** Set URIS and Literals In Scope and on form and supporting methods */
|
||||
private void setUrisAndLiteralsInScope(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
||||
//Uris in scope always contain subject and predicate
|
||||
HashMap<String, List<String>> urisInScope = new HashMap<String, List<String>>();
|
||||
urisInScope.put(editConfiguration.getVarNameForSubject(),
|
||||
Arrays.asList(new String[]{editConfiguration.getSubjectUri()}));
|
||||
urisInScope.put(editConfiguration.getVarNameForPredicate(),
|
||||
Arrays.asList(new String[]{editConfiguration.getPredicateUri()}));
|
||||
editConfiguration.setUrisInScope(urisInScope);
|
||||
//no literals in scope
|
||||
HashMap<String, List<Literal>> literalsInScope = new HashMap<String, List<Literal>>();
|
||||
editConfiguration.setLiteralsInScope(literalsInScope);
|
||||
|
||||
}
|
||||
|
||||
private void setUrisAndLiteralsOnForm(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
||||
List<String> urisOnForm = new ArrayList<String>();
|
||||
//If an existing person is being used as an author, need to get the person uri
|
||||
urisOnForm.add("personUri");
|
||||
editConfiguration.setUrisOnform(urisOnForm);
|
||||
|
||||
//for person who is not in system, need to add first name, last name and middle name
|
||||
//Also need to store authorship rank and label of author
|
||||
List<String> literalsOnForm = list("firstName",
|
||||
"middleName",
|
||||
"lastName",
|
||||
"rank",
|
||||
"label");
|
||||
editConfiguration.setLiteralsOnForm(literalsOnForm);
|
||||
}
|
||||
|
||||
/** Set SPARQL Queries and supporting methods. */
|
||||
private void setSparqlQueries(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
||||
//Sparql queries are all empty for existing values
|
||||
//This form is different from the others that it gets multiple authors on the same page
|
||||
//and that information will be queried and stored in the additional form specific data
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
editConfiguration.setSparqlForExistingUris(new HashMap<String, String>());
|
||||
editConfiguration.setSparqlForExistingLiterals(new HashMap<String, String>());
|
||||
editConfiguration.setSparqlForAdditionalUrisInScope(new HashMap<String, String>());
|
||||
editConfiguration.setSparqlForAdditionalLiteralsInScope(new HashMap<String, String>());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Set Fields and supporting methods
|
||||
*/
|
||||
|
||||
private void setFields(EditConfigurationVTwo editConfiguration, VitroRequest vreq, String predicateUri) {
|
||||
setLabelField(editConfiguration);
|
||||
setFirstNameField(editConfiguration);
|
||||
setMiddleNameField(editConfiguration);
|
||||
setLastNameField(editConfiguration);
|
||||
setRankField(editConfiguration);
|
||||
setPersonUriField(editConfiguration);
|
||||
}
|
||||
|
||||
private void setLabelField(EditConfigurationVTwo editConfiguration) {
|
||||
editConfiguration.addField(new FieldVTwo().
|
||||
setName("label").
|
||||
setValidators(list("datatype:" + XSD.xstring.toString())).
|
||||
setRangeDatatypeUri(XSD.xstring.toString())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void setFirstNameField(EditConfigurationVTwo editConfiguration) {
|
||||
editConfiguration.addField(new FieldVTwo().
|
||||
setName("firstName").
|
||||
setValidators(list("datatype:" + XSD.xstring.toString())).
|
||||
setRangeDatatypeUri(XSD.xstring.toString())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void setMiddleNameField(EditConfigurationVTwo editConfiguration) {
|
||||
editConfiguration.addField(new FieldVTwo().
|
||||
setName("middleName").
|
||||
setValidators(list("datatype:" + XSD.xstring.toString())).
|
||||
setRangeDatatypeUri(XSD.xstring.toString())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void setLastNameField(EditConfigurationVTwo editConfiguration) {
|
||||
editConfiguration.addField(new FieldVTwo().
|
||||
setName("lastName").
|
||||
setValidators(list("datatype:" + XSD.xstring.toString())).
|
||||
setRangeDatatypeUri(XSD.xstring.toString())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
private void setRankField(EditConfigurationVTwo editConfiguration) {
|
||||
editConfiguration.addField(new FieldVTwo().
|
||||
setName("rank").
|
||||
setValidators(list("nonempty")).
|
||||
setRangeDatatypeUri(XSD.xint.toString())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void setPersonUriField(EditConfigurationVTwo editConfiguration) {
|
||||
editConfiguration.addField(new FieldVTwo().
|
||||
setName("personUri").
|
||||
setValidators(list("")).
|
||||
setObjectClassUri(personClass)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
//Form specific data
|
||||
public void addFormSpecificData(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
||||
HashMap<String, Object> formSpecificData = new HashMap<String, Object>();
|
||||
//Get the existing authorships
|
||||
formSpecificData.put("existingAuthorInfo", getExistingAuthorships(vreq));
|
||||
formSpecificData.put("newRank", getMaxRank(vreq) + 1);
|
||||
formSpecificData.put("rankPredicate", authorRankPredicate);
|
||||
editConfiguration.setFormSpecificData(formSpecificData);
|
||||
}
|
||||
|
||||
private List<AuthorshipInfo> getExistingAuthorships(VitroRequest vreq) {
|
||||
Individual infoResource = EditConfigurationUtils.getSubjectIndividual(vreq);
|
||||
List<Individual> authorships = infoResource.getRelatedIndividuals(
|
||||
EditConfigurationUtils.getPredicateUri(vreq));
|
||||
//TODO: Check if sorted correctly
|
||||
sortAuthorshipIndividuals(authorships);
|
||||
|
||||
return getAuthorshipInfo(authorships);
|
||||
}
|
||||
|
||||
private List<AuthorshipInfo> getAuthorshipInfo(
|
||||
List<Individual> authorships) {
|
||||
List<AuthorshipInfo> info = new ArrayList<AuthorshipInfo>();
|
||||
for ( Individual authorship : authorships ) {
|
||||
String authorshipUri = authorship.getURI();
|
||||
String authorshipName = authorship.getName();
|
||||
String authorUri = "";
|
||||
String authorName = "";
|
||||
Individual author = authorship.getRelatedIndividual(linkedAuthorPredicate);
|
||||
if(author != null) {
|
||||
authorUri = author.getURI();
|
||||
authorName = author.getName();
|
||||
}
|
||||
AuthorshipInfo aaInfo = new AuthorshipInfo(authorshipUri, authorshipName, authorUri, authorName);
|
||||
info.add(aaInfo);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
private int getMaxRank(VitroRequest vreq) {
|
||||
Individual infoResource = EditConfigurationUtils.getSubjectIndividual(vreq);
|
||||
List<Individual> authorships = infoResource.getRelatedIndividuals(
|
||||
EditConfigurationUtils.getPredicateUri(vreq));
|
||||
sortAuthorshipIndividuals(authorships);
|
||||
int maxRank = 0;
|
||||
for(Individual authorship: authorships) {
|
||||
DataPropertyStatement rankStmt = authorship.getDataPropertyStatement(authorRankPredicate);
|
||||
if (rankStmt != null) {
|
||||
maxRank = Integer.parseInt(rankStmt.getData());
|
||||
}
|
||||
}
|
||||
return maxRank;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void sortAuthorshipIndividuals(List<Individual> authorships) {
|
||||
DataPropertyComparator comp = new DataPropertyComparator(authorRankPredicate);
|
||||
Collections.sort(authorships, comp);
|
||||
}
|
||||
|
||||
//This is the information about authors the form will require
|
||||
public class AuthorshipInfo {
|
||||
//This is the authorship node information
|
||||
private String authorshipUri;
|
||||
private String authorshipName;
|
||||
//Author information for authorship node
|
||||
private String authorUri;
|
||||
private String authorName;
|
||||
|
||||
public AuthorshipInfo(String inputAuthorshipUri,
|
||||
String inputAuthorshipName,
|
||||
String inputAuthorUri,
|
||||
String inputAuthorName) {
|
||||
authorshipUri = inputAuthorshipUri;
|
||||
authorshipName = inputAuthorshipName;
|
||||
authorUri = inputAuthorUri;
|
||||
authorName = inputAuthorName;
|
||||
|
||||
}
|
||||
|
||||
//Getters - specifically required for Freemarker template's access to POJO
|
||||
public String getAuthorshipUri() {
|
||||
return authorshipUri;
|
||||
}
|
||||
|
||||
public String getAuthorshipName() {
|
||||
return authorshipName;
|
||||
}
|
||||
|
||||
public String getAuthorUri() {
|
||||
return authorUri;
|
||||
}
|
||||
|
||||
public String getAuthorName() {
|
||||
return authorName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,18 +1,153 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||
|
||||
public class AddPublicationToPersonGenerator extends BaseEditConfigurationGenerator implements EditConfigurationGenerator {
|
||||
|
||||
@Override
|
||||
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq,
|
||||
HttpSession session) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new Error(this.getClass().getName() + " is not yet implement");
|
||||
}
|
||||
@Override
|
||||
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq,
|
||||
HttpSession session) {
|
||||
EditConfigurationVTwo editConfiguration = new EditConfigurationVTwo();
|
||||
initBasics(editConfiguration, vreq);
|
||||
initPropertyParameters(vreq, session, editConfiguration);
|
||||
initObjectPropForm(editConfiguration, vreq);
|
||||
//Overriding url to return to
|
||||
setUrlToReturnTo(editConfiguration, vreq);
|
||||
setVarNames(editConfiguration);
|
||||
|
||||
|
||||
// Required N3
|
||||
editConfiguration.setN3Required(generateN3Required());
|
||||
|
||||
// Optional N3
|
||||
editConfiguration.setN3Optional( generateN3Optional());
|
||||
|
||||
editConfiguration.setNewResources( generateNewResources(vreq) );
|
||||
|
||||
//In scope
|
||||
setUrisAndLiteralsInScope(editConfiguration, vreq);
|
||||
|
||||
//on Form
|
||||
setUrisAndLiteralsOnForm(editConfiguration, vreq);
|
||||
|
||||
//Sparql queries
|
||||
setSparqlQueries(editConfiguration, vreq);
|
||||
|
||||
//set fields
|
||||
setFields(editConfiguration, vreq, EditConfigurationUtils.getPredicateUri(vreq));
|
||||
|
||||
//template file
|
||||
editConfiguration.setTemplate("addAuthorsToInformationResource.ftl");
|
||||
//no validators or preprocessors
|
||||
|
||||
//Adding additional data, specifically edit mode
|
||||
addFormSpecificData(editConfiguration, vreq);
|
||||
return editConfiguration;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void setVarNames(EditConfigurationVTwo editConfiguration) {
|
||||
editConfiguration.setVarNameForSubject("infoResource");
|
||||
editConfiguration.setVarNameForPredicate("predicate");
|
||||
editConfiguration.setVarNameForObject("authorshipUri");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void setUrlToReturnTo(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
||||
editConfiguration.setUrlPatternToReturnTo(EditConfigurationUtils.getFormUrlWithoutContext(vreq));
|
||||
|
||||
}
|
||||
|
||||
/***N3 strings both required and optional***/
|
||||
private List<String> generateN3Optional() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private List<String> generateN3Required() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Get new resources */
|
||||
private Map<String, String> generateNewResources(VitroRequest vreq) {
|
||||
String DEFAULT_NS_TOKEN=null; //null forces the default NS
|
||||
|
||||
HashMap<String, String> newResources = new HashMap<String, String>();
|
||||
newResources.put("role", DEFAULT_NS_TOKEN);
|
||||
newResources.put("roleActivity", DEFAULT_NS_TOKEN);
|
||||
newResources.put("intervalNode", DEFAULT_NS_TOKEN);
|
||||
newResources.put("startNode", DEFAULT_NS_TOKEN);
|
||||
newResources.put("endNode", DEFAULT_NS_TOKEN);
|
||||
return newResources;
|
||||
}
|
||||
|
||||
/** Set URIS and Literals In Scope and on form and supporting methods */
|
||||
private void setUrisAndLiteralsInScope(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
||||
HashMap<String, List<String>> urisInScope = new HashMap<String, List<String>>();
|
||||
editConfiguration.setUrisInScope(urisInScope);
|
||||
HashMap<String, List<Literal>> literalsInScope = new HashMap<String, List<Literal>>();
|
||||
editConfiguration.setLiteralsInScope(literalsInScope);
|
||||
|
||||
}
|
||||
|
||||
private void setUrisAndLiteralsOnForm(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
||||
List<String> urisOnForm = new ArrayList<String>();
|
||||
//add role activity and roleActivityType to uris on form
|
||||
urisOnForm.add("roleActivity");
|
||||
urisOnForm.add("roleActivityType");
|
||||
//Also adding the predicates
|
||||
//TODO: Check how to override this in case of default parameter? Just write hidden input to form?
|
||||
urisOnForm.add("roleToActivityPredicate");
|
||||
urisOnForm.add("activityToRolePredicate");
|
||||
editConfiguration.setUrisOnform(urisOnForm);
|
||||
|
||||
//activity label and role label are literals on form
|
||||
List<String> literalsOnForm = new ArrayList<String>();
|
||||
literalsOnForm.add("activityLabel");
|
||||
literalsOnForm.add("roleLabel");
|
||||
editConfiguration.setLiteralsOnForm(literalsOnForm);
|
||||
}
|
||||
|
||||
/** Set SPARQL Queries and supporting methods. */
|
||||
private void setSparqlQueries(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
||||
//Queries for activity label, role label, start Field value, end Field value
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
editConfiguration.setSparqlForExistingUris(map);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Set Fields and supporting methods
|
||||
*/
|
||||
|
||||
private void setFields(EditConfigurationVTwo editConfiguration, VitroRequest vreq, String predicateUri) {
|
||||
|
||||
}
|
||||
|
||||
//Form specific data
|
||||
public void addFormSpecificData(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
||||
HashMap<String, Object> formSpecificData = new HashMap<String, Object>();
|
||||
editConfiguration.setFormSpecificData(formSpecificData);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ public abstract class VivoBaseGenerator extends BaseEditConfigurationGenerator i
|
|||
|
||||
final static String vivoCore ="http://vivoweb.org/ontology/core#" ;
|
||||
final static String rdfs =VitroVocabulary.RDFS ;
|
||||
|
||||
final static String foaf = "http://xmlns.com/foaf/0.1/";
|
||||
final static String type =VitroVocabulary.RDF_TYPE ;
|
||||
final static String label =rdfs+"label" ;
|
||||
|
||||
|
@ -24,6 +24,8 @@ public abstract class VivoBaseGenerator extends BaseEditConfigurationGenerator i
|
|||
final static String degreeEarned =vivoCore+"degreeEarned" ;
|
||||
final static String degreeOutcomeOf =vivoCore+"degreeOutcomeOf" ;
|
||||
final static String trainingAtOrg =vivoCore+"trainingAtOrganization" ;
|
||||
final static String authorRankPredicate = vivoCore + "authorRank";
|
||||
final static String linkedAuthorPredicate = vivoCore + "linkedAuthor";
|
||||
|
||||
final static String dateTimeValue =vivoCore+"dateTime";
|
||||
final static String dateTimeValueType =vivoCore+"DateTimeValue";
|
||||
|
@ -35,6 +37,7 @@ public abstract class VivoBaseGenerator extends BaseEditConfigurationGenerator i
|
|||
final static String intervalToEnd =vivoCore+"end";
|
||||
|
||||
final static String orgClass ="http://xmlns.com/foaf/0.1/Organization" ;
|
||||
final static String personClass = foaf + "Person";
|
||||
|
||||
//TODO: Define these elsewhere
|
||||
final static String UMLSClass = vivoCore + "UMLS";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue