diff --git a/pom.xml b/pom.xml
index 6376b9e..5275dbd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,11 +3,11 @@
org.gcube.tools
maven-parent
- LATEST
+ 1.1.0-SNAPSHOT
org.gcube.spatial.data
sdi-library
- 1.0.0-SNAPSHOT
+ 1.1.2-SNAPSHOT
SDI Library
Client library to interact with gCube SDI Service
@@ -66,15 +66,21 @@
org.glassfish.jersey.core
jersey-client
- 2.22.2
+ 2.24.1
org.glassfish.jersey.media
jersey-media-json-jackson
- 2.22.2
+ 2.24.1
+
+ org.glassfish.jersey.media
+ jersey-media-multipart
+ 2.24.1
+
+
org.slf4j
slf4j-api
diff --git a/src/main/java/org/gcube/spatial/data/sdi/SDIClient.java b/src/main/java/org/gcube/spatial/data/sdi/SDIClient.java
index 0511889..922e377 100644
--- a/src/main/java/org/gcube/spatial/data/sdi/SDIClient.java
+++ b/src/main/java/org/gcube/spatial/data/sdi/SDIClient.java
@@ -10,15 +10,16 @@ import org.gcube.common.clients.delegates.ProxyDelegate;
import org.gcube.spatial.data.sdi.interfaces.Metadata;
import org.gcube.spatial.data.sdi.model.metadata.MetadataPublishOptions;
import org.gcube.spatial.data.sdi.model.metadata.MetadataReport;
+import org.gcube.spatial.data.sdi.model.metadata.TemplateCollection;
import org.gcube.spatial.data.sdi.model.metadata.TemplateDescriptor;
public class SDIClient implements Metadata{
- @Override
- public Set getAvailableTemplates() {
- // TODO Auto-generated method stub
- return null;
- }
+// @Override
+// public Set getAvailableTemplates() {
+// // TODO Auto-generated method stub
+// return null;
+// }
@Override
public MetadataReport pushMetadata(File toPublish) {
@@ -38,4 +39,10 @@ public class SDIClient implements Metadata{
this.delegate = new AsyncProxyDelegate(config);
}
+
+ @Override
+ public TemplateCollection getAvailableTemplates() {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
diff --git a/src/main/java/org/gcube/spatial/data/sdi/plugins/MetadataPlugin.java b/src/main/java/org/gcube/spatial/data/sdi/plugins/MetadataPlugin.java
index 2513f99..b8a40ac 100644
--- a/src/main/java/org/gcube/spatial/data/sdi/plugins/MetadataPlugin.java
+++ b/src/main/java/org/gcube/spatial/data/sdi/plugins/MetadataPlugin.java
@@ -36,7 +36,9 @@ public class MetadataPlugin extends SDIAbstractPlugin{
Node node =result.getNode();
Node child=node.getFirstChild();
String address = child.getTextContent();
- GcubeService service = GcubeService.service().withName(new QName(ServiceConstants.NAMESPACE,ServiceConstants.Metadata.INTERFACE)).andPath(ServiceConstants.Metadata.INTERFACE);
+ GcubeService service = GcubeService.service().
+ withName(new QName(ServiceConstants.NAMESPACE,ServiceConstants.Metadata.INTERFACE)).
+ andPath(ServiceConstants.Metadata.INTERFACE);
return TargetFactory.stubFor(service).at(address);
}
diff --git a/src/main/java/org/gcube/spatial/data/sdi/proxies/DefaultMetadata.java b/src/main/java/org/gcube/spatial/data/sdi/proxies/DefaultMetadata.java
index 104f22f..7360323 100644
--- a/src/main/java/org/gcube/spatial/data/sdi/proxies/DefaultMetadata.java
+++ b/src/main/java/org/gcube/spatial/data/sdi/proxies/DefaultMetadata.java
@@ -1,9 +1,10 @@
package org.gcube.spatial.data.sdi.proxies;
import java.io.File;
-import java.lang.reflect.GenericArrayType;
+import java.util.HashSet;
import java.util.Set;
+import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
@@ -15,43 +16,130 @@ import org.gcube.spatial.data.sdi.interfaces.Metadata;
import org.gcube.spatial.data.sdi.model.ServiceConstants;
import org.gcube.spatial.data.sdi.model.metadata.MetadataPublishOptions;
import org.gcube.spatial.data.sdi.model.metadata.MetadataReport;
-import org.gcube.spatial.data.sdi.model.metadata.SetWrapper;
+import org.gcube.spatial.data.sdi.model.metadata.TemplateCollection;
import org.gcube.spatial.data.sdi.model.metadata.TemplateDescriptor;
+import org.gcube.spatial.data.sdi.model.metadata.TemplateInvocation;
+import org.glassfish.jersey.media.multipart.FormDataMultiPart;
+import org.glassfish.jersey.media.multipart.MultiPartFeature;
+import org.glassfish.jersey.media.multipart.file.FileDataBodyPart;
public class DefaultMetadata implements Metadata{
private final ProxyDelegate delegate;
-
+
public DefaultMetadata(ProxyDelegate config){
this.delegate = config;
}
+
+
@Override
- public Set getAvailableTemplates() {
+ public TemplateCollection getAvailableTemplates() {
Call> call = new Call>() {
@Override
public Set call(WebTarget templates) throws Exception {
- return templates.path(ServiceConstants.Metadata.LIST_METHOD).request(MediaType.APPLICATION_JSON).get(SetWrapper.class).getSet();
+ GenericType> generic=new GenericType>() {
+ };
+ return templates.path(ServiceConstants.Metadata.LIST_METHOD).request(MediaType.APPLICATION_JSON).get(generic);
}
};
try {
- return delegate.make(call);
+ return new TemplateCollection(new HashSet(delegate.make(call)));
}catch(Exception e) {
throw new RuntimeException(e);
}
}
-
+
@Override
public MetadataReport pushMetadata(File toPublish) {
- // TODO Auto-generated method stub
- return null;
+ return pushMetadata(toPublish, new MetadataPublishOptions());
}
-
+
@Override
- public MetadataReport pushMetadata(File toPublish, MetadataPublishOptions options) {
- // TODO Auto-generated method stub
- return null;
+ public MetadataReport pushMetadata(final File toPublish, final MetadataPublishOptions options) {
+ // upload Meta
+
+ Call applyTemplatesCall=null; //needs uploaded id
+ Call publishCall=null; //needs uploaded id
+
+ try{
+ Call uploadCall=new Call() {
+
+ @Override
+ public String call(WebTarget endpoint) throws Exception {
+ endpoint.register(MultiPartFeature.class);
+ FormDataMultiPart multi=new FormDataMultiPart();
+// multi.field("file",toPublish,MediaType.APPLICATION_OCTET_STREAM_TYPE);
+ FileDataBodyPart fileDataBodyPart = new FileDataBodyPart(ServiceConstants.Metadata.UPLOADED_FILE_PARAMETER,
+ toPublish,MediaType.APPLICATION_OCTET_STREAM_TYPE);
+ multi.bodyPart(fileDataBodyPart);
+ Response resp= endpoint.request().post(Entity.entity(multi, multi.getMediaType()));
+ checkResponse(resp);
+ return resp.readEntity(String.class);
+ }
+ };
+
+
+ final String id=delegate.make(uploadCall);
+
+ applyTemplatesCall=new Call() {
+ @Override
+ public MetadataReport call(WebTarget endpoint) throws Exception {
+
+
+ Response resp= endpoint.path(id).
+ request(MediaType.APPLICATION_JSON).put(Entity.entity(
+ new HashSet(options.getTemplateInvocations()),MediaType.APPLICATION_JSON));
+ checkResponse(resp);
+ return resp.readEntity(MetadataReport.class);
+ }
+ };
+
+ publishCall=new Call(){
+ @Override
+ public MetadataReport call(WebTarget endpoint) throws Exception {
+ Response resp= endpoint.path(ServiceConstants.Metadata.PUBLISH_METHOD).path(id).path(options.getGeonetworkCategory()).
+ queryParam(ServiceConstants.Metadata.VALIDATE_PARAMETER, options.isValidate()).
+ queryParam(ServiceConstants.Metadata.PUBLIC_PARAMETER, options.isMakePublic()).
+ queryParam(ServiceConstants.Metadata.STYLESHEET_PARAMETER, options.getGeonetworkStyleSheet()).
+ request(MediaType.APPLICATION_JSON).get();
+ checkResponse(resp);
+ return resp.readEntity(MetadataReport.class);
+ }
+ };
+ }catch(Throwable t){
+ throw new RuntimeException("Unable to upload file.",t);
+ }
+
+
+ //APPLY TEMPLATES
+ MetadataReport templateReport =null;
+ try{
+ if(!options.getTemplateInvocations().isEmpty())
+ templateReport=delegate.make(applyTemplatesCall);
+ }catch(Throwable t){
+ throw new RuntimeException("Unable to apply templates",t);
+ }
+
+ //PUBLISH
+
+
+ try{
+ MetadataReport publishReport=delegate.make(publishCall);
+ if(templateReport!=null) publishReport.setAppliedTemplates(templateReport.getAppliedTemplates());
+ return publishReport;
+ }catch(Throwable t){
+ throw new RuntimeException("Unable to publish metadata. ",t);
+ }
+
}
+
+ protected void checkResponse(Response toCheck) throws Exception{
+ switch(toCheck.getStatusInfo().getFamily()){
+ case SUCCESSFUL : break;
+ default : throw new Exception("Unexpected Response code : "+toCheck.getStatus(),new Exception(toCheck.readEntity(String.class)));
+ }
+ }
}
diff --git a/src/test/java/org/gcube/spatial/data/sdi/MetadataTests.java b/src/test/java/org/gcube/spatial/data/sdi/MetadataTests.java
index 3d34156..5537789 100644
--- a/src/test/java/org/gcube/spatial/data/sdi/MetadataTests.java
+++ b/src/test/java/org/gcube/spatial/data/sdi/MetadataTests.java
@@ -1,16 +1,46 @@
package org.gcube.spatial.data.sdi;
-import org.gcube.spatial.data.sdi.interfaces.*;
+import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Paths;
+
+import org.gcube.spatial.data.sdi.interfaces.Metadata;
+import org.gcube.spatial.data.sdi.model.metadata.MetadataPublishOptions;
+import org.gcube.spatial.data.sdi.model.metadata.TemplateInvocationBuilder;
import org.gcube.spatial.data.sdi.plugins.SDIAbstractPlugin;
+import org.junit.Before;
import org.junit.Test;
public class MetadataTests {
- @Test
- public void getAvailableTemplatesTest(){
+ @Before
+ public void setScope(){
+// TokenSetter.set("/pred4s/preprod/preVRE");
TokenSetter.set("/gcube/devsec/devVRE");
- Metadata meta=SDIAbstractPlugin.metadata().build();
- System.out.println(meta.getAvailableTemplates());
}
+ @Test
+ public void getAvailableTemplatesTest() throws IllegalArgumentException, URISyntaxException{
+
+ Metadata meta=SDIAbstractPlugin.metadata().at(new URI("http://sdi-d-d4s.d4science.org/sdi-service/gcube/service")).build();
+ System.out.println(meta.getAvailableTemplates());
+ }
+
+
+ @Test
+ public void pushMetadata() throws IllegalArgumentException, URISyntaxException{
+ File toPubilsh=Paths.get("src/test/resources/toEnrichMeta.xml").toFile();
+
+ Metadata meta=SDIAbstractPlugin.metadata().at(new URI("http://sdi-d-d4s.d4science.org/sdi-service/gcube/service")).build();
+ System.out.println(meta.pushMetadata(toPubilsh));
+
+ MetadataPublishOptions opts=new MetadataPublishOptions(new TemplateInvocationBuilder().threddsOnlineResources("my_hostname", "some_dataset.nc", "myPersonalCatalog").get());
+ opts.setGeonetworkCategory("service");
+ opts.setValidate(false);
+ System.out.println(meta.pushMetadata(toPubilsh, opts));
+ }
+
+
+
}
diff --git a/src/test/java/org/gcube/spatial/data/sdi/utils/RegisterGN.java b/src/test/java/org/gcube/spatial/data/sdi/utils/RegisterGN.java
new file mode 100644
index 0000000..32d054b
--- /dev/null
+++ b/src/test/java/org/gcube/spatial/data/sdi/utils/RegisterGN.java
@@ -0,0 +1,10 @@
+package org.gcube.spatial.data.sdi.utils;
+
+public class RegisterGN {
+
+ public static void main(String[] args) {
+ // Get definition
+ // push to service
+ }
+
+}
diff --git a/src/test/resources/toEnrichMeta.xml b/src/test/resources/toEnrichMeta.xml
new file mode 100644
index 0000000..0554337
--- /dev/null
+++ b/src/test/resources/toEnrichMeta.xml
@@ -0,0 +1,119 @@
+
+
+
+ Dataset
+
+
+
+
+ CNR
+
+
+ Point of contact
+
+
+
+
+ Geographic Information — Metadata Part 1: Fundamentals
+
+
+ ISO 19115-1:2014(E)
+
+
+
+
+ 4
+
+
+
+
+ 721
+
+
+
+
+
+
+ 361
+
+
+
+
+
+
+ 11
+
+
+
+
+
+
+ 1
+
+
+
+
+ Area
+
+
+ false
+
+
+
+
+
+
+
+
+ NetCDF of ARGO data aggregated at .25 degrees - produced by D4Science through the DataMiner platform
+
+
+
+
+ CNR
+
+
+ Originator
+
+
+
+
+ Paolo Scarponi - scarponi@isti.cnr.it; Gianpaolo Coro - coro@isti.cnr.it
+
+
+
+
+
+
+ CNR
+
+
+ Point of contact
+
+
+
+
+
+
+
+
+
+
+
+
+ Backscattering
+
+
+
+
+ double[721][361][11][1]
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file