ref 19081: DM Pool Manager uses a deprecated social networking api

https://support.d4science.org/issues/19081

Updated to new Social Networking API
This commit is contained in:
Giancarlo Panichi 2020-04-17 10:22:36 +02:00
parent d771201580
commit d0d3d50920
1 changed files with 26 additions and 21 deletions

View File

@ -54,9 +54,8 @@ public class SendMail ***REMOVED***
retrieveSocialService(); retrieveSocialService();
String postBody = createPostBody(subject, body); String postBody = createPostBody(subject, body);
String requestForMessage = getRequestMessage(WRITE_MESSAGE_ADDRESS_PATH);
sendPostRequest(requestForMessage, postBody); sendPostRequest(postBody);
***REMOVED*** ***REMOVED***
@ -83,7 +82,7 @@ public class SendMail ***REMOVED***
***REMOVED*** ***REMOVED***
data.put("recipients", recipients); data.put("recipients", recipients);
logger.info("Post Body: " + data); logger.debug("Post Body: " + data);
return data.toString(); return data.toString();
***REMOVED*** catch (EMailException e) ***REMOVED*** ***REMOVED*** catch (EMailException e) ***REMOVED***
@ -118,17 +117,6 @@ public class SendMail ***REMOVED***
***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*** private String username(String token) throws ObjectNotFound, Exception ***REMOVED***
AuthorizationEntry entry = authorizationService().get(token); AuthorizationEntry entry = authorizationService().get(token);
@ -136,10 +124,20 @@ public class SendMail ***REMOVED***
return entry.getClientInfo().getId(); return entry.getClientInfo().getId();
***REMOVED*** ***REMOVED***
private void sendPostRequest(String endpoint, String postBody) throws EMailException ***REMOVED*** private void sendPostRequest(String postBody) throws EMailException ***REMOVED***
logger.info("Execute Post:" + endpoint);
logger.info("Post Body:" + postBody);
try ***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 ***REMOVED*** Send the request
URL url = new URL(endpoint); URL url = new URL(endpoint);
@ -238,9 +236,16 @@ public class SendMail ***REMOVED***
***REMOVED*** Try to retrieve a url like this: ***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 ***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(); CloseableHttpClient client = HttpClientBuilder.create().build();
HttpGet getReq = new HttpGet(requestAdminsUrl); HttpGet getReq = new HttpGet(requestAdminsUrl);