use of org.bedework.sysevents.events.SysEventBase.SysCode 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;
}
use of org.bedework.sysevents.events.SysEventBase.SysCode 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;
}
use of org.bedework.sysevents.events.SysEventBase.SysCode in project bw-calendar-engine by Bedework.
the class DataCounts method update.
/**
* @param ev
*/
public void update(final SysEvent ev) {
SysCode sc = ev.getSysCode();
DataValue dl = dlMap.get(sc);
if (dl != null) {
dl.inc();
}
}
use of org.bedework.sysevents.events.SysEventBase.SysCode in project bw-calendar-engine by Bedework.
the class DataValues method update.
/**
* @param ev
*/
public void update(final SysEvent ev) {
SysCode sc = ev.getSysCode();
if (ev instanceof TimedEvent) {
TimedEvent te = (TimedEvent) ev;
String lbl = te.getLabel();
DataAvg dv = timedValuesMap.get(lbl);
if (dv == null) {
dv = new DataAvg(lbl, ev.getSysCode());
timedValuesMap.put(lbl, dv);
}
dv.inc(te.getMillis());
return;
}
if (ev instanceof MillisecsEvent) {
DataAvg dv = dvMap.get(sc);
if (dv != null) {
dv.inc(((MillisecsEvent) ev).getMillis());
}
return;
}
if (sc == SysCode.STATS) {
StatsEvent se = (StatsEvent) ev;
String sname = se.getName();
DataAvg da = statMap.get(sname);
if (da == null) {
da = new DataAvg(sname, sc);
statMap.put(sname, da);
}
StatType st = StatsEvent.getStatType(sname);
if (st != StatType.lnum) {
da.inc(1);
} else if (se.getLongValue() != null) {
da.inc(se.getLongValue());
}
return;
}
}
use of org.bedework.sysevents.events.SysEventBase.SysCode in project bw-calendar-engine by Bedework.
the class DataCounts method addDl.
private DataValue addDl(final String name, final SysCode scode) {
DataValue dl = new DataValue(name, scode);
dls.add(dl);
SysCode s = dl.getSysCode();
if (s != null) {
dlMap.put(s, dl);
}
return dl;
}
Aggregations