From 43289ba71e117f561f5814406cffb118ce59fbc2 Mon Sep 17 00:00:00 2001 From: Brian Lowe Date: Fri, 28 May 2021 15:52:16 +0300 Subject: [PATCH 1/4] Get language-aware results for existing labels in ManageLabelsForPersonGenerator --- .../generators/ManageLabelsForPersonGenerator.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManageLabelsForPersonGenerator.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManageLabelsForPersonGenerator.java index fe2f2609c..41da2d39a 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManageLabelsForPersonGenerator.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManageLabelsForPersonGenerator.java @@ -432,28 +432,27 @@ public int compare(LabelInformation l1, LabelInformation l2) { + " ?subject rdfs:label ?label \n" + "} ORDER BY ?label"; - + private ArrayList getExistingLabels(String subjectUri, VitroRequest vreq) { String queryStr = QueryUtils.subUriForQueryVar(LABEL_QUERY, "subject", subjectUri); log.debug("queryStr = " + queryStr); ArrayList labels = new ArrayList(); try { - //We want to get the labels for all the languages, not just the display language - ResultSet results = QueryUtils.getLanguageNeutralQueryResults(queryStr, vreq); + // No longer retrieving language-neutral results here, so that + // language editing is consistent with other editing forms. + // Editable values depend on the interface's locale selector. + ResultSet results = QueryUtils.getQueryResults(queryStr, vreq); while (results.hasNext()) { QuerySolution soln = results.nextSolution(); Literal nodeLiteral = soln.get("label").asLiteral(); labels.add(nodeLiteral); - - } } catch (Exception e) { log.error(e, e); } return labels; -} - + } //Putting this into a method allows overriding it in subclasses From dc56107d4d870b04f1e88683324339c94de7c954 Mon Sep 17 00:00:00 2001 From: Brian Lowe Date: Fri, 4 Jun 2021 17:00:26 +0300 Subject: [PATCH 2/4] Pass languageCount value to label macro --- .../body/individual/individual--foaf-person-2column.ftl | 2 +- .../body/individual/individual--foaf-person-quickview.ftl | 2 +- .../templates/body/individual/individual--foaf-person.ftl | 2 +- .../webapp/themes/wilma/templates/individual--foaf-person.ftl | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/webapp/src/main/webapp/templates/freemarker/body/individual/individual--foaf-person-2column.ftl b/webapp/src/main/webapp/templates/freemarker/body/individual/individual--foaf-person-2column.ftl index 15b782f7e..95231ad58 100644 --- a/webapp/src/main/webapp/templates/freemarker/body/individual/individual--foaf-person-2column.ftl +++ b/webapp/src/main/webapp/templates/freemarker/body/individual/individual--foaf-person-2column.ftl @@ -51,7 +51,7 @@ <#else>

style="float:left;border-right:1px solid #A6B1B0;"> <#-- Label --> - <@p.label individual editable labelCount localesCount/> + <@p.label individual editable labelCount localesCount languageCount />

<#-- Display preferredTitle if it exists; otherwise mostSpecificTypes --> <#assign title = propertyGroups.pullProperty("http://purl.obolibrary.org/obo/ARG_2000028","http://www.w3.org/2006/vcard/ns#Title")!> diff --git a/webapp/src/main/webapp/templates/freemarker/body/individual/individual--foaf-person-quickview.ftl b/webapp/src/main/webapp/templates/freemarker/body/individual/individual--foaf-person-quickview.ftl index 0745d7c40..fa2997eaa 100644 --- a/webapp/src/main/webapp/templates/freemarker/body/individual/individual--foaf-person-quickview.ftl +++ b/webapp/src/main/webapp/templates/freemarker/body/individual/individual--foaf-person-quickview.ftl @@ -62,7 +62,7 @@
${individualImage}

style="float:left;border-right:1px solid #A6B1B0;"> <#-- Label --> - <@p.label individual editable labelCount localesCount/> + <@p.label individual editable labelCount localesCount languageCount />

<#-- Display preferredTitle if it exists; otherwise mostSpecificTypes --> <#assign title = propertyGroups.pullProperty("http://purl.obolibrary.org/obo/ARG_2000028","http://www.w3.org/2006/vcard/ns#Title")!> diff --git a/webapp/src/main/webapp/themes/tenderfoot/templates/body/individual/individual--foaf-person.ftl b/webapp/src/main/webapp/themes/tenderfoot/templates/body/individual/individual--foaf-person.ftl index 4d32f3e76..4c32496af 100644 --- a/webapp/src/main/webapp/themes/tenderfoot/templates/body/individual/individual--foaf-person.ftl +++ b/webapp/src/main/webapp/themes/tenderfoot/templates/body/individual/individual--foaf-person.ftl @@ -65,7 +65,7 @@

<#-- Label --> - <@p.label individual editable labelCount localesCount/> + <@p.label individual editable labelCount localesCount languageCount />

<#-- Display preferredTitle if it exists; otherwise mostSpecificTypes --> diff --git a/webapp/src/main/webapp/themes/wilma/templates/individual--foaf-person.ftl b/webapp/src/main/webapp/themes/wilma/templates/individual--foaf-person.ftl index 8dbf46234..0aaa19de6 100644 --- a/webapp/src/main/webapp/themes/wilma/templates/individual--foaf-person.ftl +++ b/webapp/src/main/webapp/themes/wilma/templates/individual--foaf-person.ftl @@ -89,7 +89,7 @@ <#else>

<#-- Label --> - <@p.label individual editable labelCount localesCount/> + <@p.label individual editable labelCount localesCount languageCount />

<#-- Display preferredTitle if it exists; otherwise mostSpecificTypes --> From f4f6dddb118a644b5e627eedea97c6aa341d8f96 Mon Sep 17 00:00:00 2001 From: Brian Lowe Date: Wed, 16 Jun 2021 21:43:30 +0300 Subject: [PATCH 3/4] Retrieve locales used in label statements instead of only selectable locales --- .../ManageLabelsForPersonGenerator.java | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManageLabelsForPersonGenerator.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManageLabelsForPersonGenerator.java index 41da2d39a..b2f0923e3 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManageLabelsForPersonGenerator.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManageLabelsForPersonGenerator.java @@ -15,6 +15,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Set; import javax.servlet.http.HttpSession; @@ -41,6 +42,7 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.FoafNameToRdfsLabelPreprocessor; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ManageLabelsForPersonPreprocessor; import edu.cornell.mannlib.vitro.webapp.i18n.selection.SelectedLocale; +import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringUtils; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.DataPropertyStatementTemplateModel; /** @@ -246,12 +248,12 @@ private List getExistingSortedLanguageNamesList() { private void addFormSpecificData(EditConfigurationVTwo config, VitroRequest vreq) { + ArrayList existingLabels = this.getExistingLabels(config.getSubjectUri(), vreq); //Get all language codes/labels in the system, and this list is sorted by language name - List> locales = this.getLocales(vreq); + List> locales = this.getLocales(vreq, existingLabels); //Get code to label hashmap - we use this to get the language name for the language code returned in the rdf literal HashMap localeCodeToNameMap = this.getFullCodeToLanguageNameMap(locales); //the labels already added by the user - ArrayList existingLabels = this.getExistingLabels(config.getSubjectUri(), vreq); int numberExistingLabels = existingLabels.size(); //existing labels keyed by language name and each of the list of labels is sorted by language name HashMap> existingLabelsByLanguageName = this.getLabelsSortedByLanguageName(existingLabels, localeCodeToNameMap, config, vreq); @@ -466,30 +468,32 @@ protected String getTemplate() { return template; } + //get locales present in list of literals + public List> getLocales(VitroRequest vreq, + List existingLiterals) { + Set locales = new HashSet(); + for(Literal literal : existingLiterals) { + String language = literal.getLanguage(); + if(!StringUtils.isEmpty(language)) { + locales.add(LanguageFilteringUtils.languageToLocale(language)); + } + } + if (locales.isEmpty()) { + return Collections.emptyList(); + } + List> list = new ArrayList>(); + Locale currentLocale = SelectedLocale.getCurrentLocale(vreq); + for (Locale locale : locales) { + try { + list.add(buildLocaleMap(locale, currentLocale)); + } catch (FileNotFoundException e) { + log.warn("Can't show locale '" + locale + "': " + e); + } + } - - //get locales - public List> getLocales(VitroRequest vreq) { - List selectables = SelectedLocale.getSelectableLocales(vreq); - if (selectables.isEmpty()) { - return Collections.emptyList(); - } - List> list = new ArrayList>(); - Locale currentLocale = SelectedLocale.getCurrentLocale(vreq); - for (Locale locale : selectables) { - try { - list.add(buildLocaleMap(locale, currentLocale)); - } catch (FileNotFoundException e) { - log.warn("Can't show the Locale selector for '" + locale - + "': " + e); - } - } - - return list; + return list; } - - public HashMap getFullCodeToLanguageNameMap(List> localesList) { HashMap codeToLanguageMap = new HashMap(); for(Map locale: localesList) { From 3de9a03ab54d0ba29ba3b7c0efa99b57b9fbff0a Mon Sep 17 00:00:00 2001 From: Brian Lowe Date: Wed, 16 Jun 2021 21:54:48 +0300 Subject: [PATCH 4/4] Update comment --- .../generators/ManageLabelsForPersonGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManageLabelsForPersonGenerator.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManageLabelsForPersonGenerator.java index b2f0923e3..d91462130 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManageLabelsForPersonGenerator.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManageLabelsForPersonGenerator.java @@ -249,7 +249,7 @@ private List getExistingSortedLanguageNamesList() { private void addFormSpecificData(EditConfigurationVTwo config, VitroRequest vreq) { ArrayList existingLabels = this.getExistingLabels(config.getSubjectUri(), vreq); - //Get all language codes/labels in the system, and this list is sorted by language name + //Get language codes/labels for existing labels, and this list is sorted by language name List> locales = this.getLocales(vreq, existingLabels); //Get code to label hashmap - we use this to get the language name for the language code returned in the rdf literal HashMap localeCodeToNameMap = this.getFullCodeToLanguageNameMap(locales);