diff --git a/control-base/src/main/java/fi/nls/oskari/control/data/SearchOptionsHandler.java b/control-base/src/main/java/fi/nls/oskari/control/data/SearchOptionsHandler.java index 3f97690f24..e56d8983d8 100755 --- a/control-base/src/main/java/fi/nls/oskari/control/data/SearchOptionsHandler.java +++ b/control-base/src/main/java/fi/nls/oskari/control/data/SearchOptionsHandler.java @@ -6,6 +6,7 @@ import fi.nls.oskari.control.ActionHandler; import fi.nls.oskari.control.ActionParameters; import fi.nls.oskari.domain.User; +import fi.nls.oskari.search.channel.SearchAutocomplete; import fi.nls.oskari.search.channel.SearchableChannel; import fi.nls.oskari.service.OskariComponentManager; import fi.nls.oskari.util.JSONHelper; @@ -52,7 +53,13 @@ public void handleAction(final ActionParameters params) throws ActionException { JSONObject json = new JSONObject(); JSONHelper.putValue(json, "id", channel.getId()); JSONHelper.putValue(json, "isDefault", channel.isDefaultChannel()); - JSONHelper.putValue(json, "locale", channel.getUILabels().optJSONObject(params.getLocale().getLanguage())); + JSONHelper.putValue(json, "isSuggestions", channel instanceof SearchAutocomplete); + JSONObject labels = channel.getUILabels(); + if (labels.has(params.getLocale().getLanguage())) { + JSONHelper.putValue(json, "locale", channel.getUILabels().optJSONObject(params.getLocale().getLanguage())); + } else { + JSONHelper.putValue(json, "locale", channel.getUILabels().optJSONObject(PropertyUtil.getDefaultLanguage())); + } channelsJSONArray.put(json); } JSONObject response = new JSONObject(); diff --git a/service-search/src/main/java/fi/nls/oskari/search/channel/SearchChannel.java b/service-search/src/main/java/fi/nls/oskari/search/channel/SearchChannel.java index a3c888c140..c3b1abfd0e 100755 --- a/service-search/src/main/java/fi/nls/oskari/search/channel/SearchChannel.java +++ b/service-search/src/main/java/fi/nls/oskari/search/channel/SearchChannel.java @@ -31,6 +31,7 @@ public abstract class SearchChannel extends OskariComponent implements Searchabl // store encountered types here to only log about possible configs for new types private Set types = new HashSet(); private int maxCount = 100; + private JSONObject uiLabels = null; public String getId() { return getName(); @@ -69,8 +70,46 @@ public ChannelSearchResult reverseGeocode(SearchCriteria searchCriteria) throws } public JSONObject getUILabels() { + if (uiLabels != null) { + return uiLabels; + } + String defaultLang = PropertyUtil.getDefaultLanguage(); + uiLabels = new JSONObject(); + final Object labelObj = PropertyUtil.getLocalizableProperty("search.channel." + getName() + ".label", getId()); + if (labelObj instanceof String) { + // single value configured + JSONHelper.putValue(uiLabels, defaultLang, JSONHelper.createJSONObject("name", labelObj)); + } else if (labelObj instanceof Map) { + // localized values configured + Map values = (Map) labelObj; + values.keySet().forEach(lang -> + JSONHelper.putValue(uiLabels, lang, JSONHelper.createJSONObject("name", values.get(lang)))); + } + // inject descriptions + final Object descObj = PropertyUtil.getLocalizableProperty("search.channel." + getName() + ".desc"); + if (descObj instanceof String) { + // single value configured + JSONObject langBlock = uiLabels.optJSONObject(defaultLang); + if (langBlock != null) { + JSONHelper.putValue(langBlock, "desc", descObj); + } + } else if (descObj instanceof Map) { + // localized values configured + Map values = (Map) descObj; + values.keySet().forEach(lang -> { + JSONObject langBlock = uiLabels.optJSONObject(lang); + if (langBlock != null) { + JSONHelper.putValue(langBlock, "desc", values.get(lang)); + } + }); + } + if (uiLabels.keys().hasNext()) { + return uiLabels; + } + // fallback to channel id JSONObject name = JSONHelper.createJSONObject("name", getId()); - return JSONHelper.createJSONObject(PropertyUtil.getDefaultLanguage(), name); + JSONHelper.putValue(uiLabels, defaultLang, name); + return uiLabels; } public boolean isValidSearchTerm(SearchCriteria criteria) {