Search in sources :

Example 11 with CoreEventInfo

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

the class CoreEvents method doRecurrence.

/* Retrieves the overides for a recurring event and if required,
   * retrieves the instances.
   *
   * The overrides we retrieve are optionally limited by date.
   *
   * The CalDAV spec requires that we retrieve all overrides which fall within
   * the given date range AND all instances in that date range including
   * overriden instances that WOULD have fallen in that range had they not been
   * overriden.
   *
   * Thus we need to search both overrides and instances - unless no date range
   * is given in which case all overrides will appear along with the instances.
   *
   * If the calendars parameter is non-null, as it usually will be for a call
   * from getEvents, we limit the result to instances that appear within that
   * set of calendars. This handles the case of an overriden instance moved to a
   * different calendar, for example the trash.
   */
@SuppressWarnings("unchecked")
private void doRecurrence(final CoreEventInfo cei, final RecurringRetrievalMode recurRetrieval) throws CalFacadeException {
    final BwEvent master = cei.getEvent();
    final Set<String> overrides = new HashSet<>();
    final CurrentAccess ca = cei.getCurrentAccess();
    // Always fetch all overrides
    final Collection<BwEventAnnotation> ovs = dao.eventQuery(BwEventAnnotation.class, null, null, null, master, // overrides
    true, // recurRetrieval);
    null);
    if (ovs != null) {
        for (final BwEventAnnotation override : ovs) {
            final CoreEventInfo ocei = makeOverrideProxy(override, ca);
            cei.addOverride(ocei);
            overrides.add(ocei.getEvent().getRecurrenceId());
        }
    }
    if ((recurRetrieval == null) || (recurRetrieval.mode != Rmode.expanded)) {
        return;
    }
    /* Create a list of all instance date/times before overrides. */
    final int maxYears;
    final int maxInstances;
    maxYears = getAuthprops().getMaxYears();
    maxInstances = getAuthprops().getMaxInstances();
    final RecurPeriods rp = RecurUtil.getPeriods(master, maxYears, maxInstances);
    if (rp.instances.isEmpty()) {
        // No instances for an alleged recurring event.
        return;
    // throw new CalFacadeException(CalFacadeException.noRecurrenceInstances);
    }
    final String stzid = master.getDtstart().getTzid();
    final boolean dateOnly = master.getDtstart().getDateType();
    /* Emit all instances that aren't overridden. */
    final TreeSet<CoreEventInfo> ceis = new TreeSet<>();
    for (final Period p : rp.instances) {
        String dtval = p.getStart().toString();
        if (dateOnly) {
            dtval = dtval.substring(0, 8);
        }
        final BwDateTime rstart = BwDateTime.makeBwDateTime(dateOnly, dtval, stzid);
        if (overrides.contains(rstart.getDate())) {
            // Overrides built separately - skip this instance.
            continue;
        }
        final String recurrenceId = rstart.getDate();
        dtval = p.getEnd().toString();
        if (dateOnly) {
            dtval = dtval.substring(0, 8);
        }
        final BwDateTime rend = BwDateTime.makeBwDateTime(dateOnly, dtval, stzid);
        final BwRecurrenceInstance inst = new BwRecurrenceInstance(rstart, rend, recurrenceId, master, null);
        final CoreEventInfo instcei = makeInstanceProxy(inst, ca);
        if (instcei != null) {
            // if (debug) {
            // debugMsg("Ev: " + proxy);
            // }
            ceis.add(instcei);
        }
    }
    cei.setInstances(ceis);
}
Also used : BwDateTime(org.bedework.calfacade.BwDateTime) CoreEventInfo(org.bedework.calcorei.CoreEventInfo) Period(net.fortuna.ical4j.model.Period) BwEvent(org.bedework.calfacade.BwEvent) BwRecurrenceInstance(org.bedework.calfacade.BwRecurrenceInstance) BwEventAnnotation(org.bedework.calfacade.BwEventAnnotation) TreeSet(java.util.TreeSet) CurrentAccess(org.bedework.access.Acl.CurrentAccess) RecurPeriods(org.bedework.icalendar.RecurUtil.RecurPeriods) HashSet(java.util.HashSet)

Example 12 with CoreEventInfo

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

the class CoreEvents method makeInstanceProxy.

/**
 * The master has been checked for access and we now build and
 * return an event proxy for an instance which has no override.
 *
 * @param inst        the instance
 * @param ca          Checked access from master
 * @return CoreEventInfo
 * @throws CalFacadeException on error
 */
private CoreEventInfo makeInstanceProxy(final BwRecurrenceInstance inst, final CurrentAccess ca) throws CalFacadeException {
    final BwEvent mstr = inst.getMaster();
    /*
    if (recurRetrieval.mode == Rmode.masterOnly) {
      // Master only and we've just seen it for the first time
      // Note we will not do this for freebusy. We need all recurrences.

      /* XXX I think this was wrong. Why make an override?
       * /
      // make a fake one pointing at the owners override
      override = new BwEventAnnotation();
      override.setTarget(mstr);
      override.setMaster(mstr);

      BwDateTime start = mstr.getDtstart();
      BwDateTime end = mstr.getDtend();

      override.setDtstart(start);
      override.setDtend(end);
      override.setDuration(BwDateTime.makeDuration(start, end).toString());
      override.setCreatorHref(mstr.getCreatorHref());
      override.setOwnerHref(getUser().getPrincipalRef());

      return new CoreEventInfo(new BwEventProxy(override), ca);
    }
    */
    /* success so now we build a proxy with the event and any override.
     */
    final BwEventAnnotation override = new BwEventAnnotation();
    override.setTarget(mstr);
    override.setMaster(mstr);
    final BwDateTime start = inst.getDtstart();
    final BwDateTime end = inst.getDtend();
    override.setRecurrenceId(inst.getRecurrenceId());
    override.setDtstart(start);
    override.setDtend(end);
    override.setDuration(BwDateTime.makeDuration(start, end).toString());
    override.setCreatorHref(mstr.getCreatorHref());
    override.setOwnerHref(mstr.getOwnerHref());
    override.setOverride(true);
    override.setName(mstr.getName());
    override.setUid(mstr.getUid());
    /* At this point we have an event with possible overrides. If this is free
     * busy we need to replace it all with a skeleton event holding only date/time
     * information.
     *
     * We can't do this before I think because we need to allow the user to
     * override the transparency on a particular instance,
     */
    final BwEvent proxy = new BwEventProxy(override);
    return new CoreEventInfo(proxy, ca);
}
Also used : BwDateTime(org.bedework.calfacade.BwDateTime) BwEventAnnotation(org.bedework.calfacade.BwEventAnnotation) CoreEventInfo(org.bedework.calcorei.CoreEventInfo) BwEvent(org.bedework.calfacade.BwEvent) BwEventProxy(org.bedework.calfacade.BwEventProxy)

Example 13 with CoreEventInfo

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

the class CoreEvents method buildVavail.

private Collection<CoreEventInfo> buildVavail(final Collection<CoreEventInfo> ceis) throws CalFacadeException {
    final TreeSet<CoreEventInfo> outevs = new TreeSet<>();
    final Map<String, CoreEventInfo> vavails = new HashMap<>();
    final List<CoreEventInfo> unclaimed = new ArrayList<>();
    for (final CoreEventInfo cei : ceis) {
        final BwEvent ev = cei.getEvent();
        if (ev.getEntityType() == IcalDefs.entityTypeAvailable) {
            final CoreEventInfo vavail = vavails.get(ev.getUid());
            if (vavail != null) {
                vavail.addContainedItem(cei);
            } else {
                unclaimed.add(cei);
            }
            continue;
        }
        if (ev.getEntityType() == IcalDefs.entityTypeVavailability) {
            // Keys are the list of AVAILABLE uids
            for (final String auid : ev.getAvailableUids()) {
                vavails.put(auid, cei);
            }
        }
        outevs.add(cei);
    }
    for (final CoreEventInfo cei : unclaimed) {
        final CoreEventInfo vavail = vavails.get(cei.getEvent().getUid());
        if (vavail != null) {
            vavail.addContainedItem(cei);
            continue;
        }
    /*
         This is an orphaned available object. We should probably retrieve the
         vavailability.
         I guess this could happen if we have a date range query that excludes
         the vavailability?
       */
    }
    return outevs;
}
Also used : HashMap(java.util.HashMap) CoreEventInfo(org.bedework.calcorei.CoreEventInfo) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) BwEvent(org.bedework.calfacade.BwEvent)

Example 14 with CoreEventInfo

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

the class CoreEvents method getEvent.

@Override
@SuppressWarnings("unchecked")
public CoreEventInfo getEvent(final String colPath, final String name, final RecurringRetrievalMode recurRetrieval) throws CalFacadeException {
    final List<BwEvent> evs = dao.getEventsByName(colPath, name);
    /* If this is availability we should have one vavailability and a number of
     * available. Otherwise just a single event.
     */
    BwEvent ev = null;
    List<BwEvent> avails = null;
    if (evs.size() == 1) {
        ev = evs.get(0);
    } else {
        for (final BwEvent lev : evs) {
            final int etype = lev.getEntityType();
            if (etype == IcalDefs.entityTypeAvailable) {
                if (avails == null) {
                    avails = new ArrayList<>();
                }
                avails.add(lev);
            } else if (etype == IcalDefs.entityTypeVavailability) {
                if (ev != null) {
                    throwException(new CalFacadeException(CalFacadeException.duplicateName));
                    return null;
                }
                ev = lev;
            } else {
                throwException(new CalFacadeException(CalFacadeException.duplicateName));
                return null;
            }
        }
    }
    if (ev == null) {
        // Try annotation
        ev = dao.getEventsAnnotationName(colPath, name);
    }
    if (ev == null) {
        return null;
    }
    final CoreEventInfo cei = postGetEvent(ev, privRead, returnResultAlways, null);
    if (cei != null) {
        if (avails != null) {
            for (final BwEvent aev : avails) {
                final CoreEventInfo acei = postGetEvent(aev, privRead, returnResultAlways, null);
                if (acei == null) {
                    continue;
                }
                if (aev.testRecurring()) {
                    doRecurrence(acei, recurRetrieval);
                }
                cei.addContainedItem(acei);
            }
        } else {
            ev = cei.getEvent();
            if (ev.testRecurring()) {
                doRecurrence(cei, recurRetrieval);
            }
        }
    }
    return cei;
}
Also used : CoreEventInfo(org.bedework.calcorei.CoreEventInfo) BwEvent(org.bedework.calfacade.BwEvent) 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