Fixed workspace folder creation #19056

This commit is contained in:
Luca Frosini 2020-04-11 00:10:02 +02:00
parent 1f560d0b01
commit 4477b0e735
6 changed files with 64 additions and 13 deletions

View File

@ -2,6 +2,7 @@
<!DOCTYPE xml>
<ReleaseNotes>
<Changeset component="org.gcube.accounting.accounting-aggregator-se-plugin.1.6.0" date="${buildDate}">
<Change>Fixed workspace folder creation #19056</Change>
<Change>Using StorageHubClient in place of Home Library Webapp HTTP calls</Change>
<Change>Added the generation of a CSV to post analyze the calledMethods</Change>
<Change>Fixing project to migrate monthly aggregated accounting records in a dedicated bucket #12803</Change>

View File

@ -8,7 +8,7 @@ import org.gcube.common.storagehub.client.dsl.FolderContainer;
*/
public class WorkSpaceDirectoryStructure extends DirectoryStructure<FolderContainer>{
private static final String BACKUP_FOLDER_DESCRIPTION = "Accounting Aggregator Plugin Backup Folder";
public static final String BACKUP_FOLDER_DESCRIPTION = "Accounting Aggregator Plugin Backup Folder";
@Override
protected FolderContainer getRoot() throws Exception {

View File

@ -9,11 +9,13 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.gcube.accounting.aggregator.utility.Utility;
import org.gcube.common.storagehub.client.dsl.ContainerType;
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.ListResolverTyped;
import org.gcube.common.storagehub.client.dsl.ListResolver;
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
import org.gcube.common.storagehub.model.items.Item;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -127,9 +129,26 @@ public class WorkSpaceManagement {
}
}
protected FolderContainer getFolder(FolderContainer parent, String name) throws StorageHubException {
FolderContainer destinationFolder = null;
ListResolver listResolver = parent.findByName(name);
List<ItemContainer<? extends Item>> itemContainers = listResolver.getContainers();
if(itemContainers.size()>=1){
ItemContainer<? extends Item> itemContainer = itemContainers.get(0);
if(itemContainer.getType().compareTo(ContainerType.FOLDER)==0) {
destinationFolder = (FolderContainer) itemContainer;
}
}
return destinationFolder;
}
public FolderContainer getOrCreateFolder(FolderContainer parent, String name, String description, boolean hidden)
throws Exception {
FolderContainer destinationFolder = null;
FolderContainer destinationFolder = getFolder(parent, name);
/*
ListResolverTyped listResolverTyped = parent.list();
List<ItemContainer<? extends Item>> containers = listResolverTyped.includeHidden().getContainers();
for(ItemContainer<? extends Item> itemContainer : containers) {
@ -139,6 +158,8 @@ public class WorkSpaceManagement {
}
}
}
*/
if(destinationFolder == null) {
if(hidden) {
destinationFolder = parent.newHiddenFolder(name, description);

View File

@ -31,11 +31,11 @@ public class ContextTest {
protected static Properties properties;
protected static final String PROPERTIES_FILENAME = "token.properties";
public static final String PARENT_DEFAULT_TEST_SCOPE;
public static final String DEFAULT_TEST_SCOPE;
public static final String ALTERNATIVE_TEST_SCOPE;
public static final String ROOT_DEV_SCOPE;
public static final String VO_DEFAULT_TEST_SCOPE;
public static final String VRE_DEFAULT_TEST_SCOPE;
public static final String DEFAULT_TEST_SCOPE_ANOTHER_USER;
public static final String VO_DEFAULT_TEST_SCOPE_ANOTHER_USER;
static {
properties = new Properties();
@ -53,14 +53,14 @@ public class ContextTest {
// ALTERNATIVE_TEST_SCOPE = DEFAULT_TEST_SCOPE_NAME + "/preVRE";
PARENT_DEFAULT_TEST_SCOPE = "/gcube";
DEFAULT_TEST_SCOPE = PARENT_DEFAULT_TEST_SCOPE + "/devNext";
ALTERNATIVE_TEST_SCOPE = DEFAULT_TEST_SCOPE + "/NextNext";
ROOT_DEV_SCOPE = "/gcube";
VO_DEFAULT_TEST_SCOPE = ROOT_DEV_SCOPE + "/devNext";
VRE_DEFAULT_TEST_SCOPE = VO_DEFAULT_TEST_SCOPE + "/NextNext";
DEFAULT_TEST_SCOPE_ANOTHER_USER = "lucio.lelii_" + DEFAULT_TEST_SCOPE;
VO_DEFAULT_TEST_SCOPE_ANOTHER_USER = "lucio.lelii_" + VO_DEFAULT_TEST_SCOPE;
try {
setContextByName(DEFAULT_TEST_SCOPE);
setContextByName(VO_DEFAULT_TEST_SCOPE);
} catch(Exception e) {
throw new RuntimeException(e);
}
@ -91,7 +91,7 @@ public class ContextTest {
@BeforeClass
public static void beforeClass() throws Exception {
setContextByName(DEFAULT_TEST_SCOPE);
setContextByName(VO_DEFAULT_TEST_SCOPE);
}
@AfterClass

View File

@ -0,0 +1,28 @@
package org.gcube.accounting.aggregator.workspace;
import org.gcube.accounting.aggregator.directory.WorkSpaceDirectoryStructure;
import org.gcube.accounting.aggregator.plugin.ContextTest;
import org.gcube.common.storagehub.client.dsl.FolderContainer;
import org.junit.Test;
public class WorkSpaceManagementTest extends ContextTest {
@Test
public void testCreatedirectory() throws Exception {
ContextTest.setContextByName(ROOT_DEV_SCOPE);
//ContextTest.setContextByName(AccountingAggregatorPluginTest.ROOT_PROD);
WorkSpaceManagement workSpaceManagement = WorkSpaceManagement.getInstance();
FolderContainer root = workSpaceManagement.getWorkspaceRoot();
for(int i=0; i<5; i++) {
FolderContainer accountingAggregatorPlugin = workSpaceManagement.getOrCreateFolder(root, "Accounting-Aggregator-Plugin", WorkSpaceDirectoryStructure.BACKUP_FOLDER_DESCRIPTION, false);
FolderContainer yearly = workSpaceManagement.getOrCreateFolder(accountingAggregatorPlugin, "MONTHLY", WorkSpaceDirectoryStructure.BACKUP_FOLDER_DESCRIPTION, false);
workSpaceManagement.getOrCreateFolder(yearly, "2015", WorkSpaceDirectoryStructure.BACKUP_FOLDER_DESCRIPTION, false);
workSpaceManagement.getOrCreateFolder(yearly, "2016", WorkSpaceDirectoryStructure.BACKUP_FOLDER_DESCRIPTION, false);
}
}
}

View File

@ -3,3 +3,4 @@
/gcube.gcubekey
/preprod.gcubekey
/token.properties
/d4science.research-infrastructures.eu.gcubekey