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:
parent
d771201580
commit
d0d3d50920
|
@ -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(postBody);
|
||||||
sendPostRequest(requestForMessage, 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);
|
||||||
|
@ -193,7 +191,7 @@ public class SendMail ***REMOVED***
|
||||||
if (!success) ***REMOVED***
|
if (!success) ***REMOVED***
|
||||||
String message = res.getString("message");
|
String message = res.getString("message");
|
||||||
logger.error("Error in send email notification: " + 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***
|
||||||
|
|
||||||
***REMOVED*** catch (JSONException e) ***REMOVED***
|
***REMOVED*** catch (JSONException e) ***REMOVED***
|
||||||
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue