Search in sources :

Example 46 with BwCalendar

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

the class ESQueryFilter method makeFilter.

private FilterBuilder makeFilter(final FilterBase f) throws CalFacadeException {
    if (f == null) {
        return null;
    }
    if (f instanceof BooleanFilter) {
        final BooleanFilter bf = (BooleanFilter) f;
        if (!bf.getValue()) {
            return new MatchNone();
        } else {
            return new MatchAllFilterBuilder();
        }
    }
    if (f instanceof AndFilter) {
        final List<FilterBuilder> fbs = makeFilters(f.getChildren(), true);
        if (fbs.size() == 1) {
            return fbs.get(0);
        }
        final AndFilterBuilder afb = new AndFilterBuilder();
        afb.filterName(f.getName());
        for (final FilterBuilder fb : fbs) {
            if (fb instanceof TermOrTerms) {
                afb.add(makeFilter((TermOrTerms) fb));
            } else {
                afb.add(fb);
            }
        }
        return afb;
    }
    if (f instanceof OrFilter) {
        final List<FilterBuilder> fbs = makeFilters(f.getChildren(), false);
        if (fbs.size() == 1) {
            return fbs.get(0);
        }
        final OrFilterBuilder ofb = new OrFilterBuilder();
        ofb.filterName(f.getName());
        for (final FilterBuilder fb : fbs) {
            if (fb instanceof TermOrTerms) {
                ofb.add(((TermOrTerms) fb).makeFb());
            } else {
                ofb.add(fb);
            }
        }
        return ofb;
    }
    if (f instanceof BwViewFilter) {
        return doView((BwViewFilter) f);
    }
    if (f instanceof BwHrefFilter) {
        queryLimited = true;
        final TermFilterBuilder tfb = FilterBuilders.termFilter(hrefJname, ((BwHrefFilter) f).getHref());
        tfb.filterName(f.getName());
        return tfb;
    }
    if (!(f instanceof PropertyFilter)) {
        return null;
    }
    final PropertyFilter pf = (PropertyFilter) f;
    /*
    if (pf.getPropertyIndex() == PropertyInfoIndex.CATEGORY_PATH) {
      // Special case this one.
      return new TermOrTerms(PropertyInfoIndex.CATEGORY_PATH.getJname(),
                             ((ObjectFilter)pf).getEntity());
    }*/
    final BwIcalPropertyInfo.BwIcalPropertyInfoEntry pi = BwIcalPropertyInfo.getPinfo(pf.getPropertyIndex());
    if (pi == null) {
        throw new CalFacadeException("org.bedework.filters.unknownproperty", String.valueOf(pf.getPropertyIndex()));
    }
    final String fieldName;
    final PropertyInfoIndex pii = pf.getPropertyIndex();
    if (pf.getParentPropertyIndex() != null) {
        fieldName = makePropertyRef(pf.getParentPropertyIndex(), pii);
    } else {
        fieldName = getJname(pii);
    }
    if (f instanceof PresenceFilter) {
        final PresenceFilter prf = (PresenceFilter) f;
        if (prf.getTestPresent()) {
            return makeFilter(pf.getPropertyIndexes(), null, pf.getIntKey(), pf.getStrKey(), OperationType.presence, pf.getNot());
        }
        return makeFilter(pf.getPropertyIndexes(), null, pf.getIntKey(), pf.getStrKey(), OperationType.absence, pf.getNot());
    }
    if (pf instanceof TimeRangeFilter) {
        return makeFilter(pf.getPropertyIndexes(), ((TimeRangeFilter) pf).getEntity(), pf.getIntKey(), pf.getStrKey(), OperationType.timeRange, pf.getNot());
    }
    if (pf instanceof BwCollectionFilter) {
        if (!pf.getNot()) {
            queryLimited = true;
        }
        final BwCalendar col = ((BwCollectionFilter) pf).getEntity();
        return new TermOrTerms(colpathJname, col.getPath(), pf.getNot(), f.getName());
    }
    if (pf instanceof EntityTypeFilter) {
        final EntityTypeFilter etf = (EntityTypeFilter) pf;
        return new TermOrTerms(entityTypeJname, IcalDefs.entityTypeNames[etf.getEntity()], pf.getNot(), f.getName());
    }
    if (pf instanceof EntityTimeRangeFilter) {
        final EntityTimeRangeFilter etrf = (EntityTimeRangeFilter) pf;
        final TimeRange tr = etrf.getEntity();
        String start = null;
        String end = null;
        if (tr.getStart() != null) {
            start = tr.getStart().toString();
        }
        if (tr.getEnd() != null) {
            end = tr.getEnd().toString();
        }
        return addDateRangeFilter(null, etrf.getEntityType(), start, end);
    }
    if (pii == PropertyInfoIndex.COLLECTION) {
        if (!pf.getNot()) {
            queryLimited = true;
        }
    }
    if (pf instanceof ObjectFilter) {
        final OperationType op;
        if (((ObjectFilter) pf).getPrefixMatch()) {
            op = OperationType.prefix;
        } else {
            op = OperationType.compare;
        }
        return makeFilter(pf.getPropertyIndexes(), getValue((ObjectFilter) pf), pf.getIntKey(), pf.getStrKey(), op, pf.getNot());
    }
    return null;
/*
    if (f instanceof TimeRangeFilter) {
      addThisJoin(pi);
      return;
    }

    if (f instanceof BwObjectFilter) {
      addThisJoin(pi);
      return;
    }*/
}
Also used : BooleanFilter(org.bedework.caldav.util.filter.BooleanFilter) PresenceFilter(org.bedework.caldav.util.filter.PresenceFilter) EntityTimeRangeFilter(org.bedework.caldav.util.filter.EntityTimeRangeFilter) TimeRangeFilter(org.bedework.caldav.util.filter.TimeRangeFilter) BwIcalPropertyInfo(org.bedework.calfacade.ical.BwIcalPropertyInfo) EntityTypeFilter(org.bedework.caldav.util.filter.EntityTypeFilter) BwCollectionFilter(org.bedework.calfacade.filter.BwCollectionFilter) AndFilterBuilder(org.elasticsearch.index.query.AndFilterBuilder) TermFilterBuilder(org.elasticsearch.index.query.TermFilterBuilder) FilterBuilder(org.elasticsearch.index.query.FilterBuilder) OrFilterBuilder(org.elasticsearch.index.query.OrFilterBuilder) RangeFilterBuilder(org.elasticsearch.index.query.RangeFilterBuilder) BoolFilterBuilder(org.elasticsearch.index.query.BoolFilterBuilder) QueryFilterBuilder(org.elasticsearch.index.query.QueryFilterBuilder) NotFilterBuilder(org.elasticsearch.index.query.NotFilterBuilder) NestedFilterBuilder(org.elasticsearch.index.query.NestedFilterBuilder) MatchAllFilterBuilder(org.elasticsearch.index.query.MatchAllFilterBuilder) TermsFilterBuilder(org.elasticsearch.index.query.TermsFilterBuilder) AndFilterBuilder(org.elasticsearch.index.query.AndFilterBuilder) BwHrefFilter(org.bedework.calfacade.filter.BwHrefFilter) OrFilter(org.bedework.caldav.util.filter.OrFilter) BwCalendar(org.bedework.calfacade.BwCalendar) ObjectFilter(org.bedework.caldav.util.filter.ObjectFilter) EntityTimeRangeFilter(org.bedework.caldav.util.filter.EntityTimeRangeFilter) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) OrFilterBuilder(org.elasticsearch.index.query.OrFilterBuilder) AndFilter(org.bedework.caldav.util.filter.AndFilter) BwViewFilter(org.bedework.calfacade.filter.BwViewFilter) TimeRange(org.bedework.caldav.util.TimeRange) MatchAllFilterBuilder(org.elasticsearch.index.query.MatchAllFilterBuilder) PropertyInfoIndex(org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex) TermFilterBuilder(org.elasticsearch.index.query.TermFilterBuilder) PropertyFilter(org.bedework.caldav.util.filter.PropertyFilter) BwIcalPropertyInfoEntry(org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry)

Example 47 with BwCalendar

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

the class EntityBuilder method makeCollection.

BwCalendar makeCollection() throws CalFacadeException {
    final BwCalendar col = new BwCalendar();
    restoreSharedEntity(col);
    col.setName(getString(PropertyInfoIndex.NAME));
    col.setPath(getString(PropertyInfoIndex.HREF));
    col.setCreated(getString(PropertyInfoIndex.CREATED));
    col.setLastmod(new BwCollectionLastmod(col, getString(PropertyInfoIndex.LAST_MODIFIED)));
    col.setSummary(getString(PropertyInfoIndex.SUMMARY));
    col.setDescription(getString(PropertyInfoIndex.DESCRIPTION));
    col.setAffectsFreeBusy(getBool(PropertyInfoIndex.AFFECTS_FREE_BUSY));
    col.setAliasUri(getString(PropertyInfoIndex.ALIAS_URI));
    col.setCalType(getInt(PropertyInfoIndex.CALTYPE));
    col.setDisplay(getBool(PropertyInfoIndex.DISPLAY));
    col.setFilterExpr(getString(PropertyInfoIndex.FILTER_EXPR));
    col.setIgnoreTransparency(getBool(PropertyInfoIndex.IGNORE_TRANSP));
    col.setLastRefresh(getString(PropertyInfoIndex.LAST_REFRESH));
    col.setLastRefreshStatus(getString(PropertyInfoIndex.LAST_REFRESH_STATUS));
    col.setRefreshRate(getInt(PropertyInfoIndex.REFRESH_RATE));
    col.setRemoteId(getString(PropertyInfoIndex.REMOTE_ID));
    col.setRemotePw(getString(PropertyInfoIndex.REMOTE_PW));
    col.setUnremoveable(getBool(PropertyInfoIndex.UNREMOVEABLE));
    restoreProperties(col);
    restoreCategories(col);
    return col;
}
Also used : BwCollectionLastmod(org.bedework.calfacade.BwCollectionLastmod) BwCalendar(org.bedework.calfacade.BwCalendar)

Example 48 with BwCalendar

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

the class CoreEvents method deleteEvent.

@Override
public DelEventResult deleteEvent(final EventInfo ei, final boolean scheduling, final boolean reallyDelete) throws CalFacadeException {
    final DelEventResult der = new DelEventResult(false, 0);
    BwEvent ev = ei.getEvent();
    final boolean isMaster = ev.testRecurring() && (ev.getRecurrenceId() == null);
    final boolean isInstance = (ev.getRecurrenceId() != null) && (ev instanceof BwEventProxy);
    if (!isInstance && ev.unsaved()) {
        final CoreEventInfo cei = getEvent(ev.getColPath(), ev.getName(), RecurringRetrievalMode.overrides);
        if (cei == null) {
            return der;
        }
        ev = cei.getEvent();
    }
    final long startTime = System.currentTimeMillis();
    final int desiredAccess;
    final boolean shared;
    try {
        final BwCalendar col = getEntityCollection(ev.getColPath(), privAny, scheduling, false);
        shared = col.getPublick() || col.getShared();
        if (!scheduling) {
            desiredAccess = privUnbind;
        } else {
            /* Delete message while tidying up in/outbox.
         * Set desiredAccess to something that works.
         *  */
            final CalendarWrapper cw = (CalendarWrapper) col;
            desiredAccess = cw.getLastDesiredAccess();
        }
        ac.checkAccess(ev, desiredAccess, false);
    } catch (final CalFacadeException cfe) {
        dao.rollback();
        throw cfe;
    }
    if (!reallyDelete && ev.getTombstoned()) {
        // no-op - just pretend
        der.eventDeleted = true;
        return der;
    }
    if (isMaster) {
        // Master event - delete all instances and overrides.
        deleteInstances(ev, shared);
        notifyDelete(reallyDelete, ev, shared);
        if (reallyDelete) {
            dao.delete(ev);
        } else {
            tombstoneEvent(ev);
        }
        der.eventDeleted = true;
        stat(StatsEvent.deleteTime, startTime);
        unindexEntity(ei);
        return der;
    }
    if (isInstance) {
        /* Deleting a single instance. Delete any overrides, delete the instance
       * and add an exdate to the master.
       */
        final BwEventProxy proxy = (BwEventProxy) ev;
        final BwEventAnnotation ann = proxy.getRef();
        BwEvent master = ann.getMaster();
        if (master.unsaved()) {
            final CoreEventInfo cei = getEvent(master.getColPath(), master.getName(), RecurringRetrievalMode.overrides);
            if (cei == null) {
                return der;
            }
            master = cei.getEvent();
        }
        /* Fetch the instance so we can delete it */
        final BwRecurrenceInstance inst = dao.getInstance(master, ev.getRecurrenceId());
        if (inst == null) {
            stat(StatsEvent.deleteTime, startTime);
            return der;
        }
        notifyDelete(true, ev, shared);
        dao.delete(inst);
        if (!ann.unsaved()) {
            // der.alarmsDeleted = deleteAlarms(ann);
            ann.getAttendees().clear();
            dao.delete(ann);
        }
        final BwDateTime instDate = inst.getDtstart();
        if (!master.getRdates().remove(instDate)) {
            // Wasn't an rdate event
            master.addExdate(instDate);
        }
        master.updateLastmod();
        dao.update(master);
        der.eventDeleted = true;
        stat(StatsEvent.deleteTime, startTime);
        indexEntity(ei.getRetrievedEvent());
        return der;
    }
    // Single non recurring event.
    BwEvent deletee = ev;
    if (ev instanceof BwEventProxy) {
        // Deleting an annotation
        deletee = ((BwEventProxy) ev).getRef();
    }
    // I think we need something like this -- fixReferringAnnotations(deletee);
    // XXX This could be wrong.
    /* If this is a proxy we should only delete alarmas attached to the
     * proxy - any attached to the underlying event should be left alone.
     */
    // der.alarmsDeleted = deleteAlarms(deletee);
    // sess.delete(sess.merge(deletee));
    notifyDelete(reallyDelete, ev, shared);
    if (reallyDelete) {
        clearCollection(ev.getAttendees());
        dao.delete(deletee);
    } else {
        tombstoneEvent(deletee);
    }
    der.eventDeleted = true;
    stat(StatsEvent.deleteTime, startTime);
    unindexEntity(ei);
    return der;
}
Also used : BwDateTime(org.bedework.calfacade.BwDateTime) CoreEventInfo(org.bedework.calcorei.CoreEventInfo) BwEvent(org.bedework.calfacade.BwEvent) BwCalendar(org.bedework.calfacade.BwCalendar) BwEventProxy(org.bedework.calfacade.BwEventProxy) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) BwRecurrenceInstance(org.bedework.calfacade.BwRecurrenceInstance) BwEventAnnotation(org.bedework.calfacade.BwEventAnnotation) CalendarWrapper(org.bedework.calfacade.wrappers.CalendarWrapper)

Example 49 with BwCalendar

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

the class CoreEvents method getSynchEvents.

@Override
public Set<CoreEventInfo> getSynchEvents(final String path, final String token) throws CalFacadeException {
    if (path == null) {
        dao.rollback();
        throw new CalFacadeBadRequest("Missing path");
    }
    final String fpath = fixPath(path);
    final BwCalendar col = getCollection(fpath);
    ac.checkAccess(col, privAny, false);
    @SuppressWarnings("unchecked") final List<BwEvent> evs = dao.getSynchEventObjects(fpath, token);
    if (debug) {
        trace(" ----------- number evs = " + evs.size());
    }
    final Set<CoreEventInfo> res = new TreeSet<>();
    for (final BwEvent ev : evs) {
        final CurrentAccess ca = new CurrentAccess(true);
        res.add(new CoreEventInfo(ev, ca));
    }
    return res;
}
Also used : CalFacadeBadRequest(org.bedework.calfacade.exc.CalFacadeBadRequest) CoreEventInfo(org.bedework.calcorei.CoreEventInfo) TreeSet(java.util.TreeSet) BwEvent(org.bedework.calfacade.BwEvent) CurrentAccess(org.bedework.access.Acl.CurrentAccess) BwCalendar(org.bedework.calfacade.BwCalendar)

Example 50 with BwCalendar

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

Aggregations

BwCalendar (org.bedework.calfacade.BwCalendar)134 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)46 EventInfo (org.bedework.calfacade.svc.EventInfo)23 BwEvent (org.bedework.calfacade.BwEvent)19 ArrayList (java.util.ArrayList)18 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)18 BwPrincipal (org.bedework.calfacade.BwPrincipal)15 TreeSet (java.util.TreeSet)10 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)10 BwCategory (org.bedework.calfacade.BwCategory)10 BwResource (org.bedework.calfacade.BwResource)10 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)9 FilterBase (org.bedework.caldav.util.filter.FilterBase)8 BwPreferences (org.bedework.calfacade.svc.BwPreferences)8 BwEventProxy (org.bedework.calfacade.BwEventProxy)7 CalendarWrapper (org.bedework.calfacade.wrappers.CalendarWrapper)7 CurrentAccess (org.bedework.access.Acl.CurrentAccess)6 CalendarsI (org.bedework.calsvci.CalendarsI)6 Acl (org.bedework.access.Acl)5 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)5