From 773ca756ffeef5570cc9231c3d973c6167949d4c Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 14 Nov 2022 16:59:00 +0100 Subject: [PATCH] revisited parsing of the "Geoportal-DataViewer-Configs" GR --- .../GNADataViewerConfigProfileReader.java | 52 +------------------ .../shared/GNADataViewerConfigProfile.java | 49 +---------------- .../org/gcube/application/TestGNACommon.java | 9 +--- 3 files changed, 3 insertions(+), 107 deletions(-) diff --git a/src/main/java/org/gcube/application/geoportalcommon/GNADataViewerConfigProfileReader.java b/src/main/java/org/gcube/application/geoportalcommon/GNADataViewerConfigProfileReader.java index f2606c1..de915e4 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/GNADataViewerConfigProfileReader.java +++ b/src/main/java/org/gcube/application/geoportalcommon/GNADataViewerConfigProfileReader.java @@ -3,21 +3,13 @@ package org.gcube.application.geoportalcommon; import static org.gcube.resources.discovery.icclient.ICFactory.client; import java.io.StringReader; -import java.net.URLDecoder; -import java.util.HashMap; import java.util.List; -import java.util.Map; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathFactory; import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile; -import org.gcube.application.geoportalcommon.shared.LayerItem; import org.gcube.application.geoportalcommon.shared.exception.ApplicationProfileNotFoundException; -import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV; import org.gcube.common.resources.gcore.utils.XPathHelper; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.resources.discovery.client.api.DiscoveryClient; @@ -26,9 +18,6 @@ import org.gcube.resources.discovery.client.queries.impl.QueryBox; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; import org.xml.sax.InputSource; /** @@ -46,7 +35,6 @@ public class GNADataViewerConfigProfileReader { */ public static final String SECONDARY_TYPE = "ApplicationProfile"; public static final String GENERIC_RESOURCE_NAME = "Geoportal-DataViewer-Configs"; - private static final String PATH_TO_ITEM_FIELDS_CONFIG = RESOURCE_PROFILE_BODY + "/item_fields_config"; private static Logger LOG = LoggerFactory.getLogger(GNADataViewerConfigProfileReader.class); private String secondaryType; @@ -88,7 +76,7 @@ public class GNADataViewerConfigProfileReader { Query q = new QueryBox(queryString); DiscoveryClient client = client(); List appProfile = client.submit(q); - String item_fields = ""; +// String item_fields = ""; if (appProfile == null || appProfile.size() == 0) throw new ApplicationProfileNotFoundException("ApplicationProfile with SecondaryType: " + secondaryType @@ -115,44 +103,6 @@ public class GNADataViewerConfigProfileReader { } else throw new Exception("I'm not able to read the path: " + xPathExp); - XPath xPath = XPathFactory.newInstance().newXPath(); - NodeList nodeList = (NodeList) xPath.compile("/Resource/Profile/Body/AvailableLayers/Layer") - .evaluate(doc, XPathConstants.NODESET); - - Map mapLayers = new HashMap(nodeList.getLength()); - - for (int i = 0; i < nodeList.getLength(); i++) { - Node layerNode = nodeList.item(i); - if (layerNode.getNodeType() == Node.ELEMENT_NODE) { - Element eElement = (Element) layerNode; - String layerType = eElement.getElementsByTagName("Type").item(0).getTextContent(); - String wmsLink = eElement.getElementsByTagName("WMSLink").item(0).getTextContent(); - String decodedURL = URLDecoder.decode(wmsLink, "UTF-8"); - LayerItem layer = new LayerItem(); - layer.setWmsLink(decodedURL); - mapLayers.put(layerType.toLowerCase(), layer); - } - } - - profile.setMapLayers(mapLayers); - - xPathExp = PATH_TO_ITEM_FIELDS_CONFIG + "/text()"; - currValue = helper.evaluate(xPathExp); - - if (currValue != null && currValue.size() > 0) { - item_fields = currValue.get(0); - } else - throw new Exception("I'm not able to read the path: " + xPathExp); - - // replacing \n with new_line string - LOG.debug("read " + PATH_TO_ITEM_FIELDS_CONFIG + ": " + item_fields); - String value_with_new_lines = item_fields.replaceAll("\\\\n", System.lineSeparator()); - LOG.debug(PATH_TO_ITEM_FIELDS_CONFIG + " with new lines: " + value_with_new_lines); - - GNAConfigsConverter gnc = new GNAConfigsConverter(); - List listItemFieldsConfig = gnc.readListItemsConfig(value_with_new_lines); - profile.setListItemFields(listItemFieldsConfig); - LOG.info("returning: " + profile); return profile; } diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/GNADataViewerConfigProfile.java b/src/main/java/org/gcube/application/geoportalcommon/shared/GNADataViewerConfigProfile.java index 9656514..9aab899 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/shared/GNADataViewerConfigProfile.java +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/GNADataViewerConfigProfile.java @@ -1,10 +1,6 @@ package org.gcube.application.geoportalcommon.shared; import java.io.Serializable; -import java.util.List; -import java.util.Map; - -import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV; /** * The Class GNADataViewerConfigProfile. @@ -21,9 +17,6 @@ public class GNADataViewerConfigProfile implements Serializable { private static final long serialVersionUID = 2968334957258327191L; private String restrictedPortletURL; private String openPortletURL; - // the key is the layer type - private Map mapLayers; - private List listItemFields; /** * Instantiates a new geo na data viewer profile. @@ -68,42 +61,6 @@ public class GNADataViewerConfigProfile implements Serializable { this.openPortletURL = openPortletURL; } - /** - * Gets the map layers. - * - * @return the map layers - */ - public Map getMapLayers() { - return mapLayers; - } - - /** - * Sets the map layers. - * - * @param mapLayers the map layers - */ - public void setMapLayers(Map mapLayers) { - this.mapLayers = mapLayers; - } - - /** - * Gets the list item fields. - * - * @return the list item fields - */ - public List getListItemFields() { - return listItemFields; - } - - /** - * Sets the list item fields. - * - * @param listItemFields the new list item fields - */ - public void setListItemFields(List listItemFields) { - this.listItemFields = listItemFields; - } - @Override public String toString() { StringBuilder builder = new StringBuilder(); @@ -111,12 +68,8 @@ public class GNADataViewerConfigProfile implements Serializable { builder.append(restrictedPortletURL); builder.append(", openPortletURL="); builder.append(openPortletURL); - builder.append(", mapLayers="); - builder.append(mapLayers); - builder.append(", listItemFields="); - builder.append(listItemFields); builder.append("]"); return builder.toString(); } - + } diff --git a/src/test/java/org/gcube/application/TestGNACommon.java b/src/test/java/org/gcube/application/TestGNACommon.java index de925de..2c78bf0 100644 --- a/src/test/java/org/gcube/application/TestGNACommon.java +++ b/src/test/java/org/gcube/application/TestGNACommon.java @@ -122,14 +122,7 @@ public class TestGNACommon { try { ScopeProvider.instance.set(CONTEXT); GNADataViewerConfigProfile configurations = r.readGNADataViewerConfig(null); - - System.out.println("Map layers are:"); - System.out.println(configurations.getMapLayers()); - System.out.println("Item Fields are:"); - int i = 0; - for (ItemFieldDV item : configurations.getListItemFields()) { - System.out.println(++i + " " + item); - } + System.out.println(configurations.toString()); } catch (Exception e) { e.printStackTrace(); }