Search in sources :

Example 21 with EventInfo

use of org.bedework.calfacade.svc.EventInfo 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 22 with EventInfo

use of org.bedework.calfacade.svc.EventInfo 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)

Example 23 with EventInfo

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

the class BwEventUtil method makeNewEvent.

private static EventInfo makeNewEvent(final IcalCallback cb, final int entityType, final String uid, final String colPath) throws CalFacadeException {
    final BwEvent ev = new BwEventObj();
    final EventInfo evinfo = new EventInfo(ev);
    // ev.setDtstamps();
    ev.setEntityType(entityType);
    ev.setCreatorHref(cb.getPrincipal().getPrincipalRef());
    ev.setOwnerHref(cb.getOwner().getPrincipalRef());
    ev.setUid(uid);
    ev.setColPath(colPath);
    final ChangeTable chg = evinfo.getChangeset(cb.getPrincipal().getPrincipalRef());
    // get that out of the way
    chg.changed(PropertyInfoIndex.UID, null, uid);
    evinfo.setNewEvent(true);
    return evinfo;
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) ChangeTable(org.bedework.calfacade.util.ChangeTable) BwEvent(org.bedework.calfacade.BwEvent) BwEventObj(org.bedework.calfacade.BwEventObj)

Example 24 with EventInfo

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

the class BwEventUtil method findMaster.

/* See if the master event is already in the collection of events
   * we've processed for this calendar. Only called if we have an event
   * with a recurrence id
   */
private static EventInfo findMaster(final String guid, final Collection evs) {
    if (evs == null) {
        return null;
    }
    Iterator it = evs.iterator();
    while (it.hasNext()) {
        EventInfo ei = (EventInfo) it.next();
        BwEvent ev = ei.getEvent();
        if ((ev.getRecurrenceId() == null) && guid.equals(ev.getUid())) /* &&
          ei.getNewEvent()  */
        {
            return ei;
        }
    }
    return null;
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) Iterator(java.util.Iterator) BwEvent(org.bedework.calfacade.BwEvent)

Example 25 with EventInfo

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

the class BwFreeBusyUtil method toFreeBusy.

/**
 * @param cb
 * @param val
 * @return BwFreeBusy
 * @throws CalFacadeException
 */
public static EventInfo toFreeBusy(final IcalCallback cb, final VFreeBusy val) throws CalFacadeException {
    if (val == null) {
        return null;
    }
    boolean debug = getLog().isDebugEnabled();
    try {
        PropertyList pl = val.getProperties();
        if (pl == null) {
            // Empty VEvent
            return null;
        }
        BwEvent fb = new BwEventObj();
        EventInfo ei = new EventInfo(fb);
        ChangeTable chg = ei.getChangeset(cb.getPrincipal().getPrincipalRef());
        fb.setEntityType(IcalDefs.entityTypeFreeAndBusy);
        setDates(cb.getPrincipal().getPrincipalRef(), ei, (DtStart) pl.getProperty(Property.DTSTART), (DtEnd) pl.getProperty(Property.DTEND), (Duration) pl.getProperty(Property.DURATION));
        Iterator it = pl.iterator();
        while (it.hasNext()) {
            Property prop = (Property) it.next();
            String pval = prop.getValue();
            if ((pval != null) && (pval.length() == 0)) {
                pval = null;
            }
            PropertyInfoIndex pi = PropertyInfoIndex.fromName(prop.getName());
            if (pi == null) {
                debugMsg("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval);
                continue;
            }
            switch(pi) {
                case ATTENDEE:
                    /* ------------------- Attendee -------------------- */
                    BwAttendee att = getAttendee(cb, (Attendee) prop);
                    fb.addAttendee(att);
                    chg.addValue(pi, att);
                    break;
                case COMMENT:
                    /* ------------------- Comment -------------------- */
                    // LANG
                    fb.addComment(null, pval);
                    chg.addValue(pi, pval);
                case DTEND:
                    break;
                case DTSTAMP:
                    /* ------------------- DtStamp -------------------- */
                    chg.changed(pi, fb.getDtstamp(), pval);
                    fb.setDtstamp(pval);
                case DTSTART:
                    break;
                case FREEBUSY:
                    /* ------------------- freebusy -------------------- */
                    FreeBusy fbusy = (FreeBusy) prop;
                    PeriodList perpl = fbusy.getPeriods();
                    Parameter par = getParameter(fbusy, "FBTYPE");
                    int fbtype;
                    if (par == null) {
                        fbtype = BwFreeBusyComponent.typeBusy;
                    } else if (par.equals(FbType.BUSY)) {
                        fbtype = BwFreeBusyComponent.typeBusy;
                    } else if (par.equals(FbType.BUSY_TENTATIVE)) {
                        fbtype = BwFreeBusyComponent.typeBusyTentative;
                    } else if (par.equals(FbType.BUSY_UNAVAILABLE)) {
                        fbtype = BwFreeBusyComponent.typeBusyUnavailable;
                    } else if (par.equals(FbType.FREE)) {
                        fbtype = BwFreeBusyComponent.typeFree;
                    } else {
                        if (debug) {
                            debugMsg("Unsupported parameter " + par.getName());
                        }
                        throw new IcalMalformedException("parameter " + par.getName());
                    }
                    BwFreeBusyComponent fbc = new BwFreeBusyComponent();
                    fbc.setType(fbtype);
                    Iterator perit = perpl.iterator();
                    while (perit.hasNext()) {
                        Period per = (Period) perit.next();
                        fbc.addPeriod(per);
                    }
                    fb.addFreeBusyPeriod(fbc);
                    chg.addValue(pi, fbc);
                    break;
                case ORGANIZER:
                    /* ------------------- Organizer -------------------- */
                    BwOrganizer org = getOrganizer(cb, (Organizer) prop);
                    fb.setOrganizer(org);
                    chg.addValue(pi, org);
                    break;
                case UID:
                    /* ------------------- Uid -------------------- */
                    chg.changed(pi, fb.getUid(), pval);
                    fb.setUid(pval);
                    break;
                default:
                    if (debug) {
                        debugMsg("Unsupported property with class " + prop.getClass() + " and value " + pval);
                    }
            }
        }
        return ei;
    } catch (CalFacadeException cfe) {
        throw cfe;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : BwFreeBusyComponent(org.bedework.calfacade.BwFreeBusyComponent) EventInfo(org.bedework.calfacade.svc.EventInfo) VFreeBusy(net.fortuna.ical4j.model.component.VFreeBusy) FreeBusy(net.fortuna.ical4j.model.property.FreeBusy) PeriodList(net.fortuna.ical4j.model.PeriodList) Period(net.fortuna.ical4j.model.Period) BwEvent(org.bedework.calfacade.BwEvent) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) PropertyList(net.fortuna.ical4j.model.PropertyList) PropertyInfoIndex(org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex) ChangeTable(org.bedework.calfacade.util.ChangeTable) Iterator(java.util.Iterator) Parameter(net.fortuna.ical4j.model.Parameter) Property(net.fortuna.ical4j.model.Property) BwAttendee(org.bedework.calfacade.BwAttendee) BwEventObj(org.bedework.calfacade.BwEventObj) BwOrganizer(org.bedework.calfacade.BwOrganizer)

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