fixed also for messages
This commit is contained in:
parent
a4b8e945d6
commit
ff33c24f7c
|
@ -39,6 +39,7 @@ import org.gcube.portal.social.networking.ws.inputs.Recipient;
|
|||
import org.gcube.portal.social.networking.ws.outputs.ResponseBean;
|
||||
import org.gcube.portal.social.networking.ws.utils.ErrorMessages;
|
||||
import org.gcube.portal.social.networking.ws.utils.TokensUtils;
|
||||
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
||||
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||
|
@ -91,23 +92,33 @@ public class Messages {
|
|||
logger.debug("Incoming message bean is " + input);
|
||||
|
||||
Caller caller = AuthorizationProvider.instance.get();
|
||||
|
||||
UserManager um = UserManagerWSBuilder.getInstance().getUserManager();
|
||||
GCubeUser senderUser = null;
|
||||
SocialNetworkingUser user = null;
|
||||
// check if the token belongs to an application token. In this case use J.A.R.V.I.S (the username used to communicate with Liferay)
|
||||
String senderId = null;
|
||||
String username = null;
|
||||
String fullName = "";
|
||||
logger.debug("Catalogue Notification called by " + caller.getClient().getId() + " isUser?"+TokensUtils.isUserToken(caller));
|
||||
if(!TokensUtils.isUserToken(caller)){
|
||||
GCubeUser jarvis = UserManagerWSBuilder.getInstance().getUserManager().getUserByEmail(LiferayJSONWsCredentials.getSingleton().getUser());
|
||||
SecurityTokenProvider.instance.set(LiferayJSONWsCredentials.getSingleton().getNotifierUserToken());
|
||||
senderId = jarvis.getUsername();
|
||||
username = jarvis.getUsername();
|
||||
fullName = caller.getClient().getId().replace("service-account-", ""); // the actual name of the IAM Client
|
||||
senderUser = um.getUserByUsername(username);
|
||||
user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), fullName, senderUser.getUserAvatarURL());
|
||||
}else{
|
||||
senderId = caller.getClient().getId();
|
||||
}
|
||||
username = caller.getClient().getId();
|
||||
senderUser = um.getUserByUsername(username);
|
||||
fullName = senderUser.getFullname();
|
||||
user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), fullName, senderUser.getUserAvatarURL());
|
||||
}
|
||||
String scope = ScopeProvider.instance.get();
|
||||
ResponseBean responseBean = new ResponseBean();
|
||||
Status status = Status.CREATED;
|
||||
String body = input.getBody();
|
||||
String subject = input.getSubject();
|
||||
List<Recipient> recipientsIds = input.getRecipients(); // "recipients":[{"recipient":"id recipient"}, ......]
|
||||
logger.info("Sender is going to be the token's owner [" + senderId + "]");
|
||||
logger.info("Sender is going to be [" + fullName + "]");
|
||||
|
||||
// get the recipients ids (simple check, trim)
|
||||
List<String> recipientsListFiltered = new ArrayList<String>();
|
||||
|
@ -139,23 +150,16 @@ public class Messages {
|
|||
|
||||
try{
|
||||
|
||||
logger.debug("Trying to send message with body " + body + " subject " + subject + " to users " + recipientsIds + " from " + senderId);
|
||||
|
||||
// sender info
|
||||
GCubeUser senderUser = UserManagerWSBuilder.getInstance().getUserManager().getUserByUsername(senderId);
|
||||
MessageManagerClient client = AbstractPlugin.messages().build();
|
||||
logger.debug("Trying to send message with body " + body + " subject " + subject + " to users " + recipientsIds + " from " + username);
|
||||
|
||||
// send message
|
||||
MessageManagerClient client = AbstractPlugin.messages().build();
|
||||
logger.debug("Sending message to " + recipientsListFiltered);
|
||||
String messageId = client.sendMessage(recipientsListFiltered, subject, body, null);
|
||||
|
||||
// send notification
|
||||
logger.debug("Message sent to " + recipientsIds + ". Sending message notification to: " + recipientsIds);
|
||||
SocialNetworkingSite site = SocialNetworkingSiteFinder.getSocialNetworkingSiteFromScope(scope);
|
||||
SocialNetworkingUser user = new SocialNetworkingUser(
|
||||
senderUser.getUsername(), senderUser.getEmail(),
|
||||
senderUser.getFullname(), senderUser.getUserAvatarURL());
|
||||
|
||||
NotificationsManager nm = new ApplicationNotificationsManager(UserManagerWSBuilder.getInstance().getUserManager(), site, ScopeProvider.instance.get(), user);
|
||||
new Thread(new MessageNotificationsThread(recipientsBeans, messageId, subject, body, nm)).start();
|
||||
responseBean.setSuccess(true);
|
||||
|
|
Loading…
Reference in New Issue