diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs
index f897a7f..ff7698f 100644
--- a/.settings/org.eclipse.m2e.core.prefs
+++ b/.settings/org.eclipse.m2e.core.prefs
@@ -1,4 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
-resolveWorkspaceProjects=true
+resolveWorkspaceProjects=false
version=1
diff --git a/pom.xml b/pom.xml
index 5326b50..b69f85c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,9 +28,79 @@
org.gcube.core
- common-fw-clients
- [1.1.0-SNAPSHOT,1.2.0)
+ common-fw-clients
+
+
+ org.gcube.common
+ authorization-client
+
+
+ org.gcube.core
+ common-generic-clients
+
+
+
+ org.gcube.core
+ common-gcube-calls
+
+
+
+ org.gcube.common
+ common-jaxrs-client
+ [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)
+
+
+
+ org.gcube.core
+ common-generic-clients
+
+
+
+ org.gcube.spatial.data
+ sdi-interface
+ [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)
+
+
+
+
+ org.glassfish.jersey.core
+ jersey-client
+ 2.22.2
+
+
+
+ org.glassfish.jersey.media
+ jersey-media-json-jackson
+ 2.22.2
+
+
+
+ org.slf4j
+ slf4j-api
+
+
+
+
+
+ junit
+ junit
+ 4.10
+ test
+
+
+
+
+
+
+
+ ch.qos.logback
+ logback-classic
+ 1.0.13
+ test
+
+
+
\ No newline at end of file
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 9ac334d..0511889 100644
--- a/src/main/java/org/gcube/spatial/data/sdi/SDIClient.java
+++ b/src/main/java/org/gcube/spatial/data/sdi/SDIClient.java
@@ -1,14 +1,41 @@
package org.gcube.spatial.data.sdi;
+import java.io.File;
+import java.util.Set;
+
+import javax.ws.rs.client.WebTarget;
+
import org.gcube.common.clients.delegates.AsyncProxyDelegate;
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.TemplateDescriptor;
-public class SDIClient {
+public class SDIClient implements Metadata{
-// private final AsyncProxyDelegate delegate;
-//
-// public FHNManagerClient(ProxyDelegate config) {
-// this.delegate = new AsyncProxyDelegate(config);
-// }
+ @Override
+ public Set getAvailableTemplates() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public MetadataReport pushMetadata(File toPublish) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public MetadataReport pushMetadata(File toPublish, MetadataPublishOptions options) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ private final AsyncProxyDelegate delegate;
+
+ public SDIClient(ProxyDelegate config) {
+ this.delegate = new AsyncProxyDelegate(config);
+ }
}
diff --git a/src/main/java/org/gcube/spatial/data/sdi/TokenFilter.java b/src/main/java/org/gcube/spatial/data/sdi/TokenFilter.java
new file mode 100644
index 0000000..f2a05a8
--- /dev/null
+++ b/src/main/java/org/gcube/spatial/data/sdi/TokenFilter.java
@@ -0,0 +1,28 @@
+package org.gcube.spatial.data.sdi;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Map.Entry;
+
+import javax.ws.rs.client.ClientRequestContext;
+import javax.ws.rs.client.ClientRequestFilter;
+
+import org.gcube.common.calls.Call;
+import org.gcube.common.calls.Interceptors;
+import org.gcube.common.calls.Request;
+import org.gcube.spatial.data.sdi.utils.ScopeUtils;
+
+
+public class TokenFilter implements ClientRequestFilter {
+
+ @Override
+ public void filter(final ClientRequestContext rc) throws IOException {
+ if (ScopeUtils.getCurrentScope()!=null){
+ Request requestContext = Interceptors.executeRequestChain(new Call());
+
+ for (Entry entry: requestContext.getHeaders()){
+ rc.getHeaders().put(entry.getKey(), Collections.singletonList((Object)entry.getValue()));
+ }
+ }
+ }
+}
diff --git a/src/main/java/org/gcube/spatial/data/sdi/plugins/AbstractPlugin.java b/src/main/java/org/gcube/spatial/data/sdi/plugins/AbstractPlugin.java
new file mode 100644
index 0000000..16b3935
--- /dev/null
+++ b/src/main/java/org/gcube/spatial/data/sdi/plugins/AbstractPlugin.java
@@ -0,0 +1,62 @@
+package org.gcube.spatial.data.sdi.plugins;
+
+import javax.ws.rs.client.WebTarget;
+
+import org.gcube.common.clients.ProxyBuilder;
+import org.gcube.common.clients.ProxyBuilderImpl;
+import org.gcube.common.clients.Plugin;
+import org.gcube.spatial.data.sdi.interfaces.Metadata;
+import org.gcube.spatial.data.sdi.model.ServiceConstants;
+
+public abstract class AbstractPlugin implements Plugin{
+
+
+ private static final MetadataPlugin metadata_plugin=new MetadataPlugin();
+
+
+ public static ProxyBuilder manager() {
+ return new ProxyBuilderImpl(metadata_plugin);
+ }
+
+// public static ProxyBuilder classification() {
+// return new ProxyBuilderImpl(classification_plugin);
+// }
+//
+// public static ProxyBuilder occurrences() {
+// return new ProxyBuilderImpl(occurrence_plugin);
+// }
+//
+// public static ProxyBuilder executor() {
+// return new ProxyBuilderImpl(executor_plugin);
+// }
+//
+// public static ProxyBuilder resultset(String endpointId) {
+// LegacyQuery query = new LegacyQuery(resultset_plugin);
+// query.addCondition("$resource/ID/string() eq '"+endpointId+"'");
+// return new ProxyBuilderImpl(resultset_plugin, query);
+// }
+
+
+ public final String name;
+
+ public AbstractPlugin(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String serviceClass() {
+ return ServiceConstants.SERVICE_CLASS;
+ }
+ @Override
+ public String serviceName() {
+ return ServiceConstants.SERVICE_NAME;
+ }
+ @Override
+ public String name() {
+ return name;
+ }
+ @Override
+ public String namespace() {
+ return ServiceConstants.NAMESPACE;
+ }
+}
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
new file mode 100644
index 0000000..f195392
--- /dev/null
+++ b/src/main/java/org/gcube/spatial/data/sdi/plugins/MetadataPlugin.java
@@ -0,0 +1,43 @@
+package org.gcube.spatial.data.sdi.plugins;
+
+import javax.ws.rs.client.WebTarget;
+import javax.xml.namespace.QName;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.ws.EndpointReference;
+
+import org.gcube.common.calls.jaxrs.GcubeService;
+import org.gcube.common.calls.jaxrs.TargetFactory;
+import org.gcube.common.clients.config.ProxyConfig;
+import org.gcube.common.clients.delegates.ProxyDelegate;
+import org.gcube.spatial.data.sdi.interfaces.Metadata;
+import org.gcube.spatial.data.sdi.model.ServiceConstants;
+import org.gcube.spatial.data.sdi.proxies.DefaultMetadata;
+import org.w3c.dom.Node;
+
+public class MetadataPlugin extends AbstractPlugin{
+
+ public MetadataPlugin() {
+ super("sdi-service/gcube/service");
+ }
+
+ @Override
+ public Exception convert(Exception arg0, ProxyConfig, ?> arg1) {
+ return arg0;
+ }
+ @Override
+ public Metadata newProxy(ProxyDelegate arg0) {
+ return new DefaultMetadata(arg0);
+ }
+
+ @Override
+ public WebTarget resolve(EndpointReference epr, ProxyConfig, ?> arg1) throws Exception {
+ DOMResult result = new DOMResult();
+ epr.writeTo(result);
+ 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);
+ 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
new file mode 100644
index 0000000..104f22f
--- /dev/null
+++ b/src/main/java/org/gcube/spatial/data/sdi/proxies/DefaultMetadata.java
@@ -0,0 +1,57 @@
+package org.gcube.spatial.data.sdi.proxies;
+
+import java.io.File;
+import java.lang.reflect.GenericArrayType;
+import java.util.Set;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.gcube.common.clients.Call;
+import org.gcube.common.clients.delegates.ProxyDelegate;
+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.TemplateDescriptor;
+
+public class DefaultMetadata implements Metadata{
+
+ private final ProxyDelegate delegate;
+
+
+ public DefaultMetadata(ProxyDelegate config){
+ this.delegate = config;
+ }
+
+ @Override
+ public Set 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();
+ }
+ };
+ try {
+ return delegate.make(call);
+ }catch(Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public MetadataReport pushMetadata(File toPublish) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public MetadataReport pushMetadata(File toPublish, MetadataPublishOptions options) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/main/java/org/gcube/spatial/data/sdi/utils/ScopeUtils.java b/src/main/java/org/gcube/spatial/data/sdi/utils/ScopeUtils.java
new file mode 100644
index 0000000..860adff
--- /dev/null
+++ b/src/main/java/org/gcube/spatial/data/sdi/utils/ScopeUtils.java
@@ -0,0 +1,40 @@
+package org.gcube.spatial.data.sdi.utils;
+
+import org.gcube.common.authorization.library.AuthorizationEntry;
+import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
+import org.gcube.common.scope.api.ScopeProvider;
+
+import static org.gcube.common.authorization.client.Constants.authorizationService;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class ScopeUtils {
+
+ public static String getCurrentScope(){
+ try{
+ String token=SecurityTokenProvider.instance.get();
+ log.debug("Token is : "+token);
+ if(token==null) throw new Exception("Security Token is null");
+ AuthorizationEntry entry = authorizationService().get(token);
+ return entry.getContext();
+ }catch(Exception e ){
+ log.debug("Unable to resolve token, checking scope provider..",e);
+ return ScopeProvider.instance.get();
+ }
+ }
+
+
+ public static String getCurrentCaller(){
+ try{
+ String token=SecurityTokenProvider.instance.get();
+ log.debug("Token is : "+token);
+ if(token==null) throw new Exception("Security Token is null");
+ AuthorizationEntry entry = authorizationService().get(token);
+ return entry.getClientInfo().getId();
+ }catch(Exception e ){
+ log.debug("Unable to resolve token, checking scope provider..",e);
+ return "Unidentified data-transfer user";
+ }
+ }
+}
\ No newline at end of file