@Override
public void generateResponse(Event event) {
if (event instanceof RunEvent) {
RunEvent re = (RunEvent)event;
Run r = re.getEventObject();
RunQC lastAdded = null;
List<RunQC> lqc = new ArrayList<RunQC>(r.getRunQCs());
if (!lqc.isEmpty()) {
try {
Collections.sort(lqc, new DateComparator(RunQC.class, "getQcDate"));
lastAdded = lqc.get(lqc.size()-1);
}
catch (NoSuchMethodException e) {
log.error("Cannot sort list of run QCs", e);
e.printStackTrace();
}
}
for (User user : r.getWatchers()) {
Alert a = new DefaultAlert(user);
String qcInfo = "";
String qcType = "";
if (lastAdded != null) {
qcType = lastAdded.getQcType().getName()+" ";
qcInfo = "QC'ed by "+lastAdded.getQcCreator()+ " on " + lastAdded.getQcDate() + " ("+lastAdded.getInformation()+"). ";
}
a.setAlertTitle(qcType + "Run QC Added : " + r.getAlias());
a.setAlertText("The following Run has been QCed: "+r.getAlias()+" ("+event.getEventMessage()+"). "+qcInfo+"Please view Run " +r.getId()+ " in MISO for more information.");
for (AlerterService as : alerterServices) {
try {
as.raiseAlert(a);
}