ref #11879: TDM - Update to StorageHUB

https://support.d4science.org/issues/#11879

Updated to StorageHub



git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@171464 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2018-09-14 10:50:04 +00:00
parent f840ffae53
commit 2e00334667
4 changed files with 175 additions and 160 deletions

12
pom.xml
View File

@ -72,9 +72,6 @@
<version>1.0.1</version>
<scope>runtime</scope>
</dependency>
<!-- <dependency> <groupId>org.gcube.common</groupId> <artifactId>common-authorization</artifactId>
<scope>runtime</scope> </dependency> <dependency> <groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId> <scope>runtime</scope> </dependency> -->
</dependencies>
</profile>
@ -134,17 +131,14 @@
<scope>provided</scope>
</dependency>
<!-- GCube Widgets <dependency> <groupId>org.gcube.portlets.user</groupId>
<artifactId>gcube-widgets</artifactId> <scope>compile</scope> </dependency> -->
<!-- JSON -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
<!-- SDMX -->
<dependency>
<groupId>org.gcube.data.publishing</groupId>
<artifactId>sdmx-registry-client-gcube</artifactId>

View File

@ -26,13 +26,6 @@ import java.util.UUID;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
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.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.data.analysis.tabulardata.commons.templates.model.TemplateCategory;
import org.gcube.data.analysis.tabulardata.commons.templates.model.columns.ColumnCategory;
import org.gcube.data.analysis.tabulardata.commons.templates.model.columns.TemplateColumn;
@ -295,6 +288,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset;
import org.gcube.portlets.user.td.gwtservice.shared.tr.union.UnionSession;
import org.gcube.portlets.user.td.gwtservice.shared.uriresolver.UriResolverSession;
import org.gcube.portlets.user.td.gwtservice.shared.user.UserInfo;
import org.gcube.portlets.user.td.gwtservice.shared.workspace.ItemDescription;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import org.gcube.portlets.user.td.widgetcommonevent.shared.mime.MimeTypeSupport;
import org.gcube.portlets.user.td.widgetcommonevent.shared.operations.UIOperationsId;
@ -3800,37 +3794,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements TDGWTServi
public void getFileFromWorkspace(CSVImportSession csvImportSession) throws TDGWTServiceException {
HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(httpRequest);
Workspace w = null;
WorkspaceItem wi = null;
try {
HomeManagerFactory factory = HomeLibrary.getHomeManagerFactory();
HomeManager manager = factory.getHomeManager();
Home home = manager.getHome();
w = home.getWorkspace();
wi = w.getItem(csvImportSession.getItemId());
} catch (Throwable e) {
e.printStackTrace();
throw new TDGWTServiceException(
"Error in importCSV getFileFromWorkspace accessing the workspace: " + e.getLocalizedMessage(), e);
}
if (wi == null) {
logger.error("Error retrieving the item on workspace" + csvImportSession.getItemId());
throw new TDGWTServiceException("Error retrieving the item on workspace" + csvImportSession.getItemId());
}
try {
logger.debug("WorkspaceItem [id:" + wi.getId() + " name:" + wi.getName() + " remotePath:"
+ wi.getRemotePath() + "]");
} catch (InternalErrorException e1) {
e1.printStackTrace();
throw new TDGWTServiceException("Error retrieving the item on workspace" + wi);
}
FilesStorage filesStorage = new FilesStorage();
ItemDescription itemDescription = filesStorage.getItem(serviceCredentials.getUserName(),
csvImportSession.getId());
CSVFileUploadSession fileUploadSession = new CSVFileUploadSession();
// CSVImportMonitor csvImportMonitor = new CSVImportMonitor();
@ -3845,10 +3811,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements TDGWTServi
SessionUtil.setCSVFileUploadSession(httpRequest, serviceCredentials, fileUploadSession);
try {
FilesStorage filesStorage = new FilesStorage();
InputStream is = filesStorage.retrieveInputStream(serviceCredentials.getUserName(), wi);
FileUtil.setImportFileCSV(fileUploadSession, is, wi.getName(), Constants.FILE_CSV_MIMETYPE);
InputStream is = filesStorage.retrieveInputStream(serviceCredentials.getUserName(),
itemDescription.getId());
FileUtil.setImportFileCSV(fileUploadSession, is, itemDescription.getName(), Constants.FILE_CSV_MIMETYPE);
} catch (Throwable e) {
FileUploadMonitor fum = SessionUtil.getFileUploadMonitor(httpRequest, serviceCredentials);
fum.setFailed("An error occured elaborating the file", FileUtil.exceptionDetailMessage(e));
@ -4513,7 +4478,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements TDGWTServi
logger.debug("Share with Users: " + users);
service.share(tabularResourceId, usersArray);
}
} catch (TDGWTServiceException e) {
throw e;
} catch (SecurityException e) {
@ -4526,7 +4491,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements TDGWTServi
}
}
@Override
public String startExcelExport(ExcelExportSession exportSession) throws TDGWTServiceException {
HttpServletRequest httpRequest = null;
@ -4568,12 +4532,12 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements TDGWTServi
// /
switch (exportSession.getExportType()) {
case DATASET:
OpExecution4ExcelDatasetExport opExD = new OpExecution4ExcelDatasetExport(httpRequest, serviceCredentials,
service, exportSession);
OpExecution4ExcelDatasetExport opExD = new OpExecution4ExcelDatasetExport(httpRequest,
serviceCredentials, service, exportSession);
director.setOperationExecutionBuilder(opExD);
break;
case GENERIC:
case CODELIST:
case CODELIST:
default:
logger.error("Error in Excel Export: Only Codelist and Dataset are supported!");
throw new TDGWTServiceException("Error in ExcelExport: Only Dataset are supported!");
@ -4607,8 +4571,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements TDGWTServi
}
}
@Override
public String startSDMXTemplateExport(SDMXTemplateExportSession sdmxTemplateExportSession)
throws TDGWTServiceException {
@ -7381,43 +7344,11 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements TDGWTServi
@Override
public void getFileFromWorkspace(CodelistMappingSession codelistMappingSession) throws TDGWTServiceException {
Workspace w = null;
WorkspaceItem wi = null;
HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(httpRequest);
try {
HomeManagerFactory factory = HomeLibrary.getHomeManagerFactory();
HomeManager manager = factory.getHomeManager();
Home home = manager.getHome();
w = home.getWorkspace();
wi = w.getItem(codelistMappingSession.getItemId());
} catch (Throwable e) {
e.printStackTrace();
throw new TDGWTServiceException(
"Error in import Codelist Mapping getFileFromWorkspace accessing the workspace: "
+ e.getLocalizedMessage(),
e);
}
if (wi == null) {
logger.error("Error retrieving the item on workspace" + codelistMappingSession.getItemId());
throw new TDGWTServiceException(
"Error retrieving the item on workspace" + codelistMappingSession.getItemId());
}
try {
logger.debug("WorkspaceItem [id:" + wi.getId() + " name:" + wi.getName() + " remotePath:"
+ wi.getRemotePath() + "]");
} catch (InternalErrorException e1) {
e1.printStackTrace();
throw new TDGWTServiceException("Error retrieving the item on workspace" + wi);
}
FilesStorage filesStorage = new FilesStorage();
ItemDescription itemDescription = filesStorage.getItem(serviceCredentials.getUserName(),
codelistMappingSession.getItemId());
CodelistMappingFileUploadSession fileUploadSession = new CodelistMappingFileUploadSession();
// CodelistMappingMonitor codelistMappingMonitor = new
@ -7432,10 +7363,11 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements TDGWTServi
SessionUtil.setCodelistMappingFileUploadSession(httpRequest, serviceCredentials, fileUploadSession);
try {
FilesStorage filesStorage = new FilesStorage();
InputStream is = filesStorage.retrieveInputStream(serviceCredentials.getUserName(), wi);
FileUtil.setImportFileCodelistMapping(fileUploadSession, is, wi.getName(), Constants.FILE_XML_MIMETYPE);
InputStream is = filesStorage.retrieveInputStream(serviceCredentials.getUserName(),
itemDescription.getId());
FileUtil.setImportFileCodelistMapping(fileUploadSession, is, itemDescription.getName(),
Constants.FILE_XML_MIMETYPE);
} catch (Throwable e) {
FileUploadMonitor fum = SessionUtil.getFileUploadMonitor(httpRequest, serviceCredentials);
fum.setFailed("An error occured elaborating the file", FileUtil.exceptionDetailMessage(e));

View File

@ -5,7 +5,6 @@ import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
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.FolderContainer;
@ -17,6 +16,7 @@ import org.gcube.contentmanager.storageclient.wrapper.AccessType;
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException;
import org.gcube.portlets.user.td.gwtservice.shared.workspace.ItemDescription;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -46,7 +46,7 @@ public class FilesStorage {
logger.debug("remotePath: " + remotePath);
String id = client.put(true).LFile(file.getAbsolutePath()).RFile(remotePath);
client.close();
return id;
} catch (Throwable e) {
@ -111,46 +111,6 @@ public class FilesStorage {
}
}
/**
*
*
*
*
* @param user
* User
* @param wi
* Workspace item
* @param file
* File
* @throws TDGWTServiceException
* Exception
*/
/*
* public void retrieveFile(String user, WorkspaceItem wi, File file) throws
* TDGWTServiceException { try { logger.debug("retrieveFile: [user=" + user
* + ", item=" + wi + "]"); StorageHubClient shc = new StorageHubClient();
* FileContainer fileContainer = shc.open(wi.getId()).asFile();
* StreamDescriptor streamDescriptor = fileContainer.download(); try
* (BufferedInputStream bis = new
* BufferedInputStream(streamDescriptor.getStream())) { try
* (BufferedOutputStream bos = new BufferedOutputStream(new
* FileOutputStream(file))) {
*
* byte[] buffer = new byte[1024]; int readCount; while ((readCount =
* bis.read(buffer)) > 0) { bos.write(buffer, 0, readCount); } } catch
* (Throwable e) { logger.error("Error trasferring file from storage: " +
* e.getLocalizedMessage(), e); throw new
* TDGWTServiceException("Error trasferring file from storage: " +
* e.getLocalizedMessage(), e); } }
*
* } catch (Throwable e) {
* logger.error("Error retrieving file from StorageHub", e); throw new
* TDGWTServiceException("Error retrieving file from StorageHub: " +
* e.getLocalizedMessage(), e); }
*
* }
*/
/**
*
*
@ -158,22 +118,22 @@ public class FilesStorage {
* @param user
* User
*
* @param wi
* Workspace item
* @param itemId
* Workspace item id
* @return Input stream
* @throws TDGWTServiceException
* Exception
*/
public InputStream retrieveInputStream(String user, WorkspaceItem wi) throws TDGWTServiceException {
public InputStream retrieveInputStream(String user, String itemId) throws TDGWTServiceException {
InputStream is = null;
try {
logger.debug("retrieveFile: [user=" + user + ", item=" + wi + "]");
logger.debug("retrieveFile: [user=" + user + ", itemId=" + itemId + "]");
StorageHubClient shc = new StorageHubClient();
FileContainer fileContainer = shc.open(wi.getId()).asFile();
FileContainer fileContainer = shc.open(itemId).asFile();
StreamDescriptor streamDescriptor = fileContainer.download();
is = streamDescriptor.getStream();
} catch (Throwable e) {
logger.error("Error retrieving file from StorageHub", e);
throw new TDGWTServiceException("Error retrieving file from StorageHub: " + e.getLocalizedMessage(), e);
@ -219,19 +179,19 @@ public class FilesStorage {
* Uri
* @param user
* User
* @param itemName
* @param name
* Item name
* @param itemDescription
* @param description
* Item description
* @param itemMimetype
* @param mimetype
* Item mime type
* @param folderId
* Destination folder
* @throws TDGWTServiceException
* Exception
*/
public void createItemOnWorkspace(String uri, String user, String itemName, String itemDescription,
String itemMimetype, String folderId) throws TDGWTServiceException {
public void createItemOnWorkspace(String uri, String user, String name, String description, String mimetype,
String folderId) throws TDGWTServiceException {
try {
@ -246,7 +206,7 @@ public class FilesStorage {
StorageHubClient shc = new StorageHubClient();
FolderContainer folderContainer = shc.open(folderId).asFolder();
FileContainer fileContainer = folderContainer.uploadFile(is, itemName, itemDescription);
FileContainer fileContainer = folderContainer.uploadFile(is, name, description);
AbstractFileItem afi = fileContainer.get();
logger.debug("Created file on workspace: " + afi.getId());
}
@ -265,33 +225,35 @@ public class FilesStorage {
* Storage id
* @param user
* User
* @param itemName
* @param name
* Item name
* @param itemDescription
* @param description
* Item description
* @param itemMimetype
* @param mimetype
* Item mime type
* @param itemFolder
* @param folderId
* Destination Folder
* @throws TDGWTServiceException
* Exception
*/
public void createItemOnWorkspaceByStorageId(String storageId, String user, String itemName, String itemDescription,
String itemMimetype, String itemFolder) throws TDGWTServiceException {
public void createItemOnWorkspaceByStorageId(String storageId, String user, String name, String description,
String mimetype, String folderId) throws TDGWTServiceException {
try {
logger.debug("CreateItemOnWorkspaceByStorageId: [storageId=" + storageId + ", user=" + user + ", name="
+ name + ", description=" + description + ", mimeType=" + mimetype + ", folderId=" + folderId
+ "]");
IClient client = new StorageClient(user, AccessType.PUBLIC, MemoryType.VOLATILE).getClient();
try (InputStream is = client.get().RFileAsInputStream(storageId)) {
StorageHubClient shc = new StorageHubClient();
FolderContainer folderContainer = shc.open(itemFolder).asFolder();
FileContainer fileContainer = folderContainer.uploadFile(is, itemName, itemDescription);
FolderContainer folderContainer = shc.open(folderId).asFolder();
FileContainer fileContainer = folderContainer.uploadFile(is, name, description);
AbstractFileItem afi = fileContainer.get();
logger.debug("Created file on workspace: " + afi.getId());
}
client.close();
} catch (Throwable e) {
logger.error("Error creating item on workspace: " + e.getLocalizedMessage(), e);
@ -314,6 +276,7 @@ public class FilesStorage {
public String getVREFolderIdByScope(String user, String scope) throws TDGWTServiceException {
try {
logger.debug("GetVREFolderIdByScope: [user=" + user + ", scope=" + scope + "]");
StorageHubClient shc = new StorageHubClient();
FolderContainer folderContainer = shc.openVREFolder();
FolderItem vreFolder = folderContainer.get();
@ -333,4 +296,32 @@ public class FilesStorage {
}
/**
*
* @param user
* User
* @param itemId
* Item Id
* @return Item Description
* @throws TDGWTServiceException
* Error
*/
public ItemDescription getItem(String user, String itemId) throws TDGWTServiceException {
try {
logger.debug("getItem: [user=" + user + ", itemId=" + itemId + "]");
StorageHubClient shc = new StorageHubClient();
FileContainer fileContainer = shc.open(itemId).asFile();
AbstractFileItem item = fileContainer.get();
ItemDescription itemDescription = new ItemDescription(item.getId(), item.getName(), item.getOwner(),
item.getPath(), item.getClass().getSimpleName());
logger.debug("Item retrieved: " + itemDescription);
return itemDescription;
} catch (Throwable e) {
logger.error("Error retrieving Item from StorageHub: " + e.getLocalizedMessage(), e);
throw new TDGWTServiceException("Error retrieving Item from StorageHub: " + e.getLocalizedMessage(), e);
}
}
}

View File

@ -0,0 +1,98 @@
package org.gcube.portlets.user.td.gwtservice.shared.workspace;
import java.io.Serializable;
/**
*
* @author Giancarlo Panichi
*
*
*/
public class ItemDescription implements Serializable {
private static final long serialVersionUID = -6624452446980057923L;
private String id;
private String name;
private String owner;
private String path;
private String type;
private String publicLink;
public ItemDescription() {
super();
}
public ItemDescription(String id, String name, String owner, String path, String type) {
super();
this.id = id;
this.name = name;
this.owner = owner;
this.path = path;
this.type = type;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getPublicLink() {
return publicLink;
}
public void setPublicLink(String publicLink) {
this.publicLink = publicLink;
}
public boolean compareInfo(ItemDescription itemDescription) {
if (itemDescription != null && id.compareTo(itemDescription.getId()) == 0) {
return true;
} else {
return false;
}
}
@Override
public String toString() {
return "ItemDescription [id=" + id + ", name=" + name + ", owner=" + owner + ", path=" + path + ", type=" + type
+ ", publicLink=" + publicLink + "]";
}
}