From 0f3a4653abd1876c6a8940c6605810e18ed22643 Mon Sep 17 00:00:00 2001 From: tworrall Date: Thu, 10 Oct 2013 14:51:18 -0400 Subject: [PATCH] VIVO-341: new custom form et all for preferred title --- .../themes/wilma/i18n/all_es.properties | 5 +- .../config/listViewConfig-preferredTitle.xml | 43 +++++++ .../propStatement-preferredTitle.ftl | 17 +++ .../edit/forms/personHasPreferredTitle.ftl | 86 ++++++++++++++ .../edit/forms/personHasTelephoneNumber.ftl | 2 +- rdf/display/everytime/PropertyConfig.n3 | 15 +++ .../PersonHasPreferredTitleGenerator.java | 105 ++++++++++++++++++ themes/wilma/i18n/all.properties | 5 +- .../templates/individual--foaf-person.ftl | 6 +- 9 files changed, 278 insertions(+), 6 deletions(-) create mode 100644 productMods/config/listViewConfig-preferredTitle.xml create mode 100644 productMods/templates/freemarker/body/partials/individual/propStatement-preferredTitle.ftl create mode 100644 productMods/templates/freemarker/edit/forms/personHasPreferredTitle.ftl create mode 100644 src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/PersonHasPreferredTitleGenerator.java diff --git a/languages/example/themes/wilma/i18n/all_es.properties b/languages/example/themes/wilma/i18n/all_es.properties index 484980a3..ff406899 100644 --- a/languages/example/themes/wilma/i18n/all_es.properties +++ b/languages/example/themes/wilma/i18n/all_es.properties @@ -845,4 +845,7 @@ no_linked_author = ningún editor vinculados remove_editor_link = desconecte la conexión de editor add_an_editor = Agregar uno Editor add_editor = Agregar Editor -please_select_type = Por favor Seleccione un tipo de la lista desplegable. \ No newline at end of file +please_select_type = Por favor Seleccione un tipo de la lista desplegable. +preferred_title = Título Preferido +preferred_title_for = título preferido para +enter_preferred_title = Por favor, introduzca un valor en el campo Preferred Title. diff --git a/productMods/config/listViewConfig-preferredTitle.xml b/productMods/config/listViewConfig-preferredTitle.xml new file mode 100644 index 00000000..c592fbb9 --- /dev/null +++ b/productMods/config/listViewConfig-preferredTitle.xml @@ -0,0 +1,43 @@ + + + + + + + + PREFIX vcard: <http://www.w3.org/2006/vcard/ns#> + + SELECT DISTINCT ?vcard + ?title + ?preferredTitle + WHERE { + ?subject ?property ?vcard . + ?vcard vcard:hasTitle ?title + OPTIONAL { ?title vcard:title ?preferredTitle } + + } + + + + PREFIX vcard: <http://www.w3.org/2006/vcard/ns#> + CONSTRUCT { + ?subject ?property ?vcard . + ?vcard vcard:hasTitle ?title . + ?title ?titleProperty ?titleValue + } WHERE { + { + ?subject ?property ?vcard + } UNION { + ?subject ?property ?vcard . + ?vcard vcard:hasTitle ?title + } UNION { + ?subject ?property ?vcard . + ?vcard vcard:hasTitle ?title . + ?title ?titleProperty ?titleValue + } + } + + + + edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.MaintainDuplicatesObjectPropertyDataPostProcessor + diff --git a/productMods/templates/freemarker/body/partials/individual/propStatement-preferredTitle.ftl b/productMods/templates/freemarker/body/partials/individual/propStatement-preferredTitle.ftl new file mode 100644 index 00000000..c94dd474 --- /dev/null +++ b/productMods/templates/freemarker/body/partials/individual/propStatement-preferredTitle.ftl @@ -0,0 +1,17 @@ +<#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> + +<#-- + This template must be self-contained and not rely on other variables set for the individual page, because it + is also used to generate the property statement during a deletion. + --> +<@showPreferredTitle statement /> + +<#-- Use a macro to keep variable assignments local; otherwise the values carry over to the + next statement --> +<#macro showPreferredTitle statement> + + <#if statement.number?has_content> + ${statement.preferredTitle} + + + \ No newline at end of file diff --git a/productMods/templates/freemarker/edit/forms/personHasPreferredTitle.ftl b/productMods/templates/freemarker/edit/forms/personHasPreferredTitle.ftl new file mode 100644 index 00000000..2d945e4e --- /dev/null +++ b/productMods/templates/freemarker/edit/forms/personHasPreferredTitle.ftl @@ -0,0 +1,86 @@ +<#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> + +<#-- this is in request.subject.name --> + +<#-- leaving this edit/add mode code in for reference in case we decide we need it --> + +<#import "lib-vivo-form.ftl" as lvf> + +<#--Retrieve certain edit configuration information--> +<#if editConfiguration.objectUri?has_content> + <#assign editMode = "edit"> +<#else> + <#assign editMode = "add"> + + +<#assign htmlForElements = editConfiguration.pageData.htmlForElements /> + +<#--Retrieve variables needed--> +<#assign preferredTitleValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "preferredTitle") /> + +<#--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 editMode == "edit"> + <#assign titleVerb="${i18n().edit_capitalized}"> + <#assign submitButtonText="${titleVerb}" + " ${i18n().preferred_title}"> + <#assign disabledVal="disabled"> +<#else> + <#assign titleVerb="${i18n().create_capitalized}"> + <#assign submitButtonText="${titleVerb}" + " ${i18n().preferred_title}"> + <#assign disabledVal=""/> + + +<#assign requiredHint = " *" /> + +

${titleVerb} ${i18n().preferred_title_for} ${editConfiguration.subjectName}

+ +<#--Display error messages if any--> +<#if submissionErrors?has_content> + + + +<@lvf.unsupportedBrowser urls.base /> + +
+ +
+ +

+ + +

+ + + +

+ ${i18n().or} + ${i18n().cancel_link} +

+ +

* ${i18n().required_fields}

+ +
+ +
+ +${stylesheets.add('')} +${stylesheets.add('')} +${stylesheets.add('')} + +${scripts.add('', + '', + '', + '')} + + diff --git a/productMods/templates/freemarker/edit/forms/personHasTelephoneNumber.ftl b/productMods/templates/freemarker/edit/forms/personHasTelephoneNumber.ftl index c3493c29..d3035345 100644 --- a/productMods/templates/freemarker/edit/forms/personHasTelephoneNumber.ftl +++ b/productMods/templates/freemarker/edit/forms/personHasTelephoneNumber.ftl @@ -35,7 +35,7 @@ <#assign requiredHint = " *" /> -

${titleVerb} ${i18n().mailing_address_for} ${editConfiguration.subjectName}

+

${titleVerb} ${i18n().telephone_number_for} ${editConfiguration.subjectName}

<#--Display error messages if any--> <#if submissionErrors?has_content> diff --git a/rdf/display/everytime/PropertyConfig.n3 b/rdf/display/everytime/PropertyConfig.n3 index a98b2a32..56225b97 100644 --- a/rdf/display/everytime/PropertyConfig.n3 +++ b/rdf/display/everytime/PropertyConfig.n3 @@ -482,6 +482,21 @@ local:fullNameConfig a :ObjectPropertyDisplayConfig ; vitro:customEntryFormAnnot "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddFullNameToPersonGenerator"^^ ; :propertyGroup . +local:preferredTitleContext a :ConfigContext ; + :hasConfiguration local:preferredTitleConfig ; + :configContextFor ; + :qualifiedByDomain ; + :qualifiedBy . + +local:preferredTitleConfig a :ObjectPropertyDisplayConfig ; + :listViewConfigFile "listViewConfig-preferredTitle.xml"^^xsd:string ; + :displayName "preferred title" ; + vitro:displayRankAnnot 8; + vitro:hiddenFromDisplayBelowRoleLevelAnnot role:public ; + vitro:prohibitedFromUpdateBelowRoleLevelAnnot role:public ; + vitro:customEntryFormAnnot "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.PersonHasPreferredTitleGenerator"^^ ; + :propertyGroup . + ### properties using default editing form ## local:eventWithinContext a :ConfigContext ; diff --git a/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/PersonHasPreferredTitleGenerator.java b/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/PersonHasPreferredTitleGenerator.java new file mode 100644 index 00000000..b399544f --- /dev/null +++ b/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/PersonHasPreferredTitleGenerator.java @@ -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.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 org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.hp.hpl.jena.vocabulary.XSD; + +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; +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.fields.ChildVClassesOptions; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.IndividualsViaVClassOptions; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation; + +public class PersonHasPreferredTitleGenerator extends VivoBaseGenerator implements + EditConfigurationGenerator { + private Log log = LogFactory.getLog(PersonHasPreferredTitleGenerator.class); + + @Override + public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, + HttpSession session) throws Exception { + + EditConfigurationVTwo conf = new EditConfigurationVTwo(); + + initBasics(conf, vreq); + initPropertyParameters(vreq, session, conf); + initObjectPropForm(conf, vreq); + String titleUri = getTitleUri(vreq); + + conf.setTemplate("personHasPreferredTitle.ftl"); + + conf.setVarNameForSubject("person"); + conf.setVarNameForPredicate("predicate"); + conf.setVarNameForObject("individualVcard"); + + conf.setN3Required( Arrays.asList( n3ForNewPhone ) ); + conf.setN3Optional( Arrays.asList( preferredTitleAssertion ) ); + + conf.addNewResource("title", DEFAULT_NS_FOR_NEW_RESOURCE); + conf.addNewResource("individualVcard", DEFAULT_NS_FOR_NEW_RESOURCE); + + conf.setLiteralsOnForm(Arrays.asList("preferredTitle" )); + + conf.addSparqlForExistingLiteral("preferredTitle", preferredTitleQuery); + conf.addSparqlForAdditionalUrisInScope("individualVcard", individualVcardQuery); + + if ( conf.isUpdate() ) { + HashMap> urisInScope = new HashMap>(); + urisInScope.put("title", Arrays.asList(new String[]{titleUri})); + conf.addUrisInScope(urisInScope); + } + + conf.addField( new FieldVTwo(). + setName("preferredTitle") + .setRangeDatatypeUri( XSD.xstring.toString() ). + setValidators( list("nonempty") )); + + conf.addValidator(new AntiXssValidation()); + + prepare(vreq, conf); + return conf; + } + + /* N3 assertions */ + + final static String n3ForNewPhone = + "?person ?individualVcard . \n" + + "?individualVcard a . \n" + + "?individualVcard ?person . \n" + + "?individualVcard ?title . \n" + + "?title a . " ; + + final static String preferredTitleAssertion = + "?title ?preferredTitle ."; + + /* Queries for editing an existing entry */ + + final static String individualVcardQuery = + "SELECT ?existingIndividualVcard WHERE { \n" + + "?person ?existingIndividualVcard . \n" + + "}"; + + final static String preferredTitleQuery = + "SELECT ?existingPreferredTitle WHERE {\n"+ + "?title ?existingPreferredTitle . }"; + + private String getTitleUri(VitroRequest vreq) { + String titleUri = vreq.getParameter("titleUri"); + + return titleUri; + } +} diff --git a/themes/wilma/i18n/all.properties b/themes/wilma/i18n/all.properties index 6879e455..8d336220 100644 --- a/themes/wilma/i18n/all.properties +++ b/themes/wilma/i18n/all.properties @@ -863,4 +863,7 @@ no_linked_author = no linked editor remove_editor_link = remove editor link add_an_editor = Add an Editor add_editor = Add Editor -please_select_type = Please select a type from the drop-down list. \ No newline at end of file +please_select_type = Please select a type from the drop-down list. +preferred_title = Preferred Title +preferred_title_for = preferred title for +enter_preferred_title = Please enter a value in the Preferred Title field. diff --git a/themes/wilma/templates/individual--foaf-person.ftl b/themes/wilma/templates/individual--foaf-person.ftl index af5a9657..3b13188e 100644 --- a/themes/wilma/templates/individual--foaf-person.ftl +++ b/themes/wilma/templates/individual--foaf-person.ftl @@ -67,12 +67,12 @@ <@p.label individual editable labelCount localesCount/> <#-- Display preferredTitle if it exists; otherwise mostSpecificTypes --> - <#assign title = propertyGroups.pullProperty("${core}preferredTitle")!> + <#assign title = propertyGroups.pullProperty("http://purl.obolibrary.org/obo/ARG_2000028","http://www.w3.org/2006/vcard/ns#Title")!> <#if title?has_content> <#-- true when the property is in the list, even if not populated (when editing) --> <@p.addLinkWithLabel title editable /> <#list title.statements as statement> - ${statement.value} - <@p.editingLinks "${title.name}" "" statement editable /> + ${statement.preferredTitle} + <@p.editingLinks "${title.localName}" "${title.name}" statement editable /> <#-- If preferredTitle is unpopulated, display mostSpecificTypes -->