diff --git a/src/main/java/org/gcube/spatial/data/geoutility/GeoGetStylesUtility.java b/src/main/java/org/gcube/spatial/data/geoutility/GeoGetStylesUtility.java index 78e62af..530bb00 100644 --- a/src/main/java/org/gcube/spatial/data/geoutility/GeoGetStylesUtility.java +++ b/src/main/java/org/gcube/spatial/data/geoutility/GeoGetStylesUtility.java @@ -9,11 +9,13 @@ import java.util.Map; import org.apache.log4j.Logger; import org.gcube.spatial.data.geoutility.bean.NcWmsLayerMetadata; +import org.gcube.spatial.data.geoutility.bean.NcWmsLayerMetadata.METADATA; import org.gcube.spatial.data.geoutility.bean.WmsParameters; import org.gcube.spatial.data.geoutility.wms.NcWmsGetMetadata; import org.gcube.spatial.data.geoutility.wms.NcWmsGetMetadataRequest; import org.gcube.spatial.data.geoutility.wms.WmsGetStyles; import org.gcube.spatial.data.geoutility.wms.WmsUrlValidator; +import org.gcube.spatial.data.geoutility.wms.ZAxis; /** @@ -173,9 +175,16 @@ public class GeoGetStylesUtility { logger.debug("Wms GetStyles not found, Trying to get styles by 'NcWmsGetMetadata'"); isNcWms = true; try{ - NcWmsLayerMetadata ncMetadata = NcWmsGetMetadata.getMetadata(uriWMSService, layerName, connectionTimeout); + + METADATA[] meta = new METADATA[3]; + meta[0] = METADATA.SUPPORTEDSTYLES; + meta[1] = METADATA.DEFAULTPALETTE; + meta[2] = METADATA.PALETTES; + + NcWmsLayerMetadata ncMetadata = NcWmsGetMetadata.getMetadata(uriWMSService, layerName, connectionTimeout, meta); if(ncMetadata!=null && ncMetadata.getResponseCode()==200){ + //STYLES if(ncMetadata.getSupportedStyles().size()>0){ styles.add(ncMetadata.getSupportedStyles().get(0)+"/"+ncMetadata.getDefaultPalette()); //DEFAULT STYLE logger.debug("added ncWms default style: "+ncMetadata.getSupportedStyles().get(0)+"/"+ncMetadata.getDefaultPalette()); @@ -190,6 +199,10 @@ public class GeoGetStylesUtility { } } } + //Z-AXIS + if(ncMetadata.getZAxis()!=null){ + + } } }catch(Exception e){ logger.error(e); @@ -203,6 +216,30 @@ public class GeoGetStylesUtility { this.geoStyles = styles; } + /** + * Load z axis values for a ncWMS layer + * + * @param connectionTimeout the connection timeout + * @return the z axis + */ + public ZAxis loadZAxis(int connectionTimeout){ + + String uriWMSService = validator.getBaseWmsServiceUrl(); + String layerName = validator.getValueOfParsedWMSParameter(WmsParameters.LAYERS); + + METADATA[] meta = new METADATA[1]; + meta[0] = METADATA.Z_AXIS; + + try { + NcWmsLayerMetadata ncMetadata = NcWmsGetMetadata.getMetadata(uriWMSService, layerName, connectionTimeout, meta); + return ncMetadata.getZAxis(); + } + catch (Exception e) { + logger.error("Exception during ncWMS get zAxis: "+e); + return null; + } + } + /** * Gets the geo styles. * diff --git a/src/main/java/org/gcube/spatial/data/geoutility/bean/NcWmsLayerMetadata.java b/src/main/java/org/gcube/spatial/data/geoutility/bean/NcWmsLayerMetadata.java index 07ede0d..377b49f 100644 --- a/src/main/java/org/gcube/spatial/data/geoutility/bean/NcWmsLayerMetadata.java +++ b/src/main/java/org/gcube/spatial/data/geoutility/bean/NcWmsLayerMetadata.java @@ -23,10 +23,32 @@ public class NcWmsLayerMetadata implements Serializable { private static final long serialVersionUID = 5111586382138532571L; //GET PARAMETERS - public static final String SUPPORTEDSTYLES = "supportedStyles"; - public static final String PALETTES = "palettes"; - public static final String DEFAULTPALETTE = "defaultPalette"; - public static final String Z_AXIS = "zaxis"; +// public static final String SUPPORTEDSTYLES = "supportedStyles"; +// public static final String PALETTES = "palettes"; +// public static final String DEFAULTPALETTE = "defaultPalette"; +// public static final String Z_AXIS = "zaxis"; + + public static enum METADATA { + SUPPORTEDSTYLES("supportedStyles"), + PALETTES("palettes"), + DEFAULTPALETTE("defaultPalette"), + Z_AXIS("zaxis"); + + private String key; + + METADATA(String key){ + this.key = key; + } + + /** + * @return the key + */ + public String getKey() { + + return key; + } + + }; private String defaultPalette; private List supportedStyles; diff --git a/src/main/java/org/gcube/spatial/data/geoutility/wms/NcWmsGetMetadata.java b/src/main/java/org/gcube/spatial/data/geoutility/wms/NcWmsGetMetadata.java index 8072b81..3fad32f 100644 --- a/src/main/java/org/gcube/spatial/data/geoutility/wms/NcWmsGetMetadata.java +++ b/src/main/java/org/gcube/spatial/data/geoutility/wms/NcWmsGetMetadata.java @@ -11,12 +11,14 @@ import java.net.SocketTimeoutException; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import org.apache.commons.io.IOUtils; import org.apache.log4j.Logger; import org.gcube.spatial.data.geoutility.bean.NcWmsLayerMetadata; +import org.gcube.spatial.data.geoutility.bean.NcWmsLayerMetadata.METADATA; import org.gcube.spatial.data.geoutility.bean.WmsParameters; import org.gcube.spatial.data.geoutility.util.UrlEncoderUtil; import org.json.JSONArray; @@ -44,19 +46,21 @@ public class NcWmsGetMetadata { * @throws Exception the exception */ public static NcWmsLayerMetadata getMetadata(String wmsServerUri, String layerName) throws Exception { - return getMetadata(wmsServerUri, layerName, CONNECTION_TIMEOUT); + return getMetadata(wmsServerUri, layerName, CONNECTION_TIMEOUT, METADATA.values()); } + /** * Gets the metadata. * * @param wmsServerUri the wms server uri * @param layerName the layer name - * @param connectionTimeout the connection timeout sets a specified timeout value, in milliseconds, to be used when opening URLConnection. + * @param connectionTimeout the connection timeout + * @param meta the meta * @return the metadata * @throws Exception the exception */ - public static NcWmsLayerMetadata getMetadata(String wmsServerUri, String layerName, int connectionTimeout) throws Exception { + public static NcWmsLayerMetadata getMetadata(String wmsServerUri, String layerName, int connectionTimeout, NcWmsLayerMetadata.METADATA...meta) throws Exception { if(wmsServerUri==null || wmsServerUri.isEmpty()) throw new Exception("Invalid wms server uri"); @@ -70,7 +74,7 @@ public class NcWmsGetMetadata { try { String query = UrlEncoderUtil.encodeQuery(parameters); - return openConnectionGetMetadata(wmsServerUri, query, connectionTimeout); + return openConnectionGetMetadata(wmsServerUri, query, connectionTimeout, meta); }catch (Exception e) { logger.error("Error Exception with url " + wmsServerUri); @@ -86,9 +90,10 @@ public class NcWmsGetMetadata { * @param urlConn the url conn * @param query the query * @param connectionTimeout the connection timeout sets a specified timeout value, in milliseconds, to be used when opening URLConnection. + * @param meta the meta * @return the nc wms layer metadata */ - private static NcWmsLayerMetadata openConnectionGetMetadata(String urlConn, String query, int connectionTimeout) { + private static NcWmsLayerMetadata openConnectionGetMetadata(String urlConn, String query, int connectionTimeout, NcWmsLayerMetadata.METADATA...meta) { URL url; NcWmsLayerMetadata metadata = null; @@ -113,7 +118,7 @@ public class NcWmsGetMetadata { int code = httpConnection.getResponseCode(); if (code == 200) { - metadata = getMetadata(httpConnection); + metadata = getMetadata(httpConnection, meta); metadata.setResponseCode(code); }else{ logger.warn("openConnectionGetMetadata error, code = " + code +", returning"); @@ -147,10 +152,11 @@ public class NcWmsGetMetadata { * Gets the metadata. * * @param httpConnection the http connection + * @param meta the meta * @return the metadata * @throws IOException Signals that an I/O exception has occurred. */ - private static NcWmsLayerMetadata getMetadata(HttpURLConnection httpConnection) throws IOException{ + private static NcWmsLayerMetadata getMetadata(HttpURLConnection httpConnection, METADATA[] meta) throws IOException{ InputStream source = null; NcWmsLayerMetadata metadata = new NcWmsLayerMetadata(); @@ -160,44 +166,57 @@ public class NcWmsGetMetadata { String jsonTxt = IOUtils.toString(source); metadata.setRawJson(jsonTxt); + if(meta==null) + meta = METADATA.values(); + + List listMeta = Arrays.asList(meta); + JSONObject json = new JSONObject(jsonTxt); - JSONArray supportedStyles = json.getJSONArray(NcWmsLayerMetadata.SUPPORTEDSTYLES); - if(supportedStyles!=null){ - List s = new ArrayList(supportedStyles.length()); - for (int i=0; i s = new ArrayList(palettes.length()); - for (int i=0; i s = new ArrayList(values.length()); - for (int i=0; i s = new ArrayList(supportedStyles.length()); + for (int i=0; i s = new ArrayList(palettes.length()); + for (int i=0; i s = new ArrayList(values.length()); + for (int i=0; i