Search in sources :

Example 1 with BwCalendar

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

the class BwObjectFilter method match.

/* ====================================================================
   *                   matching methods
   * ==================================================================== */
@Override
public boolean match(final Object o, final String userHref) throws WebdavException {
    ObjectFilter of = getEntity();
    Object ent = of.getEntity();
    boolean not = of.getNot();
    String val = null;
    Integer ival = null;
    if (ent instanceof BwCalendar) {
        val = ((BwCalendar) ent).getPath();
    } else if (ent instanceof String) {
        val = (String) ent;
    } else if (ent instanceof Integer) {
        ival = (Integer) ent;
    } else {
        throw new WebdavException("Unmatchable filter");
    }
    BwEvent ev = null;
    if (o instanceof BwEvent) {
        ev = (BwEvent) o;
    }
    if (of instanceof EntityTypeFilter) {
        if (ev == null) {
            return false;
        }
        if (not) {
            return ev.getEntityType() != ival;
        }
        return ev.getEntityType() == ival;
    }
    PropertyInfoIndex pii = of.getPropertyIndex();
    BwIcalPropertyInfoEntry pi = BwIcalPropertyInfo.getPinfo(pii);
    if (pi.getParam()) {
        pii = of.getParentPropertyIndex();
    }
    switch(pii) {
        case CLASS:
            if (ev.getClassification() == null) {
                return false;
            }
            return stringMatch(ev.getClassification(), val);
        case CREATED:
            return stringMatch(ev.getCreated(), val);
        case DESCRIPTION:
            for (BwLongString ls : ev.getDescriptions()) {
                if (stringMatch(ls.getValue(), val)) {
                    return true;
                }
            }
            return false;
        case DTSTAMP:
            return stringMatch(ev.getDtstamp(), val);
        case DTEND:
        /* Event only */
        case DUE:
            /* Todo only */
            return matchDateTime(pi, ev.getDtend(), val);
        case DTSTART:
            return matchDateTime(pi, ev.getDtstart(), val);
        case DURATION:
            return stringMatch(ev.getDuration(), val);
        case GEO:
            if (ev.getGeo() == null) {
                return false;
            }
            return stringMatch(ev.getGeo().toString(), val);
        case LAST_MODIFIED:
            return stringMatch(ev.getLastmod(), val);
        case LOCATION:
            if (ev.getLocation() == null) {
                return false;
            }
            return stringMatch(ev.getLocation().getAddress().getValue(), val);
        case ORGANIZER:
            if (ev.getOrganizer() == null) {
                return false;
            }
            return stringMatch(ev.getOrganizer().getOrganizerUri(), val);
        case PRIORITY:
            if (ev.getPriority() == null) {
                return false;
            }
            return stringMatch(String.valueOf(ev.getPriority()), val);
        case RECURRENCE_ID:
            if (ev.getRecurrenceId() == null) {
                return false;
            }
            return stringMatch(ev.getRecurrenceId(), val);
        case SEQUENCE:
            return stringMatch(String.valueOf(ev.getSequence()), val);
        case STATUS:
            if (ev.getStatus() == null) {
                return false;
            }
            return stringMatch(ev.getStatus(), val);
        case SUMMARY:
            for (BwString s : ev.getSummaries()) {
                if (stringMatch(s.getValue(), val)) {
                    return true;
                }
            }
            return false;
        case UID:
            return stringMatch(ev.getUid(), val);
        case URL:
            if (ev.getLink() == null) {
                return false;
            }
            return stringMatch(ev.getLink(), val);
        case TRANSP:
            try {
                if (ev.getPeruserTransparency(userHref) == null) {
                    return false;
                }
                return stringMatch(ev.getPeruserTransparency(userHref), val);
            } catch (Throwable t) {
                throw new WebdavException(t);
            }
        case COMPLETED:
            if (ev.getCompleted() == null) {
                return false;
            }
            return stringMatch(ev.getCompleted(), val);
        case PERCENT_COMPLETE:
            if (ev.getPercentComplete() == null) {
                return false;
            }
            return stringMatch(String.valueOf(ev.getPercentComplete()), val);
        case ATTACH:
            break;
        case ATTENDEE:
            break;
        case CATEGORIES:
            for (BwCategory cat : ev.getCategories()) {
                if (stringMatch(cat.getWordVal(), val)) {
                    return true;
                }
            }
            return false;
        case COMMENT:
            for (BwString s : ev.getComments()) {
                if (stringMatch(s.getValue(), val)) {
                    return true;
                }
            }
            return false;
        case CONTACT:
            for (BwContact c : ev.getContacts()) {
                if (stringMatch(c.getCn().getValue(), val)) {
                    return true;
                }
            }
            return false;
        case EXDATE:
            for (BwDateTime dt : ev.getExdates()) {
                if (stringMatch(dt.getDtval(), val)) {
                    return true;
                }
            }
            return false;
        case EXRULE:
            for (String s : ev.getExrules()) {
                if (stringMatch(s, val)) {
                    return true;
                }
            }
            return false;
        case REQUEST_STATUS:
            for (BwRequestStatus rs : ev.getRequestStatuses()) {
                if (stringMatch(rs.getCode(), val)) {
                    return true;
                }
            }
            return false;
        case RELATED_TO:
            if (ev.getRelatedTo() == null) {
                return false;
            }
            return stringMatch(ev.getRelatedTo().getValue(), val);
        case RESOURCES:
            for (BwString s : ev.getResources()) {
                if (stringMatch(s.getValue(), val)) {
                    return true;
                }
            }
            return false;
        case RDATE:
            for (BwDateTime dt : ev.getRdates()) {
                if (stringMatch(dt.getDtval(), val)) {
                    return true;
                }
            }
            return false;
        case RRULE:
            for (String s : ev.getRrules()) {
                if (stringMatch(s, val)) {
                    return true;
                }
            }
            return false;
        case FREEBUSY:
            break;
        case TZID:
            break;
        case TZNAME:
            break;
        case TZOFFSETFROM:
            break;
        case TZOFFSETTO:
            break;
        case TZURL:
            break;
        case ACTION:
            break;
        case REPEAT:
            break;
        case TRIGGER:
            break;
        case COLLECTION:
            return stringMatch(ev.getColPath(), val);
        case CREATOR:
            return stringMatch(ev.getCreatorHref(), val);
        case OWNER:
            return stringMatch(ev.getOwnerHref(), val);
        case ENTITY_TYPE:
            break;
    }
    return false;
}
Also used : BwDateTime(org.bedework.calfacade.BwDateTime) BwRequestStatus(org.bedework.calfacade.BwRequestStatus) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwCategory(org.bedework.calfacade.BwCategory) BwEvent(org.bedework.calfacade.BwEvent) ObjectFilter(org.bedework.caldav.util.filter.ObjectFilter) BwString(org.bedework.calfacade.BwString) BwLongString(org.bedework.calfacade.BwLongString) BwCalendar(org.bedework.calfacade.BwCalendar) BwString(org.bedework.calfacade.BwString) BwContact(org.bedework.calfacade.BwContact) EntityTypeFilter(org.bedework.caldav.util.filter.EntityTypeFilter) BwLongString(org.bedework.calfacade.BwLongString) PropertyInfoIndex(org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex) BwIcalPropertyInfoEntry(org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry)

Example 2 with BwCalendar

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

the class FilterBuilder method buildFilter.

/**
 * Build a filter from the given path. The applyFilter flag only
 * applies to the root of the tree. The filter may already have been
 * processed by the caller.
 *
 * @param path
 * @param applyFilter applies only to root of tree
 * @return FilterBase or null
 */
public FilterBase buildFilter(final String path, final boolean applyFilter, final boolean explicitSelection) {
    if (path == null) {
        return BooleanFilter.falseFilter;
    }
    BwCalendar col = colCache.get(path);
    if (col == null) {
        try {
            col = parser.getCollection(path);
        } catch (CalFacadeException cfe) {
            error(cfe);
            return BooleanFilter.falseFilter;
        }
        colCache.put(path, col);
    }
    final ArrayList<String> pathElements = new ArrayList<>();
    pathElements.add(path);
    final CalFilter calFilter;
    try {
        calFilter = makeColFilter(col, applyFilter, explicitSelection, pathElements);
    } catch (CalFacadeException cfe) {
        error(cfe);
        return BooleanFilter.falseFilter;
    }
    if (calFilter == null) {
        // No valid matches
        return BooleanFilter.falseFilter;
    }
    /* if we have any OrCalFilters it's because they refer to different
     * calendar collections.
     *
     * Re-express this as BwFilters
     */
    final FilterBase f = makeBwFilter(calFilter);
    if (debug) {
        debug(" ---------  FilterBuilder result ---------------");
        dump(f, "");
        debug(" ---------  end of FilterBuilder result ---------------");
    }
    return f;
}
Also used : ArrayList(java.util.ArrayList) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) FilterBase(org.bedework.caldav.util.filter.FilterBase)

Example 3 with BwCalendar

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

the class FilterBuilder method dump.

private void dump(final FilterBase f, final String curLine) {
    if (f instanceof OrFilter) {
        debug(curLine + "  OR ");
        Iterator<FilterBase> it = f.getChildren().iterator();
        dumpChildren(it, curLine);
        return;
    }
    if (f instanceof AndFilter) {
        debug(curLine + "  AND ");
        Iterator<FilterBase> it = f.getChildren().iterator();
        dumpChildren(it, curLine);
        return;
    }
    if (f instanceof ObjectFilter) {
        ObjectFilter of = (ObjectFilter) f;
        if (of.getEntity() instanceof BwCalendar) {
            final StringBuilder sb = new StringBuilder(curLine);
            sb.append(curLine);
            sb.append("  cal=");
            sb.append(((BwCalendar) of.getEntity()).getPath());
            debug(sb.toString());
        } else {
            debug(curLine + f.toString());
        }
    } else {
        debug(curLine + f.toString());
    }
}
Also used : AndFilter(org.bedework.caldav.util.filter.AndFilter) OrFilter(org.bedework.caldav.util.filter.OrFilter) ObjectFilter(org.bedework.caldav.util.filter.ObjectFilter) BwCalendar(org.bedework.calfacade.BwCalendar) FilterBase(org.bedework.caldav.util.filter.FilterBase)

Example 4 with BwCalendar

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

the class FilterBuilder method makeFolderFilter.

private CalFilter makeFolderFilter(final BwCalendar val, final ArrayList<String> pathElements) throws CalFacadeException {
    Collection<BwCalendar> cols = parser.getChildren(val);
    OrCalFilter res = new OrCalFilter();
    for (BwCalendar col : cols) {
        if (colCache.get(col.getPath()) == null) {
            colCache.put(col.getPath(), col);
        }
        if (!col.getDisplay()) {
            continue;
        }
        ArrayList<String> pe;
        if (pathElements == null) {
            pe = new ArrayList<>();
        } else {
            pe = new ArrayList<>(pathElements);
        }
        String path = col.getPath();
        if (pe.contains(path)) {
            throw new CalFacadeSubscriptionLoopException();
        }
        pe.add(path);
        CalFilter cf = makeColFilter(col, true, false, pe);
        if (cf == null) {
            continue;
        }
        mergeFilter(res.terms, cf, false);
    }
    if (res.terms.size() == 0) {
        return null;
    }
    if (res.terms.size() == 1) {
        /* Only one filter resulted. Return that rather than the or-filter */
        return res.terms.iterator().next();
    }
    return res;
}
Also used : CalFacadeSubscriptionLoopException(org.bedework.calfacade.exc.CalFacadeSubscriptionLoopException) BwCalendar(org.bedework.calfacade.BwCalendar)

Example 5 with BwCalendar

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

the class SimpleFilterParser method resolveVpath.

/**
 * A virtual path is the apparent path for a user looking at an explorer
 * view of collections.
 *
 * <p>We might have,
 * <pre>
 *    home-->Arts-->Theatre
 * </pre>
 *
 * <p>In reality the Arts collection might be an alias to another alias which
 * is an alias to a collection containing aliases including "Theatre".
 *
 * <p>So the real picture might be something like...
 * <pre>
 *    home-->Arts             (categories="ChemEng")
 *            |
 *            V
 *           Arts             (categories="Approved")
 *            |
 *            V
 *           Arts-->Theatre   (categories="Arts" AND categories="Theatre")
 *                     |
 *                     V
 *                    MainCal
 * </pre>
 * where the vertical links are aliasing. The importance of this is that
 * each alias might introduce another filtering term, the intent of which is
 * to restrict the retrieval to a specific subset. The parenthesized terms
 * represent example filters.
 *
 * <p>The desired filter is the ANDing of all the above.
 *
 * @param  vpath  a String virtual path
 * @return FilterBase object or null for bad path
 * @throws ParseFailed on error
 */
private FilterBase resolveVpath(final String vpath) throws ParseFailed {
    /* We decompose the virtual path into it's elements and then try to
     * build a sequence of collections that include the aliases and their
     * targets until we reach the last element in the path.
     *
     * We'll assume the path is already normalized and that no "/" are allowed
     * as parts of names.
     *
     * What we're doing here is resolving aliases to aliases and accumulating
     * any filtering that might be in place as a sequence of ANDed terms. For
     * example:
     *
     * /user/eng/Lectures has the filter cat=eng and is aliased to
     * /public/aliases/Lectures which has the filter cat=lectures and is aliased to
     * /public/cals/MainCal
     *
     * We want the filter (cat=eng) & (cat=Lectures) on MainCal.
     *
     * Below, we decompose the virtual path and we save the path to an actual
     * folder or calendar collection.
     */
    final Collection<BwCalendar> cols = callDecomposeVirtualPath(vpath);
    if (cols == null) {
        throw parseResult.fail("Bad virtual path: " + vpath);
    }
    FilterBase vfilter = null;
    BwCalendar vpathTarget = null;
    for (final BwCalendar col : cols) {
        if (debug) {
            debug("      vpath collection:" + col.getPath());
        }
        if (col.getFilterExpr() != null) {
            if (subParser == null) {
                subParser = callGetParser();
            }
            final ParseResult pr = subParser.parse(col.getFilterExpr(), false, col.getPath());
            if (!pr.ok) {
                throw parseResult.fromPr(pr);
            }
            if (pr.filter != null) {
                vfilter = and(null, vfilter, pr.filter);
            }
        }
        if (col.getCollectionInfo().onlyCalEntities || (col.getCalType() == BwCalendar.calTypeFolder)) {
            // reached an end point
            vpathTarget = col;
        }
    }
    if (vpathTarget == null) {
        throw parseResult.fail("Bad vpath - no calendar collection" + " vpath: " + vpath + " source: " + source);
    }
    final String name;
    if (vpathTarget.getAliasOrigin() != null) {
        name = vpathTarget.getAliasOrigin().getPath();
    } else {
        name = vpathTarget.getPath();
    }
    return and(name, vfilter, resolveColPath(vpathTarget.getPath(), false, false));
}
Also used : BwCalendar(org.bedework.calfacade.BwCalendar) ToString(org.bedework.util.misc.ToString) FilterBase(org.bedework.caldav.util.filter.FilterBase)

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