Fixed bug when notifications involved groups and email buffer was not cleared
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/application-support-layer/applicationSupportLayerSocial@97429 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
819ba9ab58
commit
bd058420b8
|
@ -39,4 +39,7 @@
|
|||
<Change>Updated email sending with single smtp session</Change>
|
||||
<Change>Personalized notifications in email subjects</Change>
|
||||
</Changeset>
|
||||
<Changeset component="org.gcube.applicationsupportlayer.aslsocial.0-10-1" date="2014-06-13">
|
||||
<Change>Fixed bug when notifications involved groups and email buffer was not cleared</Change>
|
||||
</Changeset>
|
||||
</ReleaseNotes>
|
||||
|
|
|
@ -21,8 +21,8 @@ import org.slf4j.LoggerFactory;
|
|||
public class EmailNotificationsConsumer extends Thread {
|
||||
private static Logger _log = LoggerFactory.getLogger(EmailNotificationsConsumer.class);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public EmailNotificationsConsumer() {
|
||||
super();
|
||||
_log.info("EmailNotificationsConsumer thread started at " + new Date());
|
||||
|
@ -30,7 +30,7 @@ public class EmailNotificationsConsumer extends Thread {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
|
||||
Properties props = System.getProperties();
|
||||
String mailServiceHost = "localhost";
|
||||
props.put("mail.smtp.host", mailServiceHost);
|
||||
|
@ -38,7 +38,7 @@ public class EmailNotificationsConsumer extends Thread {
|
|||
props.put("mail.smtp.port", mailServicePort);
|
||||
Session session = Session.getDefaultInstance(props);
|
||||
session.setDebug(true);
|
||||
|
||||
|
||||
for (;;) {
|
||||
try {
|
||||
Thread.sleep(1000*EmailPlugin.SECONDS2WAIT);
|
||||
|
@ -50,7 +50,7 @@ public class EmailNotificationsConsumer extends Thread {
|
|||
_log.debug("Emails Buffer not empty, sending emails ");
|
||||
Transport t = null;
|
||||
try {
|
||||
|
||||
|
||||
t = session.getTransport();
|
||||
t.connect();
|
||||
|
||||
|
@ -58,10 +58,15 @@ public class EmailNotificationsConsumer extends Thread {
|
|||
synchronized(EmailPlugin.BUFFER_EMAILS){
|
||||
for (NotificationMail mail : EmailPlugin.BUFFER_EMAILS) {
|
||||
Message m = EmailPlugin.getMessageNotification(session, mail.getNotification2Send(), mail.getVreName(), mail.getPortalName(), mail.getSenderEmail());
|
||||
m.saveChanges();
|
||||
Address[] addresses = m.getAllRecipients();
|
||||
t.sendMessage(m, addresses);
|
||||
_log.debug("Message sent to " + addresses.toString());
|
||||
if (m != null) {
|
||||
m.saveChanges();
|
||||
Address[] addresses = m.getAllRecipients();
|
||||
t.sendMessage(m, addresses);
|
||||
_log.debug("Message sent to " + mail.getSenderEmail());
|
||||
}
|
||||
else {
|
||||
_log.warn("Message not sent to " + mail.getNotification2Send().getUserid());
|
||||
}
|
||||
}
|
||||
//close session and empty the buffer
|
||||
_log.info("Emails sent emptying the buffer");
|
||||
|
|
|
@ -150,6 +150,8 @@ public class EmailPlugin {
|
|||
portalUrl = PortalUtil.getPortalURL(OrganizationsUtil.getCompany().getVirtualHost(), PortalUtil.getPortalPort(), true);
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
_log.warn("While trying to get email for user/group: " + notification2Save.getUserid());
|
||||
return null;
|
||||
}
|
||||
String email = user.getEmailAddress();
|
||||
|
||||
|
|
Loading…
Reference in New Issue