ref 11720: DataMiner - Update to StorageHUB

https://support.d4science.org/issues/11720

Updated to StorageHub getPublicLink and getProperties functions.

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/data-miner-manager@169410 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2018-06-22 16:30:51 +00:00
parent 40b10c8360
commit 321ecc3fb1
11 changed files with 176 additions and 141 deletions

20
pom.xml
View File

@ -109,6 +109,14 @@
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<!-- StorageHub -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-library</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Authorization --> <!-- Authorization -->
<dependency> <dependency>
<groupId>org.gcube.common</groupId> <groupId>org.gcube.common</groupId>
@ -232,6 +240,12 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- StorageHub -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-library</artifactId>
<scope>provided</scope>
</dependency>
<!-- Information System Client IC-Client --> <!-- Information System Client IC-Client -->
<dependency> <dependency>
@ -260,7 +274,7 @@
<dependency> <dependency>
<groupId>org.gcube.portlets.widgets</groupId> <groupId>org.gcube.portlets.widgets</groupId>
<artifactId>workspace-explorer</artifactId> <artifactId>workspace-explorer</artifactId>
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version> <version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
</dependency> </dependency>
<!-- Workspace Uploader --> <!-- Workspace Uploader -->
@ -360,8 +374,8 @@
<runTarget>DataMinerManager.html</runTarget> <runTarget>DataMinerManager.html</runTarget>
<hostedWebapp>${webappDirectory}</hostedWebapp> <hostedWebapp>${webappDirectory}</hostedWebapp>
<module>org.gcube.portlets.user.dataminermanager.dataminermanager</module> <module>org.gcube.portlets.user.dataminermanager.dataminermanager</module>
<!-- <style>DETAILED</style> -->
</configuration> </configuration>
</plugin> </plugin>

View File

@ -109,7 +109,7 @@ public class PortalViewport extends SimpleContainer {
} }
int viewHeight = calculateHeight(); int viewHeight = calculateHeight();
Log.info("AM resize viewWidth: " + viewWidth + " viewHeight: " Log.info("DataMiner resize viewWidth: " + viewWidth + " viewHeight: "
+ viewHeight + " clientWidth: " + Window.getClientWidth() + viewHeight + " clientWidth: " + Window.getClientWidth()
+ " clientHeight: " + Window.getClientHeight()); + " clientHeight: " + Window.getClientHeight());
try { try {
@ -127,7 +127,7 @@ public class PortalViewport extends SimpleContainer {
protected void onWindowResize(int width, int height) { protected void onWindowResize(int width, int height) {
int viewWidth = calculateWidth(); int viewWidth = calculateWidth();
int viewHeight = calculateHeight(); int viewHeight = calculateHeight();
Log.trace("AM onWindowResize viewWidth: " + viewWidth Log.trace("DataMiner onWindowResize viewWidth: " + viewWidth
+ " viewHeight: " + viewHeight + " clientWidth: " + " viewHeight: " + viewHeight + " clientWidth: "
+ Window.getClientWidth() + " clientHeight: " + Window.getClientWidth() + " clientHeight: "
+ Window.getClientHeight()); + Window.getClientHeight());
@ -138,14 +138,14 @@ public class PortalViewport extends SimpleContainer {
protected int calculateWidth() { protected int calculateWidth() {
int leftBorder = getAbsoluteLeft(); int leftBorder = getAbsoluteLeft();
Log.info("AM width: " Log.info("DataMiner width: "
+ String.valueOf(Window.getClientWidth() - 2 * leftBorder)); + String.valueOf(Window.getClientWidth() - 2 * leftBorder));
return Window.getClientWidth() - 2 * leftBorder; return Window.getClientWidth() - 2 * leftBorder;
} }
protected int calculateHeight() { protected int calculateHeight() {
int topBorder = getAbsoluteTop(); int topBorder = getAbsoluteTop();
Log.info("AM height: " Log.info("DataMiner height: "
+ String.valueOf(Window.getClientHeight() - topBorder - 34)); + String.valueOf(Window.getClientHeight() - topBorder - 34));
return Window.getClientHeight() - topBorder - 34; return Window.getClientHeight() - topBorder - 34;
} }

View File

@ -5,6 +5,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.gcube.data.analysis.dataminermanagercl.shared.workspace.ItemDescription;
import org.gcube.portal.clientcontext.client.GCubeClientContext; import org.gcube.portal.clientcontext.client.GCubeClientContext;
import org.gcube.portlets.user.dataminermanager.client.DataMinerManager; import org.gcube.portlets.user.dataminermanager.client.DataMinerManager;
import org.gcube.portlets.user.dataminermanager.client.common.EventBusProvider; import org.gcube.portlets.user.dataminermanager.client.common.EventBusProvider;
@ -18,7 +19,6 @@ import org.gcube.portlets.user.dataminermanager.client.type.DataMinerWorkAreaEle
import org.gcube.portlets.user.dataminermanager.client.util.UtilsGXT3; import org.gcube.portlets.user.dataminermanager.client.util.UtilsGXT3;
import org.gcube.portlets.user.dataminermanager.shared.Constants; import org.gcube.portlets.user.dataminermanager.shared.Constants;
import org.gcube.portlets.user.dataminermanager.shared.exception.SessionExpiredServiceException; import org.gcube.portlets.user.dataminermanager.shared.exception.SessionExpiredServiceException;
import org.gcube.data.analysis.dataminermanagercl.shared.workspace.ItemDescription;
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener; import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener;
import org.gcube.portlets.widgets.workspaceuploader.client.uploader.DialogUpload.UPLOAD_TYPE; import org.gcube.portlets.widgets.workspaceuploader.client.uploader.DialogUpload.UPLOAD_TYPE;
import org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload; import org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload;
@ -288,7 +288,9 @@ public class InputDataSetsPanel extends FramedPanel {
}; };
dnd.addWorkspaceUploadNotificationListener(workspaceUploaderListener); dnd.addWorkspaceUploadNotificationListener(workspaceUploaderListener);
Log.debug("Create ToolBar for InputDataSetsPanel");
// ToolBar // ToolBar
btnDownload = new TextButton("Download"); btnDownload = new TextButton("Download");
btnDownload.setIcon(DataMinerManager.resources.download()); btnDownload.setIcon(DataMinerManager.resources.download());

View File

@ -5,6 +5,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.gcube.data.analysis.dataminermanagercl.shared.workspace.ItemDescription;
import org.gcube.portal.clientcontext.client.GCubeClientContext; import org.gcube.portal.clientcontext.client.GCubeClientContext;
import org.gcube.portlets.user.dataminermanager.client.DataMinerManager; import org.gcube.portlets.user.dataminermanager.client.DataMinerManager;
import org.gcube.portlets.user.dataminermanager.client.common.EventBusProvider; import org.gcube.portlets.user.dataminermanager.client.common.EventBusProvider;
@ -18,7 +19,6 @@ import org.gcube.portlets.user.dataminermanager.client.type.DataMinerWorkAreaEle
import org.gcube.portlets.user.dataminermanager.client.util.UtilsGXT3; import org.gcube.portlets.user.dataminermanager.client.util.UtilsGXT3;
import org.gcube.portlets.user.dataminermanager.shared.Constants; import org.gcube.portlets.user.dataminermanager.shared.Constants;
import org.gcube.portlets.user.dataminermanager.shared.exception.SessionExpiredServiceException; import org.gcube.portlets.user.dataminermanager.shared.exception.SessionExpiredServiceException;
import org.gcube.data.analysis.dataminermanagercl.shared.workspace.ItemDescription;
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener; import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener;
import org.gcube.portlets.widgets.workspaceuploader.client.uploader.DialogUpload.UPLOAD_TYPE; import org.gcube.portlets.widgets.workspaceuploader.client.uploader.DialogUpload.UPLOAD_TYPE;
import org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload; import org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload;
@ -147,7 +147,7 @@ public class OutputDataSetsPanel extends FramedPanel {
} }
switch (event.getDataMinerWorkAreaRegionType()) { switch (event.getDataMinerWorkAreaRegionType()) {
case Computations: case Computations:
break; break;
case DataSets: case DataSets:
manageMyDataMinerWorkAreaEvents(event); manageMyDataMinerWorkAreaEvents(event);
break; break;
@ -250,10 +250,10 @@ public class OutputDataSetsPanel extends FramedPanel {
wsResourcesExplorerPanel.ensureDebugId("wsResourceExplorerPanelForOutput"); wsResourcesExplorerPanel.ensureDebugId("wsResourceExplorerPanelForOutput");
wsResourcesExplorerPanel.setHeightToInternalScroll(300); wsResourcesExplorerPanel.setHeightToInternalScroll(300);
Log.debug("Define DND for InputDataSetsPanel"); Log.debug("Define DND for OutputDataSetsPanel");
// DND // DND
dnd = new MultipleDNDUpload(); dnd = new MultipleDNDUpload();
dnd.setParameters(event.getDataMinerWorkArea().getOutputDataSets().getFolder().getId(), UPLOAD_TYPE.File); dnd.setParameters(event.getDataMinerWorkArea().getOutputDataSets().getFolder().getId(), UPLOAD_TYPE.File);
dnd.addUniqueContainer(wsResourcesExplorerPanel); dnd.addUniqueContainer(wsResourcesExplorerPanel);
@ -287,7 +287,8 @@ public class OutputDataSetsPanel extends FramedPanel {
}; };
dnd.addWorkspaceUploadNotificationListener(workspaceUploaderListener); dnd.addWorkspaceUploadNotificationListener(workspaceUploaderListener);
Log.debug("Create ToolBar for OutputDatasetsPanel");
// ToolBar // ToolBar
btnDownload = new TextButton("Download"); btnDownload = new TextButton("Download");
btnDownload.setIcon(DataMinerManager.resources.download()); btnDownload.setIcon(DataMinerManager.resources.download());
@ -340,6 +341,7 @@ public class OutputDataSetsPanel extends FramedPanel {
v.add(toolBar, new VerticalLayoutData(1, -1, new Margins(0))); v.add(toolBar, new VerticalLayoutData(1, -1, new Margins(0)));
v.add(dnd, new VerticalLayoutData(1, 1, new Margins(0))); v.add(dnd, new VerticalLayoutData(1, 1, new Margins(0)));
//v.add(wsResourcesExplorerPanel, new VerticalLayoutData(1, 1, new Margins(0)));
add(v); add(v);
v.addResizeHandler(new ResizeHandler() { v.addResizeHandler(new ResizeHandler() {
@ -429,7 +431,7 @@ public class OutputDataSetsPanel extends FramedPanel {
if (caught instanceof SessionExpiredServiceException) { if (caught instanceof SessionExpiredServiceException) {
EventBusProvider.INSTANCE.fireEvent(new SessionExpiredEvent()); EventBusProvider.INSTANCE.fireEvent(new SessionExpiredEvent());
} else { } else {
Log.error("Error open file: " + caught.getLocalizedMessage()); Log.error("Error open file: " + caught.getLocalizedMessage(),caught);
UtilsGXT3.alert("Error", caught.getLocalizedMessage()); UtilsGXT3.alert("Error", caught.getLocalizedMessage());
} }
caught.printStackTrace(); caught.printStackTrace();

View File

@ -6,8 +6,10 @@
<!-- <inherits name='com.google.gwt.user.theme.clean.Clean' /> --> <!-- <inherits name='com.google.gwt.user.theme.clean.Clean' /> -->
<inherits name='com.sencha.gxt.ui.GXT' /> <inherits name='com.sencha.gxt.ui.GXT' />
<!-- <inherits name="com.extjs.gxt.ui.GXT" /> --> <!-- <inherits name="com.extjs.gxt.ui.GXT" /> -->
<!-- <inherits name="com.google.gwt.logging.Logging" /> --> <!--
<inherits name="com.google.gwt.logging.Logging" />
-->
<inherits name="com.allen_sauer.gwt.log.gwt-log-TRACE" /> <inherits name="com.allen_sauer.gwt.log.gwt-log-TRACE" />
@ -41,16 +43,21 @@
<entry-point <entry-point
class='org.gcube.portlets.user.dataminermanager.client.DataMinerManager' /> class='org.gcube.portlets.user.dataminermanager.client.DataMinerManager' />
<!-- <set-property name="log_ConsoleLogger" value="ENABLED" /> <set-property <!--
name="log_DivLogger" value="ENABLED" /> <set-property name="log_GWTLogger" <set-property name="log_ConsoleLogger" value="ENABLED" />
value="ENABLED" /> <set-property name="log_SystemLogger" value="ENABLED" <set-property name="log_DivLogger" value="ENABLED" />
/> --> <set-property name="log_GWTLogger" value="ENABLED" />
<set-property name="log_SystemLogger" value="ENABLED" />
<set-property name="log_ConsoleLogger" value="DISABLED" />
<set-property name="log_DivLogger" value="DISABLED" />
<set-property name="log_GWTLogger" value="DISABLED" />
<set-property name="log_SystemLogger" value="DISABLED" />
<set-property name="gwt.logging.logLevel" value="SEVERE" />
<set-property name="gwt.logging.enabled" value="TRUE" />
<set-property name="gwt.logging.consoleHandler" value="ENABLED" /> -->
<set-property name="log_ConsoleLogger" value="DISABLED" /> <set-property
name="log_DivLogger" value="DISABLED" /> <set-property name="log_GWTLogger"
value="DISABLED" /> <set-property name="log_SystemLogger" value="DISABLED"
/>
<source path='client' /> <source path='client' />
<source path='shared' /> <source path='shared' />

View File

@ -139,9 +139,10 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
@Override @Override
public ComputationId resubmit(ItemDescription itemDescription) throws ServiceException { public ComputationId resubmit(ItemDescription itemDescription) throws ServiceException {
try { try {
StorageUtil storageUtil=new StorageUtil();
HttpServletRequest httpRequest = this.getThreadLocalRequest(); HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(httpRequest); ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(httpRequest);
Map<String, String> properties = StorageUtil.getProperties(serviceCredentials.getUserName(), Map<String, String> properties = storageUtil.getProperties(serviceCredentials.getUserName(),
itemDescription.getId()); itemDescription.getId());
logger.debug("Properties: " + properties); logger.debug("Properties: " + properties);
@ -182,7 +183,8 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
HttpServletRequest httpRequest = this.getThreadLocalRequest(); HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(httpRequest); ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(httpRequest);
logger.debug("DeleteItem(): " + itemDescription); logger.debug("DeleteItem(): " + itemDescription);
StorageUtil.deleteItem(serviceCredentials.getUserName(), itemDescription.getId()); StorageUtil storageUtil=new StorageUtil();
storageUtil.deleteItem(serviceCredentials.getUserName(), itemDescription.getId());
return; return;
} catch (ServiceException e) { } catch (ServiceException e) {
@ -236,7 +238,8 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
HttpServletRequest httpRequest = this.getThreadLocalRequest(); HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(httpRequest); ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(httpRequest);
logger.debug("GetPublicLink(): " + itemDescription); logger.debug("GetPublicLink(): " + itemDescription);
String link = StorageUtil.getPublicLink(serviceCredentials.getUserName(), itemDescription.getId()); StorageUtil storageUtil=new StorageUtil();
String link = storageUtil.getPublicLink(serviceCredentials.getUserName(), itemDescription.getId());
return link; return link;
} catch (ServiceException e) { } catch (ServiceException e) {
@ -293,7 +296,8 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
HttpServletRequest httpRequest = this.getThreadLocalRequest(); HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(httpRequest); ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(httpRequest);
logger.debug("OutputDataByComputationItemt(): " + itemDescription); logger.debug("OutputDataByComputationItemt(): " + itemDescription);
Map<String, String> properties = StorageUtil.getProperties(serviceCredentials.getUserName(), StorageUtil storageUtil=new StorageUtil();
Map<String, String> properties = storageUtil.getProperties(serviceCredentials.getUserName(),
itemDescription.getId()); itemDescription.getId());
logger.debug("Properties: " + properties); logger.debug("Properties: " + properties);

View File

@ -3,7 +3,11 @@ package org.gcube.portlets.user.dataminermanager.server;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
@ -106,15 +110,21 @@ public class DownloadFolderServlet extends HttpServlet {
.getParameter(Constants.DOWNLOAD_FOLDER_SERVLET_FOLDER_NAME_PARAMETER); .getParameter(Constants.DOWNLOAD_FOLDER_SERVLET_FOLDER_NAME_PARAMETER);
logger.debug("Request: [itemId=" + itemId + ", folderName=" logger.debug("Request: [itemId=" + itemId + ", folderName="
+ folderName + "]"); + folderName + "]");
StorageUtil storageUtil=new StorageUtil();
File tmpZip = StorageUtil.zipFolder( InputStream is = storageUtil.zipFolder(
serviceCredentials.getUserName(), itemId); serviceCredentials.getUserName(), itemId);
Path tempFile = Files.createTempFile("dataMinerDownload", ".zip");
Files.copy(is, tempFile, StandardCopyOption.REPLACE_EXISTING);
File tmpZip= tempFile.toFile();
response.setHeader("Content-Disposition", "attachment; filename=\"" response.setHeader("Content-Disposition", "attachment; filename=\""
+ folderName + ".zip\""); + folderName + ".zip\"");
response.setContentType("application/zip"); response.setContentType("application/zip");
response.setHeader("Content-Length", response.setHeader("Content-Length",
String.valueOf(tmpZip.length())); String.valueOf(tmpZip.length()));
OutputStream out = response.getOutputStream(); OutputStream out = response.getOutputStream();
FileInputStream fileTmpZip = new FileInputStream(tmpZip); FileInputStream fileTmpZip = new FileInputStream(tmpZip);
@ -122,13 +132,12 @@ public class DownloadFolderServlet extends HttpServlet {
out.flush(); out.flush();
out.close(); out.close();
fileTmpZip.close(); fileTmpZip.close();
tmpZip.delete(); Files.delete(tempFile);
return; return;
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Error in DownloadFolderServlet: " logger.error("Error in DownloadFolderServlet: "
+ e.getLocalizedMessage()); + e.getLocalizedMessage(),e);
e.printStackTrace();
throw new ServletException("Error:" + e.getLocalizedMessage(), e); throw new ServletException("Error:" + e.getLocalizedMessage(), e);
} }

View File

@ -1,15 +1,24 @@
package org.gcube.portlets.user.dataminermanager.server.storage; package org.gcube.portlets.user.dataminermanager.server.storage;
import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.gcube.common.homelibrary.home.HomeLibrary; import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.workspace.Properties;
import org.gcube.common.homelibrary.home.workspace.Workspace; 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.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.common.homelibrary.util.zip.ZipUtil; import org.gcube.common.storagehub.client.StreamDescriptor;
import org.gcube.common.storagehub.client.dsl.ItemContainer;
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.items.AbstractFileItem;
import org.gcube.common.storagehub.model.items.FolderItem;
import org.gcube.common.storagehub.model.items.GenericFileItem;
import org.gcube.common.storagehub.model.items.ImageFile;
import org.gcube.common.storagehub.model.items.Item;
import org.gcube.common.storagehub.model.items.PDFFileItem;
import org.gcube.portlets.user.dataminermanager.shared.exception.ServiceException; import org.gcube.portlets.user.dataminermanager.shared.exception.ServiceException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -34,19 +43,22 @@ public class StorageUtil {
* @throws ServiceException * @throws ServiceException
* service exception * service exception
*/ */
public static Map<String, String> getProperties(String user, String itemId) throws ServiceException { public Map<String, String> getProperties(String user, String itemId) throws ServiceException {
try { try {
Workspace ws = HomeLibrary.getUserWorkspace(user); StorageHubClient shc = new StorageHubClient();
Item item = shc.open(itemId).asItem().get();
WorkspaceItem workSpaceItem = ws.getItem(itemId); Metadata metadata = item.getPropertyMap();
Properties properties = workSpaceItem.getProperties(); Map<String, String> itemMap = new HashMap<String, String>();
Map<String, Object> metadataMap = metadata.getValues();
return properties.getProperties(); for (String key : metadataMap.keySet()) {
String s = String.valueOf(metadataMap.get(key));
itemMap.put(key, s);
}
return itemMap;
} catch (Throwable e) { } catch (Throwable e) {
logger.error(e.getLocalizedMessage()); logger.error("Error retrieving properties: " +e.getLocalizedMessage(), e);
e.printStackTrace(); throw new ServiceException(e.getLocalizedMessage(),e);
throw new ServiceException(e.getLocalizedMessage());
} }
} }
@ -61,50 +73,33 @@ public class StorageUtil {
* @throws ServiceException * @throws ServiceException
* service exception * service exception
*/ */
public static InputStream getInputStreamForItemOnWorkspace(String user, String itemId) throws ServiceException { public InputStream getInputStreamForItemOnWorkspace(String user, String itemId) throws ServiceException {
Workspace ws;
try { try {
ws = HomeLibrary.getUserWorkspace(user); logger.debug("getInputStreamForItemOnWorkspace: [user="+user+", itemId="+itemId+"]");
StorageHubClient shc = new StorageHubClient();
ItemContainer<Item> itemContainer = shc.open(itemId).asItem();
Item item = itemContainer.get();
if (item instanceof AbstractFileItem) {
if (item instanceof GenericFileItem | item instanceof ImageFile | item instanceof PDFFileItem) {
StreamDescriptor streamDescriptor = itemContainer.download();
return streamDescriptor.getStream();
} else {
throw new ServiceException("Is not a valid file!");
}
} else {
throw new ServiceException("Is not a valid file!");
WorkspaceItem workSpaceItem = ws.getItem(itemId);
if (workSpaceItem.isFolder()) {
throw new ServiceException("Folder is not valid!");
} }
return getInputStream(user, workSpaceItem);
} catch (Throwable e) { } catch (Throwable e) {
logger.error(e.getLocalizedMessage()); logger.error("Error retrieving InputStream for Item: " +e.getLocalizedMessage(), e);
e.printStackTrace(); throw new ServiceException(e.getLocalizedMessage(),e);
throw new ServiceException(e.getLocalizedMessage());
} }
} }
/**
*
* @param user
* user
* @param workspaceItem
* workspace item
* @return input stream
* @throws ServiceException
* service exception
*/
private static InputStream getInputStream(String user, WorkspaceItem workspaceItem) throws ServiceException {
InputStream is = null;
try {
org.gcube.common.homelibrary.home.workspace.folder.items.File gcubeItem = ((org.gcube.common.homelibrary.home.workspace.folder.items.File) workspaceItem);
is = gcubeItem.getData();
return is;
} catch (Throwable e) {
logger.error("Error retrieving InputStream from storage", e);
e.printStackTrace();
throw new ServiceException("Error retrieving file from storage: " + e.getLocalizedMessage(), e);
}
}
/** /**
* *
@ -116,23 +111,16 @@ public class StorageUtil {
* @throws ServiceException * @throws ServiceException
* service exception * service exception
*/ */
public static String getPublicLink(String user, String itemId) throws ServiceException { public String getPublicLink(String user, String itemId) throws ServiceException {
Workspace ws;
try { try {
ws = HomeLibrary.getUserWorkspace(user); logger.debug("getPublicLink: [user="+user+", itemId="+itemId+"]");
StorageHubClient shc = new StorageHubClient();
WorkspaceItem workSpaceItem = ws.getItem(itemId); URL url = shc.open(itemId).asFile().getPublicLink();
if (workSpaceItem.isFolder()) { return url.toString();
throw new ServiceException("Attention this is a folder!");
}
return workSpaceItem.getPublicLink(false);
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Error retrieving public link: " + e.getLocalizedMessage()); logger.error("Error retrieving public link: " + e.getLocalizedMessage(),e);
e.printStackTrace(); throw new ServiceException(e.getLocalizedMessage(),e);
throw new ServiceException(e.getLocalizedMessage());
} }
} }
@ -142,30 +130,29 @@ public class StorageUtil {
* user * user
* @param folderId * @param folderId
* folder id * folder id
* @return zip folder * @return input stream
* @throws ServiceException * @throws ServiceException
* service exception * service exception
*/ */
public static File zipFolder(String user, String folderId) throws ServiceException { public InputStream zipFolder(String user, String folderId) throws ServiceException {
Workspace ws;
try { try {
logger.debug("zipFolder: [user=" + user + ", folderId=" + folderId + "]"); logger.debug("zipFolder: [user=" + user + ", folderId=" + folderId + "]");
ws = HomeLibrary.getUserWorkspace(user); StorageHubClient shc = new StorageHubClient();
OpenResolver openResolver = shc.open(folderId);
WorkspaceItem workSpaceItem = ws.getItem(folderId); ItemContainer<Item> itemContainer = openResolver.asItem();
if (!workSpaceItem.isFolder()) { Item item = itemContainer.get();
throw new ServiceException("Item is not valid folder!"); if (item instanceof FolderItem) {
StreamDescriptor streamDescriptor = openResolver.asFolder().download();
InputStream is = streamDescriptor.getStream();
return is;
} else {
throw new ServiceException("Is not a valid folder!");
} }
WorkspaceFolder folder = (WorkspaceFolder) workSpaceItem;
File fileZip = ZipUtil.zipFolder(folder);
return fileZip;
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); logger.error("Error in zip Folder: " +e.getLocalizedMessage(),e);
throw new ServiceException(e.getLocalizedMessage()); throw new ServiceException(e.getLocalizedMessage(),e);
} }
} }
@ -180,9 +167,10 @@ public class StorageUtil {
* @throws ServiceException * @throws ServiceException
* service exception * service exception
*/ */
public static WorkspaceItem getItemInRootFolderOnWorkspace(String user, String itemName) throws ServiceException { public WorkspaceItem getItemInRootFolderOnWorkspace(String user, String itemName) throws ServiceException {
Workspace ws; Workspace ws;
try { try {
logger.debug("");
ws = HomeLibrary.getUserWorkspace(user); ws = HomeLibrary.getUserWorkspace(user);
WorkspaceItem item = ws.find(itemName, ws.getRoot().getId()); WorkspaceItem item = ws.find(itemName, ws.getRoot().getId());
@ -190,7 +178,7 @@ public class StorageUtil {
return item; return item;
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); logger.error("Error in get Item in RootFolder: " +e.getLocalizedMessage(),e);
throw new ServiceException(e.getLocalizedMessage()); throw new ServiceException(e.getLocalizedMessage());
} }
} }
@ -207,7 +195,7 @@ public class StorageUtil {
* @throws ServiceException * @throws ServiceException
* service exception * service exception
*/ */
public static WorkspaceItem getItemInFolderOnWorkspace(String user, String folderId, String itemName) public WorkspaceItem getItemInFolderOnWorkspace(String user, String folderId, String itemName)
throws ServiceException { throws ServiceException {
Workspace ws; Workspace ws;
try { try {
@ -218,7 +206,7 @@ public class StorageUtil {
return item; return item;
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); logger.error("Error in get Item in Folder: " +e.getLocalizedMessage(),e);
throw new ServiceException(e.getLocalizedMessage()); throw new ServiceException(e.getLocalizedMessage());
} }
} }
@ -232,7 +220,7 @@ public class StorageUtil {
* @throws ServiceException * @throws ServiceException
* service exception * service exception
*/ */
public static void deleteItem(String user, String itemId) throws ServiceException { public void deleteItem(String user, String itemId) throws ServiceException {
Workspace ws; Workspace ws;
try { try {
logger.debug("User: " + user + ", ItemId:" + itemId); logger.debug("User: " + user + ", ItemId:" + itemId);
@ -242,7 +230,7 @@ public class StorageUtil {
return; return;
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); logger.error("Error deleting Item: "+e.getLocalizedMessage(),e);
throw new ServiceException(e.getLocalizedMessage()); throw new ServiceException(e.getLocalizedMessage());
} }

View File

@ -36,8 +36,10 @@ public class DataMinerWorkAreaManager {
public DataMinerWorkArea getDataMinerWorkArea() throws ServiceException { public DataMinerWorkArea getDataMinerWorkArea() throws ServiceException {
DataMinerWorkArea dataMinerWorkArea = null; DataMinerWorkArea dataMinerWorkArea = null;
StorageUtil storageUtil=new StorageUtil();
try { try {
WorkspaceItem wiDataMinerFolder = StorageUtil
WorkspaceItem wiDataMinerFolder = storageUtil
.getItemInRootFolderOnWorkspace(serviceCredentials.getUserName(), .getItemInRootFolderOnWorkspace(serviceCredentials.getUserName(),
DATA_MINER_FOLDER); DATA_MINER_FOLDER);
@ -66,7 +68,7 @@ public class DataMinerWorkAreaManager {
InputDataSets inputDataSets = null; InputDataSets inputDataSets = null;
try { try {
WorkspaceItem wiImportedDataFolder = StorageUtil WorkspaceItem wiImportedDataFolder = storageUtil
.getItemInFolderOnWorkspace(serviceCredentials.getUserName(), .getItemInFolderOnWorkspace(serviceCredentials.getUserName(),
dataMinerWorkArea.getDataMinerWorkAreaFolder() dataMinerWorkArea.getDataMinerWorkAreaFolder()
.getId(), IMPORTED_DATA_FOLDER); .getId(), IMPORTED_DATA_FOLDER);
@ -88,7 +90,7 @@ public class DataMinerWorkAreaManager {
OutputDataSets outputDataSets = null; OutputDataSets outputDataSets = null;
try { try {
WorkspaceItem wiComputedDataFolder = StorageUtil WorkspaceItem wiComputedDataFolder = storageUtil
.getItemInFolderOnWorkspace(serviceCredentials.getUserName(), .getItemInFolderOnWorkspace(serviceCredentials.getUserName(),
dataMinerWorkArea.getDataMinerWorkAreaFolder() dataMinerWorkArea.getDataMinerWorkAreaFolder()
.getId(), COMPUTED_DATA_FOLDER); .getId(), COMPUTED_DATA_FOLDER);
@ -109,7 +111,7 @@ public class DataMinerWorkAreaManager {
Computations computations = null; Computations computations = null;
try { try {
WorkspaceItem wiComputationsDataFolder = StorageUtil WorkspaceItem wiComputationsDataFolder = storageUtil
.getItemInFolderOnWorkspace(serviceCredentials.getUserName(), .getItemInFolderOnWorkspace(serviceCredentials.getUserName(),
dataMinerWorkArea.getDataMinerWorkAreaFolder() dataMinerWorkArea.getDataMinerWorkAreaFolder()
.getId(), COMPUTATIONS_FOLDER); .getId(), COMPUTATIONS_FOLDER);

View File

@ -7,18 +7,17 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import net.sf.csv4j.CSVReader;
import org.gcube.data.analysis.dataminermanagercl.server.util.ServiceCredentials; import org.gcube.data.analysis.dataminermanagercl.server.util.ServiceCredentials;
import org.gcube.portlets.user.dataminermanager.server.storage.StorageUtil;
import org.gcube.data.analysis.dataminermanagercl.shared.data.ColumnItem; import org.gcube.data.analysis.dataminermanagercl.shared.data.ColumnItem;
import org.gcube.data.analysis.dataminermanagercl.shared.data.TableItemSimple; import org.gcube.data.analysis.dataminermanagercl.shared.data.TableItemSimple;
import org.gcube.data.analysis.dataminermanagercl.shared.workspace.ItemDescription; import org.gcube.data.analysis.dataminermanagercl.shared.workspace.ItemDescription;
import org.gcube.portlets.user.dataminermanager.server.storage.StorageUtil;
import org.gcube.portlets.user.dataminermanager.shared.exception.ServiceException; import org.gcube.portlets.user.dataminermanager.shared.exception.ServiceException;
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import net.sf.csv4j.CSVReader;
/** /**
* *
* @author Giancarlo Panichi * @author Giancarlo Panichi
@ -37,15 +36,15 @@ public class TableReader {
} }
public TableItemSimple getTableItemSimple() throws ServiceException { public TableItemSimple getTableItemSimple() throws ServiceException {
StorageUtil storageUtil=new StorageUtil();
InputStream is = StorageUtil.getInputStreamForItemOnWorkspace( InputStream is = storageUtil.getInputStreamForItemOnWorkspace(
serviceCredentials.getUserName(), item.getId()); serviceCredentials.getUserName(), item.getId());
Reader fileReader = new InputStreamReader(is); Reader fileReader = new InputStreamReader(is);
CSVReader csvReader = new CSVReader(fileReader); CSVReader csvReader = new CSVReader(fileReader);
List<String> firstLine = getFirstLine(csvReader, false); List<String> firstLine = getFirstLine(csvReader, false);
ArrayList<String> columns = new ArrayList<String>(firstLine); ArrayList<String> columns = new ArrayList<String>(firstLine);
String publicLink=StorageUtil.getPublicLink(serviceCredentials.getUserName(), item.getId()); String publicLink=storageUtil.getPublicLink(serviceCredentials.getUserName(), item.getId());
TableItemSimple tableItemSimple=new TableItemSimple(publicLink,item.getName(), item.getType()); TableItemSimple tableItemSimple=new TableItemSimple(publicLink,item.getName(), item.getType());
ArrayList<ColumnItem> columnItemList=new ArrayList<ColumnItem>(); ArrayList<ColumnItem> columnItemList=new ArrayList<ColumnItem>();

View File

@ -6,8 +6,10 @@
<!-- <inherits name='com.google.gwt.user.theme.clean.Clean' /> --> <!-- <inherits name='com.google.gwt.user.theme.clean.Clean' /> -->
<inherits name='com.sencha.gxt.ui.GXT' /> <inherits name='com.sencha.gxt.ui.GXT' />
<!-- <inherits name="com.extjs.gxt.ui.GXT" /> --> <!-- <inherits name="com.extjs.gxt.ui.GXT" /> -->
<!-- <inherits name="com.google.gwt.logging.Logging" /> --> <!--
<inherits name="com.google.gwt.logging.Logging" />
-->
<inherits name="com.allen_sauer.gwt.log.gwt-log-TRACE" /> <inherits name="com.allen_sauer.gwt.log.gwt-log-TRACE" />
@ -41,15 +43,21 @@
<entry-point <entry-point
class='org.gcube.portlets.user.dataminermanager.client.DataMinerManager' /> class='org.gcube.portlets.user.dataminermanager.client.DataMinerManager' />
<!-- <set-property name="log_ConsoleLogger" value="ENABLED" /> <set-property <!--
name="log_DivLogger" value="ENABLED" /> <set-property name="log_GWTLogger" <set-property name="log_ConsoleLogger" value="ENABLED" />
value="ENABLED" /> <set-property name="log_SystemLogger" value="ENABLED" <set-property name="log_DivLogger" value="ENABLED" />
/> --> <set-property name="log_GWTLogger" value="ENABLED" />
<set-property name="log_SystemLogger" value="ENABLED" />
<set-property name="log_ConsoleLogger" value="DISABLED" />
<set-property name="log_DivLogger" value="DISABLED" /> <set-property name="gwt.logging.logLevel" value="SEVERE" />
<set-property name="log_GWTLogger" value="DISABLED" /> <set-property name="gwt.logging.enabled" value="TRUE" />
<set-property name="log_SystemLogger" value="DISABLED" /> <set-property name="gwt.logging.consoleHandler" value="ENABLED" /> -->
<set-property name="log_ConsoleLogger" value="DISABLED" /> <set-property
name="log_DivLogger" value="DISABLED" /> <set-property name="log_GWTLogger"
value="DISABLED" /> <set-property name="log_SystemLogger" value="DISABLED"
/>
<source path='client' /> <source path='client' />
<source path='shared' /> <source path='shared' />