Created thread for job notifications. Enhanced the post notifications one with a constructor that uses Set instead of lists to avoid duplicates

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/notifications-common-library@141667 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2017-01-20 13:49:19 +00:00
parent 9b5d34d81f
commit c6f28e42f2
2 changed files with 64 additions and 6 deletions

View File

@ -0,0 +1,55 @@
package org.gcube.portal.notifications.thread;
import java.util.List;
import org.gcube.applicationsupportlayer.social.NotificationsManager;
import org.gcube.portal.databook.shared.RunningJob;
import org.gcube.portal.notifications.bean.GenericItemBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A job status notification thread.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class JobStatusNotificationThread implements Runnable {
private static final Logger logger = LoggerFactory.getLogger(JobStatusNotificationThread.class);
private RunningJob jobDescriptor;
private List<GenericItemBean> recipients;
private NotificationsManager nm;
/**
* @param jobDescriptor
* @param applicationQualifier
* @param recipients
* @param nm
*/
public JobStatusNotificationThread(RunningJob jobDescriptor, List<GenericItemBean> recipients,
NotificationsManager nm) {
super();
this.jobDescriptor = jobDescriptor;
this.recipients = recipients;
this.nm = nm;
}
@Override
public void run() {
logger.debug("Starting job notification thread. Recipients of this notification are " + recipients);
for (GenericItemBean recipient : recipients) {
try{
String userIdToNotify = recipient.getName();
nm.notifyJobStatus(userIdToNotify, jobDescriptor);
}catch(Exception e){
logger.error("Failed to send notification", e);
}
}
logger.debug("Notification job thread ended");
}
}

View File

@ -1,6 +1,6 @@
package org.gcube.portal.notifications.thread;
import java.util.List;
import java.util.Set;
import org.gcube.applicationsupportlayer.social.NotificationsManager;
import org.gcube.vomanagement.usermanagement.UserManager;
@ -19,19 +19,22 @@ public class PostNotificationsThread implements Runnable {
private String postText;
private String postId;
private long groupId;
private List<String> hashtags;
private Set<String> hashtags;
private NotificationsManager nm;
private UserManager userManager;
private Set<String> mentionedVREGroups;
/**
*
* @param userManager
* @param postId
* @param postText
* @param groupId the LR groupId
* @param groupId
* @param nm
* @param hashtags
* @param mentionedVREGroups
*/
public PostNotificationsThread(UserManager userManager, String postId, String postText, String groupId, NotificationsManager nm, List<String> hashtags) {
public PostNotificationsThread(UserManager userManager, String postId, String postText, String groupId, NotificationsManager nm, Set<String> hashtags, Set<String> mentionedVREGroups) {
super();
this.postId = postId;
this.postText = postText;
@ -39,14 +42,14 @@ public class PostNotificationsThread implements Runnable {
this.hashtags = hashtags;
this.nm = nm;
this.userManager = userManager;
this.mentionedVREGroups = mentionedVREGroups;
}
@Override
public void run() {
String[] hashtagsToPass = hashtags.toArray(new String[hashtags.size()]);
try {
for (GCubeUser user : userManager.listUsersByGroup(groupId)) {
boolean result = nm.notifyPost(user.getUsername(), postId, postText, hashtagsToPass);
boolean result = nm.notifyPost(user.getUsername(), postId, postText, mentionedVREGroups, hashtags);
_log.trace("Sending Notification for post alert to: " + user.getUsername() + " result?"+ result);
}
} catch (Exception e) {