git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/Common/storagehub-client@163319 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
5b2e8355d6
commit
02a32ba2cf
|
@ -0,0 +1,36 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
|
</classpath>
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>storagehub-client</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
|
@ -0,0 +1,6 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding//src/main/java=UTF-8
|
||||||
|
encoding//src/main/resources=UTF-8
|
||||||
|
encoding//src/test/java=UTF-8
|
||||||
|
encoding//src/test/resources=UTF-8
|
||||||
|
encoding/<project>=UTF-8
|
|
@ -0,0 +1,12 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||||
|
org.eclipse.jdt.core.compiler.source=1.8
|
|
@ -0,0 +1,4 @@
|
||||||
|
activeProfiles=
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
resolveWorkspaceProjects=true
|
||||||
|
version=1
|
|
@ -0,0 +1,96 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<artifactId>maven-parent</artifactId>
|
||||||
|
<groupId>org.gcube.tools</groupId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<relativePath />
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<groupId>org.gcube.common</groupId>
|
||||||
|
<artifactId>storagehub-client-library</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<name>toragehub-client-library</name>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.distribution</groupId>
|
||||||
|
<artifactId>gcube-bom</artifactId>
|
||||||
|
<version>LATEST</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.10</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.common</groupId>
|
||||||
|
<artifactId>storagehub-model</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish.jersey.core</groupId>
|
||||||
|
<artifactId>jersey-client</artifactId>
|
||||||
|
<version>2.24.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.jaxrs</groupId>
|
||||||
|
<artifactId>jackson-jaxrs-json-provider</artifactId>
|
||||||
|
<version>2.3.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish.jersey.media</groupId>
|
||||||
|
<artifactId>jersey-media-json-jackson</artifactId>
|
||||||
|
<version>2.24.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish.jersey.media</groupId>
|
||||||
|
<artifactId>jersey-media-multipart</artifactId>
|
||||||
|
<version>2.24.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.ws.rs</groupId>
|
||||||
|
<artifactId>javax.ws.rs-api</artifactId>
|
||||||
|
<version>2.0</version>
|
||||||
|
</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>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>2.3.2</version>
|
||||||
|
<configuration>
|
||||||
|
<target>1.8</target>
|
||||||
|
<source>1.8</source>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -0,0 +1,36 @@
|
||||||
|
package org.gcube.common.storagehub.client;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import javax.xml.namespace.QName;
|
||||||
|
|
||||||
|
public class Constants {
|
||||||
|
|
||||||
|
/** Service name. */
|
||||||
|
public static final String SERVICE_NAME = "StorageHub";
|
||||||
|
|
||||||
|
/** Service class. */
|
||||||
|
public static final String SERVICE_CLASS = "DataAccess";
|
||||||
|
|
||||||
|
public static final int DEFAULT_TIMEOUT= (int) TimeUnit.SECONDS.toMillis(10);
|
||||||
|
|
||||||
|
public static final String NAMESPACE = "http://gcube-system.org/namespaces/common/storagehub";
|
||||||
|
|
||||||
|
public static final QName MANAGER_QNAME = new QName(NAMESPACE, "itemmanager");
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
public static final GcubeService<ManagerStubs> manager = service().withName(org.gcube.data.spd.model.service.Constants.manager_name).andInterface(ManagerStubs.class);
|
||||||
|
|
||||||
|
public static final GcubeService<ClassificationStubs> classification = service().withName(org.gcube.data.spd.model.service.Constants.classification_name).andInterface(ClassificationStubs.class);
|
||||||
|
|
||||||
|
public static final GcubeService<ExecutorStubs> executor = service().withName(org.gcube.data.spd.model.service.Constants.executor_name).andInterface(ExecutorStubs.class);
|
||||||
|
|
||||||
|
public static final GcubeService<OccurrenceStubs> occurrence = service().withName(org.gcube.data.spd.model.service.Constants.occurrence_name).andInterface(OccurrenceStubs.class);
|
||||||
|
|
||||||
|
private static final GcubeService<RemoteDispatcher> remoteDispatcher = service().withName(org.gcube.data.spd.model.service.Constants.remoteDispatcher_name).andInterface(RemoteDispatcher.class);
|
||||||
|
|
||||||
|
public static final RemoteDispatcher getRemoteDispatcherService(String address){
|
||||||
|
return stubFor(remoteDispatcher).at(address);
|
||||||
|
}*/
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package org.gcube.common.storagehub.client;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
public class StreamDescriptor {
|
||||||
|
|
||||||
|
private InputStream stream;
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
public StreamDescriptor(InputStream stream, String fileName) {
|
||||||
|
super();
|
||||||
|
this.stream = stream;
|
||||||
|
this.fileName = fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStream getStream() {
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileName() {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
package org.gcube.common.storagehub.client.plugins;
|
||||||
|
|
||||||
|
import javax.ws.rs.client.WebTarget;
|
||||||
|
|
||||||
|
import org.gcube.common.clients.Plugin;
|
||||||
|
import org.gcube.common.clients.ProxyBuilder;
|
||||||
|
import org.gcube.common.clients.ProxyBuilderImpl;
|
||||||
|
import org.gcube.common.storagehub.client.Constants;
|
||||||
|
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||||
|
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public abstract class AbstractPlugin<S,P> implements Plugin<S,P> {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static final ItemManagerPlugin item_plugin = new ItemManagerPlugin();
|
||||||
|
private static final WorkspaceManagerPlugin workspace_plugin = new WorkspaceManagerPlugin();
|
||||||
|
|
||||||
|
|
||||||
|
public static ProxyBuilder<ItemManagerClient> item() {
|
||||||
|
return new ProxyBuilderImpl<WebTarget,ItemManagerClient>(item_plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ProxyBuilder<WorkspaceManagerClient> workspace() {
|
||||||
|
return new ProxyBuilderImpl<WebTarget,WorkspaceManagerClient>(workspace_plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final String name;
|
||||||
|
|
||||||
|
public AbstractPlugin(String name) {
|
||||||
|
this.name=name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String serviceClass() {
|
||||||
|
return Constants.SERVICE_CLASS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String serviceName() {
|
||||||
|
return Constants.SERVICE_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String namespace() {
|
||||||
|
return Constants.NAMESPACE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
package org.gcube.common.storagehub.client.plugins;
|
||||||
|
|
||||||
|
import javax.ws.rs.client.WebTarget;
|
||||||
|
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.common.storagehub.client.Constants;
|
||||||
|
import org.gcube.common.storagehub.client.proxies.DefaultItemManager;
|
||||||
|
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
|
||||||
|
public class ItemManagerPlugin extends AbstractPlugin<WebTarget, ItemManagerClient> {
|
||||||
|
|
||||||
|
public ItemManagerPlugin() {
|
||||||
|
super("storagehub/workspace");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Exception convert(Exception e, ProxyConfig<?, ?> arg1) {
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemManagerClient newProxy(ProxyDelegate<WebTarget> delegate) {
|
||||||
|
return new DefaultItemManager(delegate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WebTarget resolve(EndpointReference epr, ProxyConfig<?, ?> config)
|
||||||
|
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(Constants.MANAGER_QNAME).andPath("item");
|
||||||
|
return TargetFactory.stubFor(service).at(address);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
package org.gcube.common.storagehub.client.plugins;
|
||||||
|
|
||||||
|
import javax.ws.rs.client.WebTarget;
|
||||||
|
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.common.storagehub.client.Constants;
|
||||||
|
import org.gcube.common.storagehub.client.proxies.DefaultWorkspaceManager;
|
||||||
|
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
|
||||||
|
public class WorkspaceManagerPlugin extends AbstractPlugin<WebTarget, WorkspaceManagerClient> {
|
||||||
|
|
||||||
|
public WorkspaceManagerPlugin() {
|
||||||
|
super("storagehub/workspace");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Exception convert(Exception e, ProxyConfig<?, ?> arg1) {
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WorkspaceManagerClient newProxy(ProxyDelegate<WebTarget> delegate) {
|
||||||
|
return new DefaultWorkspaceManager(delegate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WebTarget resolve(EndpointReference epr, ProxyConfig<?, ?> config)
|
||||||
|
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(Constants.MANAGER_QNAME).useRootPath();
|
||||||
|
return TargetFactory.stubFor(service).at(address);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
package org.gcube.common.storagehub.client.proxies;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.ws.rs.client.Invocation;
|
||||||
|
import javax.ws.rs.client.WebTarget;
|
||||||
|
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.common.storagehub.client.StreamDescriptor;
|
||||||
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
|
import org.gcube.common.storagehub.model.service.ItemList;
|
||||||
|
|
||||||
|
public class DefaultItemManager implements ItemManagerClient {
|
||||||
|
|
||||||
|
private final ProxyDelegate<WebTarget> delegate;
|
||||||
|
|
||||||
|
|
||||||
|
public DefaultItemManager(ProxyDelegate<WebTarget> config){
|
||||||
|
this.delegate = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<? extends Item> getChildren(String id, String ... excludeNodes) {
|
||||||
|
Call<WebTarget, ItemList> call = new Call<WebTarget, ItemList>() {
|
||||||
|
@Override
|
||||||
|
public ItemList call(WebTarget manager) throws Exception {
|
||||||
|
WebTarget myManager = manager.path(id).path("children");
|
||||||
|
if (excludeNodes !=null && excludeNodes.length>0)
|
||||||
|
myManager = myManager.queryParam("exclude",excludeNodes);
|
||||||
|
Invocation.Builder builder = myManager.request(MediaType.APPLICATION_JSON);
|
||||||
|
ItemList response = builder.get(ItemList.class);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
ItemList result = delegate.make(call);
|
||||||
|
return result.getItemlist();
|
||||||
|
}catch(Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StreamDescriptor download(String id) {
|
||||||
|
Call<WebTarget, StreamDescriptor> call = new Call<WebTarget, StreamDescriptor>() {
|
||||||
|
@Override
|
||||||
|
public StreamDescriptor call(WebTarget manager) throws Exception {
|
||||||
|
WebTarget myManager = manager.path(id).path("download");
|
||||||
|
Invocation.Builder builder = myManager.request(MediaType.APPLICATION_OCTET_STREAM);
|
||||||
|
Response resp = builder.get();
|
||||||
|
InputStream stream = resp.readEntity(InputStream.class);
|
||||||
|
String disposition = resp.getHeaderString("Content-Disposition");
|
||||||
|
String fileName = disposition.replaceFirst("attachment; filename = ([^/s]+)?", "$1");
|
||||||
|
return new StreamDescriptor(stream, fileName);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
StreamDescriptor result = delegate.make(call);
|
||||||
|
return result;
|
||||||
|
}catch(Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
package org.gcube.common.storagehub.client.proxies;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.ws.rs.client.Invocation;
|
||||||
|
import javax.ws.rs.client.WebTarget;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
import org.gcube.common.clients.Call;
|
||||||
|
import org.gcube.common.clients.delegates.ProxyDelegate;
|
||||||
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
|
import org.gcube.common.storagehub.model.service.ItemList;
|
||||||
|
|
||||||
|
public class DefaultWorkspaceManager implements WorkspaceManagerClient {
|
||||||
|
|
||||||
|
private final ProxyDelegate<WebTarget> delegate;
|
||||||
|
|
||||||
|
|
||||||
|
public DefaultWorkspaceManager(ProxyDelegate<WebTarget> config){
|
||||||
|
this.delegate = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<? extends Item> getWorkspace(String... excludeNodes) {
|
||||||
|
Call<WebTarget, ItemList> call = new Call<WebTarget, ItemList>() {
|
||||||
|
@Override
|
||||||
|
public ItemList call(WebTarget manager) throws Exception {
|
||||||
|
WebTarget myManager = manager;
|
||||||
|
if (excludeNodes !=null && excludeNodes.length>0)
|
||||||
|
myManager = myManager.queryParam("exclude",excludeNodes);
|
||||||
|
Invocation.Builder builder = myManager.request(MediaType.APPLICATION_JSON);
|
||||||
|
ItemList response = builder.get(ItemList.class);
|
||||||
|
System.out.println(myManager.getUri().toString());
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
ItemList result = delegate.make(call);
|
||||||
|
return result.getItemlist();
|
||||||
|
}catch(Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package org.gcube.common.storagehub.client.proxies;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.common.storagehub.client.StreamDescriptor;
|
||||||
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public interface ItemManagerClient {
|
||||||
|
|
||||||
|
//List<? extends Item> listByPath(String path, String ... excludeNodes);
|
||||||
|
|
||||||
|
List<? extends Item> getChildren(String id, String ... excludeNodes);
|
||||||
|
|
||||||
|
StreamDescriptor download(String id);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package org.gcube.common.storagehub.client.proxies;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
|
|
||||||
|
public interface WorkspaceManagerClient {
|
||||||
|
|
||||||
|
List<? extends Item> getWorkspace(String ... excludeNodes);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,127 @@
|
||||||
|
package org.gcube.data.access.fs;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.ws.rs.client.Client;
|
||||||
|
import javax.ws.rs.client.ClientBuilder;
|
||||||
|
import javax.ws.rs.client.Entity;
|
||||||
|
import javax.ws.rs.client.Invocation;
|
||||||
|
import javax.ws.rs.client.WebTarget;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
import org.gcube.common.storagehub.model.Path;
|
||||||
|
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||||
|
import org.gcube.common.storagehub.model.items.GenericFileItem;
|
||||||
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
|
import org.gcube.common.storagehub.model.query.ItemFilter;
|
||||||
|
import org.gcube.common.storagehub.model.query.OrderBy;
|
||||||
|
import org.gcube.common.storagehub.model.service.ItemList;
|
||||||
|
import org.gcube.common.storagehub.model.service.ItemWrapper;
|
||||||
|
import org.glassfish.jersey.client.ClientConfig;
|
||||||
|
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
||||||
|
import org.glassfish.jersey.media.multipart.MultiPart;
|
||||||
|
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||||
|
import org.glassfish.jersey.media.multipart.file.FileDataBodyPart;
|
||||||
|
import org.glassfish.jersey.media.multipart.file.StreamDataBodyPart;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class Items {
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
static String baseUrl="http://workspace-repository1-d.d4science.org/storagehub";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static List<? extends Item> list(OrderBy order, Path path, ItemFilter<?> ... filters){
|
||||||
|
Client client = ClientBuilder.newClient();
|
||||||
|
WebTarget webTarget = client.target(baseUrl+"/list/byPath?gcube-token=595ca591-9921-423c-bfca-f8be19f05882-98187548");
|
||||||
|
Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON);
|
||||||
|
List<? extends Item> r = invocationBuilder.get(ItemList.class).getItemlist();
|
||||||
|
return r;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void createFolder(){
|
||||||
|
//Client client = ClientBuilder.newClient();
|
||||||
|
Client client = ClientBuilder.newBuilder()
|
||||||
|
.register(MultiPartFeature.class).build();
|
||||||
|
WebTarget webTarget = client.target(baseUrl+"/item/create?gcube-token=595ca591-9921-423c-bfca-f8be19f05882-98187548");
|
||||||
|
|
||||||
|
FolderItem folder= new FolderItem();
|
||||||
|
folder.setName("My third folder");
|
||||||
|
folder.setTitle("My third title");
|
||||||
|
final MultiPart multiPart = new FormDataMultiPart()
|
||||||
|
.field("item", new ItemWrapper<FolderItem>(folder), MediaType.APPLICATION_JSON_TYPE)
|
||||||
|
/* .field("characterProfile", jsonToSend, MediaType.APPLICATION_JSON_TYPE)
|
||||||
|
.field("filename", fileToUpload.getName(), MediaType.TEXT_PLAIN_TYPE)
|
||||||
|
.bodyPart(fileDataBodyPart)*/;
|
||||||
|
/*
|
||||||
|
Response res = webTarget.request().post(Entity.entity(multiPart, multiPart.getMediaType()));
|
||||||
|
System.out.println("status is "+res.getStatus());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void create() throws Exception{
|
||||||
|
|
||||||
|
|
||||||
|
ClientConfig clientConfig = new ClientConfig();
|
||||||
|
clientConfig.property("DEFAULT_CHUNK_SIZE", 2048);
|
||||||
|
|
||||||
|
Clie
|
||||||
|
|
||||||
|
//Client client = ClientBuilder.newClient();
|
||||||
|
Client client = ClientBuilder.newClient(clientConfig)
|
||||||
|
.register(MultiPartFeature.class);
|
||||||
|
|
||||||
|
WebTarget webTarget = client.target(baseUrl+"/item/create?gcube-token=595ca591-9921-423c-bfca-f8be19f05882-98187548");
|
||||||
|
|
||||||
|
GenericFileItem folder= new GenericFileItem();
|
||||||
|
folder.setName("testUpload.tar.gz");
|
||||||
|
folder.setTitle("testUpload.tar.gz");
|
||||||
|
|
||||||
|
FileDataBodyPart fileDataBodyPart = new FileDataBodyPart("file", new File("/home/lucio/Downloads/testUpload.tar.gz"));
|
||||||
|
final MultiPart multiPart = new FormDataMultiPart().field("item", new ItemWrapper<GenericFileItem>(folder), MediaType.APPLICATION_JSON_TYPE)
|
||||||
|
.bodyPart(fileDataBodyPart, MediaType.APPLICATION_OCTET_STREAM_TYPE);
|
||||||
|
multiPart.close();
|
||||||
|
|
||||||
|
Response res = webTarget.request().post(Entity.entity(multiPart, multiPart.getMediaType()));
|
||||||
|
System.out.println("status is "+res.getStatus());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void get() throws Exception{
|
||||||
|
Client client = ClientBuilder.newClient();
|
||||||
|
WebTarget webTarget = client.target(baseUrl+"/item/6e9b8350-4854-4c22-8aa1-ba2d8135ad6d/download?gcube-token=950a0702-6ada-40e9-92dc-d243d1b45206-98187548");
|
||||||
|
Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_OCTET_STREAM);
|
||||||
|
Response res = invocationBuilder.get();
|
||||||
|
|
||||||
|
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
|
/*while (is.read(buf)!=-1)
|
||||||
|
System.out.println("reading the buffer");
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static <T extends Item> T copy(T item, Path path){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends Item> T move(T item, Path path){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends Item> T unshareAll(T item){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
package org.gcube.data.access.fs;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
import org.gcube.common.storagehub.client.StreamDescriptor;
|
||||||
|
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
||||||
|
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||||
|
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
||||||
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class TestCall {
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setUp(){
|
||||||
|
SecurityTokenProvider.instance.set("94a3b80a-c66f-4000-ae2f-230f5dfad793-98187548");
|
||||||
|
ScopeProvider.instance.set("/gcube/devNext");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getListByPath(){
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
WorkspaceManagerClient client = AbstractPlugin.workspace().build();
|
||||||
|
List<? extends Item> items =client.getWorkspace("hl:accounting");
|
||||||
|
System.out.println("took: "+(System.currentTimeMillis()-start)+" for items "+items.size());
|
||||||
|
items.forEach(i -> System.out.println(i.getTitle()+" "+i.getId()+" "+i.isLocked()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getById() throws Exception{
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
ItemManagerClient client = AbstractPlugin.item().build();
|
||||||
|
client.getChildren("07cd8d55-a35b-4445-9680-c98f158c55de", "hl:accounting", "jcr:content").forEach(i -> System.out.println(i.getName()+" "+i.getId()));
|
||||||
|
System.out.println("took: "+(System.currentTimeMillis()-start) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void download() throws Exception{
|
||||||
|
ItemManagerClient client = AbstractPlugin.item().build();
|
||||||
|
StreamDescriptor streamDescr = client.download("07cd8d55-a35b-4445-9680-c98f158c55de");
|
||||||
|
File output = Files.createTempFile("down", streamDescr.getFileName()).toFile();
|
||||||
|
try (BufferedInputStream bi = new BufferedInputStream(streamDescr.getStream()); FileOutputStream fo = new FileOutputStream(output)){
|
||||||
|
byte[] buf = new byte[2048];
|
||||||
|
int read = -1;
|
||||||
|
while ((read=bi.read(buf))!=-1) {
|
||||||
|
fo.write(buf, 0, read);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("file written "+output.getAbsolutePath());
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Test
|
||||||
|
public void createFolder() throws Exception{
|
||||||
|
Items.createFolder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createFile() throws Exception{
|
||||||
|
Items.create();
|
||||||
|
}*/
|
||||||
|
}
|
Loading…
Reference in New Issue