From 18d2fb9287ecc5d7598f08060976d271a0d6d9e3 Mon Sep 17 00:00:00 2001 From: lucio lelii Date: Tue, 15 Nov 2022 17:58:25 +0100 Subject: [PATCH] removed double call for upload file --- .../client/proxies/DefaultItemManager.java | 16 --- .../java/org/gcube/data/access/fs/Items.java | 105 ++++++++++-------- 2 files changed, 56 insertions(+), 65 deletions(-) diff --git a/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultItemManager.java b/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultItemManager.java index d028539..af878f5 100644 --- a/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultItemManager.java +++ b/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultItemManager.java @@ -662,22 +662,6 @@ public class DefaultItemManager extends DefaultManagerClient implements ItemMana multipart.bodyPart(filePart); response = myManager.queryParams(initQueryParameters()).post(Entity.entity(multipart, multipart.getMediaType())); - - - ContentDisposition contentDisposition; - if (contentLength>0) - contentDisposition = ContentDisposition.type("attachment").fileName(fileName).size(contentLength).build(); - else - contentDisposition = ContentDisposition.type("attachment").fileName(fileName).build(); - - - BodyPart fdp = new StreamDataBodyPart("file", stream); - - multipart.bodyPart(fdp); - - Entity entity = Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA); - - response = myManager.queryParams(initQueryParameters()).header("Content-Disposition",Arrays.asList(contentDisposition.toString())).post(entity); if (response.isErrorResponse()) { if (response.hasException()) { diff --git a/src/test/java/org/gcube/data/access/fs/Items.java b/src/test/java/org/gcube/data/access/fs/Items.java index 369e374..7ac4173 100644 --- a/src/test/java/org/gcube/data/access/fs/Items.java +++ b/src/test/java/org/gcube/data/access/fs/Items.java @@ -44,7 +44,7 @@ public class Items { private static final String tokens = "dev-devvre"; //private static final String tokens = "prod-root"; - + @BeforeClass public static void setUp(){ @@ -55,7 +55,7 @@ public class Items { String[] splitValue = value.split(","); String token = splitValue[1]; //SecretManagerProvider.instance.set(new GCubeSecret(token)); - + SecurityTokenProvider.instance.set(token); ScopeProvider.instance.set(splitValue[0]); } catch (Exception e) { @@ -64,14 +64,14 @@ public class Items { } - + @Test public void addUserToVRe() throws StorageHubException { StorageHubClient shc = new StorageHubClient(); - - + + String vresFile = "C:\\Users\\tilli\\Downloads\\vresToAddGCat.txt"; - + try(InputStream is = new FileInputStream(new File(vresFile))){ Properties prop = new Properties(); prop.load(is); @@ -85,32 +85,32 @@ public class Items { e.printStackTrace(); } } - + }catch (Exception e) { e.printStackTrace(); } - - - + + + } @Test public void uploadTovolatile() throws StorageHubException { StorageHubClient shc = new StorageHubClient(); - - + + String vresFile = "/home/lucio/Downloads/stampa_crossover_retro.pdf"; - + File file = new File(vresFile); - + try ( InputStream fileIS = new FileInputStream(file)){ - shc.getWSRoot().uploadFile(fileIS, "stampa_crossover_retro.pdf", "description"); + shc.getWSRoot().uploadFile(fileIS, "stampa_crossover_retro.pdf", "description"); } catch (Exception e) { e.printStackTrace(); } } - - + + @Test public void removeTest() { try { @@ -128,29 +128,36 @@ public class Items { e.printStackTrace(); } } - + @Test public void stressTest() { try { - - - IntStream.range(1, 100).forEach( i-> { + + + IntStream.range(1, 300).forEach( i-> { try { StorageHubClient shc = new StorageHubClient(); FolderContainer vre = shc.openVREFolder().openByRelativePath("testLucio").asFolder(); FolderContainer fc = vre.newFolder("folder"+i, ""); - IntStream.range(1, 3).forEach(k -> { - String vresFile = "/home/lucio/Scaricati/NLP-Hub-Algorithms.pptx"; - - File file = new File(vresFile); - - try ( InputStream fileIS = new FileInputStream(file)){ - fc.uploadFile(fileIS, "file"+k, "description"); - } catch (Exception e) { - e.printStackTrace(); + for (int t =1 ; t<10; t++) { + StorageHubClient shc1 = new StorageHubClient(); + FolderContainer sub = shc1.open(fc.getId()).asFolder(); + FolderContainer fcsub2 = sub.newFolder("folder"+i+"-"+t, ""); + for (int k=0;k<3;k++) { + String vresFile = "/home/lucio/Downloads/GNA_foto_Cuma Necropoli mediana_4B.jpg"; + + StorageHubClient shc2 = new StorageHubClient(); + FolderContainer sub2 = shc2.open(fcsub2.getId()).asFolder(); + + File file = new File(vresFile); + + try ( InputStream fileIS = new FileInputStream(file)){ + sub2.uploadFile(fileIS, "file"+k, "description"); + } catch (Exception e) { + e.printStackTrace(); + } } - }); - + } } catch (StorageHubException e) { System.out.println("error creating stressTest"+i); } @@ -159,7 +166,7 @@ public class Items { e.printStackTrace(); } } - + @Test public void search() { try { @@ -222,7 +229,7 @@ public class Items { } } - + @Test public void getItem() throws Exception{ StorageHubClient shc = new StorageHubClient(); @@ -230,7 +237,7 @@ public class Items { System.out.println("owner is "+owner); } - + @Test public void uploadFile() throws Exception{ @@ -238,12 +245,12 @@ public class Items { FolderContainer myRoot = shc.open("11cbdc0c-e873-418c-bc53-5f6329eb88fb").asFolder(); - + long start = System.currentTimeMillis(); - + File inFile = new File("/home/lucio/Downloads/scimmia braccia aperte.mp4"); try(InputStream is = new FileInputStream(inFile)){ - myRoot.uploadFile(is, "scimmia braccia aperte.mp4", "file"); + myRoot.uploadFile(is, "scimmia braccia aperte.mp4", "file"); } System.out.println("Response in "+(System.currentTimeMillis()-start)); @@ -296,10 +303,10 @@ public class Items { /*AccessTokenSecret secret = new AccessTokenSecret("eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJSSklZNEpoNF9qdDdvNmREY0NlUDFfS1l0akcxVExXVW9oMkQ2Tzk1bFNBIn0.eyJleHAiOjE2NDQyNDM4ODUsImlhdCI6MTY0NDI0MzU4NSwiYXV0aF90aW1lIjoxNjQ0MjQzNTg1LCJqdGkiOiI1NWQ4ZDc5OS1kNTIzLTQ0YmEtYTRkMC1iZjIyYzVlMTg4NzQiLCJpc3MiOiJodHRwczovL2FjY291bnRzLmRldi5kNHNjaWVuY2Uub3JnL2F1dGgvcmVhbG1zL2Q0c2NpZW5jZSIsImF1ZCI6IiUyRmdjdWJlIiwic3ViIjoiNGMxMWRlODQtZGRjOS00ZGQxLWI5N2EtZWE4MmQyZDEzOGE2IiwidHlwIjoiQmVhcmVyIiwiYXpwIjoibmV4dC5kNHNjaWVuY2Uub3JnIiwic2Vzc2lvbl9zdGF0ZSI6ImZkZTA3MGE2LTVkOTUtNDc3Ni1hMTFiLTBhZTI1MzQ5NGQyMyIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOlsiLyoiXSwicmVzb3VyY2VfYWNjZXNzIjp7IiUyRmdjdWJlIjp7InJvbGVzIjpbIkluZnJhc3RydWN0dXJlLU1hbmFnZXIiLCJNZW1iZXIiXX19LCJhdXRob3JpemF0aW9uIjp7InBlcm1pc3Npb25zIjpbeyJyc2lkIjoiMTU5ZDcyMDQtNjlmYS00ZmY0LTlhOTQtMzVlMWUyMzA5MDQyIiwicnNuYW1lIjoiRGVmYXVsdCBSZXNvdXJjZSJ9XX0sInNjb3BlIjoiZW1haWwgcHJvZmlsZSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJuYW1lIjoiTHVjaW8gTGVsaWkiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJsdWNpby5sZWxpaSIsImdpdmVuX25hbWUiOiJMdWNpbyIsImZhbWlseV9uYW1lIjoiTGVsaWkiLCJlbWFpbCI6Imx1Y2lvLmxlbGlpQGlzdGkuY25yLml0In0.SGuGXnY63WJ45tdypywaopO--FCxY6ZWAX74MGVw_zdNMMQI5zgtGfhZQewFWQ6HhVINDStXqvdSDluhF9JwFXCUGvxB2BipfKQYsAQnm3I4K3kgMl26kuQIL5Im-apw2XWvImTgLshX1AzpyqzFR1Jpf_p65GCMpcHLEwo_nTGLkrZNtfRdtqakZ8S8lowGaV2J2mNf4AHhtARSLJF3GqwynF5pPUXR2iOMUrjw_FLnIuPMfAjk_jHMeYKIxXNBLsoEpELju3pr2gEkv1ZRH9bZkyg7_3hW4mGzxq_Ea9w1FBVJOlkp6vypuISLNyJZcVOnBa4Dg1KRxxlp3aZ6vA"); SecretManagerProvider.instance.set(secret);*/ StorageHubClient shc = new StorageHubClient(); - + shc.getVreFolderManager("gcube-devsec-devVre").addUser("vincenzo.cestone"); } - + @Test public void removeUser() throws Exception { StorageHubClient shc = new StorageHubClient(); @@ -308,8 +315,8 @@ public class Items { } - - + + @Test public void changeProp() throws Exception { StorageHubClient shc = new StorageHubClient(); @@ -351,7 +358,7 @@ public class Items { } con.connect(); int responseCode = con.getResponseCode(); - + if (responseCode < 400 && responseCode > 299) { String redirectUrl = con.getHeaderField("Location"); try { @@ -362,7 +369,7 @@ public class Items { return urlToInputStream(newUrl, args); } } - + inputStream = con.getInputStream(); return inputStream; @@ -378,12 +385,12 @@ public class Items { URL remote = new URI("https://data.bluecloud.cineca.it/api/download/gAAAAABhaSJN8TUA71la3mKMOL9D" + "mioSBvOehbZlu54_jvscz8Zu3LXgqhr8RfJemd83QIh47z6TyMn3mD0OjpcG5g0qf9WUZCeW1J4btEqNObkaWv" + "pMhabvswweyFn1Jg4m5GpwCoKayvgsYYwjbjsGsQW5Hileiw==").toURL(); - - + + try(InputStream is = remote.openStream() ){ shc.getWSRoot().uploadArchive(is, "testUploadArchive"); - + } catch (Exception e) { e.printStackTrace(); } @@ -431,7 +438,7 @@ public class Items { public void createFolderWhenNotExists() throws Exception{ StorageHubClient shc = new StorageHubClient(); FolderContainer container = shc.openVREFolder(); - + try { FolderContainer attachmentFolder = container.openByRelativePath("Attachment-Lucio").asFolder(); System.out.println("fodler name is "+attachmentFolder.get().getName()); @@ -441,7 +448,7 @@ public class Items { } } - + @Test public void downloadFile() throws Exception{ StorageHubClient shc = new StorageHubClient();