Reintroduced usage of Home Library
This commit is contained in:
parent
562150526a
commit
c13401825d
|
@ -1,3 +1,4 @@
|
|||
target
|
||||
.classpath
|
||||
.project
|
||||
.settings
|
||||
|
|
12
pom.xml
12
pom.xml
|
@ -57,6 +57,18 @@
|
|||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>gxHTTP</artifactId>
|
||||
</dependency>
|
||||
<!-- Home Library dependencies MUST be removed when the storagehub add missing features -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>home-library-jcr</artifactId>
|
||||
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>home-library</artifactId>
|
||||
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<!-- END of Home Library dependencies -->
|
||||
<!-- Test libraries -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
|
|
@ -5,6 +5,14 @@ import java.io.StringWriter;
|
|||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.homelibrary.home.Home;
|
||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
import org.gcube.common.homelibrary.home.HomeManager;
|
||||
import org.gcube.common.homelibrary.home.HomeManagerFactory;
|
||||
import org.gcube.common.homelibrary.home.User;
|
||||
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder;
|
||||
import org.gcube.common.homelibrary.home.workspace.usermanager.UserManager;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
||||
import org.gcube.common.storagehub.client.dsl.ContainerType;
|
||||
|
@ -13,6 +21,7 @@ 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.ListResolverTyped;
|
||||
import org.gcube.common.storagehub.client.dsl.OpenResolver;
|
||||
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
||||
import org.gcube.common.storagehub.model.Metadata;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
|
@ -79,7 +88,25 @@ public class StorageHubManagement {
|
|||
}
|
||||
|
||||
protected FolderContainer getWorkspaceRoot() {
|
||||
return storageHubClient.getWSRoot();
|
||||
try {
|
||||
return storageHubClient.getWSRoot();
|
||||
} catch(Exception e) {
|
||||
String username = ContextUtility.getUsername();
|
||||
logger.info("Unable to obtain the Workspace Root for {}. Going to create it.", username);
|
||||
try {
|
||||
HomeManagerFactory factory = HomeLibrary.getHomeManagerFactory();
|
||||
HomeManager manager = factory.getHomeManager();
|
||||
User user = manager.createUser(username);
|
||||
@SuppressWarnings("deprecation")
|
||||
Home home = manager.getHome(user);
|
||||
Workspace ws = home.getWorkspace();
|
||||
ws.getRoot();
|
||||
return storageHubClient.getWSRoot();
|
||||
} catch(Exception ex) {
|
||||
logger.info("Unable to create the Workspace Root for {}.", username);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected FolderContainer getOrCreateFolder(FolderContainer parent, String name, String description, boolean hidden)
|
||||
|
@ -116,7 +143,28 @@ public class StorageHubManagement {
|
|||
break;
|
||||
|
||||
case VRE:
|
||||
destinationFolder = storageHubClient.openVREFolder();
|
||||
String username = ContextUtility.getUsername();
|
||||
try {
|
||||
destinationFolder = storageHubClient.openVREFolder();
|
||||
}catch (Exception e) {
|
||||
try {
|
||||
|
||||
HomeManagerFactory factory = HomeLibrary.getHomeManagerFactory();
|
||||
UserManager userManager = factory.getUserManager();
|
||||
userManager.associateUserToGroup(currentContext, username);
|
||||
HomeManager manager = factory.getHomeManager();
|
||||
@SuppressWarnings("deprecation")
|
||||
Home home = manager.getHome(username);
|
||||
Workspace ws = home.getWorkspace();
|
||||
WorkspaceSharedFolder vreFolder= ws.getVREFolderByScope(currentContext);
|
||||
String id = vreFolder.getId();
|
||||
// destinationFolder = storageHubClient.openVREFolder();
|
||||
OpenResolver openResolver = storageHubClient.open(id);
|
||||
destinationFolder = openResolver.asFolder();
|
||||
}catch (Exception ex) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -28,84 +28,39 @@ public class ContextTest {
|
|||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ContextTest.class);
|
||||
|
||||
protected static final String PROPERTIES_FILENAME = "token.properties";
|
||||
protected static Properties properties;
|
||||
protected static final String PROPERTIES_FILENAME = "token.properties";
|
||||
|
||||
private static final String GCUBE_VARNAME = "GCUBE";
|
||||
public static final String GCUBE;
|
||||
|
||||
private static final String GCUBE_DEVNEXT_VARNAME = "GCUBE_DEVNEXT";
|
||||
public static final String GCUBE_DEVNEXT;
|
||||
|
||||
private static final String GCUBE_DEVNEXT_NEXTNEXT_VARNAME = "GCUBE_DEVNEXT_NEXTNEXT";
|
||||
public static final String GCUBE_DEVNEXT_NEXTNEXT;
|
||||
|
||||
public static final String GCUBE_DEVSEC_VARNAME = "GCUBE_DEVSEC";
|
||||
public static final String GCUBE_DEVSEC;
|
||||
|
||||
public static final String GCUBE_DEVSEC_DEVVRE_VARNAME = "GCUBE_DEVSEC_DEVVRE";
|
||||
public static final String GCUBE_DEVSEC_DEVVRE;
|
||||
|
||||
|
||||
private static final String GCUBE_DEVNEXT_ANOTHER_USER_VARNAME = "GCUBE_DEVNEXT_ANOTHER_USER";
|
||||
public static final String GCUBE_DEVNEXT_ANOTHER_USER;
|
||||
|
||||
public static final String DEFAULT_TEST_SCOPE;
|
||||
|
||||
public static final String GCUBE_PRE_PROD_PREVRE_VARNAME = "GCUBE_PRE_PROD_PREVRE";
|
||||
public static final String GCUBE_PRE_PROD_PREVRE;
|
||||
|
||||
public static final String GCUBE_PRE_PROD_PARTHENOS_REGISTRY_VARNAME = "GCUBE_PRE_PROD_PARTHENOS_REGISTRY";
|
||||
public static final String GCUBE_PRE_PROD_PARTHENOS_REGISTRY;
|
||||
|
||||
|
||||
public static final String GCUBE_PRE_PROD_PREVRE_APP_TOKEN_VARNAME = "GCUBE_PRE_PROD_PREVRE_APP_TOKEN";
|
||||
public static final String GCUBE_PRE_PROD_PREVRE_APP_TOKEN;
|
||||
|
||||
public static final String ROOT_VARNAME = "ROOT";
|
||||
public static final String ROOT;
|
||||
public static final String DEFAULT_TEST_SCOPE_NAME;
|
||||
|
||||
static {
|
||||
Properties properties = new Properties();
|
||||
properties = new Properties();
|
||||
InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME);
|
||||
|
||||
|
||||
try {
|
||||
// load the properties file
|
||||
properties.load(input);
|
||||
} catch (IOException e) {
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
GCUBE = properties.getProperty(GCUBE_VARNAME);
|
||||
|
||||
GCUBE_DEVNEXT = properties.getProperty(GCUBE_DEVNEXT_VARNAME);
|
||||
GCUBE_DEVNEXT_NEXTNEXT = properties.getProperty(GCUBE_DEVNEXT_NEXTNEXT_VARNAME);
|
||||
|
||||
GCUBE_DEVSEC = properties.getProperty(GCUBE_DEVSEC_VARNAME);
|
||||
GCUBE_DEVSEC_DEVVRE = properties.getProperty(GCUBE_DEVSEC_DEVVRE_VARNAME);
|
||||
|
||||
GCUBE_DEVNEXT_ANOTHER_USER = properties.getProperty(GCUBE_DEVNEXT_ANOTHER_USER_VARNAME);
|
||||
|
||||
GCUBE_PRE_PROD_PARTHENOS_REGISTRY = properties.getProperty(GCUBE_PRE_PROD_PARTHENOS_REGISTRY_VARNAME);
|
||||
GCUBE_PRE_PROD_PREVRE = properties.getProperty(GCUBE_PRE_PROD_PREVRE_VARNAME);
|
||||
|
||||
GCUBE_PRE_PROD_PREVRE_APP_TOKEN = properties.getProperty(GCUBE_PRE_PROD_PREVRE_APP_TOKEN_VARNAME);
|
||||
|
||||
|
||||
ROOT = properties.getProperty(ROOT_VARNAME);
|
||||
|
||||
DEFAULT_TEST_SCOPE = GCUBE_PRE_PROD_PREVRE;
|
||||
|
||||
DEFAULT_TEST_SCOPE_NAME = "/pred4s/preprod/preVRE";
|
||||
//DEFAULT_TEST_SCOPE_NAME = "/gcube/devNext/NextNext";
|
||||
}
|
||||
|
||||
public static String getCurrentScope(String token) throws ObjectNotFound, Exception{
|
||||
public static String getCurrentScope(String token) throws ObjectNotFound, Exception {
|
||||
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
||||
String context = authorizationEntry.getContext();
|
||||
logger.info("Context of token {} is {}", token, context);
|
||||
return context;
|
||||
}
|
||||
|
||||
public static void setContextByName(String fullContextName) throws ObjectNotFound, Exception {
|
||||
String token = ContextTest.properties.getProperty(fullContextName);
|
||||
setContext(token);
|
||||
}
|
||||
|
||||
public static void setContext(String token) throws ObjectNotFound, Exception{
|
||||
public static void setContext(String token) throws ObjectNotFound, Exception {
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
||||
ClientInfo clientInfo = authorizationEntry.getClientInfo();
|
||||
|
@ -117,12 +72,12 @@ public class ContextTest {
|
|||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception{
|
||||
setContext(DEFAULT_TEST_SCOPE);
|
||||
public static void beforeClass() throws Exception {
|
||||
setContextByName(DEFAULT_TEST_SCOPE_NAME);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception{
|
||||
public static void afterClass() throws Exception {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
}
|
||||
|
|
|
@ -3,11 +3,20 @@ package org.gcube.storagehub;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.common.homelibrary.home.Home;
|
||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
import org.gcube.common.homelibrary.home.HomeManager;
|
||||
import org.gcube.common.homelibrary.home.HomeManagerFactory;
|
||||
import org.gcube.common.homelibrary.home.User;
|
||||
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
||||
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.OpenResolver;
|
||||
import org.gcube.common.storagehub.model.Metadata;
|
||||
import org.gcube.common.storagehub.model.service.Version;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -16,17 +25,37 @@ public class StorageHubManagementTest extends ContextTest {
|
|||
private static final Logger logger = LoggerFactory.getLogger(StorageHubManagementTest.class);
|
||||
|
||||
//@Test
|
||||
public void testHL() throws Exception {
|
||||
ApplicationMode applicationMode = new ApplicationMode(ContextTest.properties.getProperty(DEFAULT_TEST_SCOPE_NAME));
|
||||
applicationMode.start();
|
||||
String username = ContextUtility.getUsername();
|
||||
HomeManagerFactory factory = HomeLibrary.getHomeManagerFactory();
|
||||
HomeManager manager = factory.getHomeManager();
|
||||
User user = manager.createUser(username);
|
||||
@SuppressWarnings("deprecation")
|
||||
Home home = manager.getHome(user);
|
||||
Workspace ws = home.getWorkspace();
|
||||
WorkspaceFolder workspaceFolder = ws.getRoot();
|
||||
workspaceFolder = ws.getVREFolderByScope(ContextUtility.getCurrentContext());
|
||||
// logger.debug("VRE Folder ID : {} - Owner: {}", workspaceFolder.getId(), workspaceFolder.getOwner().getPortalLogin());
|
||||
List<WorkspaceItem> workspaceItems = workspaceFolder.getChildren(true);
|
||||
for(WorkspaceItem workspaceItem : workspaceItems) {
|
||||
logger.debug("{} {}{} ID:{}", workspaceFolder.getType(), workspaceItem.getName(), workspaceItem.isHidden()? " (hidden)":"", workspaceItem.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void myTest() throws Exception {
|
||||
ApplicationMode applicationMode = new ApplicationMode(ContextTest.GCUBE_PRE_PROD_PREVRE_APP_TOKEN);
|
||||
ApplicationMode applicationMode = new ApplicationMode(ContextTest.properties.getProperty(DEFAULT_TEST_SCOPE_NAME));
|
||||
applicationMode.start();
|
||||
StorageHubManagement storageHubManagement = new StorageHubManagement();
|
||||
FolderContainer contextFolder = storageHubManagement.getContextFolder();
|
||||
logger.debug("Context Folder ID : {} - Name : {}", contextFolder.getId(), contextFolder.get().getName());
|
||||
}
|
||||
|
||||
//@Test
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
ApplicationMode applicationMode = new ApplicationMode(ContextTest.GCUBE_PRE_PROD_PREVRE_APP_TOKEN);
|
||||
ApplicationMode applicationMode = new ApplicationMode(ContextTest.properties.getProperty(DEFAULT_TEST_SCOPE_NAME));
|
||||
applicationMode.start();
|
||||
StorageHubManagement storageHubManagement = new StorageHubManagement();
|
||||
OpenResolver openResolver = storageHubManagement.storageHubClient.open("71394bdc-296f-46d4-ab7b-ecc9abc36bdd");
|
||||
|
@ -42,7 +71,7 @@ public class StorageHubManagementTest extends ContextTest {
|
|||
|
||||
//@Test
|
||||
public void listFolders() throws Exception {
|
||||
ApplicationMode applicationMode = new ApplicationMode(ContextTest.GCUBE_PRE_PROD_PREVRE_APP_TOKEN);
|
||||
ApplicationMode applicationMode = new ApplicationMode(ContextTest.properties.getProperty(DEFAULT_TEST_SCOPE_NAME));
|
||||
applicationMode.start();
|
||||
StorageHubManagement storageHubManagement = new StorageHubManagement();
|
||||
FolderContainer root = storageHubManagement.getWorkspaceRoot();
|
||||
|
@ -57,7 +86,7 @@ public class StorageHubManagementTest extends ContextTest {
|
|||
|
||||
//@Test
|
||||
public void getFileInfo() throws Exception {
|
||||
ApplicationMode applicationMode = new ApplicationMode(ContextTest.GCUBE_PRE_PROD_PREVRE_APP_TOKEN);
|
||||
ApplicationMode applicationMode = new ApplicationMode(ContextTest.properties.getProperty(DEFAULT_TEST_SCOPE_NAME));
|
||||
applicationMode.start();
|
||||
StorageHubManagement storageHubManagement = new StorageHubManagement();
|
||||
String id = "71394bdc-296f-46d4-ab7b-ecc9abc36bdd";
|
||||
|
|
Loading…
Reference in New Issue