ref 11720: DataMiner - Update to StorageHUB
https://support.d4science.org/issues/11720 Updated to StorageHub git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/data-miner-manager@169458 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
7476cec4d8
commit
992ae023fe
|
@ -3,14 +3,13 @@ package org.gcube.portlets.user.dataminermanager.server.storage;
|
|||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
||||
import org.gcube.common.storagehub.client.StreamDescriptor;
|
||||
import org.gcube.common.storagehub.client.dsl.FileContainer;
|
||||
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.client.dsl.StorageHubClient;
|
||||
import org.gcube.common.storagehub.model.Metadata;
|
||||
|
@ -54,8 +53,8 @@ public class StorageUtil {
|
|||
return itemMap;
|
||||
|
||||
} catch (Throwable e) {
|
||||
logger.error("Error retrieving properties: " +e.getLocalizedMessage(), e);
|
||||
throw new ServiceException(e.getLocalizedMessage(),e);
|
||||
logger.error("Error retrieving properties: " + e.getLocalizedMessage(), e);
|
||||
throw new ServiceException(e.getLocalizedMessage(), e);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -70,22 +69,20 @@ public class StorageUtil {
|
|||
* @throws ServiceException
|
||||
* service exception
|
||||
*/
|
||||
public InputStream getInputStreamForItemOnWorkspace(String user, String itemId) throws ServiceException {
|
||||
public InputStream getInputStreamForItemOnWorkspace(String user, String itemId) throws ServiceException {
|
||||
try {
|
||||
logger.debug("getInputStreamForItemOnWorkspace: [user="+user+", itemId="+itemId+"]");
|
||||
logger.debug("getInputStreamForItemOnWorkspace: [user=" + user + ", itemId=" + itemId + "]");
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
FileContainer fileContainer = shc.open(itemId).asFile();
|
||||
StreamDescriptor streamDescriptor = fileContainer.download();
|
||||
return streamDescriptor.getStream();
|
||||
|
||||
|
||||
} catch (Throwable e) {
|
||||
logger.error("Error retrieving InputStream for File: " +e.getLocalizedMessage(), e);
|
||||
throw new ServiceException(e.getLocalizedMessage(),e);
|
||||
logger.error("Error retrieving InputStream for File: " + e.getLocalizedMessage(), e);
|
||||
throw new ServiceException(e.getLocalizedMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param user
|
||||
|
@ -96,16 +93,16 @@ public class StorageUtil {
|
|||
* @throws ServiceException
|
||||
* service exception
|
||||
*/
|
||||
public String getPublicLink(String user, String itemId) throws ServiceException {
|
||||
public String getPublicLink(String user, String itemId) throws ServiceException {
|
||||
try {
|
||||
logger.debug("getPublicLink: [user="+user+", itemId="+itemId+"]");
|
||||
logger.debug("getPublicLink: [user=" + user + ", itemId=" + itemId + "]");
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
URL url = shc.open(itemId).asFile().getPublicLink();
|
||||
return url.toString();
|
||||
|
||||
|
||||
} catch (Throwable e) {
|
||||
logger.error("Error retrieving public link: " + e.getLocalizedMessage(),e);
|
||||
throw new ServiceException(e.getLocalizedMessage(),e);
|
||||
logger.error("Error retrieving public link: " + e.getLocalizedMessage(), e);
|
||||
throw new ServiceException(e.getLocalizedMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,7 +116,7 @@ public class StorageUtil {
|
|||
* @throws ServiceException
|
||||
* service exception
|
||||
*/
|
||||
public InputStream zipFolder(String user, String folderId) throws ServiceException {
|
||||
public InputStream zipFolder(String user, String folderId) throws ServiceException {
|
||||
try {
|
||||
logger.debug("zipFolder: [user=" + user + ", folderId=" + folderId + "]");
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
|
@ -136,8 +133,8 @@ public class StorageUtil {
|
|||
}
|
||||
|
||||
} catch (Throwable e) {
|
||||
logger.error("Error in zip Folder: " +e.getLocalizedMessage(),e);
|
||||
throw new ServiceException(e.getLocalizedMessage(),e);
|
||||
logger.error("Error in zip Folder: " + e.getLocalizedMessage(), e);
|
||||
throw new ServiceException(e.getLocalizedMessage(), e);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -152,18 +149,21 @@ public class StorageUtil {
|
|||
* @throws ServiceException
|
||||
* service exception
|
||||
*/
|
||||
public WorkspaceItem getItemInRootFolderOnWorkspace(String user, String itemName) throws ServiceException {
|
||||
Workspace ws;
|
||||
public Item getItemInRootFolderOnWorkspace(String user, String itemName) throws ServiceException {
|
||||
try {
|
||||
logger.debug("GetItemInRootFolder: [user=" + user + ", itemName=" + itemName + "]");
|
||||
ws = HomeLibrary.getUserWorkspace(user);
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
ListResolver listResolver = shc.getWSRoot().findByName(itemName);
|
||||
List<? extends Item> items = listResolver.getItems();
|
||||
|
||||
WorkspaceItem item = ws.find(itemName, ws.getRoot().getId());
|
||||
|
||||
return item;
|
||||
if (items != null && !items.isEmpty()) {
|
||||
return items.get(0);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
} catch (Throwable e) {
|
||||
logger.error("Error in get Item in RootFolder: " +e.getLocalizedMessage(),e);
|
||||
logger.error("Error in get Item in RootFolder: " + e.getLocalizedMessage(), e);
|
||||
throw new ServiceException(e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
@ -180,19 +180,21 @@ public class StorageUtil {
|
|||
* @throws ServiceException
|
||||
* service exception
|
||||
*/
|
||||
public WorkspaceItem getItemInFolderOnWorkspace(String user, String folderId, String itemName)
|
||||
throws ServiceException {
|
||||
Workspace ws;
|
||||
public Item getItemInFolderOnWorkspace(String user, String folderId, String itemName) throws ServiceException {
|
||||
try {
|
||||
logger.debug("GetItemInFolder: [user=" + user + ", folderId="+folderId+", itemName=" + itemName + "]");
|
||||
ws = HomeLibrary.getUserWorkspace(user);
|
||||
logger.debug("GetItemInFolder: [user=" + user + ", folderId=" + folderId + ", itemName=" + itemName + "]");
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
ListResolver listResolver = shc.open(folderId).asFolder().findByName(itemName);
|
||||
List<? extends Item> items = listResolver.getItems();
|
||||
|
||||
WorkspaceItem item = ws.find(itemName, folderId);
|
||||
|
||||
return item;
|
||||
if (items != null && !items.isEmpty()) {
|
||||
return items.get(0);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
} catch (Throwable e) {
|
||||
logger.error("Error in get Item in Folder: " +e.getLocalizedMessage(),e);
|
||||
logger.error("Error in get Item in Folder: " + e.getLocalizedMessage(), e);
|
||||
throw new ServiceException(e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
@ -206,17 +208,18 @@ public class StorageUtil {
|
|||
* @throws ServiceException
|
||||
* service exception
|
||||
*/
|
||||
public void deleteItem(String user, String itemId) throws ServiceException {
|
||||
Workspace ws;
|
||||
public void deleteItem(String user, String itemId) throws ServiceException {
|
||||
try {
|
||||
logger.debug("User: " + user + ", ItemId:" + itemId);
|
||||
ws = HomeLibrary.getUserWorkspace(user);
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
OpenResolver openResolver = shc.open(itemId);
|
||||
|
||||
ws.removeItems(itemId);
|
||||
ItemContainer<Item> itemContainer = openResolver.asItem();
|
||||
itemContainer.delete();
|
||||
|
||||
return;
|
||||
} catch (Throwable e) {
|
||||
logger.error("Error deleting Item: "+e.getLocalizedMessage(),e);
|
||||
logger.error("Error deleting Item: " + e.getLocalizedMessage(), e);
|
||||
throw new ServiceException(e.getLocalizedMessage());
|
||||
|
||||
}
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
package org.gcube.portlets.user.dataminermanager.server.util;
|
||||
|
||||
|
||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
||||
import org.gcube.portlets.user.dataminermanager.server.storage.StorageUtil;
|
||||
import org.gcube.portlets.user.dataminermanager.shared.exception.ServiceException;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
import org.gcube.data.analysis.dataminermanagercl.server.util.ServiceCredentials;
|
||||
import org.gcube.data.analysis.dataminermanagercl.shared.workspace.Computations;
|
||||
import org.gcube.data.analysis.dataminermanagercl.shared.workspace.OutputDataSets;
|
||||
import org.gcube.data.analysis.dataminermanagercl.shared.workspace.DataMinerWorkArea;
|
||||
import org.gcube.data.analysis.dataminermanagercl.shared.workspace.InputDataSets;
|
||||
import org.gcube.data.analysis.dataminermanagercl.shared.workspace.ItemDescription;
|
||||
import org.gcube.data.analysis.dataminermanagercl.shared.workspace.OutputDataSets;
|
||||
import org.gcube.portlets.user.dataminermanager.server.storage.StorageUtil;
|
||||
import org.gcube.portlets.user.dataminermanager.shared.exception.ServiceException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -25,8 +24,7 @@ public class DataMinerWorkAreaManager {
|
|||
private static final String COMPUTED_DATA_FOLDER = "Output Data Sets";
|
||||
private static final String COMPUTATIONS_FOLDER = "Computations";
|
||||
|
||||
public static final Logger logger = LoggerFactory
|
||||
.getLogger(DataMinerWorkAreaManager.class);
|
||||
public static final Logger logger = LoggerFactory.getLogger(DataMinerWorkAreaManager.class);
|
||||
|
||||
private ServiceCredentials serviceCredentials;
|
||||
|
||||
|
@ -36,12 +34,11 @@ public class DataMinerWorkAreaManager {
|
|||
|
||||
public DataMinerWorkArea getDataMinerWorkArea() throws ServiceException {
|
||||
DataMinerWorkArea dataMinerWorkArea = null;
|
||||
StorageUtil storageUtil=new StorageUtil();
|
||||
StorageUtil storageUtil = new StorageUtil();
|
||||
try {
|
||||
|
||||
WorkspaceItem wiDataMinerFolder = storageUtil
|
||||
.getItemInRootFolderOnWorkspace(serviceCredentials.getUserName(),
|
||||
DATA_MINER_FOLDER);
|
||||
|
||||
Item wiDataMinerFolder = storageUtil.getItemInRootFolderOnWorkspace(serviceCredentials.getUserName(),
|
||||
DATA_MINER_FOLDER);
|
||||
|
||||
if (wiDataMinerFolder == null) {
|
||||
dataMinerWorkArea = new DataMinerWorkArea(null);
|
||||
|
@ -49,13 +46,10 @@ public class DataMinerWorkAreaManager {
|
|||
} else {
|
||||
ItemDescription dataMinerWorkAreaFolder = null;
|
||||
|
||||
dataMinerWorkAreaFolder = new ItemDescription(
|
||||
wiDataMinerFolder.getId(), wiDataMinerFolder.getName(),
|
||||
wiDataMinerFolder.getOwner().getPortalLogin(),
|
||||
wiDataMinerFolder.getPath(), wiDataMinerFolder
|
||||
.getType().name());
|
||||
dataMinerWorkArea = new DataMinerWorkArea(
|
||||
dataMinerWorkAreaFolder);
|
||||
dataMinerWorkAreaFolder = new ItemDescription(wiDataMinerFolder.getId(), wiDataMinerFolder.getName(),
|
||||
wiDataMinerFolder.getOwner(), wiDataMinerFolder.getPath(),
|
||||
null);
|
||||
dataMinerWorkArea = new DataMinerWorkArea(dataMinerWorkAreaFolder);
|
||||
|
||||
}
|
||||
|
||||
|
@ -68,18 +62,13 @@ public class DataMinerWorkAreaManager {
|
|||
|
||||
InputDataSets inputDataSets = null;
|
||||
try {
|
||||
WorkspaceItem wiImportedDataFolder = storageUtil
|
||||
.getItemInFolderOnWorkspace(serviceCredentials.getUserName(),
|
||||
dataMinerWorkArea.getDataMinerWorkAreaFolder()
|
||||
.getId(), IMPORTED_DATA_FOLDER);
|
||||
Item wiImportedDataFolder = storageUtil.getItemInFolderOnWorkspace(serviceCredentials.getUserName(),
|
||||
dataMinerWorkArea.getDataMinerWorkAreaFolder().getId(), IMPORTED_DATA_FOLDER);
|
||||
ItemDescription importedDataFolder = null;
|
||||
|
||||
importedDataFolder = new ItemDescription(
|
||||
wiImportedDataFolder.getId(),
|
||||
wiImportedDataFolder.getName(), wiImportedDataFolder
|
||||
.getOwner().getPortalLogin(),
|
||||
wiImportedDataFolder.getPath(), wiImportedDataFolder
|
||||
.getType().name());
|
||||
importedDataFolder = new ItemDescription(wiImportedDataFolder.getId(), wiImportedDataFolder.getName(),
|
||||
wiImportedDataFolder.getOwner(), wiImportedDataFolder.getPath(),
|
||||
null);
|
||||
|
||||
inputDataSets = new InputDataSets(importedDataFolder);
|
||||
|
||||
|
@ -90,18 +79,13 @@ public class DataMinerWorkAreaManager {
|
|||
|
||||
OutputDataSets outputDataSets = null;
|
||||
try {
|
||||
WorkspaceItem wiComputedDataFolder = storageUtil
|
||||
.getItemInFolderOnWorkspace(serviceCredentials.getUserName(),
|
||||
dataMinerWorkArea.getDataMinerWorkAreaFolder()
|
||||
.getId(), COMPUTED_DATA_FOLDER);
|
||||
Item wiComputedDataFolder = storageUtil.getItemInFolderOnWorkspace(serviceCredentials.getUserName(),
|
||||
dataMinerWorkArea.getDataMinerWorkAreaFolder().getId(), COMPUTED_DATA_FOLDER);
|
||||
ItemDescription computedDataFolder = null;
|
||||
|
||||
computedDataFolder = new ItemDescription(
|
||||
wiComputedDataFolder.getId(),
|
||||
wiComputedDataFolder.getName(), wiComputedDataFolder
|
||||
.getOwner().getPortalLogin(),
|
||||
wiComputedDataFolder.getPath(), wiComputedDataFolder
|
||||
.getType().name());
|
||||
computedDataFolder = new ItemDescription(wiComputedDataFolder.getId(), wiComputedDataFolder.getName(),
|
||||
wiComputedDataFolder.getOwner(), wiComputedDataFolder.getPath(),
|
||||
null);
|
||||
outputDataSets = new OutputDataSets(computedDataFolder);
|
||||
|
||||
} catch (Throwable e) {
|
||||
|
@ -111,18 +95,13 @@ public class DataMinerWorkAreaManager {
|
|||
|
||||
Computations computations = null;
|
||||
try {
|
||||
WorkspaceItem wiComputationsDataFolder = storageUtil
|
||||
.getItemInFolderOnWorkspace(serviceCredentials.getUserName(),
|
||||
dataMinerWorkArea.getDataMinerWorkAreaFolder()
|
||||
.getId(), COMPUTATIONS_FOLDER);
|
||||
Item wiComputationsDataFolder = storageUtil.getItemInFolderOnWorkspace(serviceCredentials.getUserName(),
|
||||
dataMinerWorkArea.getDataMinerWorkAreaFolder().getId(), COMPUTATIONS_FOLDER);
|
||||
ItemDescription computationsDataFolder = null;
|
||||
|
||||
computationsDataFolder = new ItemDescription(
|
||||
wiComputationsDataFolder.getId(),
|
||||
wiComputationsDataFolder.getName(),
|
||||
wiComputationsDataFolder.getOwner().getPortalLogin(),
|
||||
wiComputationsDataFolder.getPath(),
|
||||
wiComputationsDataFolder.getType().name());
|
||||
computationsDataFolder = new ItemDescription(wiComputationsDataFolder.getId(),
|
||||
wiComputationsDataFolder.getName(), wiComputationsDataFolder.getOwner(),
|
||||
wiComputationsDataFolder.getPath(), null);
|
||||
computations = new Computations(computationsDataFolder);
|
||||
|
||||
} catch (Throwable e) {
|
||||
|
|
Loading…
Reference in New Issue