git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/spatial-data/sdi-library@150709 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
aa9000fbc7
commit
0c0a9586db
|
@ -1,4 +1,4 @@
|
|||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
resolveWorkspaceProjects=false
|
||||
version=1
|
||||
|
|
74
pom.xml
74
pom.xml
|
@ -28,9 +28,79 @@
|
|||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-fw-clients</artifactId>
|
||||
<version>[1.1.0-SNAPSHOT,1.2.0)</version>
|
||||
<artifactId>common-fw-clients</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-generic-clients</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-gcube-calls</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>common-jaxrs-client</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-generic-clients</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.spatial.data</groupId>
|
||||
<artifactId>sdi-interface</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<!-- JERSEY -->
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.core</groupId>
|
||||
<artifactId>jersey-client</artifactId>
|
||||
<version>2.22.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-json-jackson</artifactId>
|
||||
<version>2.22.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- TEST -->
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.10</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- Test log binding -->
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.0.13</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
|
@ -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<WebTarget> delegate;
|
||||
//
|
||||
// public FHNManagerClient(ProxyDelegate<WebTarget> config) {
|
||||
// this.delegate = new AsyncProxyDelegate<WebTarget>(config);
|
||||
// }
|
||||
@Override
|
||||
public Set<TemplateDescriptor> 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<WebTarget> delegate;
|
||||
|
||||
public SDIClient(ProxyDelegate<WebTarget> config) {
|
||||
this.delegate = new AsyncProxyDelegate<WebTarget>(config);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<String, String> entry: requestContext.getHeaders()){
|
||||
rc.getHeaders().put(entry.getKey(), Collections.singletonList((Object)entry.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<S, P> implements Plugin<S, P>{
|
||||
|
||||
|
||||
private static final MetadataPlugin metadata_plugin=new MetadataPlugin();
|
||||
|
||||
|
||||
public static ProxyBuilder<Metadata> manager() {
|
||||
return new ProxyBuilderImpl<WebTarget,Metadata>(metadata_plugin);
|
||||
}
|
||||
|
||||
// public static ProxyBuilder<ClassificationClient> classification() {
|
||||
// return new ProxyBuilderImpl<WebTarget,ClassificationClient>(classification_plugin);
|
||||
// }
|
||||
//
|
||||
// public static ProxyBuilder<OccurrenceClient> occurrences() {
|
||||
// return new ProxyBuilderImpl<WebTarget,OccurrenceClient>(occurrence_plugin);
|
||||
// }
|
||||
//
|
||||
// public static ProxyBuilder<ExecutorClient> executor() {
|
||||
// return new ProxyBuilderImpl<WebTarget,ExecutorClient>(executor_plugin);
|
||||
// }
|
||||
//
|
||||
// public static ProxyBuilder<ResultSetClient> resultset(String endpointId) {
|
||||
// LegacyQuery query = new LegacyQuery(resultset_plugin);
|
||||
// query.addCondition("$resource/ID/string() eq '"+endpointId+"'");
|
||||
// return new ProxyBuilderImpl<WebTarget,ResultSetClient>(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;
|
||||
}
|
||||
}
|
|
@ -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<WebTarget, Metadata>{
|
||||
|
||||
public MetadataPlugin() {
|
||||
super("sdi-service/gcube/service");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Exception convert(Exception arg0, ProxyConfig<?, ?> arg1) {
|
||||
return arg0;
|
||||
}
|
||||
@Override
|
||||
public Metadata newProxy(ProxyDelegate<WebTarget> 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);
|
||||
|
||||
}
|
||||
}
|
|
@ -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<WebTarget> delegate;
|
||||
|
||||
|
||||
public DefaultMetadata(ProxyDelegate<WebTarget> config){
|
||||
this.delegate = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<TemplateDescriptor> getAvailableTemplates() {
|
||||
Call<WebTarget, Set<TemplateDescriptor>> call = new Call<WebTarget, Set<TemplateDescriptor>>() {
|
||||
@Override
|
||||
public Set<TemplateDescriptor> 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue