2018-06-26 14:58:41 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2023-04-03 15:55:43 +02:00
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
|
|
|
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
2018-06-26 14:58:41 +02:00
|
|
|
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
|
2018-11-22 12:49:47 +01:00
|
|
|
import org.gcube.common.storagehubwrapper.server.WorkspaceStorageHubClientService;
|
2018-06-26 14:58:41 +02:00
|
|
|
import org.gcube.common.storagehubwrapper.server.tohl.Workspace;
|
2022-05-02 14:27:02 +02:00
|
|
|
import org.gcube.common.storagehubwrapper.shared.Member;
|
2018-06-26 14:58:41 +02:00
|
|
|
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder;
|
|
|
|
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem;
|
|
|
|
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException;
|
|
|
|
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundException;
|
2018-06-26 17:31:07 +02:00
|
|
|
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WrongItemTypeException;
|
2018-06-26 14:58:41 +02:00
|
|
|
import org.gcube.common.storagehubwrapper.shared.tohl.impl.FileItem;
|
|
|
|
import org.gcube.common.storagehubwrapper.shared.tohl.impl.ImageFile;
|
|
|
|
import org.gcube.common.storagehubwrapper.shared.tohl.impl.PDFFile;
|
2018-12-03 11:36:59 +01:00
|
|
|
import org.junit.Test;
|
2018-06-26 14:58:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
*
|
2022-04-28 11:29:25 +02:00
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jun 20, 2018
|
2018-06-26 14:58:41 +02:00
|
|
|
*/
|
|
|
|
public class WorkspaceInstance {
|
|
|
|
|
2023-04-03 15:55:43 +02:00
|
|
|
public static String SCOPE = "/gcube/devsec/devVRE";
|
|
|
|
//public static String SCOPE = "/d4science.research-infrastructures.eu";
|
2018-06-26 14:58:41 +02:00
|
|
|
|
2022-04-28 11:29:25 +02:00
|
|
|
// public static String USERNAME = "massimiliano.assante";
|
2019-09-13 16:34:49 +02:00
|
|
|
public static String USERNAME = "francesco.mangiacrapa";
|
2018-06-26 17:31:07 +02:00
|
|
|
|
2023-04-03 15:55:43 +02:00
|
|
|
//public static String TOKEN = System.getenv("TOKEN_gcube"); // YOU MUST SET THIS AS Environment variable
|
|
|
|
|
|
|
|
public static String TOKEN = "";
|
2018-06-26 14:58:41 +02:00
|
|
|
|
2018-11-21 17:45:29 +01:00
|
|
|
public static String FIND_FILE_NAME = "francesco";
|
|
|
|
public static String rootId = null;
|
|
|
|
private StorageHubWrapper storageHubWrapper = null;
|
2018-06-26 14:58:41 +02:00
|
|
|
|
2018-11-22 12:49:47 +01:00
|
|
|
private WorkspaceStorageHubClientService workspace;
|
|
|
|
|
2023-04-03 15:55:43 +02:00
|
|
|
//@Before
|
2022-04-28 11:29:25 +02:00
|
|
|
public void init() {
|
2018-06-26 14:58:41 +02:00
|
|
|
|
2022-04-28 11:29:25 +02:00
|
|
|
if (TOKEN == null) {
|
2021-03-03 11:19:26 +01:00
|
|
|
System.err.println("You must set the token as Environment variable");
|
|
|
|
}
|
2018-11-21 17:45:29 +01:00
|
|
|
|
2022-04-28 11:29:25 +02:00
|
|
|
System.out.println("Read TOKEN_gcube: " + TOKEN);
|
2023-04-03 15:55:43 +02:00
|
|
|
|
|
|
|
ScopeProvider.instance.set(SCOPE);
|
|
|
|
SecurityTokenProvider.instance.set(TOKEN);
|
2018-11-21 17:45:29 +01:00
|
|
|
|
2022-04-28 11:29:25 +02:00
|
|
|
// METHOD 1
|
2018-11-22 12:49:47 +01:00
|
|
|
storageHubWrapper = new StorageHubWrapper(SCOPE, TOKEN, false, false, true);
|
2022-04-28 11:29:25 +02:00
|
|
|
// workspace = storageHubWrapper.getWorkspace();
|
2018-06-26 14:58:41 +02:00
|
|
|
|
2022-04-28 11:29:25 +02:00
|
|
|
// METHOD 2
|
2018-06-26 14:58:41 +02:00
|
|
|
// StorageHubClientService storageHubClientService = new StorageHubClientService(SCOPE, TOKEN);
|
|
|
|
// workspace = new WorkspaceStorageHubClientService.WorkspaceStorageHubClientServiceBuilder(storageHubClientService).
|
2018-11-22 12:49:47 +01:00
|
|
|
// withAccounting(false).
|
2018-06-26 14:58:41 +02:00
|
|
|
// withMapProperties(true).
|
|
|
|
// build();
|
|
|
|
}
|
|
|
|
|
2022-04-28 11:29:25 +02:00
|
|
|
// @Test
|
2018-06-26 14:58:41 +02:00
|
|
|
public void getRoot() {
|
|
|
|
System.out.println("Get Root test");
|
|
|
|
WorkspaceFolder root;
|
|
|
|
try {
|
|
|
|
root = storageHubWrapper.getWorkspace().getRoot();
|
2018-06-26 17:31:07 +02:00
|
|
|
rootId = root.getId();
|
2022-04-28 11:29:25 +02:00
|
|
|
System.out.println("The root is:" + root);
|
|
|
|
} catch (Exception e) {
|
2018-06-26 14:58:41 +02:00
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-04-28 11:29:25 +02:00
|
|
|
// @Test
|
|
|
|
public void getChildren() throws Exception {
|
2018-06-26 14:58:41 +02:00
|
|
|
System.out.println("Get children test");
|
|
|
|
|
|
|
|
WorkspaceFolder root = storageHubWrapper.getWorkspace().getRoot();
|
2018-10-03 10:52:51 +02:00
|
|
|
List<? extends WorkspaceItem> children = storageHubWrapper.getWorkspace().getChildren(root.getId());
|
2018-11-22 12:49:47 +01:00
|
|
|
|
2022-04-28 11:29:25 +02:00
|
|
|
// WorkspaceFolder root = workspace.getRoot();
|
|
|
|
// List<? extends WorkspaceItem> children = workspace.getChildren(root.getId());
|
2018-11-22 12:49:47 +01:00
|
|
|
|
2018-10-03 10:52:51 +02:00
|
|
|
int i = 0;
|
|
|
|
for (WorkspaceItem workspaceItem : children) {
|
2022-04-28 11:29:25 +02:00
|
|
|
System.out.println(++i + ")" + workspaceItem.getId() + " name: " + workspaceItem.getName() + " type: "
|
|
|
|
+ workspaceItem.getType() + " class: " + workspaceItem.getClass());
|
2021-03-03 11:19:26 +01:00
|
|
|
}
|
2018-11-21 17:45:29 +01:00
|
|
|
|
2021-03-03 11:19:26 +01:00
|
|
|
}
|
2022-04-28 11:29:25 +02:00
|
|
|
|
|
|
|
// @Test
|
|
|
|
public void getPathOnShared() throws Exception {
|
2021-03-03 11:19:26 +01:00
|
|
|
System.out.println("Get Path on Shared");
|
2018-11-21 17:45:29 +01:00
|
|
|
|
2021-03-03 11:19:26 +01:00
|
|
|
WorkspaceFolder root = storageHubWrapper.getWorkspace().getRoot();
|
|
|
|
List<? extends WorkspaceItem> children = storageHubWrapper.getWorkspace().getChildren(root.getId());
|
2018-11-21 17:45:29 +01:00
|
|
|
|
2021-03-03 11:19:26 +01:00
|
|
|
int i = 0;
|
|
|
|
for (WorkspaceItem workspaceItem : children) {
|
2022-04-28 11:29:25 +02:00
|
|
|
if (workspaceItem.isShared()) {
|
|
|
|
System.out.println(++i + ")" + workspaceItem.getId() + " name: " + workspaceItem.getName() + " type: "
|
|
|
|
+ workspaceItem.getPath());
|
2021-03-03 11:19:26 +01:00
|
|
|
}
|
2018-06-26 14:58:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-04-03 15:55:43 +02:00
|
|
|
|
|
|
|
//@Test
|
|
|
|
public void getVREFolder() throws Exception {
|
|
|
|
System.out.println("Get VRE Folder");
|
|
|
|
|
|
|
|
StorageHubClient shClient = new StorageHubClient();
|
|
|
|
FolderContainer vre= shClient.openVREFolder();
|
|
|
|
System.out.println("VRE folder: "+vre.getId() + " ACLs: "+vre.getAcls());
|
|
|
|
}
|
|
|
|
|
2018-06-26 14:58:41 +02:00
|
|
|
|
2022-04-28 11:29:25 +02:00
|
|
|
// @Test
|
|
|
|
public void getFilteredChildren() throws Exception {
|
2018-11-22 15:31:44 +01:00
|
|
|
System.out.println("Get children test");
|
|
|
|
|
|
|
|
WorkspaceFolder root = storageHubWrapper.getWorkspace().getRoot();
|
|
|
|
Class filterClass = org.gcube.common.storagehub.model.items.FolderItem.class;
|
2022-04-28 11:29:25 +02:00
|
|
|
List<? extends WorkspaceItem> children = storageHubWrapper.getWorkspace().getFilteredChildren(root.getId(),
|
|
|
|
filterClass);
|
2018-11-22 15:31:44 +01:00
|
|
|
|
2022-04-28 11:29:25 +02:00
|
|
|
// WorkspaceFolder root = workspace.getRoot();
|
|
|
|
// List<? extends WorkspaceItem> children = workspace.getChildren(root.getId());
|
2018-11-22 15:31:44 +01:00
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
for (WorkspaceItem workspaceItem : children) {
|
2022-04-28 11:29:25 +02:00
|
|
|
System.out.println(++i + ")" + workspaceItem);
|
|
|
|
System.out.println(workspaceItem.getType() + " " + workspaceItem.getClass());
|
2018-11-22 15:31:44 +01:00
|
|
|
|
|
|
|
// System.out.println(++i+")");
|
|
|
|
// if(workspaceItem.isFolder()){
|
|
|
|
// WorkspaceFolder folder = (WorkspaceFolder) workspaceItem;
|
|
|
|
// System.out.println("is public? "+folder.isPublicFolder());
|
|
|
|
// }
|
|
|
|
|
|
|
|
printMap(workspaceItem);
|
|
|
|
System.out.println("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-04-28 11:29:25 +02:00
|
|
|
public static void printMap(WorkspaceItem workspaceItem) {
|
|
|
|
if (workspaceItem.getPropertyMap() != null) {
|
|
|
|
System.out.println(workspaceItem.getId() + " name: " + workspaceItem.getName() + " isFolder: "
|
|
|
|
+ workspaceItem.isFolder());
|
|
|
|
System.out.println("Property Map: " + workspaceItem.getPropertyMap().getValues().toString());
|
2018-11-21 11:49:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-28 11:29:25 +02:00
|
|
|
// @Test
|
|
|
|
public void getWorkspaceId() {
|
2018-06-26 17:31:07 +02:00
|
|
|
System.out.println("Getting the workspaceId test");
|
2018-06-26 14:58:41 +02:00
|
|
|
try {
|
2018-11-22 12:49:47 +01:00
|
|
|
|
|
|
|
Workspace ws = storageHubWrapper.getWorkspace();
|
|
|
|
|
2022-04-28 11:29:25 +02:00
|
|
|
// Workspace ws = workspace;
|
2018-11-22 12:49:47 +01:00
|
|
|
|
2022-04-28 11:29:25 +02:00
|
|
|
if (ws != null) {
|
2018-11-22 12:49:47 +01:00
|
|
|
WorkspaceFolder root = ws.getRoot();
|
2022-04-28 11:29:25 +02:00
|
|
|
System.out.println("Retrieve the root " + root.getId() + " correctly");
|
2018-06-26 14:58:41 +02:00
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-03 15:55:43 +02:00
|
|
|
@Test
|
2022-04-28 11:29:25 +02:00
|
|
|
public void getSharedFolderMembers() {
|
|
|
|
System.out.println("Getting getSharedFolderMembers");
|
|
|
|
try {
|
2022-05-02 14:33:31 +02:00
|
|
|
|
2023-04-03 15:55:43 +02:00
|
|
|
//String sharedFolderId = "7e3c6636-927c-4139-9fcc-64986ea70cbf"; // devVRE (VRE Folder)
|
|
|
|
String sharedFolderId = "f8275521-5da1-4501-8385-bb9c79055aa6"; // PROD - d4science.research-infrastructures.eu-D4OS-Blue-Cloud2026Project (VRE Folder)
|
|
|
|
//String sharedFolderId = "4d6f1fe9-8f04-45c9-a87e-ee6093553d77"; // PROD - AriadnePlus-LiDAR Dataset (simple Shared Folder)
|
|
|
|
//String sharedFolderId = "a4837a77-c1d0-4ea4-9f9d-c4bd5cf07e9a"; // PROD - Sample Reports and Templates (private Folder)
|
|
|
|
//sharedFolderId = "c141d53d-4cae-4bfc-a6f7-9b8bbd8c0e2b"; //NextNext
|
2022-05-02 14:27:02 +02:00
|
|
|
SCOPE = "/gcube";
|
2023-04-03 15:55:43 +02:00
|
|
|
SCOPE = "/d4science.research-infrastructures.eu";
|
2022-05-02 14:33:31 +02:00
|
|
|
TOKEN = "";
|
2022-04-28 11:29:25 +02:00
|
|
|
storageHubWrapper = new StorageHubWrapper(SCOPE, TOKEN);
|
2022-05-02 14:27:02 +02:00
|
|
|
List<Member> listMembers = storageHubWrapper.getWorkspace().getSharedFolderMembers(sharedFolderId);
|
2022-04-28 11:29:25 +02:00
|
|
|
|
2022-05-02 14:33:31 +02:00
|
|
|
System.out.println("Foud " + listMembers.size() + " member/s");
|
|
|
|
|
|
|
|
for (Member member : listMembers) {
|
|
|
|
System.out.println(member);
|
|
|
|
}
|
2022-04-28 11:29:25 +02:00
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @Test
|
|
|
|
public void getChildrenPerWorkspaceItem() throws InternalErrorException {
|
2018-06-26 14:58:41 +02:00
|
|
|
System.out.println("Get children test per workspace item");
|
|
|
|
|
|
|
|
try {
|
2018-11-22 12:49:47 +01:00
|
|
|
|
2018-10-16 15:18:59 +02:00
|
|
|
WorkspaceFolder root = storageHubWrapper.getWorkspace().getRoot();
|
2018-06-26 14:58:41 +02:00
|
|
|
List<? extends WorkspaceItem> children = storageHubWrapper.getWorkspace().getChildren(root.getId());
|
2018-11-22 12:49:47 +01:00
|
|
|
|
|
|
|
// WorkspaceFolder root = workspace.getRoot();
|
|
|
|
// List<? extends WorkspaceItem> children = workspace.getChildren(root.getId());
|
|
|
|
|
2018-06-26 14:58:41 +02:00
|
|
|
int i = 0;
|
2022-04-28 11:29:25 +02:00
|
|
|
Map<String, List<WorkspaceItem>> map = new HashMap<String, List<WorkspaceItem>>();
|
2018-06-26 14:58:41 +02:00
|
|
|
for (WorkspaceItem workspaceItem : children) {
|
|
|
|
String key = workspaceItem.getType().name();
|
|
|
|
List<WorkspaceItem> list = map.get(key);
|
2022-04-28 11:29:25 +02:00
|
|
|
if (list == null) {
|
2018-06-26 14:58:41 +02:00
|
|
|
list = new ArrayList<WorkspaceItem>();
|
|
|
|
}
|
|
|
|
|
|
|
|
list.add(workspaceItem);
|
|
|
|
map.put(key, list);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (String key : map.keySet()) {
|
|
|
|
List<WorkspaceItem> list = map.get(key);
|
|
|
|
for (WorkspaceItem workspaceItem : list) {
|
|
|
|
switch (workspaceItem.getType()) {
|
|
|
|
case FILE_ITEM:
|
|
|
|
FileItem fileItem = (FileItem) workspaceItem;
|
|
|
|
switch (fileItem.getFileItemType()) {
|
|
|
|
case PDF_DOCUMENT:
|
|
|
|
PDFFile pdfFile = (PDFFile) fileItem;
|
2022-04-28 11:29:25 +02:00
|
|
|
System.out.println("PDF_DOCUMENT " + pdfFile);
|
|
|
|
PDFFile completeItem = (PDFFile) storageHubWrapper.getWorkspace().getItem(fileItem.getId(),
|
|
|
|
true, true, true);
|
2018-06-26 14:58:41 +02:00
|
|
|
System.out.println(completeItem);
|
|
|
|
break;
|
|
|
|
case IMAGE_DOCUMENT:
|
|
|
|
ImageFile imageFile = (ImageFile) fileItem;
|
2022-04-28 11:29:25 +02:00
|
|
|
System.out.println("IMAGE_DOCUMENT " + imageFile);
|
2018-06-26 14:58:41 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-04-28 11:29:25 +02:00
|
|
|
System.out.println(fileItem.getFileItemType() + " " + workspaceItem.getClass());
|
2018-06-26 14:58:41 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-28 11:29:25 +02:00
|
|
|
} catch (Exception e) {
|
2018-06-26 14:58:41 +02:00
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-06-26 17:31:07 +02:00
|
|
|
|
2022-04-28 11:29:25 +02:00
|
|
|
// @Test
|
|
|
|
public void findFileName() throws InternalErrorException {
|
2018-06-26 17:31:07 +02:00
|
|
|
System.out.println("Find file name test");
|
|
|
|
getRoot();
|
|
|
|
try {
|
2022-04-28 11:29:25 +02:00
|
|
|
// List<WorkspaceItem> foundItems =
|
|
|
|
// storageHubWrapper.getWorkspace().find(FIND_FILE_NAME,rootId);
|
|
|
|
List<? extends WorkspaceItem> foundItems = workspace.find(FIND_FILE_NAME, rootId);
|
2018-06-26 17:31:07 +02:00
|
|
|
|
2022-04-28 11:29:25 +02:00
|
|
|
if (foundItems == null || foundItems.size() == 0) {
|
|
|
|
System.out.println("No Items found with name: " + FIND_FILE_NAME + " in the parent: " + rootId);
|
2018-06-26 17:31:07 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-28 11:29:25 +02:00
|
|
|
System.out.println("Items found with name: " + FIND_FILE_NAME + " in the parent: " + rootId + " are:");
|
2018-06-26 17:31:07 +02:00
|
|
|
for (WorkspaceItem workspaceItem : foundItems) {
|
|
|
|
System.out.println(workspaceItem);
|
|
|
|
}
|
2022-04-28 11:29:25 +02:00
|
|
|
} catch (ItemNotFoundException | WrongItemTypeException e) {
|
2018-06-26 17:31:07 +02:00
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-06-26 14:58:41 +02:00
|
|
|
}
|