Skip to content

Commit

Permalink
SAK-40721 Defer bullhorn alerts if site unpublished
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianfish authored and Miguel Pellicer committed Oct 31, 2018
1 parent 78656f6 commit d3271a6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public class BullhornAlert {
@Temporal(TemporalType.TIMESTAMP)
private Date eventDate;

@Column(name="DEFERRED", nullable=false)
private Boolean deferred;

@Transient
private String fromDisplayName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public void init() {
HANDLED_EVENTS.add(AssignmentConstants.EVENT_GRADE_ASSIGNMENT_SUBMISSION);
HANDLED_EVENTS.add(CommonsEvents.COMMENT_CREATED);
HANDLED_EVENTS.add(LessonBuilderEvents.COMMENT_CREATE);
HANDLED_EVENTS.add(SiteService.EVENT_SITE_PUBLISH);
eventTrackingService.addLocalObserver(this);
}

Expand Down Expand Up @@ -341,6 +342,25 @@ public void update(Observable o, final Object arg) {
} catch (NumberFormatException nfe) {
log.error("Caught number format exception whilst handling events", nfe);
}
} else if (SiteService.EVENT_SITE_PUBLISH.equals(event)) {
final String siteId = pathParts[2];

transactionTemplate.execute(new TransactionCallbackWithoutResult() {

protected void doInTransactionWithoutResult(TransactionStatus status) {

final List<BullhornAlert> deferredAlerts
= sessionFactory.getCurrentSession().createCriteria(BullhornAlert.class)
.add(Restrictions.eq("deferred", true))
.add(Restrictions.eq("siteId", siteId)).list();

for (BullhornAlert da : deferredAlerts) {
da.setDeferred(false);
sessionFactory.getCurrentSession().update(da);
countCache.remove(da.getToUser());
}
}
});
}
} catch (Exception ex) {
log.error("Caught exception whilst handling events", ex);
Expand Down Expand Up @@ -380,6 +400,7 @@ private void lock(SecurityAdvisor securityAdvisor) {
private void doAcademicInsert(String from, String to, String event, String ref
, String title, String siteId, Date eventDate, String url) {


transactionTemplate.execute(new TransactionCallbackWithoutResult() {

protected void doInTransactionWithoutResult(TransactionStatus status) {
Expand All @@ -395,6 +416,14 @@ protected void doInTransactionWithoutResult(TransactionStatus status) {
ba.setEventDate(eventDate);
ba.setUrl(url);

boolean deferred = false;
try {
deferred = !siteService.getSite(siteId).isPublished();
} catch (IdUnusedException iue) {
log.warn("Failed to find site with id '" + siteId + "'. deferred will be false.");
}
ba.setDeferred(deferred);

sessionFactory.getCurrentSession().persist(ba);
}
});
Expand All @@ -416,6 +445,7 @@ protected void doInTransactionWithoutResult(TransactionStatus status) {
ba.setSiteId("");
ba.setEventDate(eventDate);
ba.setUrl(url);
ba.setDeferred(false);

sessionFactory.getCurrentSession().persist(ba);
}
Expand Down Expand Up @@ -515,6 +545,7 @@ public List<BullhornAlert> getAcademicAlerts(String userId) {

List<BullhornAlert> alerts = sessionFactory.getCurrentSession().createCriteria(BullhornAlert.class)
.add(Restrictions.eq("alertType", ACADEMIC))
.add(Restrictions.eq("deferred", false))
.add(Restrictions.eq("toUser", userId)).list();

for (BullhornAlert alert : alerts) {
Expand Down Expand Up @@ -552,6 +583,7 @@ public long getAcademicAlertCount(String userId) {
count = (Long) sessionFactory.getCurrentSession().createCriteria(BullhornAlert.class)
.add(Restrictions.eq("alertType", ACADEMIC))
.add(Restrictions.eq("toUser", userId))
.add(Restrictions.eq("deferred", false))
.setProjection(Projections.rowCount()).uniqueResult();
cachedCounts.put("academic", count);
countCache.put(userId, cachedCounts);
Expand All @@ -571,8 +603,9 @@ public boolean clearAllAcademicAlerts(String userId) {

private boolean clearAllAlerts(String alertType, String userId) {

sessionFactory.getCurrentSession().createQuery("delete BullhornAlert where alertType = :alertType and toUser = :toUser")
.setString("alertType", alertType).setString("toUser", userId)
sessionFactory.getCurrentSession().createQuery(
"delete BullhornAlert where alertType = :alertType and toUser = :toUser and deferred = :deferred")
.setString("alertType", alertType).setString("toUser", userId).setBoolean("deferred", false)
.executeUpdate();
countCache.remove(userId);
return true;
Expand Down

0 comments on commit d3271a6

Please sign in to comment.