Merge branch 'develop' of https://github.com/vivo-project/VIVO into develop

This commit is contained in:
brianjlowe 2013-09-26 14:27:31 -04:00
commit b8cff8458a
6 changed files with 156 additions and 64 deletions

View file

@ -3,17 +3,17 @@
<#assign isPersonType = editConfiguration.pageData.isPersonType /> <#assign isPersonType = editConfiguration.pageData.isPersonType />
<form id="addLabelForm" name="addLabelForm" class="customForm" action="${submitUrl}"> <form id="addLabelForm" name="addLabelForm" class="customForm" action="${submitUrl}">
<h2>${i18n().add_label}</h2> <h2>${i18n().add_label}</h2>
<#if isPersonType = "true"> <#if isPersonType?has_content && isPersonType = "true">
<p> <p>
<label for="firstName">${i18n().first_name} ${requiredHint}</label> <label for="firstName">${i18n().first_name} ${requiredHint}</label>
<input size="30" type="text" id="firstName" name="firstName" value="${firstNameValue}" /> <input size="30" type="text" id="firstName" name="firstName" value="${firstNameValue}" />
</p> </p>
<#--TODO: With ISF changes, add middle name input--> <#--TODO: With ISF changes, add middle name input-->
<!--p--> <p>
<!--label for="middleName">${i18n().middle_name} ${requiredHint}</label> <label for="middleName">${i18n().middle_name} </label>
<input size="30" type="text" id="middleName" name="middleName" value="${middleNameValue}" /> <input size="30" type="text" id="middleName" name="middleName" value="${middleNameValue}" />
</p--> </p>
<p> <p>
<label for="lastName">${i18n().last_name} ${requiredHint}</label> <label for="lastName">${i18n().last_name} ${requiredHint}</label>

View file

@ -5,8 +5,7 @@
<#--Get existing value for specific data literals and uris, in case the form is returned because of an error--> <#--Get existing value for specific data literals and uris, in case the form is returned because of an error-->
<#assign firstNameValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "firstName")/> <#assign firstNameValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "firstName")/>
<#assign lastNameValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "lastName")/> <#assign lastNameValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "lastName")/>
<#--With ISF changes, we also have a niddle name value, also add error field below--> <#assign middleNameValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "middleName") />
<#--assign middleNameValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "middleName") /-->
<#assign labelValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "label")/> <#assign labelValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "label")/>
<#assign newLabelLanguageValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "newLabelLanguage")/> <#assign newLabelLanguageValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "newLabelLanguage")/>

View file

@ -11,6 +11,8 @@
<#--Get existing value for specific data literals and uris--> <#--Get existing value for specific data literals and uris-->
<#assign firstNameValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "firstName")/> <#assign firstNameValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "firstName")/>
<#assign lastNameValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "lastName")/> <#assign lastNameValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "lastName")/>
<#assign middleNameValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "middleName")/>
<#assign labelValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "label")/> <#assign labelValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "label")/>
<#--If edit submission exists, then retrieve validation errors if they exist--> <#--If edit submission exists, then retrieve validation errors if they exist-->
@ -52,6 +54,11 @@
<input size="30" type="text" id="firstName" name="firstName" value="${firstNameValue}" /> <input size="30" type="text" id="firstName" name="firstName" value="${firstNameValue}" />
</p> </p>
<p>
<label for="lastName">${i18n().middle_name} </label>
<input size="30" type="text" id="middleName" name="middleName" value="${middleNameValue}" />
</p>
<p> <p>
<label for="lastName">${i18n().last_name} ${requiredHint}</label> <label for="lastName">${i18n().last_name} ${requiredHint}</label>
<input size="30" type="text" id="lastName" name="lastName" value="${lastNameValue}" /> <input size="30" type="text" id="lastName" name="lastName" value="${lastNameValue}" />

View file

@ -54,6 +54,7 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTw
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.FoafNameToRdfsLabelPreprocessor; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.FoafNameToRdfsLabelPreprocessor;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ManageLabelsForIndividualPreprocessor; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ManageLabelsForIndividualPreprocessor;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ManageLabelsForPersonPreprocessor;
import edu.cornell.mannlib.vitro.webapp.i18n.selection.LocaleSelectionDataGetter; import edu.cornell.mannlib.vitro.webapp.i18n.selection.LocaleSelectionDataGetter;
import edu.cornell.mannlib.vitro.webapp.i18n.selection.LocaleSelectorUtilities; import edu.cornell.mannlib.vitro.webapp.i18n.selection.LocaleSelectorUtilities;
import edu.cornell.mannlib.vitro.webapp.i18n.selection.SelectedLocale; import edu.cornell.mannlib.vitro.webapp.i18n.selection.SelectedLocale;
@ -69,12 +70,7 @@ public class ManageLabelsForPersonGenerator extends BaseEditConfigurationGenerat
private static String template = "manageLabelsForPerson.ftl"; private static String template = "manageLabelsForPerson.ftl";
private HashMap<String, List<LabelInformation>> labelsSortedByLanguage = null; private HashMap<String, List<LabelInformation>> labelsSortedByLanguage = null;
private List<Literal> existingLabelLiterals = null; private List<Literal> existingLabelLiterals = null;
//list of language names sorted alphabetically
private List<String> existingSortedLanguageNameList = null;
//This would be for the full list and can be used for the existing labels list as well
private HashMap<String, String> fullLanguageNameToCodeMap = null;
private static String predicateUri = RDFS.label.getURI();
@Override @Override
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, HttpSession session) { public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, HttpSession session) {
@ -115,7 +111,7 @@ public class ManageLabelsForPersonGenerator extends BaseEditConfigurationGenerat
addFormSpecificData(config, vreq); addFormSpecificData(config, vreq);
//This preprocessor handles getting the correct label language and putting the attribute on the label //This preprocessor handles getting the correct label language and putting the attribute on the label
config.addEditSubmissionPreprocessor( config.addEditSubmissionPreprocessor(
new ManageLabelsForIndividualPreprocessor(config)); new ManageLabelsForPersonPreprocessor(config));
//This will handle generating the label from the first name, middle, and last names and also make sure to associate //This will handle generating the label from the first name, middle, and last names and also make sure to associate
//a language with that label //a language with that label
config.addModelChangePreprocessor(new FoafNameToRdfsLabelPreprocessor()); config.addModelChangePreprocessor(new FoafNameToRdfsLabelPreprocessor());
@ -150,22 +146,20 @@ public class ManageLabelsForPersonGenerator extends BaseEditConfigurationGenerat
private List<String> generateN3Optional(VitroRequest vreq) { private List<String> generateN3Optional(VitroRequest vreq) {
List<String> n3Optional = new ArrayList<String>(); List<String> n3Optional = new ArrayList<String>();
String predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
String n3 = "?subject <" + predicateUri + "> ?label "; String personFullNameN3 = this.N3_PREFIX +
//n3 used if the subject is a person
//String personN3 = this.N3_PREFIX + "?subject foaf:firstName ?firstName ; foaf:lastName ?lastName .";
//This n3 will be different with the ISF changes
String personN3 = this.N3_PREFIX +
"?subject <http://purl.obolibrary.org/obo/ARG_2000028> ?individualVcard . \n" + "?subject <http://purl.obolibrary.org/obo/ARG_2000028> ?individualVcard . \n" +
"?individualVcard a <http://www.w3.org/2006/vcard/ns#Individual> . \n" + "?individualVcard a <http://www.w3.org/2006/vcard/ns#Individual> . \n" +
"?individualVcard <http://purl.obolibrary.org/obo/ARG_2000029> ?subject . \n" + "?individualVcard <http://purl.obolibrary.org/obo/ARG_2000029> ?subject . \n" +
"?individualVcard <http://www.w3.org/2006/vcard/ns#hasName> ?fullName . \n" + "?individualVcard <http://www.w3.org/2006/vcard/ns#hasName> ?fullName . \n" +
"?fullName a <http://www.w3.org/2006/vcard/ns#Name> . \n" + "?fullName a <http://www.w3.org/2006/vcard/ns#Name> .";
"?fullName <http://www.w3.org/2006/vcard/ns#givenName> ?firstName . \n" + String personFirstNameN3 =
"?fullName <http://www.w3.org/2006/vcard/ns#givenName> ?firstName . ";
String personLastNameN3 =
"?fullName <http://www.w3.org/2006/vcard/ns#familyName> ?lastName ."; "?fullName <http://www.w3.org/2006/vcard/ns#familyName> ?lastName .";
String personMiddleNameN3 = "?fullName <http://www.w3.org/2006/vcard/ns#middleName> ?middleName .";
n3Optional.add(n3); n3Optional.add(personFullNameN3 + "\n " + personFirstNameN3 + "\n " + personLastNameN3);
n3Optional.add(personN3); n3Optional.add(personMiddleNameN3);
return n3Optional; return n3Optional;
} }
@ -174,9 +168,7 @@ public class ManageLabelsForPersonGenerator extends BaseEditConfigurationGenerat
private void setFields(EditConfigurationVTwo editConfiguration, VitroRequest vreq, String predicateUri) { private void setFields(EditConfigurationVTwo editConfiguration, VitroRequest vreq, String predicateUri) {
Map<String, FieldVTwo> fields = new HashMap<String, FieldVTwo>(); Map<String, FieldVTwo> fields = new HashMap<String, FieldVTwo>();
editConfiguration.setFields(fields); editConfiguration.setFields(fields);
editConfiguration.addField(new FieldVTwo().
setName("label").
setValidators(getLabelValidators(vreq, editConfiguration)));
editConfiguration.addField(new FieldVTwo( editConfiguration.addField(new FieldVTwo(
).setName("newLabelLanguage")); ).setName("newLabelLanguage"));
//no validators since all of this is optional //no validators since all of this is optional
@ -186,7 +178,7 @@ public class ManageLabelsForPersonGenerator extends BaseEditConfigurationGenerat
setValidators(getFirstNameValidators(vreq, editConfiguration))); setValidators(getFirstNameValidators(vreq, editConfiguration)));
editConfiguration.addField(new FieldVTwo(). editConfiguration.addField(new FieldVTwo().
setName("middleName"). setName("middleName").
setValidators(getLastNameValidators(vreq, editConfiguration))); setValidators(getMiddleNameValidators(vreq, editConfiguration)));
editConfiguration.addField(new FieldVTwo(). editConfiguration.addField(new FieldVTwo().
setName("lastName"). setName("lastName").
@ -199,39 +191,36 @@ public class ManageLabelsForPersonGenerator extends BaseEditConfigurationGenerat
//first and last name have validators if is person is true //first and last name have validators if is person is true
private List<String> getFirstNameValidators(VitroRequest vreq, EditConfigurationVTwo config) { private List<String> getFirstNameValidators(VitroRequest vreq, EditConfigurationVTwo config) {
List<String> validators = new ArrayList<String>(); List<String> validators = new ArrayList<String>();
if(isPersonType(vreq, config)) {
validators.add("nonempty"); validators.add("nonempty");
}
return validators;
}
private List<String> getMiddleNameValidators(VitroRequest vreq, EditConfigurationVTwo config) {
List<String> validators = new ArrayList<String>();
return validators; return validators;
} }
private List<String> getLastNameValidators(VitroRequest vreq, EditConfigurationVTwo config) { private List<String> getLastNameValidators(VitroRequest vreq, EditConfigurationVTwo config) {
List<String> validators = new ArrayList<String>(); List<String> validators = new ArrayList<String>();
if(isPersonType(vreq, config)) {
validators.add("nonempty"); validators.add("nonempty");
}
return validators; return validators;
} }
//validate label if person is not true
private List<String> getLabelValidators(VitroRequest vreq, EditConfigurationVTwo config) {
List<String> validators = new ArrayList<String>();
if(!isPersonType(vreq, config)) {
validators.add("nonempty");
}
return validators;
}
private void setUrisAndLiteralsOnForm(EditConfigurationVTwo config, private void setUrisAndLiteralsOnForm(EditConfigurationVTwo config,
VitroRequest vreq) { VitroRequest vreq) {
List<String> literalsOnForm = new ArrayList<String>(); List<String> literalsOnForm = new ArrayList<String>();
literalsOnForm.add("label");
literalsOnForm.add("newLabelLanguage"); literalsOnForm.add("newLabelLanguage");
//optional for person //optional for person
literalsOnForm.add("firstName"); literalsOnForm.add("firstName");
literalsOnForm.add("lastName"); literalsOnForm.add("lastName");
literalsOnForm.add("middleName");
config.setLiteralsOnForm(literalsOnForm); config.setLiteralsOnForm(literalsOnForm);
} }
@ -253,17 +242,6 @@ public class ManageLabelsForPersonGenerator extends BaseEditConfigurationGenerat
private void initExistingLabels(EditConfigurationVTwo config, private void initExistingLabels(EditConfigurationVTwo config,
VitroRequest vreq) { VitroRequest vreq) {
this.existingLabelLiterals = this.getExistingLabels(config.getSubjectUri(), vreq); this.existingLabelLiterals = this.getExistingLabels(config.getSubjectUri(), vreq);
// this.labelsSortedByLanguage = this.getLabelsSortedByLanguage(config,vreq);
//language names sorted for the existing languages
// this.existingSortedLanguageNameList = getExistingSortedLanguageNamesList();
//Generate a label to language code hash map
//TODO:
//HashMap<String, String> labelToLanguageCode = new HashMap<String, String>();
//this.labels = getExistingLabels(config.getSubjectUri(), vreq);
//this.labelsSortedByLanguage = getLabelsSortedByLanguage(config.getSubjectUri(), vreq);
} }
@ -318,15 +296,7 @@ public class ManageLabelsForPersonGenerator extends BaseEditConfigurationGenerat
config.addFormSpecificData("subjectName", null); config.addFormSpecificData("subjectName", null);
} }
//Put in whether or not person type config.addFormSpecificData("isPersonType", "true");
if(isPersonType(vreq, config)) {
//Doing this b/c unsure how freemarker will handle boolean value from JAVA
config.addFormSpecificData("isPersonType", "true");
} else {
config.addFormSpecificData("isPersonType", "false");
}
//Include whether or not editable to enable edit/remove links and add to show up //Include whether or not editable to enable edit/remove links and add to show up
config.addFormSpecificData("editable", isEditable(vreq, config)); config.addFormSpecificData("editable", isEditable(vreq, config));
} }
@ -376,7 +346,6 @@ public class ManageLabelsForPersonGenerator extends BaseEditConfigurationGenerat
//Copied from NewIndividualFormGenerator //Copied from NewIndividualFormGenerator
//TODO: Refactor so common code can be used by both generators
public String getFOAFPersonClassURI() { public String getFOAFPersonClassURI() {
return "http://xmlns.com/foaf/0.1/Person"; return "http://xmlns.com/foaf/0.1/Person";
} }

View file

@ -41,6 +41,7 @@ public class NewIndividualFormGenerator extends BaseEditConfigurationGenerator i
)); ));
//Optional because user may have selected either person or individual of another kind //Optional because user may have selected either person or individual of another kind
//Person uses first name and last name whereas individual of other class would use label //Person uses first name and last name whereas individual of other class would use label
//middle name is also optional
config.setN3Optional(list( config.setN3Optional(list(
N3_PREFIX + "@prefix vcard:<http://www.w3.org/2006/vcard/ns#> .\n" N3_PREFIX + "@prefix vcard:<http://www.w3.org/2006/vcard/ns#> .\n"
+ " ?newInd <http://purl.obolibrary.org/obo/ARG_2000028> ?newVcardInd . \n" + " ?newInd <http://purl.obolibrary.org/obo/ARG_2000028> ?newVcardInd . \n"
@ -50,6 +51,7 @@ public class NewIndividualFormGenerator extends BaseEditConfigurationGenerator i
+ " ?newVcardName a <http://www.w3.org/2006/vcard/ns#Name> . \n" + " ?newVcardName a <http://www.w3.org/2006/vcard/ns#Name> . \n"
+ " ?newVcardName vcard:givenName ?firstName . \n" + " ?newVcardName vcard:givenName ?firstName . \n"
+ " ?newVcardName vcard:familyName ?lastName .", + " ?newVcardName vcard:familyName ?lastName .",
"?newVcardName <http://www.w3.org/2006/vcard/ns#middleName> ?middleName .",
N3_PREFIX + " ?newInd <" + RDFS.label.getURI() + "> ?label ." N3_PREFIX + " ?newInd <" + RDFS.label.getURI() + "> ?label ."
)); ));
@ -58,7 +60,7 @@ public class NewIndividualFormGenerator extends BaseEditConfigurationGenerator i
config.addNewResource("newVcardName", vreq.getWebappDaoFactory().getDefaultNamespace()); config.addNewResource("newVcardName", vreq.getWebappDaoFactory().getDefaultNamespace());
config.setUrisOnform(list ()); config.setUrisOnform(list ());
config.setLiteralsOnForm( list( "label", "firstName", "lastName" )); config.setLiteralsOnForm( list( "label", "firstName", "lastName", "middleName" ));
setUrisAndLiteralsInScope(config); setUrisAndLiteralsInScope(config);
//No SPARQL queries for existing since this is only used to create new, never for edit //No SPARQL queries for existing since this is only used to create new, never for edit
@ -67,6 +69,11 @@ public class NewIndividualFormGenerator extends BaseEditConfigurationGenerator i
setRangeDatatypeUri(XSD.xstring.getURI()). setRangeDatatypeUri(XSD.xstring.getURI()).
setValidators(getFirstNameValidators(vreq))); setValidators(getFirstNameValidators(vreq)));
config.addField(new FieldVTwo().
setName("middleName").
setRangeDatatypeUri(XSD.xstring.getURI()).
setValidators(getMiddleNameValidators(vreq)));
config.addField(new FieldVTwo(). config.addField(new FieldVTwo().
setName("lastName"). setName("lastName").
setRangeDatatypeUri(XSD.xstring.getURI()). setRangeDatatypeUri(XSD.xstring.getURI()).
@ -96,7 +103,12 @@ public class NewIndividualFormGenerator extends BaseEditConfigurationGenerator i
return config; return config;
} }
//first and last name have validators if is person is true private List<String> getMiddleNameValidators(VitroRequest vreq) {
List<String> validators = new ArrayList<String>();
return validators;
}
//first and last name have validators if is person is true
private List<String> getFirstNameValidators(VitroRequest vreq) { private List<String> getFirstNameValidators(VitroRequest vreq) {
List<String> validators = new ArrayList<String>(); List<String> validators = new ArrayList<String>();
if(isPersonType(vreq)) { if(isPersonType(vreq)) {

View file

@ -0,0 +1,105 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.ResIterator;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Statement;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
/*
* This preprocessor is used to set the language attribute on the label based on the user selection
* on the manage labels page when adding a new label.
*/
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.BaseEditSubmissionPreprocessorVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.MultiValueEditSubmission;
public class ManageLabelsForPersonPreprocessor extends ManageLabelsForIndividualPreprocessor {
public ManageLabelsForPersonPreprocessor(EditConfigurationVTwo editConfig) {
super(editConfig);
}
@Override
public void preprocess(MultiValueEditSubmission inputSubmission, VitroRequest vreq) {
//Use the ManageLabelsForIndividualPreprocessor in addition to this code specific for person
super.preprocess(inputSubmission, vreq);
//First name and last name would also have a language selected so make sure those literals are also
//correctly typed
//Middle name is optional
if(inputSubmission.hasLiteralValue("firstName") && inputSubmission.hasLiteralValue("lastName") && inputSubmission.hasLiteralValue("newLabelLanguage")) {
Map<String, List<Literal>> literalsFromForm = inputSubmission.getLiteralsFromForm();
List<Literal> newLabelLanguages = literalsFromForm.get("newLabelLanguage");
List<Literal> firstNames = literalsFromForm.get("firstName");
List<Literal> lastNames = literalsFromForm.get("lastName");
List<Literal> middleNames = new ArrayList<Literal>();
if(inputSubmission.hasLiteralValue("middleName")) {
middleNames = literalsFromForm.get("middleName");
}
//Expecting only one language
if(firstNames.size() > 0 && lastNames.size() > 0 && newLabelLanguages.size() > 0) {
Literal newLabelLanguage = newLabelLanguages.get(0);
Literal firstNameLiteral = firstNames.get(0);
Literal lastNameLiteral = lastNames.get(0);
//Get the string
String lang = this.getLanguage(newLabelLanguage.getString());
String firstNameValue = firstNameLiteral.getString();
String lastNameValue = lastNameLiteral.getString();
//Now add the language category to the literal
Literal firstNameWithLanguage = inputSubmission.createLiteral(firstNameValue,
null,
lang);
Literal lastNameWithLanguage = inputSubmission.createLiteral(lastNameValue,
null,
lang);
firstNames = new ArrayList<Literal>();
lastNames = new ArrayList<Literal>();
firstNames.add(firstNameWithLanguage);
lastNames.add(lastNameWithLanguage);
//replace the label with one with language, again assuming only one label being returned
literalsFromForm.put("firstName", firstNames);
literalsFromForm.put("lastName", lastNames);
//Middle name handling
if(middleNames.size() > 0) {
Literal middleNameLiteral = middleNames.get(0);
String middleNameValue = middleNameLiteral.getString();
Literal middleNameWithLanguage = inputSubmission.createLiteral(middleNameValue,
null,
lang);
middleNames = new ArrayList<Literal>();
middleNames.add(middleNameWithLanguage);
literalsFromForm.put("middleName", middleNames);
}
//Set literals
inputSubmission.setLiteralsFromForm(literalsFromForm);
}
}
}
}