use of org.bedework.caldav.util.notifications.suggest.SuggestResponseNotificationType in project bw-calendar-engine by Bedework.
the class Notifier method processSuggested.
private ProcessMessageResult processSuggested(final SysEvent msg) {
try {
final SysCode sysCode = msg.getSysCode();
String targetPrincipal = null;
SuggestBaseNotificationType sbnt = null;
if (sysCode == SysCode.SUGGESTED) {
final EntitySuggestedEvent ese = (EntitySuggestedEvent) msg;
final SuggestNotificationType snt = new SuggestNotificationType();
snt.setUid(Uid.getUid());
snt.setHref(ese.getHref());
snt.setSuggesterHref(ese.getAuthPrincipalHref());
snt.setSuggesteeHref(ese.getTargetPrincipalHref());
targetPrincipal = ese.getTargetPrincipalHref();
sbnt = snt;
} else if (sysCode == SysCode.SUGGESTED_RESPONSE) {
final EntitySuggestedResponseEvent esre = (EntitySuggestedResponseEvent) msg;
final SuggestResponseNotificationType srnt = new SuggestResponseNotificationType();
srnt.setUid(Uid.getUid());
srnt.setHref(esre.getHref());
srnt.setSuggesteeHref(esre.getAuthPrincipalHref());
srnt.setSuggesterHref(esre.getTargetPrincipalHref());
srnt.setAccepted(esre.getAccepted());
targetPrincipal = srnt.getSuggesterHref();
sbnt = srnt;
}
if (sbnt == 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(sbnt.getElementName())) {
if ((n == null) || (n.getNotification() == null)) {
// Bad notiifcation?
continue;
}
final SuggestBaseNotificationType ns = (SuggestBaseNotificationType) n.getNotification();
if (sbnt.getHref().equals(ns.getHref())) {
// Suggested resource
storedNote = n;
break;
}
}
if (storedNote == null) {
// save this one
sbnt.setName(getEncodedUuid());
final NotificationType n = new NotificationType();
n.setNotification(sbnt);
getNotes().add(n);
return ProcessMessageResult.PROCESSED;
}
return ProcessMessageResult.IGNORED;
} finally {
closeSvci(getSvc());
}
} catch (final CalFacadeStaleStateException csse) {
if (debug) {
trace("Stale state exception");
}
return ProcessMessageResult.STALE_STATE;
} catch (final Throwable t) {
rollback(getSvc());
error(t);
} finally {
try {
closeSvci(getSvc());
} catch (final Throwable ignored) {
}
}
return ProcessMessageResult.FAILED;
}
Aggregations