Search in sources :

Example 16 with BwEvent

use of org.bedework.calfacade.BwEvent 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;
    }
}
Also used : CoreEventInfo(org.bedework.calcorei.CoreEventInfo) EventInfo(org.bedework.calfacade.svc.EventInfo) Icalendar(org.bedework.icalendar.Icalendar) StringReader(java.io.StringReader) BwEvent(org.bedework.calfacade.BwEvent) IcalTranslator(org.bedework.icalendar.IcalTranslator) BwAlarm(org.bedework.calfacade.BwAlarm) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 17 with BwEvent

use of org.bedework.calfacade.BwEvent 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));
                }
            }
        }
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) TreeSet(java.util.TreeSet) Iterator(java.util.Iterator) BwEvent(org.bedework.calfacade.BwEvent)

Example 18 with BwEvent

use of org.bedework.calfacade.BwEvent 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;
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) BwEvent(org.bedework.calfacade.BwEvent) JAXBElement(javax.xml.bind.JAXBElement) ArrayOfProperties(ietf.params.xml.ns.icalendar_2.ArrayOfProperties) ProdidPropType(ietf.params.xml.ns.icalendar_2.ProdidPropType) VcalendarType(ietf.params.xml.ns.icalendar_2.VcalendarType) BaseComponentType(ietf.params.xml.ns.icalendar_2.BaseComponentType) BasePropertyType(ietf.params.xml.ns.icalendar_2.BasePropertyType) IcalendarType(ietf.params.xml.ns.icalendar_2.IcalendarType) MethodPropType(ietf.params.xml.ns.icalendar_2.MethodPropType) ArrayOfComponents(ietf.params.xml.ns.icalendar_2.ArrayOfComponents) VersionPropType(ietf.params.xml.ns.icalendar_2.VersionPropType)

Example 19 with BwEvent

use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.

the class IcalTranslator method addToCalendar.

/* ====================================================================
                      Private methods
     ==================================================================== */
private void addToCalendar(final Calendar cal, final EventInfo val, final TreeSet<String> added) throws CalFacadeException {
    String currentPrincipal = null;
    BwPrincipal principal = cb.getPrincipal();
    if (principal != null) {
        currentPrincipal = principal.getPrincipalRef();
    }
    BwEvent ev = val.getEvent();
    EventTimeZonesRegistry tzreg = new EventTimeZonesRegistry(this, ev);
    if (!cb.getTimezonesByReference()) {
        /* Add referenced timezones to the calendar */
        addIcalTimezones(cal, ev, added, tzreg);
    }
    if (!ev.getSuppressed()) {
        /* Add it to the calendar */
        Component comp;
        if (ev.getEntityType() == IcalDefs.entityTypeFreeAndBusy) {
            comp = VFreeUtil.toVFreeBusy(ev);
        } else {
            comp = VEventUtil.toIcalComponent(val, false, tzreg, currentPrincipal);
        }
        cal.getComponents().add((CalendarComponent) comp);
    }
    if (val.getNumOverrides() > 0) {
        for (final EventInfo oei : val.getOverrides()) {
            cal.getComponents().add((CalendarComponent) VEventUtil.toIcalComponent(oei, true, tzreg, currentPrincipal));
        }
    }
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) EventInfo(org.bedework.calfacade.svc.EventInfo) BwEvent(org.bedework.calfacade.BwEvent) CalendarComponent(net.fortuna.ical4j.model.component.CalendarComponent) StartEndComponent(org.bedework.calfacade.base.StartEndComponent) Component(net.fortuna.ical4j.model.Component)

Example 20 with BwEvent

use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.

the class JcalHandler method outJcal.

public static void outJcal(final Writer wtr, final Collection<EventInfo> vals, final int methodType, final IcalendarType pattern, final String currentPrincipal, final EventTimeZonesRegistry tzreg) throws CalFacadeException {
    try {
        final JsonGenerator jgen = jsonFactory.createJsonGenerator(wtr);
        if (Logger.getLogger(JcalHandler.class).isDebugEnabled()) {
            jgen.useDefaultPrettyPrinter();
        }
        jgen.writeStartArray();
        calendarProps(jgen, methodType);
        // for components
        jgen.writeStartArray();
        for (final EventInfo ei : vals) {
            BwEvent ev = ei.getEvent();
            final Component comp;
            if (ev.getEntityType() == IcalDefs.entityTypeFreeAndBusy) {
                comp = VFreeUtil.toVFreeBusy(ev);
            } else {
                comp = VEventUtil.toIcalComponent(ei, false, tzreg, currentPrincipal);
            }
            outComp(jgen, comp);
            if (ei.getNumOverrides() > 0) {
                for (final EventInfo oei : ei.getOverrides()) {
                    ev = oei.getEvent();
                    outComp(jgen, VEventUtil.toIcalComponent(oei, true, tzreg, currentPrincipal));
                }
            }
        }
        // for components
        jgen.writeEndArray();
        jgen.writeEndArray();
        jgen.flush();
    } catch (final CalFacadeException cfe) {
        throw cfe;
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) BwEvent(org.bedework.calfacade.BwEvent) Component(net.fortuna.ical4j.model.Component) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

BwEvent (org.bedework.calfacade.BwEvent)160 EventInfo (org.bedework.calfacade.svc.EventInfo)80 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)55 BwEventProxy (org.bedework.calfacade.BwEventProxy)33 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)26 BwAttendee (org.bedework.calfacade.BwAttendee)25 BwDateTime (org.bedework.calfacade.BwDateTime)25 BwString (org.bedework.calfacade.BwString)24 UpdateResult (org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)23 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)23 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)21 BwCalendar (org.bedework.calfacade.BwCalendar)21 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)20 BwXproperty (org.bedework.calfacade.BwXproperty)16 TreeSet (java.util.TreeSet)15 BwEventObj (org.bedework.calfacade.BwEventObj)13 ArrayList (java.util.ArrayList)12 Period (net.fortuna.ical4j.model.Period)12 BwCategory (org.bedework.calfacade.BwCategory)10 BwContact (org.bedework.calfacade.BwContact)10