Added a method for handling webnotifications, and som roles and types

to webnotificatiosndao

Change-Id: Ia2f6e3dc2b425463b04d3a637eee6d62fe2a53d6
This commit is contained in:
joha-asc 2011-07-15 12:59:12 +02:00
parent 0ddcc9e75d
commit 982bea4355
10 changed files with 272 additions and 32 deletions

@ -17,5 +17,9 @@ public interface NotificationController {
String subject,
String messageBody,
NotificationEventType notificationEvent);
public void processWebNotification(User usertoNotify,
Roles userRole,
String subject,
String messageBody, Long typeId,
NotificationEventType notificationEvent);
}

@ -7,7 +7,8 @@ import org.springframework.stereotype.Controller;
import se.su.dsv.scipro.data.controllers.NotificationController;
import se.su.dsv.scipro.data.dao.interfaces.MailEventDao;
import se.su.dsv.scipro.data.dataobjects.MailEvent;
import se.su.dsv.scipro.data.dao.interfaces.NotificationDao;
import se.su.dsv.scipro.data.dataobjects.Notification;
import se.su.dsv.scipro.data.dataobjects.User;
import se.su.dsv.scipro.data.enums.NotificationEventType;
import se.su.dsv.scipro.security.auth.roles.Roles;
@ -26,6 +27,9 @@ public class NotificationControllerImpl implements NotificationController {
final protected String systemFromEmail;
final protected boolean sendMailEnabled;
@Autowired
private NotificationDao notificationDao;
public NotificationControllerImpl() {
String systemFromName = null;
String systemFromEmail = null;
@ -70,11 +74,33 @@ public class NotificationControllerImpl implements NotificationController {
/*
* 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) {
/*
* 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);
// }
Notification notification = new Notification();
notification.setUser(usertoNotify);
notification.setInfoText(messageBody);
notification.setTypeId(typeId);
notification.setRole(userRole);
notification.setNotificationEventType(notificationEvent);
notificationDao.save(notification);
}
}

@ -5,7 +5,10 @@ package se.su.dsv.scipro.data.dao.interfaces;
import java.util.List;
import se.su.dsv.scipro.data.dataobjects.Notification;
import se.su.dsv.scipro.data.dataobjects.User;
/**
* @author Johan Aschan - aschan@dsv.su.se
@ -14,5 +17,8 @@ import se.su.dsv.scipro.data.dataobjects.Notification;
public interface NotificationDao extends Dao<Notification>{
List<Notification> getNotifications(final User user);
int getNumberOfNotifications(final User user);
}

@ -44,8 +44,9 @@ public class BoardMessageDaoJPAImp extends AbstractDaoJPAImp<BoardMessage>
TypedQuery<BoardMessage> query = em
.createQuery(
"select bm FROM BoardMessage bm, MessageBoard mb " +
"WHERE bm member of mb.boardMessageSet ORDER BY bm.dateCreated DESC", BoardMessage.class);
"WHERE bm member of mb.boardMessageSet AND mb = :mb ORDER BY bm.dateCreated DESC", BoardMessage.class);
query.setHint(QueryHints.HINT_CACHEABLE, "true");
query.setParameter("mb", mb);
query.setFirstResult(first);
query.setMaxResults(count);
try {
@ -67,8 +68,9 @@ public class BoardMessageDaoJPAImp extends AbstractDaoJPAImp<BoardMessage>
TypedQuery<Long> query = em
.createQuery(
"SELECT COUNT (bm) FROM BoardMessage bm, MessageBoard mb " +
"WHERE bm member of mb.boardMessageSet ORDER BY bm.dateCreated DESC", Long.class);
"WHERE bm member of mb.boardMessageSet AND mb = :mb", Long.class);
query.setHint(QueryHints.HINT_CACHEABLE, "true");
query.setParameter("mb", mb);
return query.getSingleResult().intValue();
}

@ -5,10 +5,22 @@ package se.su.dsv.scipro.data.dao.jpa;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceException;
import javax.persistence.TypedQuery;
import org.hibernate.ejb.QueryHints;
import org.springframework.orm.jpa.JpaCallback;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import se.su.dsv.scipro.data.dao.interfaces.NotificationDao;
import se.su.dsv.scipro.data.dataobjects.Notification;
import se.su.dsv.scipro.data.dataobjects.User;
/**
* @author Johan Aschan - aschan@dsv.su.se
@ -22,4 +34,48 @@ public class NotificationDaoJPAImp extends AbstractDaoJPAImp<Notification>
public NotificationDaoJPAImp() {
super(Notification.class);
}
@Transactional(readOnly = true)
@Override
public List<Notification> getNotifications(final User user){
return getJpaTemplate().execute(new JpaCallback<List<Notification>>() {
@Override
public List<Notification> doInJpa(EntityManager em)
throws PersistenceException {
String q = "SELECT n FROM Notification n "
+ "where n.user = :user AND n.readByUser = false ORDER BY n.dateCreated DESC";
TypedQuery<Notification> query = em.createQuery(q,
Notification.class);
query.setParameter("user", user);
query.setHint(QueryHints.HINT_CACHEABLE, "true");
try {
return query.getResultList();
} catch (NoResultException e) {
return new ArrayList<Notification>();
}
}
});
}
@Transactional(readOnly = true)
@Override
public int getNumberOfNotifications(final User user){
return getJpaTemplate().execute(new JpaCallback<Integer>() {
@Override
public Integer doInJpa(EntityManager em)
throws PersistenceException {
String q = "SELECT COUNT (n) FROM Notification n "
+ "where n.user = :user AND n.readByUser = false ";
TypedQuery<Long> query = em.createQuery(q,
Long.class);
query.setParameter("user", user);
query.setHint(QueryHints.HINT_CACHEABLE, "true");
return query.getSingleResult().intValue();
}
});
}
}

@ -4,18 +4,17 @@
package se.su.dsv.scipro.data.dataobjects;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import javax.persistence.Cacheable;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Cache;
@ -52,7 +51,6 @@ public class BoardMessage extends DomainObject implements Commentable, Comparabl
@ManyToOne(optional=false)
private MessageBoard messageBoard;
@Override
public Long getId() {
return id;
@ -147,5 +145,7 @@ public class BoardMessage extends DomainObject implements Commentable, Comparabl
//By now we have to conclude the two objects are basically two objects full of nulls
return 0;
}
}

@ -39,6 +39,15 @@ public class GeneralSystemSettings extends DomainObject{
@Basic(optional=false)
private int daysBeforeFinalSeminarCanRegisterAsOpponent = 3;
@Basic(optional=false)
private String turnItInUsername = "joha-asc";
@Basic(optional=false)
private String turnItInForname = "Johan";
@Basic(optional=false)
private String turnItInSurname = "Aschan";
@Basic(optional=true)
private int projectPartnerDaysToLive;
@ -116,6 +125,41 @@ public class GeneralSystemSettings extends DomainObject{
public boolean isPeerDisplayNumberOfReviewsPerformed() {
return peerDisplayNumberOfReviewsPerformed;
}
/**
* @return the turnItInUsername
*/
public String getTurnItInUsername() {
return turnItInUsername;
}
/**
* @param turnItInUsername the turnItInUsername to set
*/
public void setTurnItInUsername(String turnItInUsername) {
this.turnItInUsername = turnItInUsername;
}
/**
* @return the turnItInForname
*/
public String getTurnItInForname() {
return turnItInForname;
}
/**
* @param turnItInForname the turnItInForname to set
*/
public void setTurnItInForname(String turnItInForname) {
this.turnItInForname = turnItInForname;
}
/**
* @return the turnItInSurname
*/
public String getTurnItInSurname() {
return turnItInSurname;
}
/**
* @param turnItInSurname the turnItInSurname to set
*/
public void setTurnItInSurname(String turnItInSurname) {
this.turnItInSurname = turnItInSurname;
}
}

@ -4,6 +4,7 @@
package se.su.dsv.scipro.data.dataobjects;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
@ -16,6 +17,7 @@ import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
@ -47,14 +49,14 @@ public class MessageBoard extends DomainObject{
@Override
public Long getId() {
// TODO Auto-generated method stub
return id;
}
@Basic(optional=false)
public String title;
@ManyToMany
private Set<User> subscribers = new HashSet<User>();
@Basic(optional=false)
@Column(length=255)
private String commentableKey;
@ -131,5 +133,21 @@ public class MessageBoard extends DomainObject{
public void setTitle(String title) {
this.title = title;
}
/**
* @return the subscribers
*/
public Set<User> getSubscribers() {
return subscribers;
}
/**
* @param subscribers the subscribers to set
*/
public void setSubscribers(Set<User> subscribers) {
this.subscribers = subscribers;
}
}

@ -3,25 +3,29 @@
*/
package se.su.dsv.scipro.data.dataobjects;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.Cacheable;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import se.su.dsv.scipro.data.enums.NotificationEventType;
import se.su.dsv.scipro.security.auth.roles.Roles;
/**
* @author Johan Aschan - aschan@dsv.su.se
*
*/
@Entity
@Table(name="notification")
@Cacheable(true)
@ -36,8 +40,22 @@ public class Notification extends DomainObject{
@Lob
private String infoText;
@ManyToMany
private Set<User> subscribers = new HashSet<User>();
@Basic(optional=false)
private Long typeId;
@Basic(optional = false)
@Enumerated(EnumType.STRING)
private Roles role;
@Basic(optional = false)
@Enumerated(EnumType.STRING)
private NotificationEventType notificationEventType;
@ManyToOne(optional=false)
private User user;
private boolean readByUser = false;
@Override
public Long getId() {
@ -60,23 +78,87 @@ public class Notification extends DomainObject{
this.infoText = infoText;
}
/**
* @return the subscribers
* @return the user
*/
public Set<User> getSubscribers() {
return subscribers;
public User getUser() {
return user;
}
/**
* @param subscribers the subscribers to set
* @param user the user to set
*/
public void setSubscribers(Set<User> subscribers) {
this.subscribers = subscribers;
public void setUser(User user) {
this.user = user;
}
/**
* @return the readByUser
*/
public boolean isReadByUser() {
return readByUser;
}
/**
* @param readByUser the readByUser to set
*/
public void setReadByUser(boolean readByUser) {
this.readByUser = readByUser;
}
/**
* @return the typeId
*/
public Long getTypeId() {
return typeId;
}
/**
* @param typeId the typeId to set
*/
public void setTypeId(Long typeId) {
this.typeId = typeId;
}
/**
* @return the role
*/
public Roles getRole() {
return role;
}
/**
* @param role the role to set
*/
public void setRole(Roles role) {
this.role = role;
}
/**
* @return the notificationEventType
*/
public NotificationEventType getNotificationEventType() {
return notificationEventType;
}
/**
* @param notificationEventType the notificationEventType to set
*/
public void setNotificationEventType(NotificationEventType notificationEventType) {
this.notificationEventType = notificationEventType;
}

@ -6,6 +6,8 @@ public enum NotificationEventType {
PEER_REVIEW_ACCEPTED,
PEER_REVIEW_RATED,
PEER_REVIEW_GRADED,
NEW_PRIVATE_MESSAGE,
NEW_MESSAGE_IN_CONFERENCE
}