revisited parsing of the "Geoportal-DataViewer-Configs" GR
This commit is contained in:
parent
657fded79c
commit
773ca756ff
|
@ -3,21 +3,13 @@ package org.gcube.application.geoportalcommon;
|
||||||
import static org.gcube.resources.discovery.icclient.ICFactory.client;
|
import static org.gcube.resources.discovery.icclient.ICFactory.client;
|
||||||
|
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.net.URLDecoder;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
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.GNADataViewerConfigProfile;
|
||||||
import org.gcube.application.geoportalcommon.shared.LayerItem;
|
|
||||||
import org.gcube.application.geoportalcommon.shared.exception.ApplicationProfileNotFoundException;
|
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.resources.gcore.utils.XPathHelper;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.w3c.dom.Document;
|
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;
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,7 +35,6 @@ public class GNADataViewerConfigProfileReader {
|
||||||
*/
|
*/
|
||||||
public static final String SECONDARY_TYPE = "ApplicationProfile";
|
public static final String SECONDARY_TYPE = "ApplicationProfile";
|
||||||
public static final String GENERIC_RESOURCE_NAME = "Geoportal-DataViewer-Configs";
|
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 static Logger LOG = LoggerFactory.getLogger(GNADataViewerConfigProfileReader.class);
|
||||||
private String secondaryType;
|
private String secondaryType;
|
||||||
|
@ -88,7 +76,7 @@ public class GNADataViewerConfigProfileReader {
|
||||||
Query q = new QueryBox(queryString);
|
Query q = new QueryBox(queryString);
|
||||||
DiscoveryClient<String> client = client();
|
DiscoveryClient<String> client = client();
|
||||||
List<String> appProfile = client.submit(q);
|
List<String> appProfile = client.submit(q);
|
||||||
String item_fields = "";
|
// String item_fields = "";
|
||||||
|
|
||||||
if (appProfile == null || appProfile.size() == 0)
|
if (appProfile == null || appProfile.size() == 0)
|
||||||
throw new ApplicationProfileNotFoundException("ApplicationProfile with SecondaryType: " + secondaryType
|
throw new ApplicationProfileNotFoundException("ApplicationProfile with SecondaryType: " + secondaryType
|
||||||
|
@ -115,44 +103,6 @@ public class GNADataViewerConfigProfileReader {
|
||||||
} else
|
} else
|
||||||
throw new Exception("I'm not able to read the path: " + xPathExp);
|
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<String, LayerItem> mapLayers = new HashMap<String, LayerItem>(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<ItemFieldDV> listItemFieldsConfig = gnc.readListItemsConfig(value_with_new_lines);
|
|
||||||
profile.setListItemFields(listItemFieldsConfig);
|
|
||||||
|
|
||||||
LOG.info("returning: " + profile);
|
LOG.info("returning: " + profile);
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
package org.gcube.application.geoportalcommon.shared;
|
package org.gcube.application.geoportalcommon.shared;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class GNADataViewerConfigProfile.
|
* The Class GNADataViewerConfigProfile.
|
||||||
|
@ -21,9 +17,6 @@ public class GNADataViewerConfigProfile implements Serializable {
|
||||||
private static final long serialVersionUID = 2968334957258327191L;
|
private static final long serialVersionUID = 2968334957258327191L;
|
||||||
private String restrictedPortletURL;
|
private String restrictedPortletURL;
|
||||||
private String openPortletURL;
|
private String openPortletURL;
|
||||||
// the key is the layer type
|
|
||||||
private Map<String, LayerItem> mapLayers;
|
|
||||||
private List<ItemFieldDV> listItemFields;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new geo na data viewer profile.
|
* Instantiates a new geo na data viewer profile.
|
||||||
|
@ -68,42 +61,6 @@ public class GNADataViewerConfigProfile implements Serializable {
|
||||||
this.openPortletURL = openPortletURL;
|
this.openPortletURL = openPortletURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the map layers.
|
|
||||||
*
|
|
||||||
* @return the map layers
|
|
||||||
*/
|
|
||||||
public Map<String, LayerItem> getMapLayers() {
|
|
||||||
return mapLayers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the map layers.
|
|
||||||
*
|
|
||||||
* @param mapLayers the map layers
|
|
||||||
*/
|
|
||||||
public void setMapLayers(Map<String, LayerItem> mapLayers) {
|
|
||||||
this.mapLayers = mapLayers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the list item fields.
|
|
||||||
*
|
|
||||||
* @return the list item fields
|
|
||||||
*/
|
|
||||||
public List<ItemFieldDV> getListItemFields() {
|
|
||||||
return listItemFields;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the list item fields.
|
|
||||||
*
|
|
||||||
* @param listItemFields the new list item fields
|
|
||||||
*/
|
|
||||||
public void setListItemFields(List<ItemFieldDV> listItemFields) {
|
|
||||||
this.listItemFields = listItemFields;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
@ -111,10 +68,6 @@ public class GNADataViewerConfigProfile implements Serializable {
|
||||||
builder.append(restrictedPortletURL);
|
builder.append(restrictedPortletURL);
|
||||||
builder.append(", openPortletURL=");
|
builder.append(", openPortletURL=");
|
||||||
builder.append(openPortletURL);
|
builder.append(openPortletURL);
|
||||||
builder.append(", mapLayers=");
|
|
||||||
builder.append(mapLayers);
|
|
||||||
builder.append(", listItemFields=");
|
|
||||||
builder.append(listItemFields);
|
|
||||||
builder.append("]");
|
builder.append("]");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,14 +122,7 @@ public class TestGNACommon {
|
||||||
try {
|
try {
|
||||||
ScopeProvider.instance.set(CONTEXT);
|
ScopeProvider.instance.set(CONTEXT);
|
||||||
GNADataViewerConfigProfile configurations = r.readGNADataViewerConfig(null);
|
GNADataViewerConfigProfile configurations = r.readGNADataViewerConfig(null);
|
||||||
|
System.out.println(configurations.toString());
|
||||||
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);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue