Search in sources :

Example 21 with BwDateTime

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

the class RdatePropUpdater method addDt.

private boolean addDt(final BwDateTime newdt, final Set<BwDateTime> evDts, final ChangeTableEntry cte) {
    if (!Util.isEmpty(evDts)) {
        for (BwDateTime evDt : evDts) {
            if (evDt.getDate().equals(newdt.getDate())) {
                // Already there
                return false;
            }
        }
    }
    evDts.add(newdt);
    cte.addAddedValue(newdt);
    return true;
}
Also used : BwDateTime(org.bedework.calfacade.BwDateTime)

Example 22 with BwDateTime

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

the class RdatePropUpdater method removeDt.

private boolean removeDt(final String dtUTC, final Set<BwDateTime> evDts, final ChangeTableEntry cte) {
    if (Util.isEmpty(evDts)) {
        // Nothing to remove
        return false;
    }
    for (BwDateTime evDt : evDts) {
        if (evDt.getDate().equals(dtUTC)) {
            evDts.remove(evDt);
            cte.addRemovedValue(evDt);
            break;
        }
    }
    return true;
}
Also used : BwDateTime(org.bedework.calfacade.BwDateTime)

Example 23 with BwDateTime

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

the class BwIndexEsImpl method indexEvent.

private IndexResponse indexEvent(final EventInfo ei) throws CalFacadeException {
    try {
        /* If it's not recurring or a stand-alone instance index it */
        final BwEvent ev = ei.getEvent();
        if (!ev.testRecurring() && (ev.getRecurrenceId() == null)) {
            return indexEvent(ei, ItemKind.master, ev.getDtstart(), ev.getDtend(), // ev.getRecurrenceId(),
            null, null);
        }
        if (ev.getRecurrenceId() != null) {
            error("Not implemented - index of single override");
            return null;
        }
        /* Delete all instances of this event: we'll do a delete by query
       * We need to find all with the same path and uid.
       */
        /* TODO - do a query for all recurrence ids and delete the ones
          we don't want.
       */
        deleteEvent(ei);
        /* Create a list of all instance date/times before overrides. */
        final int maxYears;
        final int maxInstances;
        final DateLimits dl = new DateLimits();
        if (ev.getPublick()) {
            maxYears = unauthpars.getMaxYears();
            maxInstances = unauthpars.getMaxInstances();
        } else {
            maxYears = authpars.getMaxYears();
            maxInstances = authpars.getMaxInstances();
        }
        final RecurPeriods rp = RecurUtil.getPeriods(ev, maxYears, maxInstances);
        if (rp.instances.isEmpty()) {
            // No instances for an alleged recurring event.
            return null;
        // throw new CalFacadeException(CalFacadeException.noRecurrenceInstances);
        }
        final String stzid = ev.getDtstart().getTzid();
        int instanceCt = maxInstances;
        final boolean dateOnly = ev.getDtstart().getDateType();
        /* First build a table of overrides so we can skip these later
       */
        final Map<String, String> overrides = new HashMap<>();
        /*
      if (!Util.isEmpty(ei.getOverrideProxies())) {
        for (BwEvent ov: ei.getOverrideProxies()) {
          overrides.put(ov.getRecurrenceId(), ov.getRecurrenceId());
        }
      }
      */
        final IndexResponse iresp;
        if (!Util.isEmpty(ei.getOverrides())) {
            for (final EventInfo oei : ei.getOverrides()) {
                final BwEvent ov = oei.getEvent();
                overrides.put(ov.getRecurrenceId(), ov.getRecurrenceId());
                final String start;
                if (ov.getDtstart().getDateType()) {
                    start = ov.getRecurrenceId().substring(0, 8);
                } else {
                    start = ov.getRecurrenceId();
                }
                final BwDateTime rstart = BwDateTime.makeBwDateTime(ov.getDtstart().getDateType(), start, stzid);
                final BwDateTime rend = rstart.addDuration(BwDuration.makeDuration(ov.getDuration()));
                /*iresp = */
                indexEvent(oei, ItemKind.override, rstart, rend, ov.getRecurrenceId(), dl);
                instanceCt--;
            }
        }
        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.get(rstart.getDate()) != null) {
                // Overrides indexed 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);
            /*iresp = */
            indexEvent(ei, entity, rstart, rend, recurrenceId, dl);
            instanceCt--;
            if (instanceCt == 0) {
                // That's all you're getting from me
                break;
            }
        }
        // </editor-fold>
        // <editor-fold desc="Emit the master event with a date range covering the entire period.">
        final BwDateTime start = BwDateTime.makeBwDateTime(dateOnly, dl.minStart, stzid);
        final BwDateTime end = BwDateTime.makeBwDateTime(dateOnly, dl.maxEnd, stzid);
        iresp = indexEvent(ei, ItemKind.master, start, end, null, null);
        return iresp;
    } catch (final CalFacadeException cfe) {
        throw cfe;
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) BwDateTime(org.bedework.calfacade.BwDateTime) HashMap(java.util.HashMap) Period(net.fortuna.ical4j.model.Period) BwEvent(org.bedework.calfacade.BwEvent) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse) DeleteIndexResponse(org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse) IndexResponse(org.elasticsearch.action.index.IndexResponse) RecurPeriods(org.bedework.icalendar.RecurUtil.RecurPeriods)

Example 24 with BwDateTime

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

the class DocBuilder method makeBwDateTimes.

private void makeBwDateTimes(final PropertyInfoIndex pi, final Set<BwDateTime> vals) throws CalFacadeException {
    try {
        if (Util.isEmpty(vals)) {
            return;
        }
        startArray(getJname(pi));
        for (final BwDateTime dt : vals) {
            indexDate(null, dt);
        }
        endArray();
    } catch (final IndexException e) {
        throw new CalFacadeException(e);
    }
}
Also used : BwDateTime(org.bedework.calfacade.BwDateTime) IndexException(org.bedework.util.indexing.IndexException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 25 with BwDateTime

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

the class EntityBuilder method restoreBwDateTimeSet.

private Set<BwDateTime> restoreBwDateTimeSet(final PropertyInfoIndex pi) throws CalFacadeException {
    final List<Object> vals = getFieldValues(pi);
    if (Util.isEmpty(vals)) {
        return null;
    }
    final Set<BwDateTime> tms = new TreeSet<>();
    for (final Object o : vals) {
        try {
            pushFields(o);
            final String date = getString(PropertyInfoIndex.LOCAL);
            final String utcDate = getString(PropertyInfoIndex.UTC);
            final String tzid = getString(PropertyInfoIndex.TZID);
            final boolean floating = getBool(PropertyInfoIndex.FLOATING);
            final boolean dateType = date.length() == 8;
            final BwDateTime tm = BwDateTime.makeBwDateTime(dateType, date, utcDate, tzid, floating);
            tms.add(tm);
        } catch (final IndexException ie) {
            throw new CalFacadeException(ie);
        } finally {
            popFields();
        }
    }
    return tms;
}
Also used : BwDateTime(org.bedework.calfacade.BwDateTime) IndexException(org.bedework.util.indexing.IndexException) TreeSet(java.util.TreeSet) BwString(org.bedework.calfacade.BwString) BwLongString(org.bedework.calfacade.BwLongString) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

BwDateTime (org.bedework.calfacade.BwDateTime)45 BwEvent (org.bedework.calfacade.BwEvent)23 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)20 Period (net.fortuna.ical4j.model.Period)11 DateTime (net.fortuna.ical4j.model.DateTime)9 DtStart (net.fortuna.ical4j.model.property.DtStart)8 BwEventProxy (org.bedework.calfacade.BwEventProxy)8 BwRecurrenceInstance (org.bedework.calfacade.BwRecurrenceInstance)8 EventInfo (org.bedework.calfacade.svc.EventInfo)8 Date (net.fortuna.ical4j.model.Date)7 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)7 BwString (org.bedework.calfacade.BwString)7 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)7 Dur (net.fortuna.ical4j.model.Dur)6 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)6 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)6 RecurPeriods (org.bedework.icalendar.RecurUtil.RecurPeriods)6 TreeSet (java.util.TreeSet)5 ChangeTable (org.bedework.calfacade.util.ChangeTable)5 DateDatetimePropertyType (ietf.params.xml.ns.icalendar_2.DateDatetimePropertyType)4