2018-02-15 18:13:50 +01:00
|
|
|
package org.gcube.data.access.fs;
|
|
|
|
|
2019-09-09 16:29:40 +02:00
|
|
|
import java.io.BufferedInputStream;
|
2018-02-15 18:13:50 +01:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
2018-09-04 11:21:08 +02:00
|
|
|
import java.io.FileOutputStream;
|
2018-03-29 18:19:01 +02:00
|
|
|
import java.io.InputStream;
|
2021-10-15 19:53:14 +02:00
|
|
|
import java.net.URI;
|
|
|
|
import java.net.URL;
|
2018-09-04 11:21:08 +02:00
|
|
|
import java.nio.file.Files;
|
2019-01-03 12:16:53 +01:00
|
|
|
import java.util.Arrays;
|
2021-04-29 16:58:14 +02:00
|
|
|
import java.util.Enumeration;
|
2019-01-03 12:16:53 +01:00
|
|
|
import java.util.HashSet;
|
2020-01-15 19:10:33 +01:00
|
|
|
import java.util.List;
|
2019-07-25 17:47:18 +02:00
|
|
|
import java.util.Map.Entry;
|
2021-04-29 16:58:14 +02:00
|
|
|
import java.util.Properties;
|
2022-12-14 14:54:08 +01:00
|
|
|
import java.util.stream.Collectors;
|
2022-11-15 12:22:54 +01:00
|
|
|
import java.util.stream.IntStream;
|
2018-07-05 12:31:52 +02:00
|
|
|
|
2022-11-11 17:28:12 +01:00
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
2018-06-22 10:52:56 +02:00
|
|
|
import org.gcube.common.storagehub.client.StreamDescriptor;
|
2021-10-15 19:53:14 +02:00
|
|
|
import org.gcube.common.storagehub.client.dsl.ContainerType;
|
2018-06-22 10:52:56 +02:00
|
|
|
import org.gcube.common.storagehub.client.dsl.FileContainer;
|
2018-09-26 15:24:21 +02:00
|
|
|
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
2018-06-22 10:52:56 +02:00
|
|
|
import org.gcube.common.storagehub.client.dsl.ItemContainer;
|
2021-10-15 19:53:14 +02:00
|
|
|
import org.gcube.common.storagehub.client.dsl.OpenResolver;
|
2018-04-18 15:55:20 +02:00
|
|
|
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
2021-10-15 19:53:14 +02:00
|
|
|
import org.gcube.common.storagehub.client.dsl.VREFolderManager;
|
2020-03-16 16:58:12 +01:00
|
|
|
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
|
|
|
import org.gcube.common.storagehub.client.proxies.UserManagerClient;
|
2019-07-25 17:47:18 +02:00
|
|
|
import org.gcube.common.storagehub.model.Metadata;
|
2019-01-03 12:16:53 +01:00
|
|
|
import org.gcube.common.storagehub.model.acls.AccessType;
|
2019-03-13 18:33:58 +01:00
|
|
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
2022-12-14 14:54:08 +01:00
|
|
|
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
2021-04-29 16:58:14 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.FolderItem;
|
2018-06-22 10:52:56 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.Item;
|
2018-03-29 18:19:01 +02:00
|
|
|
import org.junit.BeforeClass;
|
|
|
|
import org.junit.Test;
|
2018-02-15 18:13:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class Items {
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2022-02-07 10:24:33 +01:00
|
|
|
private static final String propFile = "/home/lucio/tokens.properties";
|
2021-04-29 16:58:14 +02:00
|
|
|
|
2022-11-18 15:43:56 +01:00
|
|
|
private static final String tokens = "dev-root";
|
2021-04-29 16:58:14 +02:00
|
|
|
//private static final String tokens = "prod-root";
|
2022-11-15 17:58:25 +01:00
|
|
|
|
2018-03-29 18:19:01 +02:00
|
|
|
@BeforeClass
|
|
|
|
public static void setUp(){
|
2021-04-29 16:58:14 +02:00
|
|
|
|
|
|
|
try(InputStream is = new FileInputStream(new File(propFile))){
|
|
|
|
Properties prop = new Properties();
|
|
|
|
prop.load(is);
|
|
|
|
String value =(String)prop.get(tokens);
|
|
|
|
String[] splitValue = value.split(",");
|
|
|
|
String token = splitValue[1];
|
2022-07-27 11:09:05 +02:00
|
|
|
//SecretManagerProvider.instance.set(new GCubeSecret(token));
|
2022-11-15 17:58:25 +01:00
|
|
|
|
2022-11-11 17:28:12 +01:00
|
|
|
SecurityTokenProvider.instance.set(token);
|
|
|
|
ScopeProvider.instance.set(splitValue[0]);
|
2021-04-29 16:58:14 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
2018-03-29 18:19:01 +02:00
|
|
|
}
|
2021-04-29 16:58:14 +02:00
|
|
|
|
2022-11-15 17:58:25 +01:00
|
|
|
|
2019-10-14 10:18:54 +02:00
|
|
|
@Test
|
2021-04-29 16:58:14 +02:00
|
|
|
public void addUserToVRe() throws StorageHubException {
|
2019-10-14 10:18:54 +02:00
|
|
|
StorageHubClient shc = new StorageHubClient();
|
2022-11-15 17:58:25 +01:00
|
|
|
|
|
|
|
|
2021-04-29 16:58:14 +02:00
|
|
|
String vresFile = "C:\\Users\\tilli\\Downloads\\vresToAddGCat.txt";
|
2022-11-15 17:58:25 +01:00
|
|
|
|
2021-04-29 16:58:14 +02:00
|
|
|
try(InputStream is = new FileInputStream(new File(vresFile))){
|
|
|
|
Properties prop = new Properties();
|
|
|
|
prop.load(is);
|
|
|
|
Enumeration<Object> enumer = prop.keys();
|
|
|
|
while (enumer.hasMoreElements()) {
|
|
|
|
try {
|
|
|
|
String vre= (String) enumer.nextElement();
|
|
|
|
shc.getVreFolderManager(vre).addUser("gCat");
|
|
|
|
System.out.println("added to "+vre);
|
|
|
|
}catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2022-11-15 17:58:25 +01:00
|
|
|
|
2021-04-29 16:58:14 +02:00
|
|
|
}catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2022-11-15 17:58:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
}
|
2021-04-29 16:58:14 +02:00
|
|
|
|
2022-12-14 14:54:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void removeVersion() throws Exception {
|
|
|
|
|
|
|
|
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
String id = "024c8cab-f9f7-4fd8-bed2-f6076e5edf91";
|
|
|
|
FileContainer file = shc.open(id).asFile();
|
|
|
|
file.deleteVersion("1.0");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-11-11 17:28:12 +01:00
|
|
|
@Test
|
|
|
|
public void uploadTovolatile() throws StorageHubException {
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
2022-11-15 17:58:25 +01:00
|
|
|
|
|
|
|
|
2022-11-18 15:43:56 +01:00
|
|
|
String vresFile = "/home/lucio/Scaricati/zoom_amd64.deb";
|
2022-11-15 17:58:25 +01:00
|
|
|
|
2022-11-11 17:28:12 +01:00
|
|
|
File file = new File(vresFile);
|
2022-11-15 17:58:25 +01:00
|
|
|
|
2022-11-15 12:22:54 +01:00
|
|
|
try ( InputStream fileIS = new FileInputStream(file)){
|
2022-11-18 15:43:56 +01:00
|
|
|
shc.getWSRoot().uploadFile(new URI("https://data.d4science.org/shub/E_RGNhNU9aaVhZM3ovNEN2dEdtdXpCWitac0tScmMvcGZSeDlISUtOb2JOMklRQkxrdjBCWnJ4YlJHVlM4VnVjVQ=="), "testfile.jpg", "description");
|
|
|
|
//shc.uploadFileOnVolatile(fileIS, "zoom_amd645.deb", file.length());
|
2022-11-15 12:22:54 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2022-11-11 17:28:12 +01:00
|
|
|
}
|
2022-11-15 17:58:25 +01:00
|
|
|
|
|
|
|
|
2022-12-14 14:54:08 +01:00
|
|
|
@Test
|
|
|
|
public void uploadfile() {
|
|
|
|
try{
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
shc.impersonate("pasquale.pagano");
|
|
|
|
URI toUpload = new URI("https://data.d4science.org/shub/E_RGNhNU9aaVhZM3ovNEN2dEdtdXpCWitac0tScmMvcGZSeDlISUtOb2JOMklRQkxrdjBCWnJ4YlJHVlM4VnVjVQ==");
|
|
|
|
String fileName = "DRR014055.fastq.gz";
|
|
|
|
|
|
|
|
shc.open("514295c6-2176-49d5-9487-99fb0fb85372").asFolder().uploadFile(toUpload, fileName, "description");
|
|
|
|
//shc.uploadFileOnVolatile(fileIS, "zoom_amd645.deb", file.length());
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-15 12:22:54 +01:00
|
|
|
@Test
|
|
|
|
public void removeTest() {
|
|
|
|
try {
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
FolderContainer root = shc.getWSRoot();
|
|
|
|
root.list().getContainers().stream().filter(c -> c.get().getTitle().startsWith("stressTest")).forEach(c-> {
|
|
|
|
try {
|
|
|
|
c.forceDelete();
|
|
|
|
} catch (StorageHubException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
});;
|
|
|
|
}catch (Exception e ) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2022-11-15 17:58:25 +01:00
|
|
|
|
2022-12-14 14:54:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-11-15 12:22:54 +01:00
|
|
|
@Test
|
|
|
|
public void stressTest() {
|
|
|
|
try {
|
2022-11-15 17:58:25 +01:00
|
|
|
|
2022-11-18 15:43:56 +01:00
|
|
|
IntStream.range(1, 100).forEach( i-> {
|
2022-11-15 12:22:54 +01:00
|
|
|
try {
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
FolderContainer vre = shc.openVREFolder().openByRelativePath("testLucio").asFolder();
|
|
|
|
FolderContainer fc = vre.newFolder("folder"+i, "");
|
2022-11-18 15:43:56 +01:00
|
|
|
for (int t =1 ; t<5; t++) {
|
2022-11-15 17:58:25 +01:00
|
|
|
StorageHubClient shc1 = new StorageHubClient();
|
|
|
|
FolderContainer sub = shc1.open(fc.getId()).asFolder();
|
|
|
|
FolderContainer fcsub2 = sub.newFolder("folder"+i+"-"+t, "");
|
2022-11-18 15:43:56 +01:00
|
|
|
for (int k=0;k<4;k++) {
|
|
|
|
String vresFile = "/home/lucio/Scaricati/GNA_foto_Cuma Necropoli mediana_3B.jpg";
|
2022-11-15 17:58:25 +01:00
|
|
|
|
|
|
|
StorageHubClient shc2 = new StorageHubClient();
|
|
|
|
FolderContainer sub2 = shc2.open(fcsub2.getId()).asFolder();
|
2022-11-18 15:43:56 +01:00
|
|
|
|
2022-11-15 17:58:25 +01:00
|
|
|
File file = new File(vresFile);
|
|
|
|
|
|
|
|
try ( InputStream fileIS = new FileInputStream(file)){
|
2022-11-18 15:43:56 +01:00
|
|
|
final String filename ="file"+k;
|
|
|
|
FileContainer fileCont = sub2.uploadFile(fileIS, filename, "description");
|
|
|
|
new Thread(() -> {getPublicLinkAndDownload(fileCont.getId(), filename);}).start();;
|
2022-11-15 17:58:25 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2022-11-15 12:22:54 +01:00
|
|
|
}
|
2022-11-15 17:58:25 +01:00
|
|
|
}
|
2022-11-15 12:22:54 +01:00
|
|
|
} catch (StorageHubException e) {
|
|
|
|
System.out.println("error creating stressTest"+i);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}catch (Exception e ) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2022-11-15 17:58:25 +01:00
|
|
|
|
2022-11-18 15:43:56 +01:00
|
|
|
private void getPublicLinkAndDownload(String id, String fileName) {
|
|
|
|
try {
|
|
|
|
Thread.sleep(500);
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
URL link = shc.open(id).asFile().getPublicLink();
|
|
|
|
try( InputStream is = link.openStream()) {
|
|
|
|
byte[] buffer = new byte[1024];
|
|
|
|
for (int length; (length = is.read(buffer)) != -1; ) {}
|
|
|
|
}
|
|
|
|
System.out.println("downloaded file "+fileName);
|
2022-12-14 14:54:08 +01:00
|
|
|
|
2022-11-18 15:43:56 +01:00
|
|
|
}catch (Exception e) {
|
|
|
|
System.err.println("error downloading public link for id "+id);
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-29 16:58:14 +02:00
|
|
|
@Test
|
|
|
|
public void search() {
|
|
|
|
try {
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
List<? extends Item> s = shc.getWSRoot().search("WD%",false).getItems();
|
|
|
|
s.forEach(i -> System.out.println(i.getName()+" "+i.getId()));
|
|
|
|
}catch (Exception e ) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-23 15:18:37 +02:00
|
|
|
@Test
|
|
|
|
public void forceDelete() throws Exception{
|
2019-05-06 16:54:51 +02:00
|
|
|
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
2020-09-16 11:03:06 +02:00
|
|
|
//shc.open("41b904cd-128a-4121-8fd7-82498187ca06").asFolder().getAnchestors().getItems().forEach(i -> System.out.println(i.getTitle()));
|
|
|
|
shc.open("7ac99eea-d768-4864-a248-6d4ccf43d931").asFile().setDescription("new descr");
|
2019-05-06 16:54:51 +02:00
|
|
|
}
|
|
|
|
|
2019-09-09 16:29:40 +02:00
|
|
|
@Test
|
|
|
|
public void changeAcls() throws Exception{
|
|
|
|
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
2021-10-15 19:53:14 +02:00
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
//System.out.println(shc.open("65e502ff-92ef-46cc-afbd-3e91f4b680be").asFolder().canWrite());
|
|
|
|
OpenResolver openResolver= shc.open("1322e7b2-bad6-4d64-a063-db0d05b16a67");
|
|
|
|
if(openResolver.resolve().getType()==ContainerType.FILE) {
|
|
|
|
String publicLink = openResolver.asFile().getPublicLink().toString();
|
|
|
|
String itemName = openResolver.asFile().get().getTitle();
|
|
|
|
|
|
|
|
builder.append(itemName + " ("+publicLink+")");
|
|
|
|
builder.append("\n");
|
|
|
|
} else {
|
|
|
|
System.out.println("\n\n\nNON e' un FILE cosè? = " + openResolver.resolve().getType());
|
|
|
|
}
|
|
|
|
System.out.println(builder.toString());
|
2019-09-09 16:29:40 +02:00
|
|
|
}
|
2021-04-29 16:58:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void setAdmin() throws Exception{
|
|
|
|
try {
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
|
|
|
|
shc.getVreFolderManager("gcube-devsec-devVRE").setAdmin("giancarlo.panichi");
|
|
|
|
}catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void removeAdmin() throws Exception{
|
|
|
|
try {
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
|
|
|
|
shc.getVreFolderManager("gcube-devsec-devVRE").removeAdmin("luca.frosini");
|
|
|
|
}catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-15 17:58:25 +01:00
|
|
|
|
2022-02-07 10:24:33 +01:00
|
|
|
@Test
|
|
|
|
public void getItem() throws Exception{
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
String owner = shc.open("fb838c64-0924-48b4-9b45-de9be39ba860").asItem().get().getOwner();
|
|
|
|
System.out.println("owner is "+owner);
|
|
|
|
}
|
2021-04-29 16:58:14 +02:00
|
|
|
|
2022-11-15 17:58:25 +01:00
|
|
|
|
2018-10-11 18:36:21 +02:00
|
|
|
@Test
|
2021-10-15 19:53:14 +02:00
|
|
|
public void uploadFile() throws Exception{
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-11 18:36:21 +02:00
|
|
|
StorageHubClient shc = new StorageHubClient();
|
2021-04-29 16:58:14 +02:00
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
FolderContainer myRoot = shc.open("11cbdc0c-e873-418c-bc53-5f6329eb88fb").asFolder();
|
2021-04-29 16:58:14 +02:00
|
|
|
|
2022-11-15 17:58:25 +01:00
|
|
|
|
2021-10-28 15:49:12 +02:00
|
|
|
long start = System.currentTimeMillis();
|
2022-11-15 17:58:25 +01:00
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
File inFile = new File("/home/lucio/Downloads/scimmia braccia aperte.mp4");
|
2021-10-28 15:49:12 +02:00
|
|
|
try(InputStream is = new FileInputStream(inFile)){
|
2022-11-15 17:58:25 +01:00
|
|
|
myRoot.uploadFile(is, "scimmia braccia aperte.mp4", "file");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
}
|
2021-10-28 15:49:12 +02:00
|
|
|
System.out.println("Response in "+(System.currentTimeMillis()-start));
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-11 18:36:21 +02:00
|
|
|
}
|
2018-12-11 17:58:49 +01:00
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-07-17 17:55:30 +02:00
|
|
|
@Test
|
2018-09-28 17:02:20 +02:00
|
|
|
public void uploadAndcopyFile() throws Exception {
|
2018-03-29 18:19:01 +02:00
|
|
|
StorageHubClient shc = new StorageHubClient();
|
2021-04-29 16:58:14 +02:00
|
|
|
|
2018-09-28 17:02:20 +02:00
|
|
|
FileContainer file = null;
|
2021-04-29 16:58:14 +02:00
|
|
|
try(InputStream is = new FileInputStream(new File("c:\\Users\\tilli\\Downloads\\expired.png"))){
|
|
|
|
file = shc.getWSRoot().uploadFile(is, "expired/exp.png", "test");
|
2019-05-07 11:41:57 +02:00
|
|
|
}
|
2021-04-29 16:58:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
//file.copy(shc.getWSRoot(), "firstCopy.jpg");
|
2018-03-29 18:19:01 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-26 15:24:21 +02:00
|
|
|
@Test
|
|
|
|
public void download() throws Exception {
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
|
2021-04-29 16:58:14 +02:00
|
|
|
|
|
|
|
StreamDescriptor streamDescr = shc.open("abb59b44-e3cb-408d-a1ff-73d6d8ad2ca1").asFile().download();
|
2020-04-09 14:52:26 +02:00
|
|
|
System.out.println("length "+streamDescr.getContentLenght());
|
2020-03-05 15:19:45 +01:00
|
|
|
long start = System.currentTimeMillis();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-26 15:24:21 +02:00
|
|
|
File output = Files.createTempFile("down", streamDescr.getFileName()).toFile();
|
|
|
|
try (BufferedInputStream bi = new BufferedInputStream(streamDescr.getStream()); FileOutputStream fo = new FileOutputStream(output)){
|
2020-03-05 15:19:45 +01:00
|
|
|
byte[] buf = new byte[2046];
|
2018-09-26 15:24:21 +02:00
|
|
|
int read = -1;
|
|
|
|
while ((read=bi.read(buf))!=-1) {
|
|
|
|
fo.write(buf, 0, read);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-29 16:58:14 +02:00
|
|
|
|
|
|
|
|
2020-03-05 15:19:45 +01:00
|
|
|
System.out.println("file written "+output.getAbsolutePath()+" in "+(System.currentTimeMillis()-start));
|
2021-04-29 16:58:14 +02:00
|
|
|
|
2018-09-26 15:24:21 +02:00
|
|
|
}
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2018-09-24 16:42:00 +02:00
|
|
|
@Test
|
2021-10-15 19:53:14 +02:00
|
|
|
public void addUser() throws Exception {
|
2022-07-27 11:09:05 +02:00
|
|
|
/*AccessTokenSecret secret = new AccessTokenSecret("eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJSSklZNEpoNF9qdDdvNmREY0NlUDFfS1l0akcxVExXVW9oMkQ2Tzk1bFNBIn0.eyJleHAiOjE2NDQyNDM4ODUsImlhdCI6MTY0NDI0MzU4NSwiYXV0aF90aW1lIjoxNjQ0MjQzNTg1LCJqdGkiOiI1NWQ4ZDc5OS1kNTIzLTQ0YmEtYTRkMC1iZjIyYzVlMTg4NzQiLCJpc3MiOiJodHRwczovL2FjY291bnRzLmRldi5kNHNjaWVuY2Uub3JnL2F1dGgvcmVhbG1zL2Q0c2NpZW5jZSIsImF1ZCI6IiUyRmdjdWJlIiwic3ViIjoiNGMxMWRlODQtZGRjOS00ZGQxLWI5N2EtZWE4MmQyZDEzOGE2IiwidHlwIjoiQmVhcmVyIiwiYXpwIjoibmV4dC5kNHNjaWVuY2Uub3JnIiwic2Vzc2lvbl9zdGF0ZSI6ImZkZTA3MGE2LTVkOTUtNDc3Ni1hMTFiLTBhZTI1MzQ5NGQyMyIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOlsiLyoiXSwicmVzb3VyY2VfYWNjZXNzIjp7IiUyRmdjdWJlIjp7InJvbGVzIjpbIkluZnJhc3RydWN0dXJlLU1hbmFnZXIiLCJNZW1iZXIiXX19LCJhdXRob3JpemF0aW9uIjp7InBlcm1pc3Npb25zIjpbeyJyc2lkIjoiMTU5ZDcyMDQtNjlmYS00ZmY0LTlhOTQtMzVlMWUyMzA5MDQyIiwicnNuYW1lIjoiRGVmYXVsdCBSZXNvdXJjZSJ9XX0sInNjb3BlIjoiZW1haWwgcHJvZmlsZSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJuYW1lIjoiTHVjaW8gTGVsaWkiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJsdWNpby5sZWxpaSIsImdpdmVuX25hbWUiOiJMdWNpbyIsImZhbWlseV9uYW1lIjoiTGVsaWkiLCJlbWFpbCI6Imx1Y2lvLmxlbGlpQGlzdGkuY25yLml0In0.SGuGXnY63WJ45tdypywaopO--FCxY6ZWAX74MGVw_zdNMMQI5zgtGfhZQewFWQ6HhVINDStXqvdSDluhF9JwFXCUGvxB2BipfKQYsAQnm3I4K3kgMl26kuQIL5Im-apw2XWvImTgLshX1AzpyqzFR1Jpf_p65GCMpcHLEwo_nTGLkrZNtfRdtqakZ8S8lowGaV2J2mNf4AHhtARSLJF3GqwynF5pPUXR2iOMUrjw_FLnIuPMfAjk_jHMeYKIxXNBLsoEpELju3pr2gEkv1ZRH9bZkyg7_3hW4mGzxq_Ea9w1FBVJOlkp6vypuISLNyJZcVOnBa4Dg1KRxxlp3aZ6vA");
|
|
|
|
SecretManagerProvider.instance.set(secret);*/
|
2021-10-15 19:53:14 +02:00
|
|
|
StorageHubClient shc = new StorageHubClient();
|
2022-11-15 17:58:25 +01:00
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
shc.getVreFolderManager("gcube-devsec-devVre").addUser("vincenzo.cestone");
|
2021-10-15 19:53:14 +02:00
|
|
|
}
|
2022-11-15 17:58:25 +01:00
|
|
|
|
2021-10-15 19:53:14 +02:00
|
|
|
@Test
|
|
|
|
public void removeUser() throws Exception {
|
2018-09-24 16:42:00 +02:00
|
|
|
StorageHubClient shc = new StorageHubClient();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2022-11-11 17:28:12 +01:00
|
|
|
shc.deleteUserAccount("");
|
2018-09-24 16:42:00 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-11-15 17:58:25 +01:00
|
|
|
|
|
|
|
|
2019-07-25 17:47:18 +02:00
|
|
|
@Test
|
|
|
|
public void changeProp() throws Exception {
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
2021-04-29 16:58:14 +02:00
|
|
|
|
2019-07-25 17:47:18 +02:00
|
|
|
ItemContainer item = shc.open("6399daa7-2173-4314-b4f7-2afa24eae8f8").asItem();
|
|
|
|
Metadata first = item.get().getMetadata();
|
|
|
|
first.getMap().put("lucio", "ok");
|
2021-04-29 16:58:14 +02:00
|
|
|
|
2019-07-25 17:47:18 +02:00
|
|
|
item.setMetadata(first);
|
2021-04-29 16:58:14 +02:00
|
|
|
|
2019-07-25 17:47:18 +02:00
|
|
|
Metadata second = item.get().getMetadata();
|
|
|
|
for (Entry<String, Object> entry: second.getMap().entrySet())
|
|
|
|
System.out.println(entry.getKey()+" "+entry.getValue());
|
2021-04-29 16:58:14 +02:00
|
|
|
|
|
|
|
|
2019-07-25 17:47:18 +02:00
|
|
|
second.getMap().put("lucio", null);
|
|
|
|
second.getMap().put("lelii", "0");
|
2021-04-29 16:58:14 +02:00
|
|
|
|
2019-07-25 17:47:18 +02:00
|
|
|
item.setMetadata(second);
|
2021-04-29 16:58:14 +02:00
|
|
|
|
2019-07-25 17:47:18 +02:00
|
|
|
Metadata third = item.get().getMetadata();
|
|
|
|
for (Entry<String, Object> entry: third.getMap().entrySet())
|
|
|
|
System.out.println(entry.getKey()+" "+entry.getValue());
|
2021-04-29 16:58:14 +02:00
|
|
|
|
2019-07-25 17:47:18 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-10-15 19:53:14 +02:00
|
|
|
/*private InputStream urlToInputStream(URL url, Map<String, String> args) {
|
|
|
|
HttpURLConnection con = null;
|
|
|
|
InputStream inputStream = null;
|
|
|
|
try {
|
|
|
|
con = (HttpURLConnection) url.openConnection();
|
|
|
|
con.setConnectTimeout(15000);
|
|
|
|
con.setReadTimeout(15000);
|
|
|
|
if (args != null) {
|
|
|
|
for (Entry<String, String> e : args.entrySet()) {
|
|
|
|
con.setRequestProperty(e.getKey(), e.getValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
con.connect();
|
|
|
|
int responseCode = con.getResponseCode();
|
2022-11-15 17:58:25 +01:00
|
|
|
|
2021-10-15 19:53:14 +02:00
|
|
|
if (responseCode < 400 && responseCode > 299) {
|
|
|
|
String redirectUrl = con.getHeaderField("Location");
|
|
|
|
try {
|
|
|
|
URL newUrl = new URL(redirectUrl);
|
|
|
|
return urlToInputStream(newUrl, args);
|
|
|
|
} catch (MalformedURLException e) {
|
|
|
|
URL newUrl = new URL(url.getProtocol() + "://" + url.getHost() + redirectUrl);
|
|
|
|
return urlToInputStream(newUrl, args);
|
|
|
|
}
|
|
|
|
}
|
2022-11-15 17:58:25 +01:00
|
|
|
|
2021-10-15 19:53:14 +02:00
|
|
|
|
|
|
|
inputStream = con.getInputStream();
|
|
|
|
return inputStream;
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}*/
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-07-30 12:38:34 +02:00
|
|
|
@Test
|
|
|
|
public void uploadArchive() throws Exception {
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
|
2021-10-15 19:53:14 +02:00
|
|
|
URL remote = new URI("https://data.bluecloud.cineca.it/api/download/gAAAAABhaSJN8TUA71la3mKMOL9D"
|
|
|
|
+ "mioSBvOehbZlu54_jvscz8Zu3LXgqhr8RfJemd83QIh47z6TyMn3mD0OjpcG5g0qf9WUZCeW1J4btEqNObkaWv"
|
|
|
|
+ "pMhabvswweyFn1Jg4m5GpwCoKayvgsYYwjbjsGsQW5Hileiw==").toURL();
|
2022-11-15 17:58:25 +01:00
|
|
|
|
|
|
|
|
2021-10-15 19:53:14 +02:00
|
|
|
try(InputStream is = remote.openStream() ){
|
|
|
|
shc.getWSRoot().uploadArchive(is, "testUploadArchive");
|
2018-07-30 12:38:34 +02:00
|
|
|
|
2022-11-15 17:58:25 +01:00
|
|
|
|
2018-07-30 12:38:34 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-07-05 16:24:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-22 17:42:29 +02:00
|
|
|
@Test
|
2019-03-13 18:33:58 +01:00
|
|
|
public void getPublicLink() throws Exception{
|
2018-06-22 17:42:29 +02:00
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
System.out.println(shc.open("c2573eec-3942-47ec-94a7-04869e97bb69").asFile().getPublicLink());
|
|
|
|
}
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2018-06-26 15:30:30 +02:00
|
|
|
@Test
|
|
|
|
public void findByName() throws Exception{
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-01-03 12:16:53 +01:00
|
|
|
FolderContainer root = shc.open("2fd081dc-3b57-4e5f-aadf-38439aea4c1f").asFolder();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-01-03 12:16:53 +01:00
|
|
|
FolderContainer fc = root.newFolder("Computations", "description");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-01-03 12:16:53 +01:00
|
|
|
fc.share(new HashSet<>(Arrays.asList("giancarlo.panichi")), AccessType.READ_ONLY);
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-01-03 12:16:53 +01:00
|
|
|
System.out.println(fc.get().getPath()+" "+fc.getId());
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
2018-06-26 15:30:30 +02:00
|
|
|
}
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2018-06-27 15:36:50 +02:00
|
|
|
@Test
|
|
|
|
public void delete() throws Exception{
|
2021-04-29 16:58:14 +02:00
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
FolderContainer container = shc.getWSRoot();
|
|
|
|
try {
|
|
|
|
FolderContainer attachmentFolder = container.openByRelativePath("Attachment").asFolder();
|
|
|
|
FolderItem folder = attachmentFolder.get();
|
|
|
|
} catch (StorageHubException e) {
|
|
|
|
System.out.println("creating folder");
|
|
|
|
container.newFolder("Attachment","Folder created automatically by the System");
|
2018-10-04 16:53:47 +02:00
|
|
|
}
|
2021-04-29 16:58:14 +02:00
|
|
|
|
2018-06-27 15:36:50 +02:00
|
|
|
}
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2021-04-29 16:58:14 +02:00
|
|
|
@Test
|
|
|
|
public void createFolderWhenNotExists() throws Exception{
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
FolderContainer container = shc.openVREFolder();
|
2022-11-15 17:58:25 +01:00
|
|
|
|
2021-04-29 16:58:14 +02:00
|
|
|
try {
|
|
|
|
FolderContainer attachmentFolder = container.openByRelativePath("Attachment-Lucio").asFolder();
|
|
|
|
System.out.println("fodler name is "+attachmentFolder.get().getName());
|
|
|
|
} catch (StorageHubException e) {
|
|
|
|
System.out.println("creating folder");
|
|
|
|
container.newFolder("Attachment-Lucio","Folder created automatically by the System");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-11-15 17:58:25 +01:00
|
|
|
|
2018-06-22 10:52:56 +02:00
|
|
|
@Test
|
2019-03-13 18:33:58 +01:00
|
|
|
public void downloadFile() throws Exception{
|
2018-06-22 10:52:56 +02:00
|
|
|
StorageHubClient shc = new StorageHubClient();
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
try {
|
|
|
|
for (ItemContainer<? extends Item> cont : shc.getWSRoot().list().getContainers()) {
|
|
|
|
if (cont.get().getTitle().equals("LucioShare1")) {
|
|
|
|
for (ItemContainer<? extends Item> c: ((FolderContainer)cont).list().getContainers()) {
|
|
|
|
c.get().getTitle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}catch (StorageHubException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
for (ItemContainer<? extends Item> cont : shc.getWSRoot().list().getContainers()) {
|
|
|
|
System.out.println(cont.get().getTitle());
|
|
|
|
}
|
|
|
|
}catch (StorageHubException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
/*
|
2019-01-14 11:51:19 +01:00
|
|
|
List<? extends Item> items = shc.getWSRoot().findByName("MyFo*").getItems();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-01-14 11:51:19 +01:00
|
|
|
for (Item item: items)
|
|
|
|
System.out.println(item.getName()+" "+item.getTitle()+" "+item.getClass().getSimpleName());
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-01-14 11:51:19 +01:00
|
|
|
/*
|
|
|
|
URL link = shc.open("6c5fb143-3711-4097-9bdc-952e41355440").asFile().getPublicLink("1.1");
|
|
|
|
System.out.println(link.toString());
|
|
|
|
/*
|
2019-01-08 12:17:36 +01:00
|
|
|
File targetFile = new File("/tmp/"+descr.getFileName());
|
|
|
|
|
|
|
|
try {
|
|
|
|
java.nio.file.Files.copy(
|
|
|
|
descr.getStream(),
|
|
|
|
targetFile.toPath(),
|
|
|
|
StandardCopyOption.REPLACE_EXISTING);
|
|
|
|
} catch (IOException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
System.out.println("file created "+targetFile.getAbsolutePath());
|
|
|
|
/*
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-06-22 10:52:56 +02:00
|
|
|
List<ItemContainer<? extends Item>> containers = shc.getWSRoot().list().getContainers();
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2018-06-22 10:52:56 +02:00
|
|
|
for (ItemContainer<? extends Item> container : containers) {
|
|
|
|
if (container.getType()==ContainerType.FILE) {
|
|
|
|
FileContainer file = (FileContainer) container;
|
|
|
|
StreamDescriptor descr = file.download();
|
|
|
|
File targetFile = new File("/tmp/"+descr.getFileName());
|
2018-07-05 16:24:49 +02:00
|
|
|
|
|
|
|
try {
|
2018-06-22 10:52:56 +02:00
|
|
|
java.nio.file.Files.copy(
|
|
|
|
descr.getStream(),
|
2018-07-05 16:24:49 +02:00
|
|
|
targetFile.toPath(),
|
|
|
|
StandardCopyOption.REPLACE_EXISTING);
|
2018-06-22 10:52:56 +02:00
|
|
|
} catch (IOException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2018-07-05 16:24:49 +02:00
|
|
|
System.out.println("file created "+targetFile.getAbsolutePath());
|
|
|
|
break;
|
2018-06-22 10:52:56 +02:00
|
|
|
}
|
2019-01-08 12:17:36 +01:00
|
|
|
}*/
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2018-06-22 10:52:56 +02:00
|
|
|
}
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
2018-09-04 11:21:08 +02:00
|
|
|
@Test
|
|
|
|
public void downloadFolderWithExcludes() throws Exception{
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
|
2021-04-29 16:58:14 +02:00
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
StreamDescriptor streamDescr = shc.open("6eb20db1-2921-41ec-ab79-909edd9b58fd").asItem().download("05098be5-61a2-423a-b382-9399a04df11e");
|
|
|
|
|
2018-09-04 11:21:08 +02:00
|
|
|
File tmpFile = Files.createTempFile(streamDescr.getFileName(),"").toFile();
|
|
|
|
System.out.println(tmpFile.getAbsolutePath());
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-04 11:21:08 +02:00
|
|
|
try(FileOutputStream fos = new FileOutputStream(tmpFile)){
|
|
|
|
InputStream is = streamDescr.getStream();
|
|
|
|
byte[] buf = new byte[2048];
|
|
|
|
int read= -1;
|
|
|
|
while ((read=is.read(buf))!=-1) {
|
|
|
|
fos.write(buf, 0, read);
|
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-04 11:21:08 +02:00
|
|
|
}
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2018-09-04 11:21:08 +02:00
|
|
|
}
|
2022-12-14 14:54:08 +01:00
|
|
|
|
|
|
|
|
2021-04-29 16:58:14 +02:00
|
|
|
@Test
|
|
|
|
public void deleteUnusefulUsers() throws Exception{
|
|
|
|
final UserManagerClient client = AbstractPlugin.users().build();
|
|
|
|
List<String> users = client.getUsers();
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
for (String user : users)
|
|
|
|
if (user.startsWith("userm")) {
|
|
|
|
shc.deleteUserAccount(user);
|
|
|
|
System.out.println("user "+user+"removed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-15 19:53:14 +02:00
|
|
|
@Test
|
|
|
|
public void removeGroup() throws Exception{
|
|
|
|
StorageHubClient sh = new StorageHubClient();
|
|
|
|
VREFolderManager vreMan = sh.getVreFolderManager("d4science.research-infrastructures.eu-OpenAIRE-OpenAIRE-Connect_EAB");
|
|
|
|
vreMan.removeVRE();
|
|
|
|
}
|
2021-04-29 16:58:14 +02:00
|
|
|
|
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
/*
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
static String baseUrl="http://workspace-repository1-d.d4science.org/storagehub";
|
|
|
|
|
2018-07-05 16:24:49 +02:00
|
|
|
|
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
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)*/;
|
2018-07-05 16:24:49 +02:00
|
|
|
/*
|
2018-02-15 18:13:50 +01:00
|
|
|
Response res = webTarget.request().post(Entity.entity(multiPart, multiPart.getMediaType()));
|
|
|
|
System.out.println("status is "+res.getStatus());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void create() throws Exception{
|
2018-07-05 16:24:49 +02:00
|
|
|
|
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
ClientConfig clientConfig = new ClientConfig();
|
|
|
|
clientConfig.property("DEFAULT_CHUNK_SIZE", 2048);
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
Clie
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
//Client client = ClientBuilder.newClient();
|
|
|
|
Client client = ClientBuilder.newClient(clientConfig)
|
|
|
|
.register(MultiPartFeature.class);
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
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");
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
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");
|
2018-07-05 16:24:49 +02:00
|
|
|
*/
|
2018-02-15 18:13:50 +01:00
|
|
|
|
2018-07-05 16:24:49 +02:00
|
|
|
/*
|
2018-02-15 18:13:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2018-07-05 16:24:49 +02:00
|
|
|
*/
|
2018-02-15 18:13:50 +01:00
|
|
|
|
2018-07-05 16:24:49 +02:00
|
|
|
}
|