use of org.bedework.caldav.util.notifications.admin.AdminNotificationType in project bw-calendar-engine by Bedework.
the class Notifier method processApproved.
private ProcessMessageResult processApproved(final SysEvent msg) {
try {
String targetPrincipal = null;
final SysCode sysCode = msg.getSysCode();
AdminNotificationType ant = null;
if (sysCode == SysCode.APPROVAL_STATUS) {
final EntityApprovalResponseEvent eare = (EntityApprovalResponseEvent) msg;
final ApprovalResponseNotificationType arnt = new ApprovalResponseNotificationType();
arnt.setUid(Uid.getUid());
arnt.setHref(eare.getHref());
arnt.setPrincipalHref(eare.getOwnerHref());
arnt.setAccepted(eare.getApproved());
arnt.setComment(eare.getComment());
arnt.setCalsuiteHref(eare.getCalsuiteHref());
targetPrincipal = eare.getCalsuiteHref();
ant = arnt;
} else if (sysCode == SysCode.APPROVAL_NEEDED) {
final EntityApprovalNeededEvent eane = (EntityApprovalNeededEvent) msg;
final AwaitingApprovalNotificationType aant = new AwaitingApprovalNotificationType();
aant.setUid(Uid.getUid());
aant.setHref(eane.getHref());
aant.setPrincipalHref(eane.getOwnerHref());
aant.setComment(eane.getComment());
aant.setCalsuiteHref(eane.getCalsuiteHref());
targetPrincipal = eane.getCalsuiteHref();
ant = aant;
}
if (ant == null) {
return ProcessMessageResult.IGNORED;
}
try {
getSvci(targetPrincipal);
/* See if we have any notifications for this entity
*
* SCHEMA: If we could store the entire encoded path in the name we
* could just do a get
*/
NotificationType storedNote = null;
for (final NotificationType n : getNotes().getMatching(ant.getElementName())) {
if ((n == null) || (n.getNotification() == null)) {
// Bad notiifcation?
continue;
}
final AdminNotificationType ns = (AdminNotificationType) n.getNotification();
if (ant.getHref().equals(ns.getHref())) {
// Already have a notification for resource
storedNote = n;
break;
}
}
if (storedNote != null) {
getNotes().remove(storedNote);
}
// save this one
ant.setName(getEncodedUuid());
final NotificationType n = new NotificationType();
n.setNotification(ant);
getNotes().add(n);
return ProcessMessageResult.PROCESSED;
} finally {
closeSvci(getSvc());
}
} catch (final Throwable t) {
rollback(getSvc());
error(t);
} finally {
try {
closeSvci(getSvc());
} catch (final Throwable ignored) {
}
}
return ProcessMessageResult.FAILED;
}
Aggregations