Updated library to be more general

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/spatial-data/geo-utility@124013 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-02-09 17:35:07 +00:00
parent 8ab2bab5c8
commit 9596e53349
3 changed files with 85 additions and 55 deletions

View File

@ -19,14 +19,14 @@ import org.gcube.spatial.data.geoutility.wms.ZAxis;
/**
* The Class GeoGetStylesUtility.
* The Class GeoNcWMSMetadataUtility.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jan 25, 2016
* Feb 9, 2016
*/
public class GeoGetStylesUtility {
public class GeoNcWMSMetadataUtility {
public static Logger logger = Logger.getLogger(GeoGetStylesUtility.class);
public static Logger logger = Logger.getLogger(GeoNcWMSMetadataUtility.class);
public static final String COLORSCALERANGE = "COLORSCALERANGE";
public static final String COLORSCALERANGE_DEFAULT_VALUE = "auto";
boolean isNcWms = false;
@ -34,8 +34,11 @@ public class GeoGetStylesUtility {
private List<String> geoStyles;
private Map<String, String> mapNcWmsStyles;
private WmsUrlValidator validator;
private int connectionTimeout;
private NcWmsLayerMetadata ncMetadata;
private ZAxis zAxis = null;
/** The Constant CONNECTION_TIMEOUT. */
public static final int CONNECTION_TIMEOUT = 1000; //DEFAULT CONNECTION TIMEOUT
public static final int DEFAULT_CONNECTION_TIMEOUT = 1000; //DEFAULT CONNECTION TIMEOUT
/**
@ -44,8 +47,8 @@ public class GeoGetStylesUtility {
* @param wmsRequest the wms request
* @throws Exception the exception
*/
public GeoGetStylesUtility(String wmsRequest) throws Exception{
this(wmsRequest, CONNECTION_TIMEOUT);
public GeoNcWMSMetadataUtility(String wmsRequest) throws Exception{
this(wmsRequest, DEFAULT_CONNECTION_TIMEOUT);
}
@ -56,22 +59,23 @@ public class GeoGetStylesUtility {
* @param connectionTimeout the connection timeout sets a specified timeout value, in milliseconds, to be used when opening URLConnection.
* @throws Exception the exception
*/
public GeoGetStylesUtility(String wmsRequest, int connectionTimeout) throws Exception{
public GeoNcWMSMetadataUtility(String wmsRequest, int connectionTimeout) throws Exception{
this.wmsRequest = wmsRequest;
this.connectionTimeout = connectionTimeout;
this.validator = new WmsUrlValidator(wmsRequest);
validator.parseWmsRequest(true, false);
loadStyles(connectionTimeout);
validateConnectionTimeout();
loadMetadata();
}
/**
* Instantiates a new geo get styles utility.
*
* @param validator the validator
* @throws Exception the exception
*/
public GeoGetStylesUtility(WmsUrlValidator validator) throws Exception{
this(validator, CONNECTION_TIMEOUT);
public GeoNcWMSMetadataUtility(WmsUrlValidator validator) throws Exception{
this(validator, DEFAULT_CONNECTION_TIMEOUT);
}
@ -82,17 +86,40 @@ public class GeoGetStylesUtility {
* @param connectionTimeout the connection timeout sets a specified timeout value, in milliseconds, to be used when opening URLConnection.
* @throws Exception the exception
*/
public GeoGetStylesUtility(WmsUrlValidator validator, int connectionTimeout) throws Exception{
public GeoNcWMSMetadataUtility(WmsUrlValidator validator, int connectionTimeout) throws Exception{
this.wmsRequest = validator.getWmsRequest();
this.validator = validator;
loadStyles(connectionTimeout);
this.connectionTimeout = connectionTimeout;
validateConnectionTimeout();
loadMetadata();
}
/**
* Load styles.
* @param connectionTimeout the connection timeout sets a specified timeout value, in milliseconds, to be used when opening URLConnection.
* Validate connection timeout.
*/
private void loadStyles(int connectionTimeout){
private void validateConnectionTimeout(){
if(this.connectionTimeout<=0)
this.connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
}
/**
* Load metadata.
*
* @throws Exception the exception
*/
private void loadMetadata() throws Exception{
String uriWMSService = validator.getBaseWmsServiceUrl();
String layerName = validator.getValueOfParsedWMSParameter(WmsParameters.LAYERS);
this.ncMetadata = NcWmsGetMetadata.getMetadata(uriWMSService, layerName, connectionTimeout, METADATA.values());
}
/**
* Load styles. This method retrieve WMS styles into List {@link #getGeoStyles()}
* and ncWMS styles into Map {@link #getMapNcWmsStyles()}
* @return
*/
public void loadStyles(){
String uriWMSService = validator.getBaseWmsServiceUrl();
String layerName = validator.getValueOfParsedWMSParameter(WmsParameters.LAYERS);
@ -176,12 +203,13 @@ public class GeoGetStylesUtility {
isNcWms = true;
try{
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){
METADATA[] meta = new METADATA[3];
meta[0] = METADATA.SUPPORTEDSTYLES;
meta[1] = METADATA.DEFAULTPALETTE;
meta[2] = METADATA.PALETTES;
this.ncMetadata = NcWmsGetMetadata.getMetadata(uriWMSService, layerName, connectionTimeout, meta);
}
if(ncMetadata!=null && ncMetadata.getResponseCode()==200){
//STYLES
@ -199,10 +227,6 @@ public class GeoGetStylesUtility {
}
}
}
//Z-AXIS
if(ncMetadata.getZAxis()!=null){
}
}
}catch(Exception e){
logger.error(e);
@ -216,30 +240,39 @@ public class GeoGetStylesUtility {
this.geoStyles = styles;
}
/**
* Load z axis values for a ncWMS layer
* Load z axis values for a ncWMS layer.
*
* @param connectionTimeout the connection timeout
* @return the z axis
* @throws Exception
*/
public ZAxis loadZAxis(int connectionTimeout){
public void loadZAxis() throws Exception{
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;
if(ncMetadata==null){
String uriWMSService = validator.getBaseWmsServiceUrl();
String layerName = validator.getValueOfParsedWMSParameter(WmsParameters.LAYERS);
METADATA[] meta = new METADATA[1];
meta[0] = METADATA.Z_AXIS;
this.ncMetadata = NcWmsGetMetadata.getMetadata(uriWMSService, layerName, connectionTimeout, meta);
}
if(this.ncMetadata==null)
this.zAxis = null;
this.zAxis = this.ncMetadata.getZAxis();
}
/**
* @return the zAxis
*/
public ZAxis getzAxis() {
return zAxis;
}
/**
* Gets the geo styles.
*
@ -296,7 +329,7 @@ public class GeoGetStylesUtility {
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("GeoGetStylesUtility [isNcWms=");
builder.append("GeoNcWMSMetadataUtility [isNcWms=");
builder.append(isNcWms);
builder.append(", wmsRequest=");
builder.append(wmsRequest);
@ -306,6 +339,12 @@ public class GeoGetStylesUtility {
builder.append(mapNcWmsStyles);
builder.append(", validator=");
builder.append(validator);
builder.append(", connectionTimeout=");
builder.append(connectionTimeout);
builder.append(", ncMetadata=");
builder.append(ncMetadata);
builder.append(", zAxis=");
builder.append(zAxis);
builder.append("]");
return builder.toString();
}

View File

@ -22,12 +22,6 @@ 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 enum METADATA {
SUPPORTEDSTYLES("supportedStyles"),
PALETTES("palettes"),
@ -40,9 +34,6 @@ public class NcWmsLayerMetadata implements Serializable {
this.key = key;
}
/**
* @return the key
*/
public String getKey() {
return key;

View File

@ -24,9 +24,9 @@ public class GeoJUnitTest {
// String wmsRequest = "http://repoigg.services.iit.cnr.it:8080/geoserver/IGG/ows?service=wms&version=1.1.0&request=GetMap&layers==IGG:area_temp_1000&width=676&height=330&srs=EPSG:4326&crs=EPSG:4326&format=application/openlayers&bbox=-85.5,-180.0,90.0,180.0";
String wmsRequest = "http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc?service=wms&version=1.3.0&request=GetMap&layers=analyzed_field&styles=&width=640&height=480&srs=EPSG:4326&CRS=EPSG:4326&format=image/png&COLORSCALERANGE=auto&bbox=-85.0,-180.0,85.0,180.0";
// String wmsRequest = "http://www.fao.org/figis/geoserver/species?SERVICE=WMS&BBOX=-176.0,-90.0,180.0,90&styles=&layers=layerName&FORMAT=image/gif";
GeoGetStylesUtility geo;
GeoNcWMSMetadataUtility geo;
try {
geo = new GeoGetStylesUtility(wmsRequest);
geo = new GeoNcWMSMetadataUtility(wmsRequest);
System.out.println("Returned styles: "+geo.getGeoStyles().toString());
}
catch (Exception e) {