|
|
|
@ -15,10 +15,13 @@ 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.ItemContainer;
|
|
|
|
|
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
|
|
|
|
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
|
|
|
|
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
|
|
|
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
|
|
|
|
import org.gcube.common.storagehub.model.items.ExternalLink;
|
|
|
|
|
import org.gcube.common.storagehub.model.items.ExternalURL;
|
|
|
|
|
import org.gcube.common.storagehub.model.items.Item;
|
|
|
|
|
import org.gcube.portlets.user.wswidget.shared.AuthorizedUser;
|
|
|
|
|
import org.gcube.portlets.user.wswidget.shared.Breadcrumb;
|
|
|
|
@ -59,21 +62,30 @@ public class WorkspaceWidget extends MVCPortlet {
|
|
|
|
|
StorageHubClient client = new StorageHubClient();
|
|
|
|
|
FileContainer fileContainer = null;
|
|
|
|
|
StreamDescriptor streamDescr = null;
|
|
|
|
|
Item item = null;
|
|
|
|
|
HttpServletResponse httpRes = PortalUtil.getHttpServletResponse(resourceResponse);
|
|
|
|
|
try {
|
|
|
|
|
fileContainer = client.open(selectedItemId).asFile();
|
|
|
|
|
streamDescr = fileContainer.download(selectedItemId);
|
|
|
|
|
ItemContainer<Item> itemContainer = client.open(selectedItemId).asItem();
|
|
|
|
|
item = itemContainer.get();
|
|
|
|
|
if (item instanceof ExternalLink) { //if is a type URL we open directly the link (StorageHub Created it)
|
|
|
|
|
ExternalLink extLink = (ExternalLink) item;
|
|
|
|
|
httpRes.sendRedirect(extLink.getValue().toString());
|
|
|
|
|
} else {
|
|
|
|
|
fileContainer = client.open(selectedItemId).asFile();
|
|
|
|
|
streamDescr = fileContainer.download(selectedItemId);
|
|
|
|
|
}
|
|
|
|
|
if (item instanceof ExternalURL) { //if is a type URL we open directly the link (HL Created it)
|
|
|
|
|
Scanner sc = new Scanner( streamDescr.getStream());
|
|
|
|
|
String text = sc.useDelimiter("\\A").next();
|
|
|
|
|
sc.close();
|
|
|
|
|
streamDescr.getStream().close();
|
|
|
|
|
httpRes.sendRedirect(text);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} catch (StorageHubException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
HttpServletResponse httpRes = PortalUtil.getHttpServletResponse(resourceResponse);
|
|
|
|
|
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 {
|
|
|
|
|
if (! (item instanceof ExternalURL || item instanceof ExternalLink)) {
|
|
|
|
|
HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(resourceRequest);
|
|
|
|
|
ServletResponseUtil.sendFile(httpReq,httpRes, streamDescr.getFileName(), streamDescr.getStream(), "application/download");
|
|
|
|
|
streamDescr.getStream().close();
|
|
|
|
|