|
|
|
@ -3,6 +3,7 @@ package org.gcube.portlets.user.wswidget;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Scanner;
|
|
|
|
|
|
|
|
|
|
import javax.portlet.PortletException;
|
|
|
|
|
import javax.portlet.PortletSession;
|
|
|
|
@ -13,8 +14,9 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
|
|
|
import org.gcube.common.storagehub.client.StreamDescriptor;
|
|
|
|
|
import org.gcube.common.storagehub.client.dsl.FileContainer;
|
|
|
|
|
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
|
|
|
|
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
|
|
|
|
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
|
|
|
|
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
|
|
|
|
import org.gcube.common.storagehub.model.items.Item;
|
|
|
|
|
import org.gcube.portlets.user.wswidget.shared.AuthorizedUser;
|
|
|
|
@ -39,6 +41,7 @@ public class WorkspaceWidget extends MVCPortlet {
|
|
|
|
|
private static com.liferay.portal.kernel.log.Log _log = LogFactoryUtil.getLog(WorkspaceWidget.class);
|
|
|
|
|
public static String BREADCRUMB_ATTR = "BREADCRUMB_ATTR_name";
|
|
|
|
|
public final static int LIMIT = 5;
|
|
|
|
|
public final static String ITEM_URL_TYPE = "nthl:externalUrl";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* all the AJAX calls are served by this method, to discriminate the operation we use the parameters:
|
|
|
|
@ -52,12 +55,22 @@ public class WorkspaceWidget extends MVCPortlet {
|
|
|
|
|
if (fileToDownloadId != null) {
|
|
|
|
|
setAuthorizationToken(resourceRequest);
|
|
|
|
|
String selectedItemId = fileToDownloadId.split("=")[1];
|
|
|
|
|
ItemManagerClient client = AbstractPlugin.item().build();
|
|
|
|
|
StreamDescriptor streamDescr = client.download(selectedItemId);
|
|
|
|
|
StorageHubClient client = new StorageHubClient();
|
|
|
|
|
FileContainer fileContainer = client.open(selectedItemId).asFile();
|
|
|
|
|
StreamDescriptor streamDescr = fileContainer.download(selectedItemId);
|
|
|
|
|
HttpServletResponse httpRes = PortalUtil.getHttpServletResponse(resourceResponse);
|
|
|
|
|
HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(resourceRequest);
|
|
|
|
|
ServletResponseUtil.sendFile(httpReq,httpRes, streamDescr.getFileName(), streamDescr.getStream(), "application/download");
|
|
|
|
|
streamDescr.getStream().close();
|
|
|
|
|
if (ITEM_URL_TYPE.compareTo(fileContainer.get().getPrimaryType()) == 0) { //if is a type URL we open drectly the link
|
|
|
|
|
Scanner sc = new Scanner( streamDescr.getStream());
|
|
|
|
|
String text = sc.useDelimiter("\\A").next();
|
|
|
|
|
sc.close();
|
|
|
|
|
streamDescr.getStream().close();
|
|
|
|
|
httpRes.sendRedirect(text);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(resourceRequest);
|
|
|
|
|
ServletResponseUtil.sendFile(httpReq,httpRes, streamDescr.getFileName(), streamDescr.getStream(), "application/download");
|
|
|
|
|
streamDescr.getStream().close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//the user is browsing the workspace or asking for recents
|
|
|
|
|
else {
|
|
|
|
@ -103,7 +116,7 @@ public class WorkspaceWidget extends MVCPortlet {
|
|
|
|
|
count = StorageHubServiceUtil.getItemChildrenCount(request, itemId);
|
|
|
|
|
}
|
|
|
|
|
else if (itemId.compareTo("recents") == 0) { //is in a VRE and asking for recents files
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
itemsList = StorageHubServiceUtil.getRecentItems(authUser);
|
|
|
|
|
count = offset;
|
|
|
|
|
toSet = (Breadcrumb) request.getPortletSession().getAttribute(BREADCRUMB_ATTR, PortletSession.APPLICATION_SCOPE);
|
|
|
|
@ -118,7 +131,7 @@ public class WorkspaceWidget extends MVCPortlet {
|
|
|
|
|
computeBreadcrumb(clicked, toSet);
|
|
|
|
|
count = StorageHubServiceUtil.getItemChildrenCount(request, itemId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject tableData = buildJSONResponse(itemsList, start, offset, draw, count, request);
|
|
|
|
|
ServletResponseUtil.write(PortalUtil.getHttpServletResponse(resourceResponse),tableData.toString());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|