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:
parent
f840ffae53
commit
2e00334667
12
pom.xml
12
pom.xml
|
@ -72,9 +72,6 @@
|
||||||
<version>1.0.1</version>
|
<version>1.0.1</version>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</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>
|
</dependencies>
|
||||||
|
|
||||||
</profile>
|
</profile>
|
||||||
|
@ -134,17 +131,14 @@
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- GCube Widgets <dependency> <groupId>org.gcube.portlets.user</groupId>
|
<!-- JSON -->
|
||||||
<artifactId>gcube-widgets</artifactId> <scope>compile</scope> </dependency> -->
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.json</groupId>
|
<groupId>org.json</groupId>
|
||||||
<artifactId>json</artifactId>
|
<artifactId>json</artifactId>
|
||||||
<version>20090211</version>
|
<version>20090211</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- SDMX -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.data.publishing</groupId>
|
<groupId>org.gcube.data.publishing</groupId>
|
||||||
<artifactId>sdmx-registry-client-gcube</artifactId>
|
<artifactId>sdmx-registry-client-gcube</artifactId>
|
||||||
|
|
|
@ -26,13 +26,6 @@ import java.util.UUID;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
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.TemplateCategory;
|
||||||
import org.gcube.data.analysis.tabulardata.commons.templates.model.columns.ColumnCategory;
|
import org.gcube.data.analysis.tabulardata.commons.templates.model.columns.ColumnCategory;
|
||||||
import org.gcube.data.analysis.tabulardata.commons.templates.model.columns.TemplateColumn;
|
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.tr.union.UnionSession;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.uriresolver.UriResolverSession;
|
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.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.TRId;
|
||||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.mime.MimeTypeSupport;
|
import org.gcube.portlets.user.td.widgetcommonevent.shared.mime.MimeTypeSupport;
|
||||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.operations.UIOperationsId;
|
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 {
|
public void getFileFromWorkspace(CSVImportSession csvImportSession) throws TDGWTServiceException {
|
||||||
HttpServletRequest httpRequest = this.getThreadLocalRequest();
|
HttpServletRequest httpRequest = this.getThreadLocalRequest();
|
||||||
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(httpRequest);
|
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(httpRequest);
|
||||||
|
FilesStorage filesStorage = new FilesStorage();
|
||||||
Workspace w = null;
|
ItemDescription itemDescription = filesStorage.getItem(serviceCredentials.getUserName(),
|
||||||
WorkspaceItem wi = null;
|
csvImportSession.getId());
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
CSVFileUploadSession fileUploadSession = new CSVFileUploadSession();
|
CSVFileUploadSession fileUploadSession = new CSVFileUploadSession();
|
||||||
// CSVImportMonitor csvImportMonitor = new CSVImportMonitor();
|
// CSVImportMonitor csvImportMonitor = new CSVImportMonitor();
|
||||||
|
@ -3845,10 +3811,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements TDGWTServi
|
||||||
SessionUtil.setCSVFileUploadSession(httpRequest, serviceCredentials, fileUploadSession);
|
SessionUtil.setCSVFileUploadSession(httpRequest, serviceCredentials, fileUploadSession);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FilesStorage filesStorage = new FilesStorage();
|
InputStream is = filesStorage.retrieveInputStream(serviceCredentials.getUserName(),
|
||||||
InputStream is = filesStorage.retrieveInputStream(serviceCredentials.getUserName(), wi);
|
itemDescription.getId());
|
||||||
|
FileUtil.setImportFileCSV(fileUploadSession, is, itemDescription.getName(), Constants.FILE_CSV_MIMETYPE);
|
||||||
FileUtil.setImportFileCSV(fileUploadSession, is, wi.getName(), Constants.FILE_CSV_MIMETYPE);
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
FileUploadMonitor fum = SessionUtil.getFileUploadMonitor(httpRequest, serviceCredentials);
|
FileUploadMonitor fum = SessionUtil.getFileUploadMonitor(httpRequest, serviceCredentials);
|
||||||
fum.setFailed("An error occured elaborating the file", FileUtil.exceptionDetailMessage(e));
|
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);
|
logger.debug("Share with Users: " + users);
|
||||||
service.share(tabularResourceId, usersArray);
|
service.share(tabularResourceId, usersArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (TDGWTServiceException e) {
|
} catch (TDGWTServiceException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
|
@ -4526,7 +4491,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements TDGWTServi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String startExcelExport(ExcelExportSession exportSession) throws TDGWTServiceException {
|
public String startExcelExport(ExcelExportSession exportSession) throws TDGWTServiceException {
|
||||||
HttpServletRequest httpRequest = null;
|
HttpServletRequest httpRequest = null;
|
||||||
|
@ -4568,12 +4532,12 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements TDGWTServi
|
||||||
// /
|
// /
|
||||||
switch (exportSession.getExportType()) {
|
switch (exportSession.getExportType()) {
|
||||||
case DATASET:
|
case DATASET:
|
||||||
OpExecution4ExcelDatasetExport opExD = new OpExecution4ExcelDatasetExport(httpRequest, serviceCredentials,
|
OpExecution4ExcelDatasetExport opExD = new OpExecution4ExcelDatasetExport(httpRequest,
|
||||||
service, exportSession);
|
serviceCredentials, service, exportSession);
|
||||||
director.setOperationExecutionBuilder(opExD);
|
director.setOperationExecutionBuilder(opExD);
|
||||||
break;
|
break;
|
||||||
case GENERIC:
|
case GENERIC:
|
||||||
case CODELIST:
|
case CODELIST:
|
||||||
default:
|
default:
|
||||||
logger.error("Error in Excel Export: Only Codelist and Dataset are supported!");
|
logger.error("Error in Excel Export: Only Codelist and Dataset are supported!");
|
||||||
throw new TDGWTServiceException("Error in ExcelExport: Only 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
|
@Override
|
||||||
public String startSDMXTemplateExport(SDMXTemplateExportSession sdmxTemplateExportSession)
|
public String startSDMXTemplateExport(SDMXTemplateExportSession sdmxTemplateExportSession)
|
||||||
throws TDGWTServiceException {
|
throws TDGWTServiceException {
|
||||||
|
@ -7381,43 +7344,11 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements TDGWTServi
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getFileFromWorkspace(CodelistMappingSession codelistMappingSession) throws TDGWTServiceException {
|
public void getFileFromWorkspace(CodelistMappingSession codelistMappingSession) throws TDGWTServiceException {
|
||||||
|
|
||||||
Workspace w = null;
|
|
||||||
WorkspaceItem wi = null;
|
|
||||||
|
|
||||||
HttpServletRequest httpRequest = this.getThreadLocalRequest();
|
HttpServletRequest httpRequest = this.getThreadLocalRequest();
|
||||||
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(httpRequest);
|
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(httpRequest);
|
||||||
|
FilesStorage filesStorage = new FilesStorage();
|
||||||
try {
|
ItemDescription itemDescription = filesStorage.getItem(serviceCredentials.getUserName(),
|
||||||
HomeManagerFactory factory = HomeLibrary.getHomeManagerFactory();
|
codelistMappingSession.getItemId());
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
CodelistMappingFileUploadSession fileUploadSession = new CodelistMappingFileUploadSession();
|
CodelistMappingFileUploadSession fileUploadSession = new CodelistMappingFileUploadSession();
|
||||||
// CodelistMappingMonitor codelistMappingMonitor = new
|
// CodelistMappingMonitor codelistMappingMonitor = new
|
||||||
|
@ -7432,10 +7363,11 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements TDGWTServi
|
||||||
SessionUtil.setCodelistMappingFileUploadSession(httpRequest, serviceCredentials, fileUploadSession);
|
SessionUtil.setCodelistMappingFileUploadSession(httpRequest, serviceCredentials, fileUploadSession);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FilesStorage filesStorage = new FilesStorage();
|
|
||||||
InputStream is = filesStorage.retrieveInputStream(serviceCredentials.getUserName(), wi);
|
InputStream is = filesStorage.retrieveInputStream(serviceCredentials.getUserName(),
|
||||||
|
itemDescription.getId());
|
||||||
FileUtil.setImportFileCodelistMapping(fileUploadSession, is, wi.getName(), Constants.FILE_XML_MIMETYPE);
|
FileUtil.setImportFileCodelistMapping(fileUploadSession, is, itemDescription.getName(),
|
||||||
|
Constants.FILE_XML_MIMETYPE);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
FileUploadMonitor fum = SessionUtil.getFileUploadMonitor(httpRequest, serviceCredentials);
|
FileUploadMonitor fum = SessionUtil.getFileUploadMonitor(httpRequest, serviceCredentials);
|
||||||
fum.setFailed("An error occured elaborating the file", FileUtil.exceptionDetailMessage(e));
|
fum.setFailed("An error occured elaborating the file", FileUtil.exceptionDetailMessage(e));
|
||||||
|
|
|
@ -5,7 +5,6 @@ import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
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.StreamDescriptor;
|
||||||
import org.gcube.common.storagehub.client.dsl.FileContainer;
|
import org.gcube.common.storagehub.client.dsl.FileContainer;
|
||||||
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
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.MemoryType;
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
|
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.exception.TDGWTServiceException;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.workspace.ItemDescription;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ public class FilesStorage {
|
||||||
logger.debug("remotePath: " + remotePath);
|
logger.debug("remotePath: " + remotePath);
|
||||||
String id = client.put(true).LFile(file.getAbsolutePath()).RFile(remotePath);
|
String id = client.put(true).LFile(file.getAbsolutePath()).RFile(remotePath);
|
||||||
client.close();
|
client.close();
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
|
|
||||||
} catch (Throwable e) {
|
} 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
|
* @param user
|
||||||
* User
|
* User
|
||||||
*
|
*
|
||||||
* @param wi
|
* @param itemId
|
||||||
* Workspace item
|
* Workspace item id
|
||||||
* @return Input stream
|
* @return Input stream
|
||||||
* @throws TDGWTServiceException
|
* @throws TDGWTServiceException
|
||||||
* Exception
|
* Exception
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public InputStream retrieveInputStream(String user, WorkspaceItem wi) throws TDGWTServiceException {
|
public InputStream retrieveInputStream(String user, String itemId) throws TDGWTServiceException {
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
try {
|
try {
|
||||||
logger.debug("retrieveFile: [user=" + user + ", item=" + wi + "]");
|
logger.debug("retrieveFile: [user=" + user + ", itemId=" + itemId + "]");
|
||||||
StorageHubClient shc = new StorageHubClient();
|
StorageHubClient shc = new StorageHubClient();
|
||||||
FileContainer fileContainer = shc.open(wi.getId()).asFile();
|
FileContainer fileContainer = shc.open(itemId).asFile();
|
||||||
StreamDescriptor streamDescriptor = fileContainer.download();
|
StreamDescriptor streamDescriptor = fileContainer.download();
|
||||||
is = streamDescriptor.getStream();
|
is = streamDescriptor.getStream();
|
||||||
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
logger.error("Error retrieving file from StorageHub", e);
|
logger.error("Error retrieving file from StorageHub", e);
|
||||||
throw new TDGWTServiceException("Error retrieving file from StorageHub: " + e.getLocalizedMessage(), e);
|
throw new TDGWTServiceException("Error retrieving file from StorageHub: " + e.getLocalizedMessage(), e);
|
||||||
|
@ -219,19 +179,19 @@ public class FilesStorage {
|
||||||
* Uri
|
* Uri
|
||||||
* @param user
|
* @param user
|
||||||
* User
|
* User
|
||||||
* @param itemName
|
* @param name
|
||||||
* Item name
|
* Item name
|
||||||
* @param itemDescription
|
* @param description
|
||||||
* Item description
|
* Item description
|
||||||
* @param itemMimetype
|
* @param mimetype
|
||||||
* Item mime type
|
* Item mime type
|
||||||
* @param folderId
|
* @param folderId
|
||||||
* Destination folder
|
* Destination folder
|
||||||
* @throws TDGWTServiceException
|
* @throws TDGWTServiceException
|
||||||
* Exception
|
* Exception
|
||||||
*/
|
*/
|
||||||
public void createItemOnWorkspace(String uri, String user, String itemName, String itemDescription,
|
public void createItemOnWorkspace(String uri, String user, String name, String description, String mimetype,
|
||||||
String itemMimetype, String folderId) throws TDGWTServiceException {
|
String folderId) throws TDGWTServiceException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
@ -246,7 +206,7 @@ public class FilesStorage {
|
||||||
|
|
||||||
StorageHubClient shc = new StorageHubClient();
|
StorageHubClient shc = new StorageHubClient();
|
||||||
FolderContainer folderContainer = shc.open(folderId).asFolder();
|
FolderContainer folderContainer = shc.open(folderId).asFolder();
|
||||||
FileContainer fileContainer = folderContainer.uploadFile(is, itemName, itemDescription);
|
FileContainer fileContainer = folderContainer.uploadFile(is, name, description);
|
||||||
AbstractFileItem afi = fileContainer.get();
|
AbstractFileItem afi = fileContainer.get();
|
||||||
logger.debug("Created file on workspace: " + afi.getId());
|
logger.debug("Created file on workspace: " + afi.getId());
|
||||||
}
|
}
|
||||||
|
@ -265,33 +225,35 @@ public class FilesStorage {
|
||||||
* Storage id
|
* Storage id
|
||||||
* @param user
|
* @param user
|
||||||
* User
|
* User
|
||||||
* @param itemName
|
* @param name
|
||||||
* Item name
|
* Item name
|
||||||
* @param itemDescription
|
* @param description
|
||||||
* Item description
|
* Item description
|
||||||
* @param itemMimetype
|
* @param mimetype
|
||||||
* Item mime type
|
* Item mime type
|
||||||
* @param itemFolder
|
* @param folderId
|
||||||
* Destination Folder
|
* Destination Folder
|
||||||
* @throws TDGWTServiceException
|
* @throws TDGWTServiceException
|
||||||
* Exception
|
* Exception
|
||||||
*/
|
*/
|
||||||
public void createItemOnWorkspaceByStorageId(String storageId, String user, String itemName, String itemDescription,
|
public void createItemOnWorkspaceByStorageId(String storageId, String user, String name, String description,
|
||||||
String itemMimetype, String itemFolder) throws TDGWTServiceException {
|
String mimetype, String folderId) throws TDGWTServiceException {
|
||||||
|
|
||||||
try {
|
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();
|
IClient client = new StorageClient(user, AccessType.PUBLIC, MemoryType.VOLATILE).getClient();
|
||||||
|
|
||||||
try (InputStream is = client.get().RFileAsInputStream(storageId)) {
|
try (InputStream is = client.get().RFileAsInputStream(storageId)) {
|
||||||
|
|
||||||
StorageHubClient shc = new StorageHubClient();
|
StorageHubClient shc = new StorageHubClient();
|
||||||
FolderContainer folderContainer = shc.open(itemFolder).asFolder();
|
FolderContainer folderContainer = shc.open(folderId).asFolder();
|
||||||
FileContainer fileContainer = folderContainer.uploadFile(is, itemName, itemDescription);
|
FileContainer fileContainer = folderContainer.uploadFile(is, name, description);
|
||||||
AbstractFileItem afi = fileContainer.get();
|
AbstractFileItem afi = fileContainer.get();
|
||||||
logger.debug("Created file on workspace: " + afi.getId());
|
logger.debug("Created file on workspace: " + afi.getId());
|
||||||
}
|
}
|
||||||
client.close();
|
client.close();
|
||||||
|
|
||||||
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
logger.error("Error creating item on workspace: " + e.getLocalizedMessage(), 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 {
|
public String getVREFolderIdByScope(String user, String scope) throws TDGWTServiceException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
logger.debug("GetVREFolderIdByScope: [user=" + user + ", scope=" + scope + "]");
|
||||||
StorageHubClient shc = new StorageHubClient();
|
StorageHubClient shc = new StorageHubClient();
|
||||||
FolderContainer folderContainer = shc.openVREFolder();
|
FolderContainer folderContainer = shc.openVREFolder();
|
||||||
FolderItem vreFolder = folderContainer.get();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue