From d0d3d50920b47be52fbeedc05c1dff3fcb86b8a6 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Fri, 17 Apr 2020 10:22:36 +0200 Subject: [PATCH] ref 19081: DM Pool Manager uses a deprecated social networking api https://support.d4science.org/issues/19081 Updated to new Social Networking API --- .../dataminer/poolmanager/util/SendMail.java | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/util/SendMail.java b/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/util/SendMail.java index eeb30d7..dcda1a5 100644 --- a/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/util/SendMail.java +++ b/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/util/SendMail.java @@ -54,9 +54,8 @@ public class SendMail ***REMOVED*** retrieveSocialService(); String postBody = createPostBody(subject, body); - String requestForMessage = getRequestMessage(WRITE_MESSAGE_ADDRESS_PATH); - - sendPostRequest(requestForMessage, postBody); + + sendPostRequest(postBody); ***REMOVED*** @@ -83,7 +82,7 @@ public class SendMail ***REMOVED*** ***REMOVED*** data.put("recipients", recipients); - logger.info("Post Body: " + data); + logger.debug("Post Body: " + data); return data.toString(); ***REMOVED*** catch (EMailException e) ***REMOVED*** @@ -118,17 +117,6 @@ public class SendMail ***REMOVED*** ***REMOVED*** - private String getRequestMessage(String addressPath) ***REMOVED*** - StringBuilder requestMessageBuilder = new StringBuilder(socialServiceAddress); - - if (!socialServiceAddress.endsWith("/")) - requestMessageBuilder.append('/'); - - requestMessageBuilder.append(addressPath).append(SecurityTokenProvider.instance.get()); - String requestForMessage = requestMessageBuilder.toString(); - logger.debug("Request " + requestForMessage); - return requestForMessage; -***REMOVED*** private String username(String token) throws ObjectNotFound, Exception ***REMOVED*** AuthorizationEntry entry = authorizationService().get(token); @@ -136,10 +124,20 @@ public class SendMail ***REMOVED*** return entry.getClientInfo().getId(); ***REMOVED*** - private void sendPostRequest(String endpoint, String postBody) throws EMailException ***REMOVED*** - logger.info("Execute Post:" + endpoint); - logger.info("Post Body:" + postBody); + private void sendPostRequest(String postBody) throws EMailException ***REMOVED*** + try ***REMOVED*** + logger.info("Execute Post Body:" + postBody); + + StringBuilder requestMessageBuilder = new StringBuilder(socialServiceAddress); + + if (!socialServiceAddress.endsWith("/")) + requestMessageBuilder.append('/'); + + requestMessageBuilder.append(WRITE_MESSAGE_ADDRESS_PATH); + logger.info("Execute Post Request: " + requestMessageBuilder.toString()); + requestMessageBuilder.append(SecurityTokenProvider.instance.get()); + String endpoint = requestMessageBuilder.toString(); ***REMOVED*** Send the request URL url = new URL(endpoint); @@ -193,7 +191,7 @@ public class SendMail ***REMOVED*** if (!success) ***REMOVED*** String message = res.getString("message"); logger.error("Error in send email notification: " + message); - throw new EMailException("Error in send email notification: "+message); + throw new EMailException("Error in send email notification: " + message); ***REMOVED*** ***REMOVED*** catch (JSONException e) ***REMOVED*** @@ -238,9 +236,16 @@ public class SendMail ***REMOVED*** ***REMOVED*** Try to retrieve a url like this: ***REMOVED*** https:***REMOVED***api.d4science.org/social-networking-library-ws/rest/2/users/get-usernames-by-role?role-name=DataMiner-Manager&gcube-token=xxx-xxxx-xxxx-xxx - String requestAdminsUrl = getRequestMessage(USER_ROLES_ADDRESS_PATH); + StringBuilder requestMessageBuilder = new StringBuilder(socialServiceAddress); - logger.info("Request Admins Url: " + requestAdminsUrl); + if (!socialServiceAddress.endsWith("/")) + requestMessageBuilder.append('/'); + + requestMessageBuilder.append(USER_ROLES_ADDRESS_PATH); + logger.info("Request Admins Url: " + requestMessageBuilder.toString()); + requestMessageBuilder.append(SecurityTokenProvider.instance.get()); + + String requestAdminsUrl = requestMessageBuilder.toString(); CloseableHttpClient client = HttpClientBuilder.create().build(); HttpGet getReq = new HttpGet(requestAdminsUrl);