ready to release

This commit is contained in:
Massimiliano Assante 2024-10-25 18:25:16 +02:00
parent d7ed0e3a5c
commit 494c24250e
3 changed files with 43 additions and 55 deletions

View File

@ -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

View File

@ -13,7 +13,7 @@
<artifactId>sbd-uploadshare-portlet</artifactId>
<packaging>war</packaging>
<name>SBD-UploadAndSharePortlets Portlet</name>
<version>1.3.0-SNAPSHOT</version>
<version>1.3.0</version>
<description>
Upload Dataset And Share Idea Portlets
</description>
@ -70,6 +70,10 @@
<artifactId>aslsocial</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-library</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-wrapper</artifactId>

View File

@ -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 <portlet:resourceURL var="uploadFileURL"
@ -223,7 +217,7 @@ public class RequestVRE extends MVCPortlet {
}
/**
* @return the id of the uploaded file
* @return the id of the uploaded file
*/
private String uploadToUserWorkspace(Workspace ownerWS, String fileName, String mimeType, InputStream fileData) {
WorkspaceFolder attachment = null;
@ -246,8 +240,7 @@ public class RequestVRE extends MVCPortlet {
item = ownerWS.uploadFile(attachment.getId(), fileData, fileName,
"File created automatically by the System on " + new Date(), null);
} catch (Exception e) {
_log.error(
"uploadToUserWorkspace FAILED while trying to uploadFile " + fileName);
_log.error("uploadToUserWorkspace FAILED while trying to uploadFile " + fileName);
e.printStackTrace();
}
String toReturn = item.getId();
@ -265,7 +258,7 @@ public class RequestVRE extends MVCPortlet {
currentUser.getScreenName());
ScopeProvider.instance.set(context);
SecurityTokenProvider.instance.set(authorizationToken);
Workspace workspace = getWorkspace(currentUser.getScreenName(), context);
List<String> recipientIds = new ArrayList<String>();
List<GenericItemBean> recipients = new ArrayList<GenericItemBean>();
@ -285,7 +278,7 @@ public class RequestVRE extends MVCPortlet {
List<String> 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<String> listAttachmentsId)
private String getPublicLinksForAttachs(List<String> 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<WorkspaceItem> attachments = new ArrayList<WorkspaceItem>();
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 "";
}