Search in sources :

Example 16 with EventInfo

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;
    }
}
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 EventInfo

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()));
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) EventInfo(org.bedework.calfacade.svc.EventInfo) ArrayList(java.util.ArrayList)

Example 18 with EventInfo

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

Example 19 with EventInfo

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;
}
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 20 with EventInfo

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);
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) TreeSet(java.util.TreeSet) BwCalendar(org.bedework.calfacade.BwCalendar) Calendar(net.fortuna.ical4j.model.Calendar) Iterator(java.util.Iterator) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

EventInfo (org.bedework.calfacade.svc.EventInfo)111 BwEvent (org.bedework.calfacade.BwEvent)80 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)37 BwCalendar (org.bedework.calfacade.BwCalendar)27 BwEventProxy (org.bedework.calfacade.BwEventProxy)24 BwAttendee (org.bedework.calfacade.BwAttendee)19 ArrayList (java.util.ArrayList)16 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)15 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)15 BwString (org.bedework.calfacade.BwString)11 BwDateTime (org.bedework.calfacade.BwDateTime)10 BwEventObj (org.bedework.calfacade.BwEventObj)10 TreeSet (java.util.TreeSet)9 BwXproperty (org.bedework.calfacade.BwXproperty)9 BwPrincipal (org.bedework.calfacade.BwPrincipal)7 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)7 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)7 Calendar (net.fortuna.ical4j.model.Calendar)6 Period (net.fortuna.ical4j.model.Period)6 BwOrganizer (org.bedework.calfacade.BwOrganizer)6