GN client basics
This commit is contained in:
parent
830f57ac1a
commit
78374efd95
|
@ -2,5 +2,5 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||||
|
|
||||||
# Changelog for org.gcube.spatial.data.gcube-geonetwork-client
|
# Changelog for org.gcube.spatial.data.gcube-geonetwork-client
|
||||||
|
|
||||||
## [v0.0.1-SNAPSHOT] - 2021-2-11
|
## [v1.0.0-SNAPSHOT] - 2021-2-11
|
||||||
First release
|
First release
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>gcube-geonetwork-client</artifactId>
|
<artifactId>gcube-geonetwork-client</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<name>gCube GeoNetwork Client</name>
|
<name>gCube GeoNetwork Client</name>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package org.gcube.spatial.data.clients.geonetwork;
|
||||||
|
|
||||||
|
import org.gcube.spatial.data.clients.AbstractGenericRESTClient;
|
||||||
|
import org.gcube.spatial.data.clients.model.ConnectionDescriptor;
|
||||||
|
|
||||||
|
public class GNRESTClientImpl extends AbstractGenericRESTClient implements GNRESTInterface {
|
||||||
|
|
||||||
|
private static final String API_BASE_PATH="rest";
|
||||||
|
|
||||||
|
public GNRESTClientImpl(ConnectionDescriptor conn) {
|
||||||
|
super(conn);
|
||||||
|
setBasePath(API_BASE_PATH);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package org.gcube.spatial.data.clients.geonetwork;
|
||||||
|
|
||||||
|
import org.gcube.spatial.data.clients.GenericLoginClient;
|
||||||
|
|
||||||
|
public interface GNRESTInterface extends GenericLoginClient{
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package org.gcube.spatial.data.clients.geonetwork;
|
||||||
|
|
||||||
|
import org.gcube.spatial.data.clients.AbstractGenericClient;
|
||||||
|
import org.gcube.spatial.data.clients.SDIGenericPlugin;
|
||||||
|
import org.gcube.spatial.data.clients.model.ClientInfo;
|
||||||
|
import org.gcube.spatial.data.clients.model.engine.Engine;
|
||||||
|
import org.gcube.spatial.data.clients.model.engine.Range;
|
||||||
|
|
||||||
|
public class GeoNetworkPlugin extends AbstractGenericClient implements SDIGenericPlugin{
|
||||||
|
|
||||||
|
public GeoNetworkPlugin() {
|
||||||
|
super(GNRESTClientImpl.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClientInfo getInfo() {
|
||||||
|
return new ClientInfo("gn-rest", "GeoNetwork REST", "GeoNetwork REST client", "come class",
|
||||||
|
new Engine(Engine.GN_ENGINE, "Default GeoNetworkVersion", new Range("2.0.0", null)));
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,16 +6,16 @@ import org.gcube.spatial.data.clients.model.ClientInfo;
|
||||||
import org.gcube.spatial.data.clients.model.engine.Engine;
|
import org.gcube.spatial.data.clients.model.engine.Engine;
|
||||||
import org.gcube.spatial.data.clients.model.engine.Range;
|
import org.gcube.spatial.data.clients.model.engine.Range;
|
||||||
|
|
||||||
public class GeoServerClient extends AbstractGenericClient implements SDIGenericPlugin{
|
public class GeoServerPlugin extends AbstractGenericClient implements SDIGenericPlugin{
|
||||||
|
|
||||||
|
|
||||||
public GeoServerClient() {
|
public GeoServerPlugin() {
|
||||||
super(GSRESTClientImpl.class);
|
super(GSRESTClientImpl.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClientInfo getInfo() {
|
public ClientInfo getInfo() {
|
||||||
return new ClientInfo("gs-rest", "GeoServer REST", "GeoServer REST client", "come class",
|
return new ClientInfo("gs-rest", "GeoServer REST", "GeoServer REST client", GSRESTClientImpl.class.getCanonicalName(),
|
||||||
new Engine(Engine.GS_ENGINE, "Default GeoServerVersion", new Range("2.0.0", null)));
|
new Engine(Engine.GS_ENGINE, "Default GeoServerVersion", new Range("2.0.0", null)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
org.gcube.spatial.data.clients.geoserver.GeoServerClient
|
|
|
@ -0,0 +1 @@
|
||||||
|
org.gcube.spatial.data.clients.geoserver.GeoServerPlugin
|
|
@ -1,8 +1,10 @@
|
||||||
package org.gcube.spatial.data.clients.geoserver;
|
package org.gcube.spatial.data.clients.geoserver;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assume.assumeTrue;
|
import static org.junit.Assume.assumeTrue;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -13,6 +15,7 @@ import org.gcube.sdi.test.GCubeSDITest;
|
||||||
import org.gcube.spatial.data.clients.SDIGenericPlugin;
|
import org.gcube.spatial.data.clients.SDIGenericPlugin;
|
||||||
import org.gcube.spatial.data.clients.model.engine.Engine;
|
import org.gcube.spatial.data.clients.model.engine.Engine;
|
||||||
import org.gcube.spatial.data.sdi.model.faults.RemoteException;
|
import org.gcube.spatial.data.sdi.model.faults.RemoteException;
|
||||||
|
import org.gcube.spatial.data.sdi.utils.Files;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -21,7 +24,7 @@ public class GSTests extends GCubeSDITest{
|
||||||
|
|
||||||
protected GSRESTClient getClient() throws RemoteException, Exception {
|
protected GSRESTClient getClient() throws RemoteException, Exception {
|
||||||
SDIGenericPlugin obj=manager().getClientByEngineId(Engine.GS_ENGINE);
|
SDIGenericPlugin obj=manager().getClientByEngineId(Engine.GS_ENGINE);
|
||||||
assertTrue(obj.getClass().isAssignableFrom(GeoServerClient.class));
|
assertTrue(obj.getClass().isAssignableFrom(GeoServerPlugin.class));
|
||||||
return (GSRESTClient) obj.getRESTClient();
|
return (GSRESTClient) obj.getRESTClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +32,8 @@ public class GSTests extends GCubeSDITest{
|
||||||
public void basics() throws RemoteException, Exception {
|
public void basics() throws RemoteException, Exception {
|
||||||
assumeTrue(isTestInfrastructureEnabled());
|
assumeTrue(isTestInfrastructureEnabled());
|
||||||
GSRESTClient client=getClient();
|
GSRESTClient client=getClient();
|
||||||
assertTrue(client.exist());
|
assertTrue(client.exist());
|
||||||
|
client.authenticate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -101,33 +105,29 @@ public class GSTests extends GCubeSDITest{
|
||||||
client.createWorkspace(ws);
|
client.createWorkspace(ws);
|
||||||
client.getWorkspace(ws);
|
client.getWorkspace(ws);
|
||||||
|
|
||||||
|
// DS
|
||||||
|
// String myDS=UUID.randomUUID().toString().replace("-", "_");
|
||||||
|
//
|
||||||
|
// HashMap<String,String> parameters=new HashMap<String, String>();
|
||||||
|
//
|
||||||
|
//// parameters.put("dbtype","gpkg");
|
||||||
|
// parameters.put("url","gpkg");
|
||||||
|
//
|
||||||
|
//// client.publishDataStore(ws,
|
||||||
|
//// new DataStoreRegistrationRequest(myDS,parameters).getDatastore());
|
||||||
|
//
|
||||||
|
// client.deleteWorkspace(ws,true);
|
||||||
|
|
||||||
String myDS=UUID.randomUUID().toString().replace("-", "_");
|
|
||||||
|
|
||||||
HashMap<String,String> parameters=new HashMap<String, String>();
|
// SLD
|
||||||
|
String myStyle=UUID.randomUUID().toString().replace("-", "_");
|
||||||
|
client.createStyle(myStyle, Files.readFileAsString("clustered_points.sld", Charset.defaultCharset()));
|
||||||
|
assertTrue("SLD registered ",client.getStylesNames().contains(myStyle));
|
||||||
|
client.deleteStyle(myStyle, true, true);
|
||||||
|
assertFalse("SLD Removed",client.getStylesNames().contains(myStyle));
|
||||||
|
|
||||||
// parameters.put("dbtype","gpkg");
|
|
||||||
parameters.put("url","gpkg");
|
|
||||||
|
|
||||||
client.publishDataStore(ws,
|
|
||||||
new DataStoreRegistrationRequest(myDS,parameters).getDatastore());
|
|
||||||
|
|
||||||
client.deleteWorkspace(ws,true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
|
||||||
// public void crudGPKG() throws RemoteException, Exception {
|
|
||||||
// assumeTrue(isTestInfrastructureEnabled());
|
|
||||||
// GSRESTClient client=getClient();
|
|
||||||
//
|
|
||||||
// client.authenticate();
|
|
||||||
// String ws=UUID.randomUUID().toString().replace("-", "_");
|
|
||||||
// client.createWorkspace(ws);
|
|
||||||
//
|
|
||||||
//String myDS=UUID.randomUUID().toString().replace("-", "_");
|
|
||||||
//
|
|
||||||
// client.publishDataStore(ws, new DataStoreRegistrationRequest(myDS).getDatastore());
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,8 +63,8 @@ public abstract class AbstractGenericRESTClient implements GenericLoginClient{
|
||||||
log.warn("Unable to check instance "+conn,e);
|
log.warn("Unable to check instance "+conn,e);
|
||||||
return false;
|
return false;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("Unable to check instance "+conn,e);
|
log.info("Server replied with error. Ignore this if it requires authentication. "+conn,e);
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
package org.gcube.spatial.data.sdi.utils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
|
||||||
|
public class Files {
|
||||||
|
|
||||||
|
public static File getFileFromResources(String fileName) {
|
||||||
|
|
||||||
|
ClassLoader classLoader =Files.class.getClassLoader();
|
||||||
|
|
||||||
|
URL resource = classLoader.getResource(fileName);
|
||||||
|
if (resource == null) {
|
||||||
|
throw new IllegalArgumentException("file is not found!");
|
||||||
|
} else {
|
||||||
|
return new File(resource.getFile());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String readFileAsString(String path, Charset encoding)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
byte[] encoded = java.nio.file.Files.readAllBytes(Paths.get(path));
|
||||||
|
return new String(encoded, encoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String getName(String path) {
|
||||||
|
|
||||||
|
return path.substring((path.contains(File.separator)?path.lastIndexOf(File.separator)+1:0)
|
||||||
|
,(path.contains(".")?path.lastIndexOf("."):path.length()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String fixFilename(String toFix) {
|
||||||
|
if(toFix.contains(".")) {
|
||||||
|
String prefix=toFix.substring(toFix.lastIndexOf("."));
|
||||||
|
toFix=toFix.substring(0,toFix.lastIndexOf("."));
|
||||||
|
return toFix.toLowerCase().replaceAll("[\\*\\+\\/\\\\ \\[\\]\\(\\)\\.\\\"\\:\\;\\|]","_")+prefix;
|
||||||
|
}
|
||||||
|
return toFix.toLowerCase().replaceAll("[\\*\\+\\/\\\\ \\[\\]\\(\\)\\.\\\"\\:\\;\\|]","_");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue