diff --git a/core/src/main/java/org/fao/geonet/kernel/search/KeywordsSearcher.java b/core/src/main/java/org/fao/geonet/kernel/search/KeywordsSearcher.java index 054f1b2d687..0d25acf7011 100644 --- a/core/src/main/java/org/fao/geonet/kernel/search/KeywordsSearcher.java +++ b/core/src/main/java/org/fao/geonet/kernel/search/KeywordsSearcher.java @@ -101,9 +101,11 @@ public static Element toRawElement(Element rootEl, KeywordBean kb) { elKeyword.addContent(elSelected); elKeyword.addContent(new Element("id").addContent(Integer.toString(kb.getId()))); - elKeyword.addContent(new Element("value").addContent(kb.getDefaultValue()).setAttribute("language", defaultLang)); - elKeyword.addContent(new Element("definition").addContent(kb.getDefaultDefinition()).setAttribute("language", defaultLang)); - elKeyword.addContent(new Element("defaultLang").addContent(defaultLang)); + if (defaultLang != null) { + elKeyword.addContent(new Element("value").addContent(kb.getDefaultValue()).setAttribute("language", defaultLang)); + elKeyword.addContent(new Element("definition").addContent(kb.getDefaultDefinition()).setAttribute("language", defaultLang)); + elKeyword.addContent(new Element("defaultLang").addContent(defaultLang)); + } Element thesaurusElement = new Element("thesaurus"); thesaurusElement.addContent(new Element("key").setText(kb.getThesaurusKey())); thesaurusElement.addContent(new Element("title").setText(kb.getThesaurusTitle())); diff --git a/schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/layout/layout-custom-fields-keywords.xsl b/schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/layout/layout-custom-fields-keywords.xsl index 10620e6653e..209b8c35e53 100644 --- a/schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/layout/layout-custom-fields-keywords.xsl +++ b/schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/layout/layout-custom-fields-keywords.xsl @@ -179,7 +179,7 @@ in default language --> diff --git a/services/src/main/java/org/fao/geonet/api/registries/vocabularies/KeywordsApi.java b/services/src/main/java/org/fao/geonet/api/registries/vocabularies/KeywordsApi.java index 2ba1e976bc1..f94043fcadd 100644 --- a/services/src/main/java/org/fao/geonet/api/registries/vocabularies/KeywordsApi.java +++ b/services/src/main/java/org/fao/geonet/api/registries/vocabularies/KeywordsApi.java @@ -46,7 +46,6 @@ import org.fao.geonet.api.exception.ResourceNotFoundException; import org.fao.geonet.api.exception.WebApplicationException; import org.fao.geonet.api.registries.model.ThesaurusInfo; -import org.fao.geonet.api.tools.i18n.LanguageUtils; import org.fao.geonet.constants.Geonet; import org.fao.geonet.domain.ISODate; import org.fao.geonet.exceptions.BadParameterEx; @@ -110,12 +109,6 @@ description = ApiParams.API_CLASS_REGISTRIES_OPS) public class KeywordsApi { - /** - * The language utils. - */ - @Autowired - LanguageUtils languageUtils; - @Autowired SettingManager settingManager; @@ -161,8 +154,7 @@ public class KeywordsApi { * @throws Exception the exception */ @io.swagger.v3.oas.annotations.Operation( - summary = "Search keywords", - description = "") + summary = "Search keywords") @RequestMapping( path = "/search", method = RequestMethod.GET, @@ -175,16 +167,14 @@ public class KeywordsApi { @ResponseBody public Object searchKeywords( @Parameter( - description = "Query", - required = false + description = "Query" ) @RequestParam( required = false ) String q, @Parameter( - description = "Query in that language", - required = false + description = "Query in that language" ) @RequestParam( value = "lang", @@ -192,8 +182,7 @@ public Object searchKeywords( ) String lang, @Parameter( - description = "Number of rows", - required = false + description = "Number of rows" ) @RequestParam( required = false, @@ -201,8 +190,7 @@ public Object searchKeywords( ) int rows, @Parameter( - description = "Start from", - required = false + description = "Start from" ) @RequestParam( defaultValue = "0", @@ -210,8 +198,7 @@ public Object searchKeywords( ) int start, @Parameter( - description = "Return keyword information in one or more languages", - required = false + description = "Return keyword information in one or more languages" ) @RequestParam( value = XmlParams.pLang, @@ -219,8 +206,7 @@ public Object searchKeywords( ) List targetLangs, @Parameter( - description = "Thesaurus identifier", - required = false + description = "Thesaurus identifier" ) @RequestParam( required = false @@ -235,24 +221,21 @@ public Object searchKeywords( // ) // String thesauriDomainName, @Parameter( - description = "Type of search", - required = false + description = "Type of search" ) @RequestParam( defaultValue = "CONTAINS" ) KeywordSearchType type, @Parameter( - description = "URI query", - required = false + description = "URI query" ) @RequestParam( required = false ) String uri, @Parameter( - description = "Sort by", - required = false + description = "Sort by" ) @RequestParam( required = false, @@ -354,23 +337,19 @@ public Object getKeywordById( @RequestParam(name = "thesaurus") String sThesaurusName, @Parameter( - description = "Languages.", - required = false) + description = "Languages.") @RequestParam(name = "lang", required = false) String[] langs, @Parameter( - description = "Only print the keyword, no thesaurus information.", - required = false) + description = "Only print the keyword, no thesaurus information.") @RequestParam(required = false, defaultValue = "false") boolean keywordOnly, @Parameter( - description = "XSL template to use (ISO19139 keyword by default, see convert.xsl).", - required = false) + description = "XSL template to use (ISO19139 keyword by default, see convert.xsl).") @RequestParam(required = false) String transformation, @Parameter( - description = "langMap, that converts the values in the 'lang' parameter to how they will be actually represented in the record. {'fre':'fra'} or {'fre':'fr'}. Missing/empty means to convert to iso 2 letter.", - required = false) + description = "langMap, that converts the values in the 'lang' parameter to how they will be actually represented in the record. {'fre':'fra'} or {'fre':'fr'}. Missing/empty means to convert to iso 2 letter.") @RequestParam (name = "langMap", required = false) String langMapJson, @Parameter(hidden = true) @@ -428,23 +407,19 @@ public Object getKeywordByIds( @RequestParam(name = "thesaurus") String sThesaurusName, @Parameter( - description = "Languages.", - required = false) + description = "Languages.") @RequestParam(name = "lang", required = false) String[] langs, @Parameter( - description = "Only print the keyword, no thesaurus information.", - required = false) + description = "Only print the keyword, no thesaurus information.") @RequestParam(required = false, defaultValue = "false") boolean keywordOnly, @Parameter( - description = "XSL template to use (ISO19139 keyword by default, see convert.xsl).", - required = false) + description = "XSL template to use (ISO19139 keyword by default, see convert.xsl).") @RequestParam(required = false) String transformation, @Parameter( - description = "langMap, that converts the values in the 'lang' parameter to how they will be actually represented in the record. {'fre':'fra'} or {'fre':'fr'}. Missing/empty means to convert to iso 2 letter.", - required = false) + description = "langMap, that converts the values in the 'lang' parameter to how they will be actually represented in the record. {'fre':'fra'} or {'fre':'fr'}. Missing/empty means to convert to iso 2 letter.") @RequestParam (name = "langMap", required = false) String langMapJson, @Parameter(hidden = true) @@ -489,7 +464,7 @@ private Object getKeyword( if (thesaurus == null) { String finalSThesaurusName = sThesaurusName; Optional thesaurusEntry = thesaurusManager.getThesauriMap().values().stream().filter(t -> t.getKey().endsWith(finalSThesaurusName)).findFirst(); - if (!thesaurusEntry.isPresent()) { + if (thesaurusEntry.isEmpty()) { throw new IllegalArgumentException(String.format( "Thesaurus '%s' not found.", sThesaurusName)); } else { @@ -501,7 +476,12 @@ private Object getKeyword( if (langs == null) { langs = context.getLanguage().split(","); } - String[] iso3langCodes = Arrays.copyOf(langs, langs.length); + List langList = new ArrayList<>(List.of(langs)); + if (!langList.contains("eng")) { + langList.add("eng"); + } + + String[] iso3langCodes = langList.toArray(String[]::new); for (int i = 0; i < langs.length; i++) { if (StringUtils.isNotEmpty(langs[i])) { langs[i] = mapper.iso639_2_to_iso639_1(langs[i], langs[i].substring(0,2)); //default: fra -> fr @@ -511,7 +491,7 @@ private Object getKeyword( Element descKeys; Map> jsonResponse = new HashMap<>(); - uri = URLDecoder.decode(uri, "UTF-8"); + uri = URLDecoder.decode(uri, StandardCharsets.UTF_8); if (uri == null) { descKeys = new Element("descKeys"); @@ -566,8 +546,8 @@ private Object getKeyword( JSONObject obj = JSONObject.fromObject(langMapJson); langConversion = new Element("languageConversions"); for(Object entry : obj.entrySet()) { - String key = ((Map.Entry) entry).getKey().toString(); - String value = ((Map.Entry) entry).getValue().toString(); + String key = ((Map.Entry) entry).getKey().toString(); + String value = ((Map.Entry) entry).getValue().toString(); Element conv = new Element("conversion"); conv.setAttribute("from", key); conv.setAttribute("to", value.replace("#","")); @@ -593,12 +573,7 @@ private Object getKeyword( Element requestParams = new Element("request"); for (Map.Entry e : allRequestParams.entrySet()) { - if (e.getKey().equals("lang")) { - requestParams.addContent(new Element(e.getKey()) - .setText(String.join(",", iso3langCodes))); - } else { - requestParams.addContent(new Element(e.getKey()).setText(e.getValue())); - } + requestParams.addContent(new Element(e.getKey()).setText(e.getValue())); } if (langConversion != null) { requestParams.addContent(langConversion); @@ -618,7 +593,6 @@ private Object getKeyword( * * @param thesaurus the thesaurus * @param response the response - * @return the thesaurus * @throws Exception the exception */ @io.swagger.v3.oas.annotations.Operation( @@ -672,7 +646,6 @@ public void getThesaurus( * Delete thesaurus. * * @param thesaurus the thesaurus - * @return the element * @throws Exception the exception */ @io.swagger.v3.oas.annotations.Operation( @@ -703,7 +676,7 @@ public void deleteThesaurus( throw new ResourceNotFoundException(String.format( "Thesaurus with identifier '%s' not found in the catalogue. Should be one of: %s", thesaurus, - thesaurusMan.getThesauriMap().keySet().toString() + thesaurusMan.getThesauriMap().keySet() )); } Path item = thesaurusObject.getFile(); @@ -767,9 +740,9 @@ public String uploadThesaurus( boolean fileUpload = file != null && !file.isEmpty(); // Upload RDF file - Path rdfFile = null; - String fname = null; - File tempDir = null; + Path rdfFile; + String fname; + File tempDir; if (fileUpload) { @@ -795,7 +768,7 @@ public String uploadThesaurus( } long fsize; - if (rdfFile != null && Files.exists(rdfFile)) { + if (Files.exists(rdfFile)) { fsize = Files.size(rdfFile); } else { throw new MissingServletRequestParameterException("Thesaurus file doesn't exist", "file"); @@ -1012,7 +985,7 @@ public Element convertCsvToSkos(Path csvFile, CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT .withFirstRecordAsHeader() .withIgnoreHeaderCase() - .withTrim()); + .withTrim()) ) { Map allConcepts = new LinkedHashMap<>(); @@ -1075,7 +1048,7 @@ public Element convertCsvToSkos(Path csvFile, } Element scheme = buildConceptScheme(csvFile, thesaurusTitle, thesaurusNamespaceUrl); - if(broaderLinks.size() > 0 && !topConcepts.isEmpty()) { + if(!broaderLinks.isEmpty() && !topConcepts.isEmpty()) { topConcepts.forEach(t -> { Element topConcept = new Element("hasTopConcept", SKOS_NAMESPACE); topConcept.setAttribute("resource", t, RDF_NAMESPACE); @@ -1210,7 +1183,7 @@ public String uploadThesaurusFromUrl( boolean registryUpload = !StringUtils.isEmpty(registryUrl); // Upload RDF file - Path rdfFile = null; + Path rdfFile; String fname = null; // Specific upload steps @@ -1307,9 +1280,9 @@ public String uploadThesaurusFromUrl( /** * Update the information related to a local thesaurus . * - * @param thesaurusInfo - * @return - * @throws Exception + * @param thesaurus name of the thesaurus to update. + * @param thesaurusInfo thesaurus information to update. + * @throws Exception the exception */ @io.swagger.v3.oas.annotations.Operation( summary = "Updates the information of a local thesaurus", @@ -1368,11 +1341,11 @@ public void updateThesaurus( * Download for each language the codelist from the registry. Combine * them into one XML document which is then XSLT processed for SKOS conversion. * - * @param registryUrl the registry url - * @param registryType - * @param itemName the item name - * @param lang the selected languages - * @param context the context + * @param registryUrl the registry url + * @param registryType type of registry + * @param itemName the item name + * @param lang the selected languages + * @param context the context * @return the path * @throws Exception the exception */ @@ -1448,7 +1421,6 @@ private Path getXMLContentFromUrl(String url, ServiceContext context) throws URI * @param fname the fname * @param type the type * @param dir the dir - * @return Element thesaurus uploaded * @throws Exception the exception */ private void uploadThesaurus(Path rdfFile, String style, diff --git a/services/src/main/java/org/fao/geonet/services/thesaurus/GetKeywordByIdAsConcept.java b/services/src/main/java/org/fao/geonet/services/thesaurus/GetKeywordByIdAsConcept.java index 1c86f3f694f..4428f73c586 100644 --- a/services/src/main/java/org/fao/geonet/services/thesaurus/GetKeywordByIdAsConcept.java +++ b/services/src/main/java/org/fao/geonet/services/thesaurus/GetKeywordByIdAsConcept.java @@ -73,7 +73,7 @@ public Element exec(Element params, ServiceContext context) searcher = new KeywordsSearcher(context, thesaurusMan); KeywordBean kb = null; - kb = searcher.searchById(uri, sThesaurusName, langForThesaurus); + kb = searcher.searchById(uri, sThesaurusName, langForThesaurus, "eng"); if (kb == null) { root = new Element("descKeys"); } else { @@ -93,11 +93,11 @@ public Element exec(Element params, ServiceContext context) reqType = KeywordRelation.RELATED; } - searcher.searchForRelated(params, reqType, KeywordSort.defaultLabelSorter(SortDirection.DESC), lang); + searcher.searchForRelated(params, reqType, KeywordSort.defaultLabelSorter(SortDirection.DESC), lang, "eng"); // build response for each request type Element keywordType = new Element(request); for (KeywordBean kbr : searcher.getResults()) { - keywordType.addContent(kbr.toElement(context.getLanguage())); + keywordType.addContent(kbr.toElement(context.getLanguage(), "eng")); } root.addContent(keywordType); } diff --git a/services/src/main/java/org/fao/geonet/services/thesaurus/GetTopConcept.java b/services/src/main/java/org/fao/geonet/services/thesaurus/GetTopConcept.java index 1654db883b2..86c6dcfb7a9 100644 --- a/services/src/main/java/org/fao/geonet/services/thesaurus/GetTopConcept.java +++ b/services/src/main/java/org/fao/geonet/services/thesaurus/GetTopConcept.java @@ -70,7 +70,7 @@ public Element exec(Element params, ServiceContext context) searcher = new KeywordsSearcher(context, thesaurusMan); try { - searcher.searchTopConcepts(sThesaurusName, langForThesaurus); + searcher.searchTopConcepts(sThesaurusName, langForThesaurus, "eng"); KeywordBean topConcept = new KeywordBean(the.getIsoLanguageMapper()); topConcept.setThesaurusInfo(the); diff --git a/web-ui/src/main/resources/catalog/components/ng-skos/templates/skos-concept.html b/web-ui/src/main/resources/catalog/components/ng-skos/templates/skos-concept.html index 3277ad12c69..1f6837be41a 100644 --- a/web-ui/src/main/resources/catalog/components/ng-skos/templates/skos-concept.html +++ b/web-ui/src/main/resources/catalog/components/ng-skos/templates/skos-concept.html @@ -71,11 +71,9 @@ ng-mouseleave="c.over = false" > - + + {{c.prefLabel[mainLanguage] || c.prefLabel['eng']}} + @@ -95,11 +93,9 @@ ng-mouseleave="c.over = false" > - + + {{c.prefLabel[mainLanguage] || c.prefLabel['eng']}} + diff --git a/web-ui/src/main/resources/catalog/components/thesaurus/ThesaurusService.js b/web-ui/src/main/resources/catalog/components/thesaurus/ThesaurusService.js index 28030bcfadd..d444e9a1c3f 100644 --- a/web-ui/src/main/resources/catalog/components/thesaurus/ThesaurusService.js +++ b/web-ui/src/main/resources/catalog/components/thesaurus/ThesaurusService.js @@ -44,7 +44,7 @@ var foundLang = _.find(UILangs, function (l) { return props.values[l] !== undefined; }); - if (foundLang) return props.values[foundLang]; + if (foundLang) return props.values[foundLang] || props.values["eng"]; } return this.props.value["#text"] || this.props.value; } @@ -152,6 +152,11 @@ if (outputLang) { parameters["pLang"] = outputLang; } + if (lang !== "eng") { + // Fallback in english if thesaurus has no translation in current record language + parameters["pLang"] = ["eng", lang]; + } + return gnUrlUtils.append( "../api/registries/vocabularies/search", gnUrlUtils.toKeyValue(parameters) diff --git a/web/src/main/webapp/xslt/services/thesaurus/to-jskos.xsl b/web/src/main/webapp/xslt/services/thesaurus/to-jskos.xsl index e8f4e575c7e..8493f48ca60 100644 --- a/web/src/main/webapp/xslt/services/thesaurus/to-jskos.xsl +++ b/web/src/main/webapp/xslt/services/thesaurus/to-jskos.xsl @@ -22,7 +22,10 @@ ~ Rome - Italy. email: geonetwork@osgeo.org --> - + @@ -45,8 +48,8 @@ - - + +