Create style

This commit is contained in:
Fabio Sinibaldi 2021-04-29 15:54:02 +02:00
parent 0ef669ab6a
commit 959892798f
8 changed files with 332 additions and 57 deletions

View File

@ -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<String> getFeatureTypesInWorkspace(String workspace)throws RemoteException,Exception;
public List<String> 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.

View File

@ -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));
}

View File

@ -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;

View File

@ -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> 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<Keyword> keywords;
private List<MetadataLink> metadataLinks;
private List<MetadataLink> dataLinks;
private String nativeCRS;
private String srs;
private BoundingBox nativeVoundingBox;
private BoundingBox latLonBoundingBox;
private List<Entry> 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<Attribute> attributes;
}

View File

@ -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());
}
}

View File

@ -0,0 +1,173 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0"
xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
xmlns="http://www.opengis.net/sld"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<NamedLayer>
<Name>vol_stacked_point</Name>
<UserStyle>
<!-- Styles can have names, titles and abstracts -->
<Title>Stacked Point</Title>
<Abstract>Styles archeomar using stacked points</Abstract>
<FeatureTypeStyle>
<Transformation>
<ogc:Function name="vec:PointStacker">
<ogc:Function name="parameter">
<ogc:Literal>data</ogc:Literal>
</ogc:Function>
<ogc:Function name="parameter">
<ogc:Literal>cellSize</ogc:Literal>
<ogc:Literal>30</ogc:Literal>
</ogc:Function>
<ogc:Function name="parameter">
<ogc:Literal>outputBBOX</ogc:Literal>
<ogc:Function name="env">
<ogc:Literal>wms_bbox</ogc:Literal>
</ogc:Function>
</ogc:Function>
<ogc:Function name="parameter">
<ogc:Literal>outputWidth</ogc:Literal>
<ogc:Function name="env">
<ogc:Literal>wms_width</ogc:Literal>
</ogc:Function>
</ogc:Function>
<ogc:Function name="parameter">
<ogc:Literal>outputHeight</ogc:Literal>
<ogc:Function name="env">
<ogc:Literal>wms_height</ogc:Literal>
</ogc:Function>
</ogc:Function>
</ogc:Function>
</Transformation>
<Rule>
<Name>rule1</Name>
<Title>Site</Title>
<ogc:Filter>
<ogc:PropertyIsLessThanOrEqualTo>
<ogc:PropertyName>count</ogc:PropertyName>
<ogc:Literal>1</ogc:Literal>
</ogc:PropertyIsLessThanOrEqualTo>
</ogc:Filter>
<PointSymbolizer>
<Graphic>
<Mark>
<WellKnownName>circle</WellKnownName>
<Fill>
<CssParameter name="fill">#FF0000</CssParameter>
</Fill>
</Mark>
<Size>8</Size>
</Graphic>
</PointSymbolizer>
</Rule>
<Rule>
<Name>rule29</Name>
<Title>2-9 Sites</Title>
<ogc:Filter>
<ogc:PropertyIsBetween>
<ogc:PropertyName>count</ogc:PropertyName>
<ogc:LowerBoundary>
<ogc:Literal>2</ogc:Literal>
</ogc:LowerBoundary>
<ogc:UpperBoundary>
<ogc:Literal>9</ogc:Literal>
</ogc:UpperBoundary>
</ogc:PropertyIsBetween>
</ogc:Filter>
<PointSymbolizer>
<Graphic>
<Mark>
<WellKnownName>circle</WellKnownName>
<Fill>
<CssParameter name="fill">#AA0000</CssParameter>
</Fill>
</Mark>
<Size>14</Size>
</Graphic>
</PointSymbolizer>
<TextSymbolizer>
<Label>
<ogc:PropertyName>count</ogc:PropertyName>
</Label>
<Font>
<CssParameter name="font-family">Arial</CssParameter>
<CssParameter name="font-size">12</CssParameter>
<CssParameter name="font-weight">bold</CssParameter>
</Font>
<LabelPlacement>
<PointPlacement>
<AnchorPoint>
<AnchorPointX>0.5</AnchorPointX>
<AnchorPointY>0.8</AnchorPointY>
</AnchorPoint>
</PointPlacement>
</LabelPlacement>
<Halo>
<Radius>2</Radius>
<Fill>
<CssParameter name="fill">#AA0000</CssParameter>
<CssParameter name="fill-opacity">0.9</CssParameter>
</Fill>
</Halo>
<Fill>
<CssParameter name="fill">#FFFFFF</CssParameter>
<CssParameter name="fill-opacity">1.0</CssParameter>
</Fill>
</TextSymbolizer>
</Rule>
<Rule>
<Name>rule10</Name>
<Title>10 Sites</Title>
<ogc:Filter>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>count</ogc:PropertyName>
<ogc:Literal>9</ogc:Literal>
</ogc:PropertyIsGreaterThan>
</ogc:Filter>
<PointSymbolizer>
<Graphic>
<Mark>
<WellKnownName>circle</WellKnownName>
<Fill>
<CssParameter name="fill">#AA0000</CssParameter>
</Fill>
</Mark>
<Size>22</Size>
</Graphic>
</PointSymbolizer>
<TextSymbolizer>
<Label>
<ogc:PropertyName>count</ogc:PropertyName>
</Label>
<Font>
<CssParameter name="font-family">Arial</CssParameter>
<CssParameter name="font-size">12</CssParameter>
<CssParameter name="font-weight">bold</CssParameter>
</Font>
<LabelPlacement>
<PointPlacement>
<AnchorPoint>
<AnchorPointX>0.5</AnchorPointX>
<AnchorPointY>0.8</AnchorPointY>
</AnchorPoint>
</PointPlacement>
</LabelPlacement>
<Halo>
<Radius>2</Radius>
<Fill>
<CssParameter name="fill">#AA0000</CssParameter>
<CssParameter name="fill-opacity">0.9</CssParameter>
</Fill>
</Halo>
<Fill>
<CssParameter name="fill">#FFFFFF</CssParameter>
<CssParameter name="fill-opacity">1.0</CssParameter>
</Fill>
</TextSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>

View File

@ -62,7 +62,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-bom</artifactId>
<version>2.0.0</version>
<version>2.0.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>

View File

@ -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> T makeCall(Call<GXWebTargetAdapterRequest, T> call) throws Exception{
protected <T> T makeCall(Call<GXWebTargetAdapterRequest, T> 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<GXWebTargetAdapterRequest, Object>() {
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> T post(String path,Entity<?> entity,Class<T> returnClazz) throws Exception {
protected <T> T post (String path,Entity<?> entity,Class<T> returnClazz,Map<String,?> queryParams) throws RemoteException,Exception{
return makeCall(new Call<GXWebTargetAdapterRequest, T>() {
public T call(GXWebTargetAdapterRequest endpoint) throws Exception {
return check(endpoint.path(path).post(entity),returnClazz);
Map<String,Object[]> actualMap=new HashMap<String, Object[]>();
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<String,?> 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));
}