Merge pull request #240 from brianjlowe/issue/VIVO-1983
[VIVO-1983] Limit label management values to current locale
This commit is contained in:
commit
e1dc5c9775
5 changed files with 38 additions and 35 deletions
|
@ -15,6 +15,7 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
@ -41,6 +42,7 @@ 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.ManageLabelsForPersonPreprocessor;
|
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.i18n.selection.SelectedLocale;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.DataPropertyStatementTemplateModel;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.DataPropertyStatementTemplateModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -246,12 +248,12 @@ public class ManageLabelsForPersonGenerator extends BaseEditConfigurationGenerat
|
||||||
|
|
||||||
private void addFormSpecificData(EditConfigurationVTwo config,
|
private void addFormSpecificData(EditConfigurationVTwo config,
|
||||||
VitroRequest vreq) {
|
VitroRequest vreq) {
|
||||||
//Get all language codes/labels in the system, and this list is sorted by language name
|
ArrayList<Literal> existingLabels = this.getExistingLabels(config.getSubjectUri(), vreq);
|
||||||
List<HashMap<String, String>> locales = this.getLocales(vreq);
|
//Get language codes/labels for existing labels, and this list is sorted by language name
|
||||||
|
List<HashMap<String, String>> 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
|
//Get code to label hashmap - we use this to get the language name for the language code returned in the rdf literal
|
||||||
HashMap<String, String> localeCodeToNameMap = this.getFullCodeToLanguageNameMap(locales);
|
HashMap<String, String> localeCodeToNameMap = this.getFullCodeToLanguageNameMap(locales);
|
||||||
//the labels already added by the user
|
//the labels already added by the user
|
||||||
ArrayList<Literal> existingLabels = this.getExistingLabels(config.getSubjectUri(), vreq);
|
|
||||||
int numberExistingLabels = existingLabels.size();
|
int numberExistingLabels = existingLabels.size();
|
||||||
//existing labels keyed by language name and each of the list of labels is sorted by language name
|
//existing labels keyed by language name and each of the list of labels is sorted by language name
|
||||||
HashMap<String, List<LabelInformation>> existingLabelsByLanguageName = this.getLabelsSortedByLanguageName(existingLabels, localeCodeToNameMap, config, vreq);
|
HashMap<String, List<LabelInformation>> existingLabelsByLanguageName = this.getLabelsSortedByLanguageName(existingLabels, localeCodeToNameMap, config, vreq);
|
||||||
|
@ -439,21 +441,20 @@ public class ManageLabelsForPersonGenerator extends BaseEditConfigurationGenerat
|
||||||
|
|
||||||
ArrayList<Literal> labels = new ArrayList<Literal>();
|
ArrayList<Literal> labels = new ArrayList<Literal>();
|
||||||
try {
|
try {
|
||||||
//We want to get the labels for all the languages, not just the display language
|
// No longer retrieving language-neutral results here, so that
|
||||||
ResultSet results = QueryUtils.getLanguageNeutralQueryResults(queryStr, vreq);
|
// 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()) {
|
while (results.hasNext()) {
|
||||||
QuerySolution soln = results.nextSolution();
|
QuerySolution soln = results.nextSolution();
|
||||||
Literal nodeLiteral = soln.get("label").asLiteral();
|
Literal nodeLiteral = soln.get("label").asLiteral();
|
||||||
labels.add(nodeLiteral);
|
labels.add(nodeLiteral);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e, e);
|
log.error(e, e);
|
||||||
}
|
}
|
||||||
return labels;
|
return labels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Putting this into a method allows overriding it in subclasses
|
//Putting this into a method allows overriding it in subclasses
|
||||||
|
@ -467,30 +468,32 @@ public class ManageLabelsForPersonGenerator extends BaseEditConfigurationGenerat
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//get locales present in list of literals
|
||||||
|
public List<HashMap<String, String>> getLocales(VitroRequest vreq,
|
||||||
//get locales
|
List<Literal> existingLiterals) {
|
||||||
public List<HashMap<String, String>> getLocales(VitroRequest vreq) {
|
Set<Locale> locales = new HashSet<Locale>();
|
||||||
List<Locale> selectables = SelectedLocale.getSelectableLocales(vreq);
|
for(Literal literal : existingLiterals) {
|
||||||
if (selectables.isEmpty()) {
|
String language = literal.getLanguage();
|
||||||
|
if(!StringUtils.isEmpty(language)) {
|
||||||
|
locales.add(LanguageFilteringUtils.languageToLocale(language));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (locales.isEmpty()) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
|
List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
|
||||||
Locale currentLocale = SelectedLocale.getCurrentLocale(vreq);
|
Locale currentLocale = SelectedLocale.getCurrentLocale(vreq);
|
||||||
for (Locale locale : selectables) {
|
for (Locale locale : locales) {
|
||||||
try {
|
try {
|
||||||
list.add(buildLocaleMap(locale, currentLocale));
|
list.add(buildLocaleMap(locale, currentLocale));
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
log.warn("Can't show the Locale selector for '" + locale
|
log.warn("Can't show locale '" + locale + "': " + e);
|
||||||
+ "': " + e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public HashMap<String, String> getFullCodeToLanguageNameMap(List<HashMap<String, String>> localesList) {
|
public HashMap<String, String> getFullCodeToLanguageNameMap(List<HashMap<String, String>> localesList) {
|
||||||
HashMap<String, String> codeToLanguageMap = new HashMap<String, String>();
|
HashMap<String, String> codeToLanguageMap = new HashMap<String, String>();
|
||||||
for(Map<String, String> locale: localesList) {
|
for(Map<String, String> locale: localesList) {
|
||||||
|
|
|
@ -51,7 +51,7 @@
|
||||||
<#else>
|
<#else>
|
||||||
<h1 itemprop="name" class="vcard foaf-person fn" <#if !editable>style="float:left;border-right:1px solid #A6B1B0;"</#if>>
|
<h1 itemprop="name" class="vcard foaf-person fn" <#if !editable>style="float:left;border-right:1px solid #A6B1B0;"</#if>>
|
||||||
<#-- Label -->
|
<#-- Label -->
|
||||||
<@p.label individual editable labelCount localesCount/>
|
<@p.label individual editable labelCount localesCount languageCount />
|
||||||
</h1>
|
</h1>
|
||||||
<#-- Display preferredTitle if it exists; otherwise mostSpecificTypes -->
|
<#-- 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")!>
|
<#assign title = propertyGroups.pullProperty("http://purl.obolibrary.org/obo/ARG_2000028","http://www.w3.org/2006/vcard/ns#Title")!>
|
||||||
|
|
|
@ -62,7 +62,7 @@
|
||||||
<div id="photo-wrapper">${individualImage}</div>
|
<div id="photo-wrapper">${individualImage}</div>
|
||||||
<h1 itemprop="name" class="vcard foaf-person fn" <#if !editable>style="float:left;border-right:1px solid #A6B1B0;"</#if>>
|
<h1 itemprop="name" class="vcard foaf-person fn" <#if !editable>style="float:left;border-right:1px solid #A6B1B0;"</#if>>
|
||||||
<#-- Label -->
|
<#-- Label -->
|
||||||
<@p.label individual editable labelCount localesCount/>
|
<@p.label individual editable labelCount localesCount languageCount />
|
||||||
</h1>
|
</h1>
|
||||||
<#-- Display preferredTitle if it exists; otherwise mostSpecificTypes -->
|
<#-- 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")!>
|
<#assign title = propertyGroups.pullProperty("http://purl.obolibrary.org/obo/ARG_2000028","http://www.w3.org/2006/vcard/ns#Title")!>
|
||||||
|
|
|
@ -65,7 +65,7 @@
|
||||||
<section class="vcard person">
|
<section class="vcard person">
|
||||||
<h1 class="foaf-person">
|
<h1 class="foaf-person">
|
||||||
<#-- Label -->
|
<#-- Label -->
|
||||||
<span itemprop="name" class="fn"><@p.label individual editable labelCount localesCount/></span>
|
<span itemprop="name" class="fn"><@p.label individual editable labelCount localesCount languageCount /></span>
|
||||||
</h1>
|
</h1>
|
||||||
<section id="preferredTitle">
|
<section id="preferredTitle">
|
||||||
<#-- Display preferredTitle if it exists; otherwise mostSpecificTypes -->
|
<#-- Display preferredTitle if it exists; otherwise mostSpecificTypes -->
|
||||||
|
|
|
@ -89,7 +89,7 @@
|
||||||
<#else>
|
<#else>
|
||||||
<h1 class="foaf-person">
|
<h1 class="foaf-person">
|
||||||
<#-- Label -->
|
<#-- Label -->
|
||||||
<span itemprop="name" class="fn"><@p.label individual editable labelCount localesCount/></span>
|
<span itemprop="name" class="fn"><@p.label individual editable labelCount localesCount languageCount /></span>
|
||||||
</h1>
|
</h1>
|
||||||
<section id="preferredTitle">
|
<section id="preferredTitle">
|
||||||
<#-- Display preferredTitle if it exists; otherwise mostSpecificTypes -->
|
<#-- Display preferredTitle if it exists; otherwise mostSpecificTypes -->
|
||||||
|
|
Loading…
Add table
Reference in a new issue