From ddd04c0ff356a25bc556c991800e03f9d8de683d Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Thu, 19 Dec 2019 16:21:01 +0100 Subject: [PATCH] Changed metadata checks due to changed in storage hub client library --- .../storagehub/StorageHubManagement.java | 4 +- .../org/gcube/storagehub/ContextTest.java | 4 +- .../storagehub/StorageHubManagementTest.java | 45 ++++++++++++++++++- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/gcube/storagehub/StorageHubManagement.java b/src/main/java/org/gcube/storagehub/StorageHubManagement.java index 4acfa5b..b266a83 100644 --- a/src/main/java/org/gcube/storagehub/StorageHubManagement.java +++ b/src/main/java/org/gcube/storagehub/StorageHubManagement.java @@ -191,7 +191,7 @@ public class StorageHubManagement { for(String name : splittedMimeType) { destinationFolder = getOrCreateFolder(destinationFolder, name, "Folder Created using mimetype", false); } - return destinationFolder; + return destinationFolder; } protected boolean isPersistedFile(FileContainer fileContainer, String filename) { @@ -231,7 +231,7 @@ public class StorageHubManagement { public void removePersistedFile(String filename, String mimeType) throws Exception { FolderContainer destinationFolder = getDestinationFolder(mimeType); ListResolver listResolver = destinationFolder.findByName(filename); - List> itemContainers = listResolver.getContainers(); + List> itemContainers = listResolver.withMetadata().getContainers(); for(ItemContainer itemContainer : itemContainers) { if(itemContainer.getType()==ContainerType.FILE) { if(isPersistedFile((FileContainer) itemContainer, filename)) { diff --git a/src/test/java/org/gcube/storagehub/ContextTest.java b/src/test/java/org/gcube/storagehub/ContextTest.java index 5f04807..9e16b4d 100644 --- a/src/test/java/org/gcube/storagehub/ContextTest.java +++ b/src/test/java/org/gcube/storagehub/ContextTest.java @@ -44,8 +44,8 @@ public class ContextTest { throw new RuntimeException(e); } - DEFAULT_TEST_SCOPE_NAME = "/pred4s/preprod/preVRE"; - //DEFAULT_TEST_SCOPE_NAME = "/gcube/devNext/NextNext"; + //DEFAULT_TEST_SCOPE_NAME = "/pred4s/preprod/preVRE"; + DEFAULT_TEST_SCOPE_NAME = "/gcube/devNext/NextNext"; } public static String getCurrentScope(String token) throws ObjectNotFound, Exception { diff --git a/src/test/java/org/gcube/storagehub/StorageHubManagementTest.java b/src/test/java/org/gcube/storagehub/StorageHubManagementTest.java index dc14ca2..9f52018 100644 --- a/src/test/java/org/gcube/storagehub/StorageHubManagementTest.java +++ b/src/test/java/org/gcube/storagehub/StorageHubManagementTest.java @@ -13,8 +13,11 @@ import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder; import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; import org.gcube.common.storagehub.client.dsl.FileContainer; import org.gcube.common.storagehub.client.dsl.FolderContainer; +import org.gcube.common.storagehub.client.dsl.ItemContainer; +import org.gcube.common.storagehub.client.dsl.ListResolver; import org.gcube.common.storagehub.client.dsl.OpenResolver; import org.gcube.common.storagehub.model.Metadata; +import org.gcube.common.storagehub.model.items.Item; import org.gcube.common.storagehub.model.service.Version; import org.junit.Test; import org.slf4j.Logger; @@ -84,12 +87,12 @@ public class StorageHubManagementTest extends ContextTest { applicationMode.end(); } - //@Test + @Test public void getFileInfo() throws Exception { ApplicationMode applicationMode = new ApplicationMode(ContextTest.properties.getProperty(DEFAULT_TEST_SCOPE_NAME)); applicationMode.start(); StorageHubManagement storageHubManagement = new StorageHubManagement(); - String id = "71394bdc-296f-46d4-ab7b-ecc9abc36bdd"; + String id = "3daf465b-b84e-4d1c-9786-a388a267382c"; OpenResolver openResolver = storageHubManagement.storageHubClient.open(id); FileContainer fileContainer = (FileContainer) openResolver.asFile(); logger.debug("StorageHub ID {} - File Name {}", id, fileContainer.get().getName()); @@ -112,5 +115,43 @@ public class StorageHubManagementTest extends ContextTest { } applicationMode.end(); } + + @Test + public void getFileInfoViaDirectoryListing() throws Exception { + ApplicationMode applicationMode = new ApplicationMode(ContextTest.properties.getProperty(DEFAULT_TEST_SCOPE_NAME)); + applicationMode.start(); + StorageHubManagement storageHubManagement = new StorageHubManagement(); + String id = "22bd9034-1da0-45ac-868f-91d1e5438344"; + OpenResolver openResolver = storageHubManagement.storageHubClient.open(id); + FolderContainer folderContainer = (FolderContainer) openResolver.asFolder(); + String filename = "56a55300-9272-4c12-9ac8-ff61411a5976"; + ListResolver listResolver = folderContainer.findByName(filename); + List> itemContainers = listResolver.withMetadata().getContainers(); + for(ItemContainer itemContainer : itemContainers) { + + FileContainer fileContainer = (FileContainer) itemContainer; + + + logger.debug("StorageHub ID {} - File Name {}", id, fileContainer.get().getName()); + + /* + ListResolver listResolver = fileContainer.getAnchestors(); + List> itemContainers = listResolver.getContainers(); + for(ItemContainer itemContainer : itemContainers) { + logger.debug("{}", itemContainer.get().getName()); + } + */ + + Metadata metadata = fileContainer.get().getMetadata(); + Map map = metadata.getMap(); + logger.debug("{}", map); + + List versions = fileContainer.getVersions(); + for(Version version : versions){ + logger.debug("Version {} {}", version.getId(), version.getName()); + } + applicationMode.end(); + } + } }