Changed metadata checks due to changed in storage hub client library

This commit is contained in:
Luca Frosini 2019-12-19 16:21:01 +01:00
parent c13401825d
commit ddd04c0ff3
3 changed files with 47 additions and 6 deletions

View File

@ -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<ItemContainer<? extends Item>> itemContainers = listResolver.getContainers();
List<ItemContainer<? extends Item>> itemContainers = listResolver.withMetadata().getContainers();
for(ItemContainer<? extends Item> itemContainer : itemContainers) {
if(itemContainer.getType()==ContainerType.FILE) {
if(isPersistedFile((FileContainer) itemContainer, filename)) {

View File

@ -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 {

View File

@ -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<ItemContainer<? extends Item>> itemContainers = listResolver.withMetadata().getContainers();
for(ItemContainer<? extends Item> itemContainer : itemContainers) {
FileContainer fileContainer = (FileContainer) itemContainer;
logger.debug("StorageHub ID {} - File Name {}", id, fileContainer.get().getName());
/*
ListResolver listResolver = fileContainer.getAnchestors();
List<ItemContainer<? extends Item>> itemContainers = listResolver.getContainers();
for(ItemContainer<? extends Item> itemContainer : itemContainers) {
logger.debug("{}", itemContainer.get().getName());
}
*/
Metadata metadata = fileContainer.get().getMetadata();
Map<String,Object> map = metadata.getMap();
logger.debug("{}", map);
List<Version> versions = fileContainer.getVersions();
for(Version version : versions){
logger.debug("Version {} {}", version.getId(), version.getName());
}
applicationMode.end();
}
}
}