use of org.bedework.calfacade.BwAlarm in project bw-calendar-engine by Bedework.
the class ToXEvent method processEventAlarm.
/**
* Process any alarms.
*
* @param ev
* @param comp
* @param pattern
* @param masterClass
* @throws CalFacadeException
*/
public static void processEventAlarm(final BwEvent ev, final BaseComponentType comp, final BaseComponentType pattern, final Class masterClass) throws CalFacadeException {
if (!emit(pattern, masterClass, ValarmType.class)) {
return;
}
Set<BwAlarm> als = ev.getAlarms();
if ((als == null) || als.isEmpty()) {
return;
}
if (!(comp instanceof VeventType) && !(comp instanceof VtodoType)) {
warn("Entity of class " + ev.getClass() + " has alarms but not allowed by entity of type " + comp.getClass());
}
ArrayOfComponents aoc = comp.getComponents();
if (aoc == null) {
aoc = new ArrayOfComponents();
comp.setComponents(aoc);
}
for (BwAlarm alarm : als) {
ValarmType va = Xalarms.toXAlarm(ev, alarm, pattern, masterClass);
aoc.getBaseComponent().add(of.createValarm(va));
}
}
use of org.bedework.calfacade.BwAlarm in project bw-calendar-engine by Bedework.
the class VAlarmUtil method processComponentAlarms.
/**
* If there are any alarms for this component add them to the events alarm
* collection
*
* @param cb IcalCallback object
* @param val
* @param ev
* @param currentPrincipal - href for current authenticated user
* @param chg
* @throws CalFacadeException
*/
public static void processComponentAlarms(final IcalCallback cb, final Component val, final BwEvent ev, final String currentPrincipal, final ChangeTable chg) throws CalFacadeException {
try {
ComponentList als = null;
if (val instanceof VEvent) {
als = ((VEvent) val).getAlarms();
} else if (val instanceof VToDo) {
als = ((VToDo) val).getAlarms();
} else if (val instanceof VPoll) {
als = ((VPoll) val).getAlarms();
} else {
return;
}
if ((als == null) || als.isEmpty()) {
return;
}
for (Object o : als) {
if (!(o instanceof VAlarm)) {
throw new IcalMalformedException("Invalid alarm list");
}
VAlarm va = (VAlarm) o;
PropertyList pl = va.getProperties();
if (pl == null) {
// Empty VAlarm
throw new IcalMalformedException("Invalid alarm list");
}
Property prop;
BwAlarm al;
/* XXX Handle mozilla alarm stuff in a way that might work better with other clients.
*
*/
prop = pl.getProperty("X-MOZ-LASTACK");
boolean mozlastAck = prop != null;
String mozSnoozeTime = null;
if (mozlastAck) {
prop = pl.getProperty("X-MOZ-SNOOZE-TIME");
if (prop == null) {
// lastack and no snooze - presume dismiss so delete alarm
continue;
}
// UTC time
mozSnoozeTime = prop.getValue();
}
// All alarm types require action and trigger
prop = pl.getProperty(Property.ACTION);
if (prop == null) {
throw new IcalMalformedException("Invalid alarm");
}
String actionStr = prop.getValue();
TriggerVal tr = getTrigger(pl, "NONE".equals(actionStr));
if (mozSnoozeTime != null) {
tr.trigger = mozSnoozeTime;
tr.triggerDateTime = true;
tr.triggerStart = false;
}
DurationRepeat dr = getDurationRepeat(pl);
if ("EMAIL".equals(actionStr)) {
al = BwAlarm.emailAlarm(ev, ev.getCreatorHref(), tr, dr.duration, dr.repeat, getOptStr(pl, "ATTACH"), getReqStr(pl, "DESCRIPTION"), getReqStr(pl, "SUMMARY"), null);
Iterator<?> atts = getReqStrs(pl, "ATTENDEE");
while (atts.hasNext()) {
al.addAttendee(getAttendee(cb, (Attendee) atts.next()));
}
} else if ("AUDIO".equals(actionStr)) {
al = BwAlarm.audioAlarm(ev, ev.getCreatorHref(), tr, dr.duration, dr.repeat, getOptStr(pl, "ATTACH"));
} else if ("DISPLAY".equals(actionStr)) {
al = BwAlarm.displayAlarm(ev, ev.getCreatorHref(), tr, dr.duration, dr.repeat, getReqStr(pl, "DESCRIPTION"));
} else if ("PROCEDURE".equals(actionStr)) {
al = BwAlarm.procedureAlarm(ev, ev.getCreatorHref(), tr, dr.duration, dr.repeat, getReqStr(pl, "ATTACH"), getOptStr(pl, "DESCRIPTION"));
} else if ("NONE".equals(actionStr)) {
al = BwAlarm.noneAlarm(ev, ev.getCreatorHref(), tr, dr.duration, dr.repeat, getOptStr(pl, "DESCRIPTION"));
} else {
al = BwAlarm.otherAlarm(ev, ev.getCreatorHref(), actionStr, tr, dr.duration, dr.repeat, getOptStr(pl, "DESCRIPTION"));
}
/* Mozilla is add xprops to the containing event to set the snooze time.
* Seems wrong - there could be multiple alarms.
*
* We possibly want to try this sort of trick..
prop = pl.getProperty("X-MOZ-LASTACK");
boolean mozlastAck = prop != null;
String mozSnoozeTime = null;
if (mozlastAck) {
prop = pl.getProperty("X-MOZ-SNOOZE-TIME");
if (prop == null) {
// lastack and no snooze - presume dismiss so delete alarm
continue;
}
mozSnoozeTime = prop.getValue(); // UTC time
}
...
TriggerVal tr = getTrigger(pl);
if (mozSnoozeTime != null) {
tr.trigger = mozSnoozeTime;
tr.triggerDateTime = true;
tr.triggerStart = false;
}
*/
Iterator it = pl.iterator();
while (it.hasNext()) {
prop = (Property) it.next();
if (prop instanceof XProperty) {
/* ------------------------- x-property --------------------------- */
XProperty xp = (XProperty) prop;
al.addXproperty(new BwXproperty(xp.getName(), xp.getParameters().toString(), xp.getValue()));
continue;
}
if (prop instanceof Uid) {
Uid p = (Uid) prop;
al.addXproperty(BwXproperty.makeIcalProperty(p.getName(), p.getParameters().toString(), p.getValue()));
continue;
}
}
al.setEvent(ev);
al.setOwnerHref(currentPrincipal);
chg.addValue(PropertyInfoIndex.VALARM, al);
}
} catch (CalFacadeException cfe) {
throw cfe;
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
use of org.bedework.calfacade.BwAlarm in project bw-calendar-engine by Bedework.
the class VAlarmUtil method processEventAlarm.
/**
* Process any alarms.
*
* @param ev
* @param comp
* @param currentPrincipal - href for current authenticated user
* @throws CalFacadeException
*/
public static void processEventAlarm(final BwEvent ev, final Component comp, final String currentPrincipal) throws CalFacadeException {
if (currentPrincipal == null) {
// No alarms for unauthenticated users.
return;
}
Collection<BwAlarm> als = ev.getAlarms();
if ((als == null) || als.isEmpty()) {
return;
}
ComponentList vals = null;
if (comp instanceof VEvent) {
vals = ((VEvent) comp).getAlarms();
} else if (comp instanceof VToDo) {
vals = ((VToDo) comp).getAlarms();
} else {
throw new CalFacadeException("org.bedework.invalid.component.type", comp.getName());
}
for (BwAlarm alarm : als) {
/* Only add alarms for the current authenticated user */
if (!currentPrincipal.equals(alarm.getOwnerHref())) {
continue;
}
vals.add(setAlarm(ev, alarm));
}
}
use of org.bedework.calfacade.BwAlarm in project bw-calendar-engine by Bedework.
the class Xalarms method toBwAlarm.
/**
* The generated alarm may not be a valid alarm if it is being used as a
* selector. It must have at least the action as a selector.
*
* @param alarm
* @param validate - true if alarm must be valid and complete
* @return ValarmType
* @throws CalFacadeException
*/
public static BwAlarm toBwAlarm(final ValarmType alarm, final boolean validate) throws CalFacadeException {
BwAlarm ba = new BwAlarm();
/* ============ Action =================== */
ActionPropType action = (ActionPropType) XcalUtil.findProperty(alarm, XcalTags.action);
if (action == null) {
throw new CalFacadeException("Invalid alarm - no action");
}
String actionVal = action.getText().toUpperCase();
int atype = -1;
for (int i = 0; i < BwAlarm.alarmTypes.length; i++) {
if (actionVal.equals(BwAlarm.alarmTypes[i])) {
atype = i;
break;
}
}
if (atype < 0) {
throw new CalFacadeException("Unhandled alarm action");
}
ba.setAlarmType(atype);
/* ============ Trigger =================== */
TriggerPropType tr = (TriggerPropType) XcalUtil.findProperty(alarm, XcalTags.trigger);
if (tr == null) {
if (validate) {
throw new CalFacadeException("Invalid alarm - no action");
}
} else {
if (tr.getDateTime() != null) {
ba.setTrigger(XcalUtil.getIcalFormatDateTime(tr.getDateTime()));
ba.setTriggerDateTime(true);
} else {
ba.setTrigger(tr.getDuration());
RelatedParamType r = (RelatedParamType) XcalUtil.findParam(tr, XcalTags.related);
ba.setTriggerStart((r == null) || (r.getText().toUpperCase().equals("START")));
}
}
/* ============ Duration =================== */
DurationPropType dur = (DurationPropType) XcalUtil.findProperty(alarm, XcalTags.duration);
if (dur != null) {
// MUST have repeat
RepeatPropType rep = (RepeatPropType) XcalUtil.findProperty(alarm, XcalTags.repeat);
ba.setDuration(dur.getDuration());
if (rep == null) {
if (validate) {
throw new CalFacadeException("Invalid alarm - no repeat");
}
} else {
ba.setRepeat(rep.getInteger().intValue());
}
}
/* ============ Description ============ */
if ((atype == BwAlarm.alarmTypeDisplay) || (atype == BwAlarm.alarmTypeEmail) || (atype == BwAlarm.alarmTypeProcedure)) {
DescriptionPropType desc = (DescriptionPropType) XcalUtil.findProperty(alarm, XcalTags.description);
if (desc != null) {
ba.setDescription(desc.getText());
}
}
/* ============ Summary ============ */
if (atype == BwAlarm.alarmTypeEmail) {
SummaryPropType s = (SummaryPropType) XcalUtil.findProperty(alarm, XcalTags.summary);
if (s != null) {
ba.setSummary(s.getText());
}
}
if ((atype == BwAlarm.alarmTypeAudio) || (atype == BwAlarm.alarmTypeEmail) || (atype == BwAlarm.alarmTypeProcedure)) {
AttachPropType a = (AttachPropType) XcalUtil.findProperty(alarm, XcalTags.attach);
// XXX Onl handle 1 attachment
if ((a != null) && (a.getUri() != null)) {
ba.setAttach(a.getUri());
}
}
if (atype == BwAlarm.alarmTypeEmail) {
for (JAXBElement<? extends BasePropertyType> bpel : alarm.getProperties().getBasePropertyOrTzid()) {
if (!bpel.getName().equals(XcalTags.attendee)) {
continue;
}
AttendeePropType attp = (AttendeePropType) bpel.getValue();
BwAttendee batt = new BwAttendee();
batt.setAttendeeUri(attp.getCalAddress());
ba.addAttendee(batt);
}
}
return ba;
}
use of org.bedework.calfacade.BwAlarm in project bw-calendar-engine by Bedework.
the class Events method compileAlarms.
/**
* Compile an alarm component
*
* @param val
* @return alarms or null
* @throws CalFacadeException
*/
public Set<BwAlarm> compileAlarms(final String val) throws CalFacadeException {
try {
StringReader sr = new StringReader(ValidateAlarmPrefix + val + ValidateAlarmSuffix);
IcalTranslator trans = new IcalTranslator(getSvc().getIcalCallback());
Icalendar ic = trans.fromIcal(null, sr);
if ((ic == null) || (ic.getEventInfo() == null)) {
if (debug) {
trace("Not single event");
}
return null;
}
/* There should be alarms in the Calendar object
*/
EventInfo ei = ic.getEventInfo();
BwEvent ev = ei.getEvent();
Set<BwAlarm> alarms = ev.getAlarms();
if (Util.isEmpty(alarms)) {
return null;
}
return alarms;
} catch (CalFacadeException cfe) {
if (debug) {
error(cfe);
}
return null;
}
}
Aggregations