Search in sources :

Example 6 with CoreEventInfo

use of org.bedework.calcorei.CoreEventInfo in project bw-calendar-engine by Bedework.

the class CoreEvents method getEvents.

@Override
public Collection<CoreEventInfo> getEvents(final Collection<BwCalendar> calendars, final FilterBase filter, final BwDateTime startDate, final BwDateTime endDate, final List<BwIcalPropertyInfoEntry> retrieveList, final DeletedState delState, RecurringRetrievalMode recurRetrieval, final boolean freeBusy) throws CalFacadeException {
    /* Ensure dates are limited explicitly or implicitly */
    recurRetrieval = defaultRecurringRetrieval(recurRetrieval, startDate, endDate);
    if (debug) {
        trace("getEvents for start=" + startDate + " end=" + endDate);
    }
    FilterBase fltr = filter;
    if (!Util.isEmpty(calendars)) {
        FilterBase colfltr = null;
        for (final BwCalendar c : calendars) {
            colfltr = FilterBase.addOrChild(colfltr, new BwCollectionFilter(null, c));
        }
        fltr = FilterBase.addAndChild(fltr, colfltr);
    }
    int desiredAccess = privRead;
    if (freeBusy) {
        // DORECUR - freebusy events must have enough info for expansion
        desiredAccess = privReadFreeBusy;
    }
    final List<PropertyInfoIndex> properties = new ArrayList<>(2);
    properties.add(PropertyInfoIndex.DTSTART);
    properties.add(PropertyInfoIndex.UTC);
    final List<SortTerm> sort = new ArrayList<>(1);
    sort.add(new SortTerm(properties, true));
    String start = null;
    String end = null;
    if (startDate != null) {
        start = startDate.getDate();
    }
    if (endDate != null) {
        end = endDate.getDate();
    }
    final SearchResult sr = // query
    getIndexer(null).search(// query
    null, false, fltr, sort, // defaultFilterContext
    null, start, end, -1, delState, recurRetrieval);
    final List<SearchResultEntry> sres = sr.getIndexer().getSearchResult(sr, 0, -1, desiredAccess);
    final TreeSet<CoreEventInfo> ceis = new TreeSet<>();
    for (final SearchResultEntry sre : sres) {
        final Object o = sre.getEntity();
        if (!(o instanceof EventInfo)) {
            continue;
        }
        final EventInfo ei = (EventInfo) o;
        final BwEvent ev = ei.getEvent();
        restoreCategories(ev);
        final CoreEventInfo cei = postGetEvent(ev, null, ei.getCurrentAccess());
        if (cei == null) {
            continue;
        }
        ceis.add(cei);
    }
    return buildVavail(ceis);
}
Also used : SortTerm(org.bedework.calfacade.filter.SortTerm) CoreEventInfo(org.bedework.calcorei.CoreEventInfo) EventInfo(org.bedework.calfacade.svc.EventInfo) CoreEventInfo(org.bedework.calcorei.CoreEventInfo) ArrayList(java.util.ArrayList) SearchResult(org.bedework.calfacade.indexing.SearchResult) BwEvent(org.bedework.calfacade.BwEvent) BwCalendar(org.bedework.calfacade.BwCalendar) BwCollectionFilter(org.bedework.calfacade.filter.BwCollectionFilter) PropertyInfoIndex(org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex) TreeSet(java.util.TreeSet) FilterBase(org.bedework.caldav.util.filter.FilterBase) SearchResultEntry(org.bedework.calfacade.indexing.SearchResultEntry)

Example 7 with CoreEventInfo

use of org.bedework.calcorei.CoreEventInfo in project bw-calendar-engine by Bedework.

the class CoreEvents method postGetEvents.

private Collection<CoreEventInfo> postGetEvents(final Collection evs, final int desiredAccess, final boolean nullForNoAccess, final Filters f) throws CalFacadeException {
    final TreeSet<CoreEventInfo> outevs = new TreeSet<>();
    for (final Object ev1 : evs) {
        final BwEvent ev = (BwEvent) ev1;
        final CoreEventInfo cei = postGetEvent(ev, desiredAccess, nullForNoAccess, f);
        if (cei == null) {
            continue;
        }
        outevs.add(cei);
    }
    return outevs;
}
Also used : CoreEventInfo(org.bedework.calcorei.CoreEventInfo) TreeSet(java.util.TreeSet) BwEvent(org.bedework.calfacade.BwEvent)

Example 8 with CoreEventInfo

use of org.bedework.calcorei.CoreEventInfo in project bw-calendar-engine by Bedework.

the class CalintfHelper method postGetEvent.

/* Post processing of event access has been checked
   */
protected CoreEventInfo postGetEvent(final BwEvent ev, final Filters f, final Acl.CurrentAccess ca) throws CalFacadeException {
    /* XXX-ALARM
    if (currentMode == userMode) {
      ev.setAlarms(getAlarms(ev, user));
    }
    */
    BwEvent event;
    if (ev instanceof BwEventAnnotation) {
        event = new BwEventProxy((BwEventAnnotation) ev);
        if ((f != null) && !f.postFilter(ev, currentPrincipal())) {
            return null;
        }
    } else {
        event = ev;
    }
    CoreEventInfo cei = new CoreEventInfo(event, ca);
    return cei;
}
Also used : BwEventAnnotation(org.bedework.calfacade.BwEventAnnotation) CoreEventInfo(org.bedework.calcorei.CoreEventInfo) BwEvent(org.bedework.calfacade.BwEvent) BwEventProxy(org.bedework.calfacade.BwEventProxy)

Example 9 with CoreEventInfo

use of org.bedework.calcorei.CoreEventInfo in project bw-calendar-engine by Bedework.

the class CalintfImpl method getFreeBusy.

/* ====================================================================
   *                   Free busy
   * ==================================================================== */
@Override
public BwEvent getFreeBusy(final Collection<BwCalendar> cals, final BwPrincipal who, final BwDateTime start, final BwDateTime end, final boolean returnAll, final boolean ignoreTransparency) throws CalFacadeException {
    if (who.getKind() != WhoDefs.whoTypeUser) {
        throw new CalFacadeException("Unsupported: non user principal for free-busy");
    }
    final Collection<CoreEventInfo> events = getFreeBusyEntities(cals, start, end, ignoreTransparency);
    final BwEvent fb = new BwEventObj();
    fb.setEntityType(IcalDefs.entityTypeFreeAndBusy);
    fb.setOwnerHref(who.getPrincipalRef());
    fb.setDtstart(start);
    fb.setDtend(end);
    try {
        final TreeSet<EventPeriod> eventPeriods = new TreeSet<>();
        for (final CoreEventInfo ei : events) {
            final BwEvent ev = ei.getEvent();
            // Ignore if times were specified and this event is outside the times
            final BwDateTime estart = ev.getDtstart();
            final BwDateTime eend = ev.getDtend();
            /* Don't report out of the requested period */
            final String dstart;
            final String dend;
            if (estart.before(start)) {
                dstart = start.getDtval();
            } else {
                dstart = estart.getDtval();
            }
            if (eend.after(end)) {
                dend = end.getDtval();
            } else {
                dend = eend.getDtval();
            }
            final DateTime psdt = new DateTime(dstart);
            final DateTime pedt = new DateTime(dend);
            psdt.setUtc(true);
            pedt.setUtc(true);
            int type = BwFreeBusyComponent.typeBusy;
            if (BwEvent.statusTentative.equals(ev.getStatus())) {
                type = BwFreeBusyComponent.typeBusyTentative;
            }
            eventPeriods.add(new EventPeriod(psdt, pedt, type));
        }
        /* iterate through the sorted periods combining them where they are
       adjacent or overlap */
        Period p = null;
        /* For the moment just build a single BwFreeBusyComponent
       */
        BwFreeBusyComponent fbc = null;
        int lastType = 0;
        for (final EventPeriod ep : eventPeriods) {
            if (debug) {
                debug(ep.toString());
            }
            if (p == null) {
                p = new Period(ep.getStart(), ep.getEnd());
                lastType = ep.getType();
            } else if ((lastType != ep.getType()) || ep.getStart().after(p.getEnd())) {
                // Non adjacent periods
                if (fbc == null) {
                    fbc = new BwFreeBusyComponent();
                    fbc.setType(lastType);
                    fb.addFreeBusyPeriod(fbc);
                }
                fbc.addPeriod(p.getStart(), p.getEnd());
                if (lastType != ep.getType()) {
                    fbc = null;
                }
                p = new Period(ep.getStart(), ep.getEnd());
                lastType = ep.getType();
            } else if (ep.getEnd().after(p.getEnd())) {
                // Extend the current period
                p = new Period(p.getStart(), ep.getEnd());
            }
        // else it falls within the existing period
        }
        if (p != null) {
            if ((fbc == null) || (lastType != fbc.getType())) {
                fbc = new BwFreeBusyComponent();
                fbc.setType(lastType);
                fb.addFreeBusyPeriod(fbc);
            }
            fbc.addPeriod(p.getStart(), p.getEnd());
        }
    } catch (final Throwable t) {
        if (debug) {
            error(t);
        }
        throw new CalFacadeException(t);
    }
    return fb;
}
Also used : EventPeriod(org.bedework.calfacade.util.Granulator.EventPeriod) BwFreeBusyComponent(org.bedework.calfacade.BwFreeBusyComponent) BwDateTime(org.bedework.calfacade.BwDateTime) CoreEventInfo(org.bedework.calcorei.CoreEventInfo) Period(net.fortuna.ical4j.model.Period) EventPeriod(org.bedework.calfacade.util.Granulator.EventPeriod) BwEvent(org.bedework.calfacade.BwEvent) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) DateTime(net.fortuna.ical4j.model.DateTime) BwDateTime(org.bedework.calfacade.BwDateTime) TreeSet(java.util.TreeSet) BwEventObj(org.bedework.calfacade.BwEventObj)

Example 10 with CoreEventInfo

use of org.bedework.calcorei.CoreEventInfo in project bw-calendar-engine by Bedework.

the class CalintfImpl method getFreeBusyEntities.

private Collection<CoreEventInfo> getFreeBusyEntities(final Collection<BwCalendar> cals, final BwDateTime start, final BwDateTime end, final boolean ignoreTransparency) throws CalFacadeException {
    /* Only events and freebusy for freebusy reports. */
    final FilterBase filter = new OrFilter();
    try {
        filter.addChild(EntityTypeFilter.makeEntityTypeFilter(null, "event", false));
        filter.addChild(EntityTypeFilter.makeEntityTypeFilter(null, "freeAndBusy", false));
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
    final RecurringRetrievalMode rrm = new RecurringRetrievalMode(Rmode.expanded, start, end);
    final Collection<CoreEventInfo> evs = getEvents(cals, filter, start, end, null, DeletedState.noDeleted, rrm, true);
    // Filter out transparent and cancelled events
    final Collection<CoreEventInfo> events = new TreeSet<>();
    for (final CoreEventInfo cei : evs) {
        final BwEvent ev = cei.getEvent();
        if (!ignoreTransparency && IcalDefs.transparencyTransparent.equals(ev.getPeruserTransparency(this.getPrincipal().getPrincipalRef()))) {
            // Ignore this one.
            continue;
        }
        if (ev.getSuppressed() || BwEvent.statusCancelled.equals(ev.getStatus())) {
            // Ignore this one.
            continue;
        }
        events.add(cei);
    }
    return events;
}
Also used : RecurringRetrievalMode(org.bedework.calfacade.RecurringRetrievalMode) CoreEventInfo(org.bedework.calcorei.CoreEventInfo) TreeSet(java.util.TreeSet) BwEvent(org.bedework.calfacade.BwEvent) OrFilter(org.bedework.caldav.util.filter.OrFilter) FilterBase(org.bedework.caldav.util.filter.FilterBase) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

CoreEventInfo (org.bedework.calcorei.CoreEventInfo)14 BwEvent (org.bedework.calfacade.BwEvent)14 TreeSet (java.util.TreeSet)9 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)7 BwEventProxy (org.bedework.calfacade.BwEventProxy)5 BwDateTime (org.bedework.calfacade.BwDateTime)4 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)4 BwCalendar (org.bedework.calfacade.BwCalendar)3 ArrayList (java.util.ArrayList)2 Period (net.fortuna.ical4j.model.Period)2 CurrentAccess (org.bedework.access.Acl.CurrentAccess)2 FilterBase (org.bedework.caldav.util.filter.FilterBase)2 BwRecurrenceInstance (org.bedework.calfacade.BwRecurrenceInstance)2 EventInfo (org.bedework.calfacade.svc.EventInfo)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 DateTime (net.fortuna.ical4j.model.DateTime)1 EventsQueryResult (org.bedework.calcore.hibernate.EventQueryBuilder.EventsQueryResult)1 OrFilter (org.bedework.caldav.util.filter.OrFilter)1