diff --git a/CHANGELOG.md b/CHANGELOG.md
index 29c2108..040c6c0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,7 +4,7 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
-## [v1.3.0-SNAPSHOT]
+## [v1.3.0]
- maven-portal-bom 4.0.0-SNAPSHOT
- maven-parent 1.2.0
diff --git a/pom.xml b/pom.xml
index d454716..932952e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -13,7 +13,7 @@
sbd-uploadshare-portlet
war
SBD-UploadAndSharePortlets Portlet
- 1.3.0-SNAPSHOT
+ 1.3.0
Upload Dataset And Share Idea Portlets
@@ -70,6 +70,10 @@
aslsocial
provided
+
+ org.gcube.common
+ storagehub-client-library
+
org.gcube.common
storagehub-client-wrapper
diff --git a/src/main/java/org/gcube/portlets/user/vremanagement/RequestVRE.java b/src/main/java/org/gcube/portlets/user/vremanagement/RequestVRE.java
index ad7a0cc..72b0e72 100644
--- a/src/main/java/org/gcube/portlets/user/vremanagement/RequestVRE.java
+++ b/src/main/java/org/gcube/portlets/user/vremanagement/RequestVRE.java
@@ -23,21 +23,16 @@ import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.api.ScopeProvider;
+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.MessageManagerClient;
-import org.gcube.common.storagehub.model.items.FolderItem;
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
import org.gcube.common.storagehubwrapper.server.tohl.Workspace;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem;
-import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItemType;
-import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InsufficientPrivilegesException;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException;
-import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemAlreadyExistException;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundException;
-import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WorkspaceFolderNotFoundException;
-import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WrongDestinationException;
-import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WrongItemTypeException;
import org.gcube.portal.notifications.bean.GenericItemBean;
import org.gcube.portal.notifications.thread.MessageNotificationsThread;
import org.gcube.vomanagement.usermanagement.exception.RoleRetrievalFault;
@@ -68,10 +63,9 @@ import com.liferay.util.bridges.mvc.MVCPortlet;
* - Request a VRE form Portlet implementation class RequestVRE
*/
public class RequestVRE extends MVCPortlet {
-
+
private static Log _log = LogFactoryUtil.getLog(RequestVRE.class);
-
-
+
private static String REQUEST_VRE_ROLE_MANAGER_NAME = "Infrastructure-Manager";
private final static String UPLOADED_FILE_ATTR_NAME = "myfile";
// make sure in the jsp there's recipientIds = new ArrayList();
List recipients = new ArrayList();
@@ -285,7 +278,7 @@ public class RequestVRE extends MVCPortlet {
List attachmentsList = Arrays.asList(attachmentIds);
String body = sb.toString();
try {
- body += getPublicLinksForAttachs(workspace, attachmentsList);
+ body += getPublicLinksForAttachs(attachmentsList, currentUser.getScreenName(), context);
} catch (Exception e) {
_log.error("Ops, could not generate publick link for some of the attachments");
e.printStackTrace();
@@ -312,53 +305,44 @@ public class RequestVRE extends MVCPortlet {
* @throws ItemNotFoundException
* @throws InternalErrorException
*/
- private String getPublicLinksForAttachs(Workspace workspace, List listAttachmentsId)
+ private String getPublicLinksForAttachs(List listAttachmentsId, String currentUser, String context )
throws ItemNotFoundException, InternalErrorException {
+ String authorizationToken = PortalContext.getConfiguration().getCurrentUserToken(context, currentUser);
+ ScopeProvider.instance.set(context);
+ SecurityTokenProvider.instance.set(authorizationToken);
+ StorageHubClient shc = new StorageHubClient();
_log.debug("Generating public link for attachments: " + listAttachmentsId.toString());
if (listAttachmentsId != null && (!listAttachmentsId.isEmpty())) {
- List attachments = new ArrayList();
- for (String itemId : listAttachmentsId) {
- try {
- attachments.add(workspace.getItem(itemId));
- } catch (Exception e) {
- _log.error(
- "in getPublicLinksForAttachs FAILED while trying workspace.getItem id=" + itemId);
- e.printStackTrace();
- }
- }
StringBuilder builder = new StringBuilder();
- if (attachments != null && attachments.size() > 0) {
- builder.append("\n\n\nThe following ");
- String msg = attachments.size() > 1 ? "files were attached to this message:"
- : "file was attached to this message:";
- builder.append(msg + "\n");
- for (WorkspaceItem workspaceItem : attachments) {
+ builder.append("\n\n\nThe following ");
+ String msg = listAttachmentsId.size() > 1 ? "files were attached to this message:"
+ : "file was attached to this message:";
+ builder.append(msg + "\n");
+ for (String itemId : listAttachmentsId) {
+ String publicLink = "";
+ String itemName = "";
+ try {
+ FileContainer file = shc.open(itemId).asFile();
+ itemName = file.get().getName();
+ String downladURL = file.getPublicLink().toString();
+ downladURL = (downladURL.startsWith("https")) ? downladURL : downladURL.replace("http", "https");
+ publicLink = downladURL;
+ } catch (Exception e) {
+ _log.error("An error occurred when creating public link for attachment, skipping file: "
+ + itemName);
+ e.printStackTrace();
+ return "";
- if (workspaceItem.getType().equals(WorkspaceItemType.FILE_ITEM)) {
- FolderItem folderItem = (FolderItem) workspaceItem;
- String publicLink = "";
- String itemName = "";
- try {
- itemName = workspaceItem.getName();
- publicLink = workspace.getPublicLinkForFile(folderItem.getId()).toString();
- } catch (Exception e) {
- _log.error("An error occurred when creating public link for attachment, skipping file: "
- + itemName);
- e.printStackTrace();
- return "";
-
- }
- builder.append(itemName + " (" + publicLink + ")");
- builder.append("\n");
}
- }
- _log.debug("returning public links: " + builder.toString());
- return builder.toString();
- } else
- return "";
+ builder.append(itemName + " (" + publicLink + ")");
+ builder.append("\n");
+ }
+ _log.debug("returning public links: " + builder.toString());
+ return builder.toString();
+
} else
return "";
}