Incident #18083 New StorageHub URLs not accessed by the widget

This commit is contained in:
Massimiliano Assante 2019-11-15 16:40:37 +01:00
parent 556d813e22
commit 785d855ee9
3 changed files with 26 additions and 13 deletions

View File

@ -12,7 +12,7 @@
<artifactId>workspace-widget-portlet</artifactId>
<packaging>war</packaging>
<name>workspace-widget-portlet Portlet</name>
<version>1.3.1-SNAPSHOT</version>
<version>1.3.2-SNAPSHOT</version>
<description>
Workspace Widget
</description>

View File

@ -8,6 +8,7 @@ import java.util.Date;
import java.util.List;
import org.gcube.common.storagehub.model.items.AbstractFileItem;
import org.gcube.common.storagehub.model.items.ExternalLink;
import org.gcube.common.storagehub.model.items.ExternalURL;
import org.gcube.common.storagehub.model.items.FolderItem;
import org.gcube.common.storagehub.model.items.Item;
@ -70,7 +71,7 @@ public class ItemBuilder {
}
else { //is a file, a Link or an XML
MDIcon mdIcon = IconsManager.getDefault();
if (workspaceItem instanceof ExternalURL) {
if (workspaceItem instanceof ExternalLink || workspaceItem instanceof ExternalURL) {
mdIcon = IconsManager.getIconTypeLink();
} else {
AbstractFileItem aItem = (AbstractFileItem) workspaceItem;

View File

@ -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();