From ad43c3782c7fbe150ccde44b3de834b72f7e8df9 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Mon, 19 Apr 2021 12:23:09 +0200 Subject: [PATCH] restored version with HL Dependency for messaging --- .settings/org.eclipse.wst.common.component | 3 ++ CHANGELOG.md | 2 - pom.xml | 30 +++++++----- .../networking/ws/methods/v1/Messages.java | 14 +++--- .../networking/ws/methods/v2/Messages.java | 46 ++++++++++--------- .../ws/providers/CustomObjectMapper.java | 2 +- 6 files changed, 54 insertions(+), 43 deletions(-) diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 817a818..6163a8d 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -12,6 +12,9 @@ uses + + uses + uses diff --git a/CHANGELOG.md b/CHANGELOG.md index ec58e66..46ac885 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,6 @@ - removed jackson dependency -- removed home library dependency - ## [v2.3.0] - 2019-10-02 - added support for mentions with @ in user's post as well as application posts diff --git a/pom.xml b/pom.xml index a094e33..10f841d 100644 --- a/pom.xml +++ b/pom.xml @@ -25,17 +25,19 @@ UTF-8 UTF-8 + - scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git - scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git - https://code-repo.d4science.org/gCubeSystem//${project.artifactId} + scm:git:https://code-repo.d4science.org/gCubeSystem/social-networking-library-ws.git + scm:git:https://code-repo.d4science.org/gCubeSystem/social-networking-library-ws.git + https://code-repo.d4science.org/gCubeSystem/social-networking-library-ws + - + org.gcube.distribution gcube-smartgears-bom - 2.1.0 + 2.0.0-SNAPSHOT pom import @@ -149,12 +151,6 @@ [2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT) compile - - org.gcube.common - storagehub-client-library - [1.2.2-SNAPSHOT, 2.0.0-SNAPSHOT) - compile - org.gcube.resources.discovery ic-client @@ -170,6 +166,18 @@ authorization-client provided + + org.gcube.common + home-library + [2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT) + compile + + + org.gcube.common + home-library-jcr + [2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT) + compile + junit junit diff --git a/src/main/java/org/gcube/portal/social/networking/ws/methods/v1/Messages.java b/src/main/java/org/gcube/portal/social/networking/ws/methods/v1/Messages.java index df57938..c1099d1 100644 --- a/src/main/java/org/gcube/portal/social/networking/ws/methods/v1/Messages.java +++ b/src/main/java/org/gcube/portal/social/networking/ws/methods/v1/Messages.java @@ -17,9 +17,9 @@ import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite; import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser; import org.gcube.common.authorization.library.provider.AuthorizationProvider; import org.gcube.common.authorization.library.utils.Caller; +import org.gcube.common.homelibrary.home.HomeLibrary; +import org.gcube.common.homelibrary.home.workspace.Workspace; import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.common.storagehub.client.plugins.AbstractPlugin; -import org.gcube.common.storagehub.client.proxies.MessageManagerClient; import org.gcube.portal.notifications.bean.GenericItemBean; import org.gcube.portal.notifications.thread.MessageNotificationsThread; import org.gcube.portal.social.networking.caches.SocialNetworkingSiteFinder; @@ -115,13 +115,13 @@ public class Messages { // sender info GCubeUser senderUser = uManager.getUserByUsername(senderId); - MessageManagerClient client = AbstractPlugin.messages().build(); + Workspace workspace = HomeLibrary.getUserWorkspace(senderId); // send message - logger.info("Sending message (v1) to: " + recipientsListFiltered); - String checkedSubject = subject; - String checkedBody = body; - String messageId = client.sendMessage(recipientsListFiltered, checkedSubject, checkedBody, null); + logger.debug("Sending message to " + recipientsListFiltered); + String messageId = workspace.getWorkspaceMessageManager() + .sendMessageToPortalLogins(subject, body, + new ArrayList(), recipientsListFiltered); // send notification logger.debug("Message sent to " + recipientsIds + ". Sending message notification to: " + recipientsIds); diff --git a/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Messages.java b/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Messages.java index e6c69d3..6883699 100644 --- a/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Messages.java +++ b/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Messages.java @@ -1,5 +1,12 @@ package org.gcube.portal.social.networking.ws.methods.v2; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.Authorization; + import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -25,10 +32,10 @@ import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser; import org.gcube.common.authorization.library.provider.AuthorizationProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.utils.Caller; +import org.gcube.common.homelibrary.home.HomeLibrary; +import org.gcube.common.homelibrary.home.workspace.Workspace; +import org.gcube.common.homelibrary.home.workspace.sharing.WorkspaceMessage; import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.common.storagehub.client.plugins.AbstractPlugin; -import org.gcube.common.storagehub.client.proxies.MessageManagerClient; -import org.gcube.common.storagehub.model.messages.Message; import org.gcube.portal.notifications.bean.GenericItemBean; import org.gcube.portal.notifications.thread.MessageNotificationsThread; import org.gcube.portal.social.networking.caches.SocialNetworkingSiteFinder; @@ -46,13 +53,6 @@ import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.slf4j.LoggerFactory; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; -import io.swagger.annotations.Authorization; - /** * Messages services REST interface * @author Costantino Perciante at ISTI-CNR @@ -136,13 +136,15 @@ public class Messages { // sender info GCubeUser senderUser = UserManagerWSBuilder.getInstance().getUserManager().getUserByUsername(senderId); - MessageManagerClient client = AbstractPlugin.messages().build(); + Workspace workspace = HomeLibrary.getUserWorkspace(senderId); + + logger.debug("Workspace is " + workspace.getRoot()); // send message - logger.debug("Sending message (v2) to: " + recipientsListFiltered); - String checkedSubject = subject; - String checkedBody = body; - String messageId = client.sendMessage(recipientsListFiltered, checkedSubject, checkedBody, null); + logger.debug("Sending message to " + recipientsListFiltered); + String messageId = workspace.getWorkspaceMessageManager() + .sendMessageToPortalLogins(subject, body, + new ArrayList(), recipientsListFiltered); // send notification logger.debug("Message sent to " + recipientsIds + ". Sending message notification to: " + recipientsIds); @@ -181,14 +183,14 @@ public class Messages { logger.info("Request for retrieving sent messages by " + username); - try { - MessageManagerClient client = AbstractPlugin.messages().build(); - List sentMessages = client.getSentMessages(); + try{ + Workspace workspace = HomeLibrary.getUserWorkspace(username); + List sentMessages = workspace.getWorkspaceMessageManager().getSentMessages(); Collections.reverse(sentMessages); responseBean.setSuccess(true); logger.debug("Result is " + sentMessages); responseBean.setResult(sentMessages); - } catch(Exception e){ + }catch(Exception e){ logger.error("Unable to retrieve sent messages", e); responseBean.setMessage(e.getMessage()); status = Status.INTERNAL_SERVER_ERROR; @@ -213,9 +215,9 @@ public class Messages { Status status = Status.OK; logger.info("Request for retrieving received messages by " + username); - try { - MessageManagerClient client = AbstractPlugin.messages().build(); - List getMessages = client.getReceivedMessages(); + try{ + Workspace workspace = HomeLibrary.getUserWorkspace(username); + List getMessages = workspace.getWorkspaceMessageManager().getReceivedMessages(); Collections.reverse(getMessages); responseBean.setSuccess(true); responseBean.setResult(getMessages); diff --git a/src/main/java/org/gcube/portal/social/networking/ws/providers/CustomObjectMapper.java b/src/main/java/org/gcube/portal/social/networking/ws/providers/CustomObjectMapper.java index 3a556df..b5b3554 100644 --- a/src/main/java/org/gcube/portal/social/networking/ws/providers/CustomObjectMapper.java +++ b/src/main/java/org/gcube/portal/social/networking/ws/providers/CustomObjectMapper.java @@ -26,7 +26,7 @@ public class CustomObjectMapper implements ContextResolver { logger.debug("new ObjectMapperResolver()"); mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); - mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); + mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE); } @Override