diff --git a/inspire-atom/src/main/java/org/fao/geonet/inspireatom/harvester/InspireAtomHarvester.java b/inspire-atom/src/main/java/org/fao/geonet/inspireatom/harvester/InspireAtomHarvester.java index fae1e933e9a..6379dbf6e84 100644 --- a/inspire-atom/src/main/java/org/fao/geonet/inspireatom/harvester/InspireAtomHarvester.java +++ b/inspire-atom/src/main/java/org/fao/geonet/inspireatom/harvester/InspireAtomHarvester.java @@ -298,7 +298,7 @@ private void processDatasetsMetadataFeeds(final ServiceContext context, try { // Find the metadata UUID using the resource identifier gmd:MD_Identifier/gmd:code - metadataUuid = InspireAtomUtil.retrieveDatasetUuidFromIdentifier(ServiceContext.get(), + metadataUuid = InspireAtomUtil.retrieveDatasetUuidFromIdentifier( gc.getBean(EsSearchManager.class), datasetFeedInfo.identifier); String atomUrl = datasetFeedInfo.feedUrl; @@ -376,7 +376,7 @@ private void processDatasetsMetadataFeedsForService(final ServiceContext context String metadataUuid = ""; try { - metadataUuid = InspireAtomUtil.retrieveDatasetUuidFromIdentifier(context, + metadataUuid = InspireAtomUtil.retrieveDatasetUuidFromIdentifier( gc.getBean(EsSearchManager.class), atomDatasetId); String atomDatasetNs = datasetFeedInfo.namespace; diff --git a/inspire-atom/src/main/java/org/fao/geonet/inspireatom/util/InspireAtomUtil.java b/inspire-atom/src/main/java/org/fao/geonet/inspireatom/util/InspireAtomUtil.java index 7a52e12f87b..6c6980b6f8c 100644 --- a/inspire-atom/src/main/java/org/fao/geonet/inspireatom/util/InspireAtomUtil.java +++ b/inspire-atom/src/main/java/org/fao/geonet/inspireatom/util/InspireAtomUtil.java @@ -1,5 +1,5 @@ //============================================================================= -//=== Copyright (C) 2001-2017 Food and Agriculture Organization of the +//=== Copyright (C) 2001-2023 Food and Agriculture Organization of the //=== United Nations (FAO-UN), United Nations World Food Programme (WFP) //=== and United Nations Environment Programme (UNEP) //=== @@ -24,7 +24,6 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import jeeves.server.ServiceConfig; import jeeves.server.context.ServiceContext; import org.apache.commons.lang.StringUtils; import org.apache.lucene.search.TotalHits; @@ -71,11 +70,6 @@ public class InspireAtomUtil { **/ private static final String EXTRACT_DATASETS = "extract-datasets.xsl"; - /** - * Xslt process to get if a metadata is a service or a dataset. - **/ - private static final String EXTRACT_MD_TYPE = "extract-type.xsl"; - /** * Xslt process to get the atom feed link from the metadata. **/ @@ -116,6 +110,10 @@ public class InspireAtomUtil { **/ public static final String LOCAL_DOWNLOAD_DATASET_URL_SUFFIX = "atom/download/dataset"; + private InspireAtomUtil() { + + } + /** * Issue an http request to retrieve the remote Atom feed document. * @@ -162,7 +160,7 @@ public static void filterDatasetFeedByCrs(final Element feed, final String crs) throws Exception { - List elementsToRemove = new ArrayList(); + List elementsToRemove = new ArrayList<>(); Iterator it = feed.getChildren().iterator(); @@ -190,7 +188,7 @@ public static void filterDatasetFeedByCrs(final Element feed, public static boolean isServiceMetadata(DataManager dm, String schema, Element md) throws Exception { java.nio.file.Path styleSheet = dm.getSchemaDir(schema).resolve("extract-type.xsl"); - Map paramsM = new HashMap(); + Map paramsM = new HashMap<>(); String mdType = Xml.transform(md, styleSheet, paramsM).getText().trim(); return "service".equalsIgnoreCase(mdType); @@ -235,7 +233,7 @@ public static List extractRelatedDatasetsInfoFromServiceFeed(fi java.nio.file.Path defaultStyleSheet = dataManager.getSchemaDir("iso19139").resolve(EXTRACT_DATASETS_FROM_SERVICE_XSLT); - Map params = new HashMap(); + Map params = new HashMap<>(); Element atomIndexFields = Xml.transform(serviceFeed, defaultStyleSheet, params); List datasetsInformation = new ArrayList<>(); @@ -287,7 +285,7 @@ private static Map processAtomFeedsInternal(DataManager dataMana List iso19139Metadata, String type, String atomProtocol) throws Exception { - Map metadataAtomFeeds = new HashMap(); + Map metadataAtomFeeds = new HashMap<>(); for (AbstractMetadata md : iso19139Metadata) { int id = md.getId(); @@ -386,8 +384,7 @@ public static List searchMetadataByTypeAndProtocol(ServiceCont } - public static String retrieveDatasetUuidFromIdentifier(ServiceContext context, - EsSearchManager searchMan, + public static String retrieveDatasetUuidFromIdentifier(EsSearchManager searchMan, String datasetIdCode) { String jsonQuery = "{" + " \"bool\": {" + @@ -515,34 +512,20 @@ private static Path getAtomFeedXSLStylesheet(final String schema, final DataMana .resolve(TRANSFORM_MD_TO_ATOM_FEED); } - public static Element getDatasetFeed(final ServiceContext context, final String spIdentifier, - final String spNamespace, final Map params, String requestedLanguage) throws Exception { + public static Element getMetadataFeedByResourceIdentifier(final ServiceContext context, final String spIdentifier, + final String spNamespace, final Map params, String requestedLanguage) throws Exception { - ServiceConfig config = new ServiceConfig(); EsSearchManager searchMan = context.getBean(EsSearchManager.class); // Search for the dataset identified by spIdentifier AbstractMetadata datasetMd = null; String jsonQuery = "{" + - " \"bool\": {" + - " \"must\": [" + - " {" + - " \"term\": {" + - " \"resourceType\": {" + - " \"value\": \"%s\"" + - " }" + - " }" + - " }, " + - " {" + - " \"term\": {" + - " \"resourceIdentifier.code\": {" + - " \"value\": \"%s\"" + - " }" + - " }" + - " }" + - " ]" + - " }" + + " \"term\": {" + + " \"resourceIdentifier.code\": {" + + " \"value\": \"%s\"" + + " }" + + " }" + "}"; ObjectMapper objectMapper = new ObjectMapper(); IMetadataUtils repo = context.getBean(IMetadataUtils.class); @@ -563,7 +546,7 @@ public static Element getDatasetFeed(final ServiceContext context, final String // searchResult = searcher.present(context, dsLuceneSearchParams.getRootElement(), config); // } // } - JsonNode esJsonQuery = objectMapper.readTree(String.format(jsonQuery, "dataset", spIdentifier)); + JsonNode esJsonQuery = objectMapper.readTree(String.format(jsonQuery, spIdentifier)); final SearchResponse result = searchMan.query( esJsonQuery, @@ -646,9 +629,9 @@ public static Element getDatasetFeed(final ServiceContext context, final String } public static Element prepareOpenSearchDescriptionEltBeforeTransform(final ServiceContext context, - final Map params, final String fileIdentifier, final String schema, - final Element serviceAtomFeed, final String defaultLanguage, - final DataManager dataManager) throws Exception { + final Map params, final String fileIdentifier, + final Element serviceAtomFeed, final String defaultLanguage + ) throws Exception { List keywords = retrieveKeywordsFromFileIdentifier(context, fileIdentifier); Namespace ns = serviceAtomFeed.getNamespace(); @@ -658,7 +641,7 @@ public static Element prepareOpenSearchDescriptionEltBeforeTransform(final Servi response.addContent(new Element("fileId").setText(fileIdentifier)); response.addContent(new Element("title").setText(serviceAtomFeed.getChildText("title", ns))); response.addContent(new Element("subtitle").setText(serviceAtomFeed.getChildText("subtitle", ns))); - List languages = new ArrayList(); + List languages = new ArrayList<>(); languages.add(XslUtil.twoCharLangCode(defaultLanguage)); Iterator linksChildren = (serviceAtomFeed.getChildren("link", ns)).iterator(); while (linksChildren.hasNext()) { @@ -685,7 +668,7 @@ public static Element prepareOpenSearchDescriptionEltBeforeTransform(final Servi response.addContent(datasetsEl); Namespace inspiredlsns = serviceAtomFeed.getNamespace("inspire_dls"); Iterator datasets = (serviceAtomFeed.getChildren("entry", ns)).iterator(); - List fileTypes = new ArrayList(); + List fileTypes = new ArrayList<>(); while (datasets.hasNext()) { Element dataset = datasets.next(); String datasetIdCode = dataset.getChildText("spatial_dataset_identifier_code", inspiredlsns); @@ -693,7 +676,7 @@ public static Element prepareOpenSearchDescriptionEltBeforeTransform(final Servi Element datasetAtomFeed = null; try { - datasetAtomFeed = InspireAtomUtil.getDatasetFeed(context, datasetIdCode, datasetIdNs, params, XslUtil.twoCharLangCode(defaultLanguage)); + datasetAtomFeed = InspireAtomUtil.getMetadataFeedByResourceIdentifier(context, datasetIdCode, datasetIdNs, params, XslUtil.twoCharLangCode(defaultLanguage)); } catch (Exception e) { Log.error(Geonet.ATOM, "No dataset metadata found with uuid:" + fileIdentifier); @@ -708,7 +691,7 @@ public static Element prepareOpenSearchDescriptionEltBeforeTransform(final Servi datasetEl.addContent(new Element("authorName").setText(authorName)); } } - Map downloadsCountByCrs = new HashMap(); + Map downloadsCountByCrs = new HashMap<>(); Iterator entries = (datasetAtomFeed.getChildren("entry", ns)).iterator(); while (entries.hasNext()) { Element entry = entries.next(); @@ -717,7 +700,7 @@ public static Element prepareOpenSearchDescriptionEltBeforeTransform(final Servi String term = category.getAttributeValue("term"); Integer count = downloadsCountByCrs.get(term); if (count == null) { - count = new Integer(0); + count = 0; } downloadsCountByCrs.put(term, count + 1); } @@ -820,15 +803,13 @@ private static Element buildDatasetInfo(final String identifier, final String na public static List retrieveKeywordsFromFileIdentifier(ServiceContext context, String uuid) { EsSearchManager searchManager = context.getBean(EsSearchManager.class); - List keywordsList = new ArrayList(); + List keywordsList = new ArrayList<>(); try { Map document = searchManager.getDocument(uuid); Object tags = document.get("tag"); if (tags instanceof List) { ArrayList> list = (ArrayList) tags; - list.forEach(tag -> { - keywordsList.add(tag.get("default")); - }); + list.forEach(tag -> keywordsList.add(tag.get("default"))); } } catch (Exception ex) { Log.error(Geonet.ATOM, ex.getMessage(), ex); diff --git a/inspire-atom/src/main/java/org/fao/geonet/services/inspireatom/AtomPredefinedFeed.java b/inspire-atom/src/main/java/org/fao/geonet/services/inspireatom/AtomPredefinedFeed.java index 33908bacbcd..f1e0f517eba 100644 --- a/inspire-atom/src/main/java/org/fao/geonet/services/inspireatom/AtomPredefinedFeed.java +++ b/inspire-atom/src/main/java/org/fao/geonet/services/inspireatom/AtomPredefinedFeed.java @@ -139,7 +139,7 @@ public HttpEntity localDatasetDescribe( if (StringUtils.isNotBlank(searchTerms)) { params.put("searchTerms", searchTerms.toLowerCase()); } - Element feed = InspireAtomUtil.getDatasetFeed(context, spIdentifier, spNamespace, params, language); + Element feed = InspireAtomUtil.getMetadataFeedByResourceIdentifier(context, spIdentifier, spNamespace, params, language); return writeOutResponse(Xml.getString(feed), "application", "atom+xml"); } @@ -247,7 +247,7 @@ public HttpEntity localDatasetDownload( if (StringUtils.isNotBlank(searchTerms)) { params.put("searchTerms", searchTerms.toLowerCase()); } - Element feed = InspireAtomUtil.getDatasetFeed(context, spIdentifier, spNamespace, params, language); + Element feed = InspireAtomUtil.getMetadataFeedByResourceIdentifier(context, spIdentifier, spNamespace, params, language); Map crsCounts = new HashMap();; Namespace ns = Namespace.getNamespace("http://www.w3.org/2005/Atom"); if (crs!=null) { @@ -368,7 +368,9 @@ private Element getOpenSearchDescription(ServiceContext context, final String uu String defaultLanguage = dm.extractDefaultLanguage(schema, md); Map params = getDefaultXSLParams(sm, context, XslUtil.twoCharLangCode(defaultLanguage)); - Element inputDoc = InspireAtomUtil.prepareOpenSearchDescriptionEltBeforeTransform(context, params, uuid, schema, InspireAtomUtil.convertDatasetMdToAtom("iso19139", InspireAtomUtil.prepareServiceFeedEltBeforeTransform(schema, md, dm), dm, params), defaultLanguage, dm); + Element inputDoc = InspireAtomUtil.prepareOpenSearchDescriptionEltBeforeTransform(context, params, uuid, + InspireAtomUtil.convertDatasetMdToAtom("iso19139", + InspireAtomUtil.prepareServiceFeedEltBeforeTransform(schema, md, dm), dm, params), defaultLanguage); return InspireAtomUtil.convertServiceMdToOpenSearchDescription(context, inputDoc, params); }