diff --git a/gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/GSRESTClient.java b/gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/GSRESTClient.java index 17793d4..05bbc1a 100644 --- a/gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/GSRESTClient.java +++ b/gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/GSRESTClient.java @@ -3,6 +3,7 @@ package org.gcube.spatial.data.clients.geoserver; import java.util.List; import org.gcube.spatial.data.clients.GenericLoginClient; +import org.gcube.spatial.data.clients.geoserver.model.FeatureTypeInfo; import org.gcube.spatial.data.sdi.model.faults.RemoteException; import org.json.simple.JSONObject; @@ -36,7 +37,7 @@ public interface GSRESTClient extends GenericLoginClient{ // FeatureTypes public List getFeatureTypesInWorkspace(String workspace)throws RemoteException,Exception; public List getFeatureTypesInDataStore(String workspace,String datastore)throws RemoteException,Exception; - public JSONObject getFeatureType(String workspace,String featureName)throws RemoteException,Exception; + public FeatureTypeInfo getFeatureType(String workspace,String featureName)throws RemoteException,Exception; //Layers @@ -49,19 +50,8 @@ public interface GSRESTClient extends GenericLoginClient{ public void createWorkspace(String ws)throws RemoteException,Exception; public void createStyle(String name,String content)throws RemoteException,Exception; -// - // publish DB layer - // publish local files // create store for postgis db - /** - * getDataStoreManager().create(workspace, encoder) - */ - - /** - * if(!gis.getCurrentGeoServer().getPublisher().publishStyle(sldFile, name) - * - */ /** @@ -70,17 +60,6 @@ public interface GSRESTClient extends GenericLoginClient{ */ - /** - * public boolean publishShp(String workspace, String storeName, NameValuePair[] storeParams, - String datasetName, UploadMethod method, URI shapefile, String srs, String defaultStyle) - throws FileNotFoundException, IllegalArgumentException { - return publishShp(workspace, storeName, storeParams, datasetName, method, shapefile, srs, - null, ProjectionPolicy.FORCE_DECLARED, defaultStyle); - } - * @param ws - * @throws RemoteException - * @throws Exception - */ /** * Publish a DS described in @param parameters. Parameters vary depending on DS type. See https://docs.geoserver.org/latest/en/api/#1.0.0/datastores.yaml for more details. diff --git a/gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/GSRESTClientImpl.java b/gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/GSRESTClientImpl.java index db3fccf..8f67ab4 100644 --- a/gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/GSRESTClientImpl.java +++ b/gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/GSRESTClientImpl.java @@ -8,11 +8,12 @@ import java.util.Map; import javax.ws.rs.client.Entity; import javax.ws.rs.core.MediaType; -import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest; import org.gcube.spatial.data.clients.AbstractGenericRESTClient; +import org.gcube.spatial.data.clients.geoserver.model.FeatureTypeInfo; import org.gcube.spatial.data.clients.model.ConnectionDescriptor; import org.gcube.spatial.data.sdi.model.faults.RemoteException; import org.json.simple.JSONObject; +import org.opengis.feature.type.FeatureType; import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.DocumentContext; @@ -127,8 +128,8 @@ public class GSRESTClientImpl extends AbstractGenericRESTClient implements GSRES @Override - public JSONObject getFeatureType(String workspace, String featureName) throws RemoteException, Exception { - return get(WS_BASE_PATH+"/"+workspace+"/"+FEATURES_BASE_PATH+"/"+featureName,JSONObject.class); + public FeatureTypeInfo getFeatureType(String workspace, String featureName) throws RemoteException, Exception { + return get(WS_BASE_PATH+"/"+workspace+"/"+FEATURES_BASE_PATH+"/"+featureName,FeatureTypeInfo.class); } @Override @@ -224,7 +225,11 @@ public class GSRESTClientImpl extends AbstractGenericRESTClient implements GSRES @Override public void createStyle(String name, String content) throws RemoteException, Exception { - put(STYLES_BASE_PATH+"/"+name, Entity.entity(content, "application/vnd.ogc.sld+xml")); + +// JSONObject obj=new JSONObject(); +// obj.put("name", name); +// obj.put(""); + post(STYLES_BASE_PATH, Entity.entity(content, "application/vnd.ogc.sld+xml"),String.class,Collections.singletonMap("name", name)); } diff --git a/gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/DataStoreRegistrationRequest.java b/gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/model/DataStoreRegistrationRequest.java similarity index 97% rename from gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/DataStoreRegistrationRequest.java rename to gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/model/DataStoreRegistrationRequest.java index 0356ec4..63502c9 100644 --- a/gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/DataStoreRegistrationRequest.java +++ b/gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/model/DataStoreRegistrationRequest.java @@ -1,4 +1,4 @@ -package org.gcube.spatial.data.clients.geoserver; +package org.gcube.spatial.data.clients.geoserver.model; import java.util.ArrayList; import java.util.Collections; diff --git a/gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/model/FeatureTypeInfo.java b/gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/model/FeatureTypeInfo.java new file mode 100644 index 0000000..741be15 --- /dev/null +++ b/gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/model/FeatureTypeInfo.java @@ -0,0 +1,92 @@ +package org.gcube.spatial.data.clients.geoserver.model; + +import java.util.List; + +import javax.xml.bind.annotation.XmlElement; + +import lombok.Data; + + +@Data +public class FeatureTypeInfo { + + public static class Namespace{ + private String name; + private String href; + } + + + public static class Keyword{ + private List string; + } + + public static class MetadataLink{ + private String type; + private String metadataType; + private String content; + } + + public static class BoundingBox{ + private Number minx; + private Number maxx; + private Number miny; + private Number maxy; + private String crs; + } + + public static class Entry{ + private String key; + private String value; + } + + + public static class Store{ + private String clazz; + private String name; + private String href; + } + + + public static class Attribute{ + private String name; + private Integer minOccurs; + private Integer maxOccurs; + private Boolean nillable; + private String binding; + private Integer length; + } + + private String name; + private String nativeName; + private Namespace namespace; + private String title; + @XmlElement(name="abstract") + private String abstractField; + private List keywords; + + private List metadataLinks; + private List dataLinks; + + + private String nativeCRS; + private String srs; + private BoundingBox nativeVoundingBox; + private BoundingBox latLonBoundingBox; + + + private List metadata; + + private Store store; + + private String cqlFilter; + private Integer maxFeatures; + private Number numDecimals; + private String responseSRS; + private Boolean overridingServiceSRS; + private Boolean skipNumberMatched; + private Boolean circularArcPresent; + private Number linearizationTolerance; + + private List attributes; + +} diff --git a/gcube-geoserver-client/src/test/java/org/gcube/spatial/data/clients/geoserver/GSTests.java b/gcube-geoserver-client/src/test/java/org/gcube/spatial/data/clients/geoserver/GSTests.java index 09402fe..d0647a9 100644 --- a/gcube-geoserver-client/src/test/java/org/gcube/spatial/data/clients/geoserver/GSTests.java +++ b/gcube-geoserver-client/src/test/java/org/gcube/spatial/data/clients/geoserver/GSTests.java @@ -4,19 +4,16 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; +import java.io.File; +import java.io.IOException; import java.nio.charset.Charset; -import java.util.Collections; -import java.util.HashMap; import java.util.UUID; -import javax.sound.midi.SysexMessage; - import org.gcube.sdi.test.GCubeSDITest; import org.gcube.spatial.data.clients.SDIGenericPlugin; import org.gcube.spatial.data.clients.model.engine.Engine; import org.gcube.spatial.data.sdi.model.faults.RemoteException; import org.gcube.spatial.data.sdi.utils.Files; -import org.json.simple.JSONObject; import org.junit.Test; public class GSTests extends GCubeSDITest{ @@ -56,13 +53,13 @@ public class GSTests extends GCubeSDITest{ }catch(RemoteException e ) {System.err.println("Unable to read SLD "+sld+" from "+ws+". Cause "+e.getResponseHTTPCode()+": "+e.getMessage());} - System.out.println(client.getDataStoresInWorkspace(ws)); + System.out.println("WS "+ws+" ->"+client.getDataStoresInWorkspace(ws)); - for(String ds:client.getDataStoresNamesInWorkspace(ws)) - if(ds!=null) { - try{ System.out.println(client.getDataStore(ws, ds)); - }catch(RemoteException e ) {System.err.println("Unable to read DS "+ds+" from "+ws+". Cause "+e.getResponseHTTPCode()+": "+e.getMessage());} - } +// for(String ds:client.getDataStoresNamesInWorkspace(ws)) +// if(ds!=null) { +// try{ System.out.println(client.getDataStore(ws, ds)); +// }catch(RemoteException e ) {System.err.println("Unable to read DS "+ds+" from "+ws+". Cause "+e.getResponseHTTPCode()+": "+e.getMessage());} +// } for(String ft : client.getFeatureTypesInWorkspace(ws)) @@ -121,7 +118,8 @@ public class GSTests extends GCubeSDITest{ // SLD String myStyle=UUID.randomUUID().toString().replace("-", "_"); - client.createStyle(myStyle, Files.readFileAsString("clustered_points.sld", Charset.defaultCharset())); + System.out.println("style name is :"+ myStyle); + client.createStyle(myStyle,read("clustered_points.sld")); assertTrue("SLD registered ",client.getStylesNames().contains(myStyle)); client.deleteStyle(myStyle, true, true); assertFalse("SLD Removed",client.getStylesNames().contains(myStyle)); @@ -129,5 +127,8 @@ public class GSTests extends GCubeSDITest{ } - + private static final String read(String toRead) throws IOException { + File f= Files.getFileFromResources(toRead); + return Files.readFileAsString(f.getAbsolutePath(), Charset.defaultCharset()); + } } diff --git a/gcube-geoserver-client/src/test/resources/clustered_points.sld b/gcube-geoserver-client/src/test/resources/clustered_points.sld new file mode 100644 index 0000000..922502d --- /dev/null +++ b/gcube-geoserver-client/src/test/resources/clustered_points.sld @@ -0,0 +1,173 @@ + + + + vol_stacked_point + + + Stacked Point + Styles archeomar using stacked points + + + + + data + + + cellSize + 30 + + + outputBBOX + + wms_bbox + + + + outputWidth + + wms_width + + + + outputHeight + + wms_height + + + + + + rule1 + Site + + + count + 1 + + + + + + circle + + #FF0000 + + + 8 + + + + + rule29 + 2-9 Sites + + + count + + 2 + + + 9 + + + + + + + circle + + #AA0000 + + + 14 + + + + + + Arial + 12 + bold + + + + + 0.5 + 0.8 + + + + + 2 + + #AA0000 + 0.9 + + + + #FFFFFF + 1.0 + + + + + rule10 + 10 Sites + + + count + 9 + + + + + + circle + + #AA0000 + + + 22 + + + + + + Arial + 12 + bold + + + + + 0.5 + 0.8 + + + + + 2 + + #AA0000 + 0.9 + + + + #FFFFFF + 1.0 + + + + + + + diff --git a/pom.xml b/pom.xml index c046bc8..0cdbc5e 100644 --- a/pom.xml +++ b/pom.xml @@ -62,7 +62,7 @@ org.gcube.distribution gcube-bom - 2.0.0 + 2.0.1 pom import diff --git a/sdi-generic-client/src/main/java/org/gcube/spatial/data/clients/AbstractGenericRESTClient.java b/sdi-generic-client/src/main/java/org/gcube/spatial/data/clients/AbstractGenericRESTClient.java index 6a92845..4ed5289 100644 --- a/sdi-generic-client/src/main/java/org/gcube/spatial/data/clients/AbstractGenericRESTClient.java +++ b/sdi-generic-client/src/main/java/org/gcube/spatial/data/clients/AbstractGenericRESTClient.java @@ -3,7 +3,11 @@ package org.gcube.spatial.data.clients; import java.io.IOException; import java.io.UnsupportedEncodingException; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; import javax.ws.rs.client.Entity; @@ -119,7 +123,7 @@ public abstract class AbstractGenericRESTClient implements GenericLoginClient{ } - protected T makeCall(Call call) throws Exception{ + protected T makeCall(Call call) throws RemoteException, Exception{ try{ return call.call(resolve()); }catch(RemoteException e) { @@ -130,35 +134,56 @@ public abstract class AbstractGenericRESTClient implements GenericLoginClient{ } - protected void delete(String path) throws Exception { - check(resolve().path(path).delete(),null); + + + //****** METHODS + + + + protected void delete(String path) throws RemoteException,Exception { + makeCall(new Call() { + + public Object call(GXWebTargetAdapterRequest endpoint) throws Exception { + return check(resolve().path(path).delete(),null); + }; + + }); + } - protected void post(String path,Entity entity)throws Exception{ - post(path,entity,null); - } - - - protected void post(String path,Object obj) throws Exception { + protected void post(String path,Object obj) throws RemoteException,Exception { post(path,Entity.entity(obj, MediaType.APPLICATION_JSON_TYPE)); } - protected T post(String path,Entity entity,Class returnClazz) throws Exception { + + + protected T post (String path,Entity entity,Class returnClazz,Map queryParams) throws RemoteException,Exception{ return makeCall(new Call() { public T call(GXWebTargetAdapterRequest endpoint) throws Exception { - return check(endpoint.path(path).post(entity),returnClazz); + Map actualMap=new HashMap(); + queryParams.forEach((String k, Object v)->{ + Object[] theArray=null; + if(v instanceof Collection) {} + else theArray=new Object[] {v}; + + actualMap.put(k, theArray); + }); + +// for(java.util.Map.Entry e:queryParams.entrySet()) { +// String k=e.getKey(); +// if(!actualMap.containsKey(k))actualMap. +// } + return check(endpoint.path(path).queryParams(actualMap).post(entity),returnClazz); }; }); } - - protected void put(String path,Entity entity)throws Exception{ - post(path,entity,null); + protected void post(String path,Entity entity)throws RemoteException,Exception{ + post(path,entity,null,Collections.emptyMap()); } - protected void put(String path,Object obj) throws Exception { post(path,Entity.entity(obj, MediaType.APPLICATION_JSON_TYPE)); }