Merge branch 'develop' of https://github.com/vivo-project/VIVO into develop
This commit is contained in:
commit
b8cff8458a
6 changed files with 156 additions and 64 deletions
|
@ -3,17 +3,17 @@
|
|||
<#assign isPersonType = editConfiguration.pageData.isPersonType />
|
||||
<form id="addLabelForm" name="addLabelForm" class="customForm" action="${submitUrl}">
|
||||
<h2>${i18n().add_label}</h2>
|
||||
<#if isPersonType = "true">
|
||||
<#if isPersonType?has_content && isPersonType = "true">
|
||||
<p>
|
||||
<label for="firstName">${i18n().first_name} ${requiredHint}</label>
|
||||
<input size="30" type="text" id="firstName" name="firstName" value="${firstNameValue}" />
|
||||
</p>
|
||||
<#--TODO: With ISF changes, add middle name input-->
|
||||
|
||||
<!--p-->
|
||||
<!--label for="middleName">${i18n().middle_name} ${requiredHint}</label>
|
||||
<p>
|
||||
<label for="middleName">${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>
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
<#--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 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 newLabelLanguageValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "newLabelLanguage")/>
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
<#--Get existing value for specific data literals and uris-->
|
||||
<#assign firstNameValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "firstName")/>
|
||||
<#assign lastNameValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "lastName")/>
|
||||
<#assign middleNameValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "middleName")/>
|
||||
|
||||
<#assign labelValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "label")/>
|
||||
|
||||
<#--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}" />
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="lastName">${i18n().middle_name} </label>
|
||||
<input size="30" type="text" id="middleName" name="middleName" value="${middleNameValue}" />
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="lastName">${i18n().last_name} ${requiredHint}</label>
|
||||
<input size="30" type="text" id="lastName" name="lastName" value="${lastNameValue}" />
|
||||
|
|
|
@ -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.configuration.preprocessors.FoafNameToRdfsLabelPreprocessor;
|
||||
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.LocaleSelectorUtilities;
|
||||
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 HashMap<String, List<LabelInformation>> labelsSortedByLanguage = 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
|
||||
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, HttpSession session) {
|
||||
|
||||
|
@ -115,7 +111,7 @@ public class ManageLabelsForPersonGenerator extends BaseEditConfigurationGenerat
|
|||
addFormSpecificData(config, vreq);
|
||||
//This preprocessor handles getting the correct label language and putting the attribute on the label
|
||||
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
|
||||
//a language with that label
|
||||
config.addModelChangePreprocessor(new FoafNameToRdfsLabelPreprocessor());
|
||||
|
@ -150,22 +146,20 @@ public class ManageLabelsForPersonGenerator extends BaseEditConfigurationGenerat
|
|||
|
||||
private List<String> generateN3Optional(VitroRequest vreq) {
|
||||
List<String> n3Optional = new ArrayList<String>();
|
||||
String predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
|
||||
String n3 = "?subject <" + predicateUri + "> ?label ";
|
||||
//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 +
|
||||
|
||||
String personFullNameN3 = this.N3_PREFIX +
|
||||
"?subject <http://purl.obolibrary.org/obo/ARG_2000028> ?individualVcard . \n" +
|
||||
"?individualVcard a <http://www.w3.org/2006/vcard/ns#Individual> . \n" +
|
||||
"?individualVcard <http://purl.obolibrary.org/obo/ARG_2000029> ?subject . \n" +
|
||||
"?individualVcard <http://www.w3.org/2006/vcard/ns#hasName> ?fullName . \n" +
|
||||
"?fullName a <http://www.w3.org/2006/vcard/ns#Name> . \n" +
|
||||
"?fullName <http://www.w3.org/2006/vcard/ns#givenName> ?firstName . \n" +
|
||||
"?fullName a <http://www.w3.org/2006/vcard/ns#Name> .";
|
||||
String personFirstNameN3 =
|
||||
"?fullName <http://www.w3.org/2006/vcard/ns#givenName> ?firstName . ";
|
||||
String personLastNameN3 =
|
||||
"?fullName <http://www.w3.org/2006/vcard/ns#familyName> ?lastName .";
|
||||
|
||||
n3Optional.add(n3);
|
||||
n3Optional.add(personN3);
|
||||
String personMiddleNameN3 = "?fullName <http://www.w3.org/2006/vcard/ns#middleName> ?middleName .";
|
||||
n3Optional.add(personFullNameN3 + "\n " + personFirstNameN3 + "\n " + personLastNameN3);
|
||||
n3Optional.add(personMiddleNameN3);
|
||||
return n3Optional;
|
||||
}
|
||||
|
||||
|
@ -174,9 +168,7 @@ public class ManageLabelsForPersonGenerator extends BaseEditConfigurationGenerat
|
|||
private void setFields(EditConfigurationVTwo editConfiguration, VitroRequest vreq, String predicateUri) {
|
||||
Map<String, FieldVTwo> fields = new HashMap<String, FieldVTwo>();
|
||||
editConfiguration.setFields(fields);
|
||||
editConfiguration.addField(new FieldVTwo().
|
||||
setName("label").
|
||||
setValidators(getLabelValidators(vreq, editConfiguration)));
|
||||
|
||||
editConfiguration.addField(new FieldVTwo(
|
||||
).setName("newLabelLanguage"));
|
||||
//no validators since all of this is optional
|
||||
|
@ -186,7 +178,7 @@ public class ManageLabelsForPersonGenerator extends BaseEditConfigurationGenerat
|
|||
setValidators(getFirstNameValidators(vreq, editConfiguration)));
|
||||
editConfiguration.addField(new FieldVTwo().
|
||||
setName("middleName").
|
||||
setValidators(getLastNameValidators(vreq, editConfiguration)));
|
||||
setValidators(getMiddleNameValidators(vreq, editConfiguration)));
|
||||
|
||||
editConfiguration.addField(new FieldVTwo().
|
||||
setName("lastName").
|
||||
|
@ -199,39 +191,36 @@ public class ManageLabelsForPersonGenerator extends BaseEditConfigurationGenerat
|
|||
//first and last name have validators if is person is true
|
||||
private List<String> getFirstNameValidators(VitroRequest vreq, EditConfigurationVTwo config) {
|
||||
List<String> validators = new ArrayList<String>();
|
||||
if(isPersonType(vreq, config)) {
|
||||
validators.add("nonempty");
|
||||
|
||||
return validators;
|
||||
}
|
||||
|
||||
private List<String> getMiddleNameValidators(VitroRequest vreq, EditConfigurationVTwo config) {
|
||||
List<String> validators = new ArrayList<String>();
|
||||
|
||||
return validators;
|
||||
}
|
||||
|
||||
private List<String> getLastNameValidators(VitroRequest vreq, EditConfigurationVTwo config) {
|
||||
List<String> validators = new ArrayList<String>();
|
||||
if(isPersonType(vreq, config)) {
|
||||
validators.add("nonempty");
|
||||
}
|
||||
|
||||
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,
|
||||
VitroRequest vreq) {
|
||||
List<String> literalsOnForm = new ArrayList<String>();
|
||||
literalsOnForm.add("label");
|
||||
literalsOnForm.add("newLabelLanguage");
|
||||
//optional for person
|
||||
literalsOnForm.add("firstName");
|
||||
literalsOnForm.add("lastName");
|
||||
literalsOnForm.add("middleName");
|
||||
config.setLiteralsOnForm(literalsOnForm);
|
||||
|
||||
}
|
||||
|
@ -253,17 +242,6 @@ public class ManageLabelsForPersonGenerator extends BaseEditConfigurationGenerat
|
|||
private void initExistingLabels(EditConfigurationVTwo config,
|
||||
VitroRequest 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);
|
||||
}
|
||||
|
||||
//Put in whether or not person type
|
||||
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
|
||||
config.addFormSpecificData("editable", isEditable(vreq, config));
|
||||
}
|
||||
|
@ -376,7 +346,6 @@ public class ManageLabelsForPersonGenerator extends BaseEditConfigurationGenerat
|
|||
|
||||
|
||||
//Copied from NewIndividualFormGenerator
|
||||
//TODO: Refactor so common code can be used by both generators
|
||||
public String getFOAFPersonClassURI() {
|
||||
return "http://xmlns.com/foaf/0.1/Person";
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ public class NewIndividualFormGenerator extends BaseEditConfigurationGenerator i
|
|||
));
|
||||
//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
|
||||
//middle name is also optional
|
||||
config.setN3Optional(list(
|
||||
N3_PREFIX + "@prefix vcard:<http://www.w3.org/2006/vcard/ns#> .\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 vcard:givenName ?firstName . \n"
|
||||
+ " ?newVcardName vcard:familyName ?lastName .",
|
||||
"?newVcardName <http://www.w3.org/2006/vcard/ns#middleName> ?middleName .",
|
||||
N3_PREFIX + " ?newInd <" + RDFS.label.getURI() + "> ?label ."
|
||||
));
|
||||
|
||||
|
@ -58,7 +60,7 @@ public class NewIndividualFormGenerator extends BaseEditConfigurationGenerator i
|
|||
config.addNewResource("newVcardName", vreq.getWebappDaoFactory().getDefaultNamespace());
|
||||
|
||||
config.setUrisOnform(list ());
|
||||
config.setLiteralsOnForm( list( "label", "firstName", "lastName" ));
|
||||
config.setLiteralsOnForm( list( "label", "firstName", "lastName", "middleName" ));
|
||||
setUrisAndLiteralsInScope(config);
|
||||
//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()).
|
||||
setValidators(getFirstNameValidators(vreq)));
|
||||
|
||||
config.addField(new FieldVTwo().
|
||||
setName("middleName").
|
||||
setRangeDatatypeUri(XSD.xstring.getURI()).
|
||||
setValidators(getMiddleNameValidators(vreq)));
|
||||
|
||||
config.addField(new FieldVTwo().
|
||||
setName("lastName").
|
||||
setRangeDatatypeUri(XSD.xstring.getURI()).
|
||||
|
@ -96,6 +103,11 @@ public class NewIndividualFormGenerator extends BaseEditConfigurationGenerator i
|
|||
return config;
|
||||
}
|
||||
|
||||
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) {
|
||||
List<String> validators = new ArrayList<String>();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue