use of org.bedework.calfacade.svc.EventInfo 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;
}
}
use of org.bedework.calfacade.svc.EventInfo in project bw-calendar-engine by Bedework.
the class IcalTranslator method toJcal.
/**
* @param val
* @param methodType
* @param pattern
* @return JSON jcal
* @throws CalFacadeException
*/
public String toJcal(final EventInfo val, final int methodType, final IcalendarType pattern) throws CalFacadeException {
String currentPrincipal = null;
BwPrincipal principal = cb.getPrincipal();
if (principal != null) {
currentPrincipal = principal.getPrincipalRef();
}
List<EventInfo> eis = new ArrayList<>();
eis.add(val);
return JcalHandler.toJcal(eis, methodType, pattern, currentPrincipal, new EventTimeZonesRegistry(this, val.getEvent()));
}
use of org.bedework.calfacade.svc.EventInfo in project bw-calendar-engine by Bedework.
the class IcalTranslator method addIcalTimezones.
/* If the start or end dates references a timezone, we retrieve the timezone definition
* and add it to the calendar.
*/
private void addIcalTimezones(final Calendar cal, final Collection vals) throws CalFacadeException {
TreeSet<String> added = new TreeSet<String>();
Iterator it = vals.iterator();
while (it.hasNext()) {
Object o = it.next();
if (o instanceof EventInfo) {
EventInfo ei = (EventInfo) o;
BwEvent ev = ei.getEvent();
if (!ev.getSuppressed()) {
/* Add referenced timezones to the calendar */
addIcalTimezones(cal, ev, added, new EventTimeZonesRegistry(this, ev));
}
if (ei.getNumOverrides() > 0) {
for (EventInfo oei : ei.getOverrides()) {
ev = oei.getEvent();
addIcalTimezones(cal, ev, added, new EventTimeZonesRegistry(this, ev));
}
}
}
}
}
use of org.bedework.calfacade.svc.EventInfo in project bw-calendar-engine by Bedework.
the class IcalTranslator method toXMLIcalendar.
/**
* @param val
* @param methodType
* @param pattern
* @return XML IcalendarType
* @throws CalFacadeException
*/
public IcalendarType toXMLIcalendar(final EventInfo val, final int methodType, final IcalendarType pattern, final boolean wrapXprops) throws CalFacadeException {
IcalendarType ical = new IcalendarType();
VcalendarType vcal = new VcalendarType();
ical.getVcalendar().add(vcal);
vcal.setProperties(new ArrayOfProperties());
List<JAXBElement<? extends BasePropertyType>> pl = vcal.getProperties().getBasePropertyOrTzid();
ProdidPropType prod = new ProdidPropType();
prod.setText(prodId);
pl.add(Xutil.of.createProdid(prod));
VersionPropType vers = new VersionPropType();
vers.setText("2.0");
pl.add(Xutil.of.createVersion(vers));
if ((methodType > ScheduleMethods.methodTypeNone) && (methodType < ScheduleMethods.methodTypeUnknown)) {
MethodPropType m = new MethodPropType();
m.setText(ScheduleMethods.methods[methodType]);
pl.add(Xutil.of.createMethod(m));
}
ArrayOfComponents aoc = vcal.getComponents();
if (aoc == null) {
aoc = new ArrayOfComponents();
vcal.setComponents(aoc);
}
BwEvent ev = val.getEvent();
JAXBElement<? extends BaseComponentType> el = null;
VcalendarType vc = null;
if ((pattern != null) && !pattern.getVcalendar().isEmpty()) {
vc = pattern.getVcalendar().get(0);
}
BaseComponentType bc = matches(vc, ev.getEntityType());
if ((vc != null) && (bc == null)) {
return ical;
}
if (!ev.getSuppressed()) {
if (ev.getEntityType() == IcalDefs.entityTypeFreeAndBusy) {
el = ToXEvent.toComponent(ev, false, wrapXprops, bc);
} else {
el = ToXEvent.toComponent(ev, false, wrapXprops, bc);
}
if (el != null) {
aoc.getBaseComponent().add(el);
}
}
if (val.getNumOverrides() == 0) {
return ical;
}
for (EventInfo oei : val.getOverrides()) {
ev = oei.getEvent();
el = ToXEvent.toComponent(ev, true, wrapXprops, bc);
if (el != null) {
aoc.getBaseComponent().add(el);
}
}
if (val.getNumContainedItems() > 0) {
for (EventInfo aei : val.getContainedItems()) {
ev = aei.getEvent();
el = ToXEvent.toComponent(ev, true, wrapXprops, bc);
if (el != null) {
aoc.getBaseComponent().add(el);
}
}
}
return ical;
}
use of org.bedework.calfacade.svc.EventInfo in project bw-calendar-engine by Bedework.
the class IcalTranslator method toIcal.
/**
* Turn a collection of events into a calendar
*
* @param vals
* @param methodType int value fromIcalendar
* @return Calendar
* @throws CalFacadeException
*/
public Calendar toIcal(final Collection vals, final int methodType) throws CalFacadeException {
Calendar cal = newIcal(methodType);
if ((vals == null) || (vals.size() == 0)) {
return cal;
}
TreeSet<String> added = new TreeSet<String>();
try {
Iterator it = vals.iterator();
while (it.hasNext()) {
Object o = it.next();
if (o instanceof EventInfo) {
addToCalendar(cal, (EventInfo) o, added);
} else {
// XXX implement
warn("Unimplemented toIcal for " + o.getClass().getName());
continue;
}
}
return cal;
} catch (CalFacadeException cfe) {
throw cfe;
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
Aggregations