DefaultManager update
This commit is contained in:
parent
433e075326
commit
ceb01cf16f
5
pom.xml
5
pom.xml
|
@ -35,10 +35,7 @@
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.gcube.common</groupId>
|
|
||||||
<artifactId>gxJRS</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
|
|
|
@ -34,8 +34,11 @@ import org.gcube.common.storagehub.model.service.ItemWrapper;
|
||||||
import org.gcube.common.storagehub.model.service.Version;
|
import org.gcube.common.storagehub.model.service.Version;
|
||||||
import org.gcube.common.storagehub.model.service.VersionList;
|
import org.gcube.common.storagehub.model.service.VersionList;
|
||||||
import org.gcube.common.storagehub.model.types.ACLList;
|
import org.gcube.common.storagehub.model.types.ACLList;
|
||||||
|
import org.glassfish.jersey.client.ClientProperties;
|
||||||
|
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
|
||||||
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
||||||
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||||
|
import org.glassfish.jersey.media.multipart.file.StreamDataBodyPart;
|
||||||
|
|
||||||
public class DefaultItemManager implements ItemManagerClient {
|
public class DefaultItemManager implements ItemManagerClient {
|
||||||
|
|
||||||
|
@ -619,7 +622,6 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
@Override
|
@Override
|
||||||
public String uploadFile(InputStream stream, String parentId, String fileName, String description) throws StorageHubException {
|
public String uploadFile(InputStream stream, String parentId, String fileName, String description) throws StorageHubException {
|
||||||
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
||||||
|
@ -629,7 +631,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
Objects.requireNonNull(parentId, "parentId cannot be null");
|
Objects.requireNonNull(parentId, "parentId cannot be null");
|
||||||
Objects.requireNonNull(fileName, "parentId cannot be null");
|
Objects.requireNonNull(fileName, "parentId cannot be null");
|
||||||
Objects.requireNonNull(description, "parentId cannot be null");
|
Objects.requireNonNull(description, "parentId cannot be null");
|
||||||
|
|
||||||
GXWebTargetAdapterRequest myManager = manager.register(MultiPartFeature.class).path(parentId)
|
GXWebTargetAdapterRequest myManager = manager.register(MultiPartFeature.class).path(parentId)
|
||||||
.path("create").path("FILE");
|
.path("create").path("FILE");
|
||||||
|
|
||||||
|
@ -638,8 +640,12 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
|
|
||||||
multipart.field("name", fileName);
|
multipart.field("name", fileName);
|
||||||
multipart.field("description", description);
|
multipart.field("description", description);
|
||||||
multipart.field("file", stream, MediaType.APPLICATION_OCTET_STREAM_TYPE);
|
|
||||||
|
|
||||||
|
StreamDataBodyPart fdp = new StreamDataBodyPart("file", stream);
|
||||||
|
multipart.bodyPart(fdp);
|
||||||
|
|
||||||
|
|
||||||
Entity<FormDataMultiPart> entity = Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA);
|
Entity<FormDataMultiPart> entity = Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA);
|
||||||
|
|
||||||
response = myManager.post(entity);
|
response = myManager.post(entity);
|
||||||
|
@ -662,7 +668,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
throw new RuntimeException(e1);
|
throw new RuntimeException(e1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
/*
|
||||||
@Override
|
@Override
|
||||||
public String uploadFile(InputStream stream, String parentId, String fileName, String description) throws StorageHubException {
|
public String uploadFile(InputStream stream, String parentId, String fileName, String description) throws StorageHubException {
|
||||||
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
||||||
|
@ -705,7 +711,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
}catch(Exception e1) {
|
}catch(Exception e1) {
|
||||||
throw new RuntimeException(e1);
|
throw new RuntimeException(e1);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String uploadFile(URI uri, String parentId, String fileName, String description) throws StorageHubException {
|
public String uploadFile(URI uri, String parentId, String fileName, String description) throws StorageHubException {
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class Items {
|
||||||
|
|
||||||
private static final String propFile = "C:\\Users\\tilli\\Documents\\eclipse\\tokens.properties";
|
private static final String propFile = "C:\\Users\\tilli\\Documents\\eclipse\\tokens.properties";
|
||||||
|
|
||||||
private static final String tokens = "prod-root";
|
private static final String tokens = "dev-root";
|
||||||
//private static final String tokens = "prod-root";
|
//private static final String tokens = "prod-root";
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
|
@ -167,16 +167,19 @@ public class Items {
|
||||||
|
|
||||||
StorageHubClient shc = new StorageHubClient();
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
|
||||||
|
|
||||||
FolderContainer myRoot = shc.getWSRoot();
|
FolderContainer myRoot = shc.getWSRoot();
|
||||||
|
|
||||||
|
|
||||||
try(InputStream is = new FileInputStream(new File("C:\\\\Users\\\\tilli\\\\Downloads\\\\Blue-Cloud_order_2021_10_15_1.zip"))){
|
long start = System.currentTimeMillis();
|
||||||
myRoot.uploadFile(is, "testUpload.zip", "file");
|
|
||||||
|
File inFile = new File("C:\\Users\\tilli\\Downloads\\testup.zip");
|
||||||
|
try(InputStream is = new FileInputStream(inFile)){
|
||||||
|
myRoot.uploadFile(is, "testUp.zip", "file");
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
System.out.println("Response in "+(System.currentTimeMillis()-start));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,10 @@ import java.io.BufferedInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -16,11 +17,14 @@ import java.util.Properties;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import javax.ws.rs.WebApplicationException;
|
||||||
import javax.ws.rs.client.Client;
|
import javax.ws.rs.client.Client;
|
||||||
import javax.ws.rs.client.ClientBuilder;
|
import javax.ws.rs.client.ClientBuilder;
|
||||||
import javax.ws.rs.client.Entity;
|
import javax.ws.rs.client.Entity;
|
||||||
import javax.ws.rs.client.WebTarget;
|
import javax.ws.rs.client.WebTarget;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.core.StreamingOutput;
|
||||||
|
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
@ -42,13 +46,9 @@ import org.gcube.common.storagehub.model.expressions.logical.ISDescendant;
|
||||||
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
||||||
import org.gcube.common.storagehub.model.items.GCubeItem;
|
import org.gcube.common.storagehub.model.items.GCubeItem;
|
||||||
import org.gcube.common.storagehub.model.items.Item;
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
import org.gcube.common.storagehub.model.messages.Message;
|
|
||||||
import org.gcube.common.storagehub.model.query.Queries;
|
import org.gcube.common.storagehub.model.query.Queries;
|
||||||
import org.gcube.common.storagehub.model.query.Query;
|
import org.gcube.common.storagehub.model.query.Query;
|
||||||
import org.glassfish.jersey.client.ClientProperties;
|
import org.glassfish.jersey.client.ClientProperties;
|
||||||
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
|
||||||
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
|
||||||
import org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException;
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -80,19 +80,19 @@ public class TestCall {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sendMessagesWithAttachment() throws Exception {
|
public void sendMessagesWithAttachment() throws Exception {
|
||||||
MessageManagerClient client = AbstractPlugin.messages().build();
|
MessageManagerClient client = AbstractPlugin.messages().build();
|
||||||
client.sendMessage(Arrays.asList("massimiliano.assante"), "subject encodato ? è ", "è econdato ??", Arrays.asList("4827dd33-6eea-4bba-b78b-b98e2fd2ddfa"));
|
client.sendMessage(Arrays.asList("massimiliano.assante"), "subject encodato ? è ", "è econdato ??", Arrays.asList("4827dd33-6eea-4bba-b78b-b98e2fd2ddfa"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setUnread() throws Exception {
|
public void setUnread() throws Exception {
|
||||||
MessageManagerClient client = AbstractPlugin.messages().build();
|
MessageManagerClient client = AbstractPlugin.messages().build();
|
||||||
client.setRead("f3b7ce40-28df-40b3-ad17-f0b9bd658016", false);
|
client.setRead("f3b7ce40-28df-40b3-ad17-f0b9bd658016", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addUserToGroup() throws StorageHubException {
|
public void addUserToGroup() throws StorageHubException {
|
||||||
GroupManagerClient client = AbstractPlugin.groups().build();
|
GroupManagerClient client = AbstractPlugin.groups().build();
|
||||||
client.addUserToGroup("andrea.rossi", "gcube-devsec-devVRE");
|
client.addUserToGroup("andrea.rossi", "gcube-devsec-devVRE");
|
||||||
|
@ -128,8 +128,8 @@ public class TestCall {
|
||||||
WorkspaceManagerClient client = AbstractPlugin.workspace().build();
|
WorkspaceManagerClient client = AbstractPlugin.workspace().build();
|
||||||
System.out.println(client.restoreFromTrash("4fc0a9df-9a51-42ef-98f2-06c21bd0669b", "f3d336cc-cd00-48ba-8339-2bffcbef825e"));
|
System.out.println(client.restoreFromTrash("4fc0a9df-9a51-42ef-98f2-06c21bd0669b", "f3d336cc-cd00-48ba-8339-2bffcbef825e"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void unshareFolder() throws Exception{
|
public void unshareFolder() throws Exception{
|
||||||
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
||||||
|
@ -183,6 +183,34 @@ public class TestCall {
|
||||||
client.createGcubeItem(ws.getId(), item);
|
client.createGcubeItem(ws.getId(), item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void uploadDirectJersey() throws Exception {
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
Client client = ClientBuilder.newClient();
|
||||||
|
client.property(ClientProperties.REQUEST_ENTITY_PROCESSING, "CHUNKED").property(ClientProperties.CHUNKED_ENCODING_SIZE, 1024).property(ClientProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, -1);
|
||||||
|
WebTarget target = client.target("https://workspace-repository.dev.d4science.org/storagehub/workspace/items/cc7513e7-fd93-4bfb-8e1b-bc9b32938c77/create/"
|
||||||
|
+ "FILE?gcube-token=b7c80297-e4ed-42ab-ab42-fdc0b8b0eabf-98187548");
|
||||||
|
|
||||||
|
target = target.queryParam("name", "test2Gb.zip").queryParam("description", "description");
|
||||||
|
|
||||||
|
|
||||||
|
File inFile = new File("C:\\Users\\tilli\\Downloads\\testup.zip");
|
||||||
|
InputStream fileInStream = new FileInputStream(inFile);
|
||||||
|
|
||||||
|
|
||||||
|
//String contentDisposition = "attachment; filename=\"" + inFile.getName() + "\"";
|
||||||
|
System.out.println("sending: " + inFile.length() + " bytes...");
|
||||||
|
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
|
||||||
|
Response response = target
|
||||||
|
.request(MediaType.APPLICATION_OCTET_STREAM_TYPE)
|
||||||
|
//.header("Content-Disposition", contentDisposition)
|
||||||
|
//.header("Content-Length", inFile.length())
|
||||||
|
.post(Entity.entity(fileInStream, MediaType.APPLICATION_OCTET_STREAM_TYPE));
|
||||||
|
System.out.println("Response status: " + response.getStatus()+ " in "+(System.currentTimeMillis()-start));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void upload() throws Exception{
|
public void upload() throws Exception{
|
||||||
final ItemManagerClient client = AbstractPlugin.item().build();
|
final ItemManagerClient client = AbstractPlugin.item().build();
|
||||||
|
@ -191,7 +219,7 @@ public class TestCall {
|
||||||
+ "mioSBvOehbZlu54_jvscz8Zu3LXgqhr8RfJemd83QIh47z6TyMn3mD0OjpcG5g0qf9WUZCeW1J4btEqNObkaWv"
|
+ "mioSBvOehbZlu54_jvscz8Zu3LXgqhr8RfJemd83QIh47z6TyMn3mD0OjpcG5g0qf9WUZCeW1J4btEqNObkaWv"
|
||||||
+ "pMhabvswweyFn1Jg4m5GpwCoKayvgsYYwjbjsGsQW5Hileiw==");
|
+ "pMhabvswweyFn1Jg4m5GpwCoKayvgsYYwjbjsGsQW5Hileiw==");
|
||||||
|
|
||||||
|
|
||||||
client.uploadFile(remote, "bc1c9525-43f7-4565-b5ea-0a0f9d7853a0", "5gb.zip", "description");
|
client.uploadFile(remote, "bc1c9525-43f7-4565-b5ea-0a0f9d7853a0", "5gb.zip", "description");
|
||||||
|
|
||||||
|
|
||||||
|
@ -259,7 +287,7 @@ public class TestCall {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getRecents() {
|
public void getRecents() {
|
||||||
|
|
||||||
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
|
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
|
||||||
List<? extends Item> items = wsclient.getRecentModifiedFilePerVre();
|
List<? extends Item> items = wsclient.getRecentModifiedFilePerVre();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue