Search in sources :

Example 86 with BwCalendar

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

the class BwCalDAVCollection method getCalType.

@Override
public int getCalType() throws WebdavException {
    final int calType;
    BwCalendar c = getCol();
    if (isAlias()) {
        c = intf.resolveAlias(col, true);
    }
    if (c == null) {
        return CalDAVCollection.calTypeUnknown;
    }
    calType = c.getCalType();
    if (calType == BwCalendar.calTypeFolder) {
        // Broken alias
        return CalDAVCollection.calTypeCollection;
    }
    if ((calType == BwCalendar.calTypeCalendarCollection) || (calType == BwCalendar.calTypeEventList) || (calType == BwCalendar.calTypeExtSub)) {
        // Broken alias
        return CalDAVCollection.calTypeCalendarCollection;
    }
    if (calType == BwCalendar.calTypeInbox) {
        // Broken alias
        return CalDAVCollection.calTypeInbox;
    }
    if (calType == BwCalendar.calTypeOutbox) {
        // Broken alias
        return CalDAVCollection.calTypeOutbox;
    }
    if (calType == BwCalendar.calTypeNotifications) {
        return CalDAVCollection.calTypeNotifications;
    }
    if (calType == BwCalendar.calTypePoll) {
        return CalDAVCollection.calTypeCalendarCollection;
    }
    return CalDAVCollection.calTypeUnknown;
}
Also used : BwCalendar(org.bedework.calfacade.BwCalendar)

Example 87 with BwCalendar

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

the class ESQueryFilter method getValue.

private Object getValue(final ObjectFilter of) throws CalFacadeException {
    Object o = of.getEntity();
    Collection c = null;
    boolean isString = o instanceof String;
    if (!isString) {
        if (o instanceof Collection) {
            c = (Collection) o;
            if (c.size() > 0) {
                o = c.iterator().next();
                isString = o instanceof String;
            }
        }
    }
    boolean doCaseless = isString && of.getCaseless();
    if (c != null) {
        // TODO - Assuming String collection
        List res = new ArrayList();
        for (Object co : c) {
            String s = (String) co;
            if (doCaseless) {
                s = s.toLowerCase();
            }
            res.add(s);
        }
        return res;
    }
    if (o instanceof BwCalendar) {
        BwCalendar cal = (BwCalendar) o;
        return cal.getPath();
    }
    if (o instanceof BwPrincipal) {
        return ((BwPrincipal) o).getPrincipalRef();
    }
    if (o instanceof BwDbentity) {
        warn("Got db entity in search " + o);
        return "";
    }
    if (of.getExact()) {
        if (doCaseless) {
            o = ((String) o).toLowerCase();
        }
        return o;
    }
    if (of.getEntity() instanceof String) {
        String s = o.toString();
        if (doCaseless) {
            s = s.toLowerCase();
        }
        // warn("Fuzzy search for " + of);
        return s;
    // sess.setString(parPrefix + qi, "%" + s + "%");
    }
    // sess.setString(parPrefix + qi, "%" + o + "%");
    warn("Fuzzy search for " + of);
    return "";
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) ArrayList(java.util.ArrayList) Collection(java.util.Collection) BwDbentity(org.bedework.calfacade.base.BwDbentity) List(java.util.List) ArrayList(java.util.ArrayList) BwCalendar(org.bedework.calfacade.BwCalendar)

Example 88 with BwCalendar

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

the class Filters method doObject.

private void doObject(final ObjectFilter of, final String master, final String fld, final String subfld, final boolean multi) {
    String dbfld;
    qseg.append('(');
    Object o = of.getEntity();
    Collection c = null;
    boolean doCaseless = false;
    if (o instanceof BwCalendar) {
        if (!of.getNot()) {
            queryLimited = true;
        }
    } else {
        boolean isString = o instanceof String;
        if (!isString) {
            if (o instanceof Collection) {
                c = (Collection) o;
                if (c.size() > 0) {
                    o = c.iterator().next();
                    isString = o instanceof String;
                }
            }
        }
        doCaseless = isString && of.getCaseless();
    }
    if (multi) {
        qseg.append("(select count(*) from ");
        qseg.append(master);
        qseg.append(".");
        qseg.append(fld);
        dbfld = fld + "_x";
        qseg.append(" ");
        qseg.append(dbfld);
        qseg.append(" where ");
    } else {
        dbfld = master + "." + fld;
    }
    if (doCaseless) {
        qseg.append("lower(");
    }
    qseg.append(dbfld);
    if (subfld != null) {
        qseg.append(".");
        qseg.append(subfld);
    }
    if (doCaseless) {
        qseg.append(")");
    }
    if (!of.getExact()) {
        if (of.getNot()) {
            qseg.append(" not");
        }
        qseg.append(" like :");
        parTerm();
    } else if (c != null) {
        if (of.getNot()) {
            qseg.append(" not in (");
        } else {
            qseg.append(" in (");
        }
        for (int i = 0; i < c.size(); i++) {
            if (i > 0) {
                qseg.append(", ");
            }
            qseg.append(":");
            parTerm();
        }
        qseg.append(")");
    } else if (of.getNot()) {
        qseg.append("<>:");
        parTerm();
    } else {
        qseg.append("=:");
        parTerm();
    }
    if (multi) {
        qseg.append(") > 0");
    }
    qseg.append(")");
}
Also used : Collection(java.util.Collection) BwCalendar(org.bedework.calfacade.BwCalendar)

Example 89 with BwCalendar

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

the class Filters method parReplace.

/* Fill in the parameters after we generated the query.
   */
private void parReplace(final FilterBase f) throws CalFacadeException {
    if (f instanceof AndFilter) {
        AndFilter fb = (AndFilter) f;
        for (FilterBase flt : fb.getChildren()) {
            parReplace(flt);
        }
        return;
    }
    if (f instanceof BwHrefFilter) {
        BwHrefFilter hf = (BwHrefFilter) f;
        // Special case this
        sess.setString(parPrefix + qi, hf.getPathPart());
        qi++;
        sess.setString(parPrefix + qi, hf.getNamePart());
        qi++;
    }
    if (f instanceof BwCategoryFilter) {
        BwCategoryFilter cf = (BwCategoryFilter) f;
        BwCategory cat = cf.getEntity();
        /* XXX - this is what we want to be able to do
      sess.setString(parPrefix + qi, cat.getUid());
      */
        sess.setEntity(parPrefix + qi, cat);
        qi++;
        return;
    }
    if (f instanceof EntityTimeRangeFilter) {
        doEntityTimeRangeReplace((EntityTimeRangeFilter) f);
        return;
    }
    if (f instanceof TimeRangeFilter) {
        TimeRangeFilter trf = (TimeRangeFilter) f;
        TimeRange tr = trf.getEntity();
        if (tr.getStart() != null) {
            sess.setParameter(parPrefix + qi, tr.getStart().toString());
            qi++;
        }
        if (tr.getEnd() != null) {
            sess.setParameter(parPrefix + qi, tr.getEnd().toString());
            qi++;
        }
        return;
    }
    if (f instanceof BwObjectFilter) {
        ObjectFilter of = ((BwObjectFilter) f).getEntity();
        Object o = of.getEntity();
        Collection c = null;
        boolean isString = o instanceof String;
        if (!isString) {
            if (o instanceof Collection) {
                c = (Collection) o;
                if (c.size() > 0) {
                    o = c.iterator().next();
                    isString = o instanceof String;
                }
            }
        }
        boolean doCaseless = isString && of.getCaseless();
        if (c != null) {
            // TODO - Assuming String collection
            for (Object co : c) {
                String s = (String) co;
                if (doCaseless) {
                    s = s.toLowerCase();
                }
                sess.setParameter(parPrefix + qi, s);
                qi++;
            }
            return;
        }
        if (o instanceof BwCalendar) {
            BwCalendar cal = unwrap((BwCalendar) o);
            sess.setString(parPrefix + qi, cal.getPath());
        } else if (o instanceof BwPrincipal) {
            sess.setString(parPrefix + qi, ((BwPrincipal) o).getPrincipalRef());
        } else if (o instanceof BwDbentity) {
            sess.setEntity(parPrefix + qi, o);
        } else if (of.getExact()) {
            if (doCaseless) {
                o = ((String) o).toLowerCase();
            }
            sess.setParameter(parPrefix + qi, o);
        } else if (of.getEntity() instanceof String) {
            String s = o.toString();
            if (doCaseless) {
                s = s.toLowerCase();
            }
            sess.setString(parPrefix + qi, "%" + s + "%");
        } else {
            sess.setString(parPrefix + qi, "%" + o + "%");
        }
        qi++;
        return;
    }
    if (f instanceof OrFilter) {
        OrFilter fb = (OrFilter) f;
        for (FilterBase flt : fb.getChildren()) {
            parReplace(flt);
        }
        return;
    }
}
Also used : BwHrefFilter(org.bedework.calfacade.filter.BwHrefFilter) EntityTimeRangeFilter(org.bedework.caldav.util.filter.EntityTimeRangeFilter) TimeRangeFilter(org.bedework.caldav.util.filter.TimeRangeFilter) BwCategory(org.bedework.calfacade.BwCategory) BwCategoryFilter(org.bedework.calfacade.filter.BwCategoryFilter) BwObjectFilter(org.bedework.calfacade.filter.BwObjectFilter) ObjectFilter(org.bedework.caldav.util.filter.ObjectFilter) BwCalendar(org.bedework.calfacade.BwCalendar) OrFilter(org.bedework.caldav.util.filter.OrFilter) EntityTimeRangeFilter(org.bedework.caldav.util.filter.EntityTimeRangeFilter) AndFilter(org.bedework.caldav.util.filter.AndFilter) TimeRange(org.bedework.caldav.util.TimeRange) BwPrincipal(org.bedework.calfacade.BwPrincipal) Collection(java.util.Collection) BwDbentity(org.bedework.calfacade.base.BwDbentity) FilterBase(org.bedework.caldav.util.filter.FilterBase) BwObjectFilter(org.bedework.calfacade.filter.BwObjectFilter)

Example 90 with BwCalendar

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

the class PrincipalsAndPrefsDAO method removeFromAllPrefs.

public void removeFromAllPrefs(final BwShareableDbentity val) throws CalFacadeException {
    final HibSession sess = getSess();
    final String q;
    if (val instanceof BwCategory) {
        q = getCategoryPrefForAllQuery;
    } else if (val instanceof BwCalendar) {
        q = removeCalendarPrefForAllQuery;
    } else if (val instanceof BwContact) {
        q = removeContactPrefForAllQuery;
    } else if (val instanceof BwLocation) {
        q = removeLocationPrefForAllQuery;
    } else {
        throw new CalFacadeException("Can't handle " + val);
    }
    sess.createQuery(q);
    sess.setInt("id", val.getId());
    sess.executeUpdate();
}
Also used : HibSession(org.bedework.calcorei.HibSession) BwLocation(org.bedework.calfacade.BwLocation) BwCategory(org.bedework.calfacade.BwCategory) BwCalendar(org.bedework.calfacade.BwCalendar) BwContact(org.bedework.calfacade.BwContact) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

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