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 87b018ecee
commit f77e60b83e
1 changed files with 26 additions and 21 deletions

View File

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