From 9bd8e4016b4da0cf5066ab10909d6151170df65c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20M=C3=A4kinen?= Date: Fri, 21 Apr 2023 15:50:00 +0300 Subject: [PATCH 1/3] Add info about auto completion support for options --- .../java/fi/nls/oskari/control/data/SearchOptionsHandler.java | 2 ++ 1 file changed, 2 insertions(+) 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..b86a38f97f 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,6 +53,7 @@ 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, "isSuggestions", channel instanceof SearchAutocomplete); JSONHelper.putValue(json, "locale", channel.getUILabels().optJSONObject(params.getLocale().getLanguage())); channelsJSONArray.put(json); } From 8064848084341d91e27e9178d821e351a09a47b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20M=C3=A4kinen?= Date: Fri, 21 Apr 2023 16:17:52 +0300 Subject: [PATCH 2/3] Add UI label config support for search channel adapters --- .../control/data/SearchOptionsHandler.java | 7 +++- .../oskari/search/channel/SearchChannel.java | 41 ++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) 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 b86a38f97f..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 @@ -54,7 +54,12 @@ public void handleAction(final ActionParameters params) throws ActionException { JSONHelper.putValue(json, "id", channel.getId()); JSONHelper.putValue(json, "isDefault", channel.isDefaultChannel()); JSONHelper.putValue(json, "isSuggestions", channel instanceof SearchAutocomplete); - JSONHelper.putValue(json, "locale", channel.getUILabels().optJSONObject(params.getLocale().getLanguage())); + 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..bb71db05cf 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", getId()); + 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) { From 04198852715fa4d4dea539b9780e88db9c9f27d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20M=C3=A4kinen?= Date: Mon, 24 Apr 2023 15:19:07 +0300 Subject: [PATCH 3/3] Don't add default description --- .../main/java/fi/nls/oskari/search/channel/SearchChannel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 bb71db05cf..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 @@ -86,7 +86,7 @@ public JSONObject getUILabels() { JSONHelper.putValue(uiLabels, lang, JSONHelper.createJSONObject("name", values.get(lang)))); } // inject descriptions - final Object descObj = PropertyUtil.getLocalizableProperty("search.channel." + getName() + ".desc", getId()); + final Object descObj = PropertyUtil.getLocalizableProperty("search.channel." + getName() + ".desc"); if (descObj instanceof String) { // single value configured JSONObject langBlock = uiLabels.optJSONObject(defaultLang);