Notification improvements with prioritychecks
Change-Id: Ib45e7ec440a65a01ed1b8620c4d1ebb3ef549804
This commit is contained in:
parent
ce9868d7a5
commit
cb5818e09b
src/main/java/se/su/dsv/scipro/data/controllers
@ -2,24 +2,18 @@ package se.su.dsv.scipro.data.controllers;
|
||||
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.data.enums.NotificationEventType;
|
||||
import se.su.dsv.scipro.data.enums.NotificationPriority;
|
||||
import se.su.dsv.scipro.security.auth.roles.Roles;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Martin Peters - mpeters@dsv.su.se
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface NotificationController {
|
||||
|
||||
public void processSystemNotification(
|
||||
User usertoNotify,
|
||||
Roles userRole,
|
||||
String subject,
|
||||
String messageBody,
|
||||
NotificationEventType notificationEvent);
|
||||
public void processWebNotification(User usertoNotify,
|
||||
Roles userRole,
|
||||
String subject,
|
||||
String messageBody, Long typeId,
|
||||
NotificationEventType notificationEvent);
|
||||
|
||||
public void processSystemNotification(User usertoNotify, Roles userRole, String subject,
|
||||
String messageBody, NotificationEventType notificationEvent);
|
||||
|
||||
public void processNotification(User usertoNotify, NotificationMessage notificationMessage, String relativeRestURL, NotificationPriority notificationPriority);
|
||||
}
|
||||
|
@ -0,0 +1,74 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package se.su.dsv.scipro.data.controllers;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan <aschan@dsv.su.se>
|
||||
*
|
||||
*/
|
||||
public class NotificationMessage {
|
||||
|
||||
private String webNotificationMessage = "";
|
||||
private String mailSubject = "";
|
||||
private String mailMessage = "";
|
||||
|
||||
/**
|
||||
* @param webNotificationMessage
|
||||
* @param mailSubject
|
||||
* @param mailMessage
|
||||
*/
|
||||
public NotificationMessage(String webNotificationMessage, String mailSubject, String mailMessage) {
|
||||
super();
|
||||
this.webNotificationMessage = webNotificationMessage;
|
||||
this.mailSubject = mailSubject;
|
||||
this.mailMessage = mailMessage;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the webNotificationMessage
|
||||
*/
|
||||
public String getWebNotificationMessage() {
|
||||
return webNotificationMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param webNotificationMessage
|
||||
* the webNotificationMessage to set
|
||||
*/
|
||||
public void setWebNotificationMessage(String webNotificationMessage) {
|
||||
this.webNotificationMessage = webNotificationMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the mailSubject
|
||||
*/
|
||||
public String getMailSubject() {
|
||||
return mailSubject;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mailSubject
|
||||
* the mailSubject to set
|
||||
*/
|
||||
public void setMailSubject(String mailSubject) {
|
||||
this.mailSubject = mailSubject;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the mailMessage
|
||||
*/
|
||||
public String getMailMessage() {
|
||||
return mailMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mailMessage
|
||||
* the mailMessage to set
|
||||
*/
|
||||
public void setMailMessage(String mailMessage) {
|
||||
this.mailMessage = mailMessage;
|
||||
}
|
||||
|
||||
}
|
@ -6,30 +6,40 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import se.su.dsv.scipro.data.controllers.NotificationController;
|
||||
import se.su.dsv.scipro.data.controllers.NotificationMessage;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.MailEventDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.NotificationDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.Notification;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserSettingsDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.WebNotificationDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.UserSettings;
|
||||
import se.su.dsv.scipro.data.dataobjects.WebNotification;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.data.enums.NotificationEventType;
|
||||
import se.su.dsv.scipro.data.enums.NotificationPriority;
|
||||
import se.su.dsv.scipro.security.auth.roles.Roles;
|
||||
import se.su.dsv.scipro.util.PropsUtils;
|
||||
|
||||
/**
|
||||
* TODO Think this through and do it properly, this is a rush-job implemented for peer-review
|
||||
* TODO Think this through and do it properly, this is a rush-job implemented
|
||||
* for peer-review
|
||||
*
|
||||
* @author Martin Peters - mpeters@dsv.su.se
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
public class NotificationControllerImpl implements NotificationController {
|
||||
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
final protected String systemFromName;
|
||||
final protected String systemFromEmail;
|
||||
final protected boolean sendMailEnabled;
|
||||
|
||||
|
||||
@Autowired
|
||||
private NotificationDao notificationDao;
|
||||
|
||||
private WebNotificationDao notificationDao;
|
||||
|
||||
@Autowired
|
||||
private UserSettingsDao userSettingsDao;
|
||||
|
||||
public NotificationControllerImpl() {
|
||||
String systemFromName = null;
|
||||
String systemFromEmail = null;
|
||||
@ -48,59 +58,84 @@ public class NotificationControllerImpl implements NotificationController {
|
||||
this.systemFromEmail = systemFromEmail;
|
||||
this.sendMailEnabled = sendMailEnabled;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
protected MailEventDao mailEventDao;
|
||||
|
||||
|
||||
/**
|
||||
* Re-implement to it takes users settings into account
|
||||
*
|
||||
* @param user
|
||||
* @param notificationEvent
|
||||
* @return
|
||||
*/
|
||||
protected boolean notifyViaMail(User user, Roles userRole, NotificationEventType notificationEvent ) {
|
||||
protected boolean notifyViaMail(User user, Roles userRole,
|
||||
NotificationEventType notificationEvent) {
|
||||
return sendMailEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processSystemNotification(
|
||||
User usertoNotify,
|
||||
Roles userRole,
|
||||
String subject,
|
||||
String messageBody,
|
||||
NotificationEventType notificationEvent) {
|
||||
public void processSystemNotification(User usertoNotify, Roles userRole, String subject,
|
||||
String messageBody, NotificationEventType notificationEvent) {
|
||||
/*
|
||||
* atm bogus-check if the user want to have this kind of notice for this kind of role
|
||||
* atm bogus-check if the user want to have this kind of notice for this
|
||||
* kind of role
|
||||
*/
|
||||
// if( notifyViaMail(usertoNotify, userRole, notificationEvent) ){
|
||||
// MailEvent me = new MailEvent(subject, messageBody, usertoNotify, systemFromName, systemFromEmail, notificationEvent);
|
||||
// me = mailEventDao.save(me);
|
||||
// }
|
||||
// if( notifyViaMail(usertoNotify, userRole, notificationEvent) ){
|
||||
// MailEvent me = new MailEvent(subject, messageBody, usertoNotify,
|
||||
// systemFromName, systemFromEmail, notificationEvent);
|
||||
// me = mailEventDao.save(me);
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void processWebNotification(
|
||||
User usertoNotify,
|
||||
Roles userRole,
|
||||
String subject,
|
||||
String messageBody, Long typeId,
|
||||
NotificationEventType notificationEvent) {
|
||||
public void processNotification(User usertoNotify, NotificationMessage notificationMessage,
|
||||
String relativeRestURL, NotificationPriority notificationPriority) {
|
||||
/*
|
||||
* atm bogus-check if the user want to have this kind of notice for this kind of role
|
||||
* atm bogus-check if the user want to have this kind of notice for this
|
||||
* kind of role
|
||||
*/
|
||||
// if( notifyViaMail(usertoNotify, userRole, notificationEvent) ){
|
||||
// MailEvent me = new MailEvent(subject, messageBody, usertoNotify, systemFromName, systemFromEmail, notificationEvent);
|
||||
// me = mailEventDao.save(me);
|
||||
// }
|
||||
// if( notifyViaMail(usertoNotify, userRole, notificationEvent) ){
|
||||
// MailEvent me = new MailEvent(subject, messageBody, usertoNotify,
|
||||
// systemFromName, systemFromEmail, notificationEvent);
|
||||
// me = mailEventDao.save(me);
|
||||
// }
|
||||
UserSettings userSettings = userSettingsDao.getUserSettings(usertoNotify);
|
||||
if(userSettings == null){
|
||||
userSettings = new UserSettings();
|
||||
userSettings.setUser(usertoNotify);
|
||||
userSettingsDao.save(userSettings);
|
||||
}
|
||||
NotificationPriority notificationPriorityForUser = userSettings.getNotificationPriority();
|
||||
|
||||
Notification notification = new Notification();
|
||||
if(notificationPriorityForUser == null){
|
||||
notificationPriorityForUser = NotificationPriority.MEDIUM;
|
||||
}
|
||||
switch (notificationPriorityForUser) {
|
||||
case HIGH:
|
||||
if (notificationPriority.equals(NotificationPriority.HIGH)) {
|
||||
|
||||
}
|
||||
break;
|
||||
case MEDIUM:
|
||||
if (notificationPriority.equals(NotificationPriority.HIGH)
|
||||
|| notificationPriority.equals(NotificationPriority.MEDIUM)) {
|
||||
|
||||
}
|
||||
break;
|
||||
case LOW:
|
||||
if (notificationPriority.equals(NotificationPriority.HIGH)
|
||||
|| notificationPriority.equals(NotificationPriority.MEDIUM)
|
||||
|| notificationPriority.equals(NotificationPriority.LOW)) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
WebNotification notification = new WebNotification();
|
||||
notification.setUser(usertoNotify);
|
||||
notification.setInfoText(messageBody);
|
||||
notification.setTypeId(typeId);
|
||||
notification.setRole(userRole);
|
||||
notification.setNotificationEventType(notificationEvent);
|
||||
notification.setInfoText(notificationMessage.getWebNotificationMessage());
|
||||
notification.setRestRelativeURL(relativeRestURL);
|
||||
notificationDao.save(notification);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user