updates for various freemarker forms still in progress

This commit is contained in:
hjkhjk54 2011-11-18 22:58:51 +00:00
parent a014f61127
commit 9084d52ec6
6 changed files with 663 additions and 67 deletions

View file

@ -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().

View file

@ -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;
}
}
}

View file

@ -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);
}
}

View file

@ -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,7 +24,9 @@ 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";
final static String dateTimePrecision =vivoCore+"dateTimePrecision";
@ -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";