This commit is contained in:
Fabio Sinibaldi 2021-02-16 18:03:10 +01:00
parent c85122a5a3
commit 1046b1ac4a
12 changed files with 224 additions and 24 deletions

View File

@ -6,16 +6,15 @@
<groupId>org.gcube.spatial.data</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>org.gcube.spatial.data</groupId>
<artifactId>gcube-geonetwork-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>gCube GeoNetwork Client</name>
<scm>
<connection>scm:git:${gitBaseUrl}/gFeed</connection>
<developerConnection>scm:git:${gitBaseUrl}/gFeed</developerConnection>
<url>${gitBaseUrl}/gFeed</url>
<connection>scm:git:${gitBaseUrl}/gcube-sdi-suite</connection>
<developerConnection>scm:git:${gitBaseUrl}/gcube-sdi-suite</developerConnection>
<url>${gitBaseUrl}/gcube-sdi-suite</url>
</scm>

View File

@ -6,21 +6,35 @@
<groupId>org.gcube.spatial.data</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>org.gcube.spatial.data</groupId>
<artifactId>gcube-geoserver-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Gcube GeoServer client</name>
<scm>
<connection>scm:git:${gitBaseUrl}/gFeed</connection>
<developerConnection>scm:git:${gitBaseUrl}/gFeed</developerConnection>
<url>${gitBaseUrl}/gFeed</url>
<connection>scm:git:${gitBaseUrl}/gcube-sdi-suite</connection>
<developerConnection>scm:git:${gitBaseUrl}/gcube-sdi-suite</developerConnection>
<url>${gitBaseUrl}/gcube-sdi-suite</url>
</scm>
<dependencies>
<dependency>
<artifactId>sdi-interface</artifactId>
<groupId>org.gcube.spatial.data</groupId>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
</dependency>
<!-- read JSON -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
</dependency>
</dependencies>

View File

@ -0,0 +1,28 @@
package org.gcube.spatial.data.clients.geoserver;
import java.util.List;
public interface GSRESTClient {
// ********** READ OPS
// WS
public List<String> getWorkspaces();
// DS
public List<String> getDataStoresInWorkspace(String ws);
// SLD
public List<String> getStyles();
public List<String> getStylesInWorkspace(String ws);
public List<String> getStylesByLayer(String layer);
// *********** CREATE OPS
public void createWorkspace(String ws);
public void createStyle(String name,String content);
}

View File

@ -0,0 +1,22 @@
package org.gcube.spatial.data.clients.geoserver;
import java.util.List;
import org.gcube.spatial.data.clients.GenericLoginClient;
import org.gcube.spatial.data.clients.model.ConnectionDescriptor;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor;
public class GSRESTClientImpl implements GSRESTClient,GenericLoginClient{
private ConnectionDescriptor conn;
WebTarget target=
public GSRESTClientImpl(ConnectionDescriptor desc) {
this.conn=desc;
}
}

View File

@ -0,0 +1,22 @@
package org.gcube.spatial.data.clients.geoserver;
import org.gcube.spatial.data.clients.SDIGenericClient;
import org.gcube.spatial.data.clients.model.ClientInfo;
import org.gcube.spatial.data.clients.model.ConnectionDescriptor;
public class GeoServerClient implements SDIGenericClient{
@Override
public ClientInfo getInfo() {
// TODO Auto-generated method stub
return null;
}
@Override
public Object getRESTClient(ConnectionDescriptor conn) {
return new GSRESTClientImpl(conn);
}
}

View File

@ -11,15 +11,34 @@
<name>Generic SDI Client</name>
<scm>
<connection>scm:git:${gitBaseUrl}/gFeed</connection>
<developerConnection>scm:git:${gitBaseUrl}/gFeed</developerConnection>
<url>${gitBaseUrl}/gFeed</url>
<scm>
<connection>scm:git:${gitBaseUrl}/gcube-sdi-suite</connection>
<developerConnection>scm:git:${gitBaseUrl}/gcube-sdi-suite</developerConnection>
<url>${gitBaseUrl}/gcube-sdi-suite</url>
</scm>
<dependencies>
<dependency>
<artifactId>sdi-interface</artifactId>
<groupId>org.gcube.spatial.data</groupId>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
</dependency>
<!-- read JSON -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
</dependency>
</dependencies>

View File

@ -1,12 +1,76 @@
package org.gcube.spatial.data.clients;
import java.io.IOException;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;
import org.glassfish.jersey.client.ClientProperties;
import org.gcube.spatial.data.clients.model.ConnectionDescriptor;
import org.gcube.spatial.data.sdi.model.faults.RemoteException;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public abstract class AbstractGenericClient {
private static ObjectMapper mapper = new ObjectMapper();
static {
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS,false);
mapper.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false);
mapper.setSerializationInclusion(Include.NON_NULL);
}
protected ConnectionDescriptor conn;
protected Client client;
public AbstractGenericClient(ConnectionDescriptor conn) {
}
private synchronized Client getWebClient() {
if(client==null) {
client = ClientBuilder.newClient()
.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
// client.register(MultiPartFeature.class);
}
return client;
}
protected static <T> T check(Response resp, Class<T> clazz) throws RemoteException{
if(resp.getStatus()<200||resp.getStatus()>=300) {
String remoteMessage=resp.readEntity(String.class);
Integer httpCode=resp.getStatus();
RemoteException e=new RemoteException("RESP STATUS IS "+httpCode+". Message : "+remoteMessage);
e.setRemoteMessage(remoteMessage);
e.setResponseHTTPCode(httpCode);
throw e;
}else {
if(clazz==null) return null;
String respString=resp.readEntity(String.class);
try {
return mapper.readValue(respString, clazz);
} catch (IOException e) {
throw new RemoteException("Unable to parse response from Zenodo. Content was : \n "+respString,e);
}
}
}
}

View File

@ -19,10 +19,10 @@
</properties>
<scm>
<connection>scm:git:${gitBaseUrl}/${project.artifactId}.git</connection>
<developerConnection>scm:git:${gitBaseUrl}/${project.artifactId}.git</developerConnection>
<url>${gitBaseUrl}/${project.artifactId}.git</url>
<scm>
<connection>scm:git:${gitBaseUrl}/gcube-sdi-suite</connection>
<developerConnection>scm:git:${gitBaseUrl}/gcube-sdi-suite</developerConnection>
<url>${gitBaseUrl}/gcube-sdi-suite</url>
</scm>

View File

@ -0,0 +1,12 @@
package org.gcube.spatial.data.clients;
import org.gcube.spatial.data.sdi.model.gn.LoginLevel;
public interface GenericLoginClient {
public void login();
public void login(LoginLevel lvl);
}

View File

@ -31,4 +31,24 @@ public class RemoteException extends Exception {
// TODO Auto-generated constructor stub
}
private String remoteMessage=null;
private Integer responseHTTPCode=0;
public void setResponseHTTPCode(Integer responseHTTPCode) {
this.responseHTTPCode = responseHTTPCode;
}
public Integer getResponseHTTPCode() {
return responseHTTPCode;
}
public String getRemoteMessage() {
return remoteMessage;
}
public void setRemoteMessage(String remoteMessage) {
this.remoteMessage = remoteMessage;
}
}

View File

@ -11,9 +11,9 @@
<description>Client library to interact with gCube SDI Service</description>
<scm>
<connection>scm:git:${gitBaseUrl}/gFeed</connection>
<developerConnection>scm:git:${gitBaseUrl}/gFeed</developerConnection>
<url>${gitBaseUrl}/gFeed</url>
<connection>scm:git:${gitBaseUrl}/gcube-sdi-suite</connection>
<developerConnection>scm:git:${gitBaseUrl}/gcube-sdi-suite</developerConnection>
<url>${gitBaseUrl}/gcube-sdi-suite</url>
</scm>
<dependencies>

View File

@ -14,9 +14,9 @@
<jersey.version>2.25.1</jersey.version>
</properties>
<scm>
<connection>scm:git:${gitBaseUrl}/gFeed</connection>
<developerConnection>scm:git:${gitBaseUrl}/gFeed</developerConnection>
<url>${gitBaseUrl}/gFeed</url>
<connection>scm:git:${gitBaseUrl}/gcube-sdi-suite</connection>
<developerConnection>scm:git:${gitBaseUrl}/gcube-sdi-suite</developerConnection>
<url>${gitBaseUrl}/gcube-sdi-suite</url>
</scm>
<dependencyManagement>
<dependencies>