Search in sources :

Example 31 with BwCategory

use of org.bedework.calfacade.BwCategory 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 32 with BwCategory

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

Example 33 with BwCategory

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

the class Restorer method restoreCategories.

protected void restoreCategories() throws CalFacadeException {
    try {
        final Path p = openDir(Defs.categoriesDirName);
        if (p == null) {
            return;
        }
        final DirRestore<BwCategory> dirRestore = new DirRestore<>(p, restoreCat);
        final EnumSet<FileVisitOption> opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
        Files.walkFileTree(p, opts, Integer.MAX_VALUE, dirRestore);
    } catch (final IOException ie) {
        throw new CalFacadeException(ie);
    } finally {
        popPath();
    }
}
Also used : Path(java.nio.file.Path) FileVisitOption(java.nio.file.FileVisitOption) BwCategory(org.bedework.calfacade.BwCategory) IOException(java.io.IOException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 34 with BwCategory

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

the class AuthUserFieldRule method field.

/* (non-Javadoc)
   * @see org.bedework.dumprestore.restore.rules.EntityFieldRule#field(java.lang.String)
   */
@Override
public void field(final String name) throws Throwable {
    BwEventProperty ep = null;
    BwCalendar cal = null;
    try {
        if (top() instanceof BwEventProperty) {
            ep = (BwEventProperty) pop();
        } else if (top() instanceof BwCalendar) {
            cal = (BwCalendar) pop();
        }
        BwAuthUser au = (BwAuthUser) top();
        if (name.equals("id") || name.equals("seq")) {
            return;
        }
        if (name.equals("userHref")) {
            au.setUserHref(Util.buildPath(false, stringFld()));
        // } else if (name.equals("account")) {   old?
        // au.setUserHref(globals.rintf.getUser(stringFld()).getPrincipalRef());
        // } else if (name.equals("user")) {
        // // done above
        } else if (name.equals("usertype")) {
            int type = intFld();
            au.setUsertype(type);
        /* Prefs stuff next */
        } else if (name.equals("autoAdd")) {
            if (inCategoryPrefs) {
                getCategoryPrefs(au).setAutoAdd(booleanFld());
            } else if (inCollectionsPrefs) {
                getCalendarPrefs(au).setAutoAdd(booleanFld());
            } else if (inContactPrefs) {
                getContactPrefs(au).setAutoAdd(booleanFld());
            } else if (inLocationPrefs) {
                getLocationPrefs(au).setAutoAdd(booleanFld());
            } else {
                error("Not in any prefs for autoAdd");
            }
        } else if (name.equals("category")) {
            au.getPrefs().getCategoryPrefs().add((BwCategory) ep);
        } else if (name.equals("collection")) {
            au.getPrefs().getCalendarPrefs().add(cal);
        } else if (name.equals("contact")) {
            au.getPrefs().getContactPrefs().add((BwContact) ep);
        } else if (name.equals("location")) {
            au.getPrefs().getLocationPrefs().add((BwLocation) ep);
        } else if (name.equals("categoryPrefs")) {
            inCategoryPrefs = false;
        } else if (name.equals("calendarPrefs")) {
            inCollectionsPrefs = false;
        } else if (name.equals("contactPrefs")) {
            inContactPrefs = false;
        } else if (name.equals("locationPrefs")) {
            inLocationPrefs = false;
        } else if (name.equals("prefs")) {
        } else if (name.equals("byteSize")) {
        } else {
            unknownTag(name);
        }
    } catch (Throwable t) {
        handleException(t);
    }
}
Also used : BwAuthUser(org.bedework.calfacade.svc.BwAuthUser) BwCategory(org.bedework.calfacade.BwCategory) BwEventProperty(org.bedework.calfacade.BwEventProperty) BwCalendar(org.bedework.calfacade.BwCalendar) BwContact(org.bedework.calfacade.BwContact)

Example 35 with BwCategory

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

the class CategoryFieldRule method field.

public void field(String name) throws Exception {
    BwString s = null;
    if (top() instanceof BwString) {
        s = (BwString) pop();
    }
    BwCategory cat = (BwCategory) top();
    if (shareableEntityTags(cat, name)) {
        return;
    }
    if (name.equals("word")) {
        cat.setWord(s);
    } else if (name.equals("description")) {
        cat.setDescription(s);
    } else if (name.equals("uid")) {
        cat.setUid(stringFld());
    } else if (name.equals("byteSize")) {
        cat.setByteSize(intFld());
    } else {
        unknownTag(name);
    }
}
Also used : BwCategory(org.bedework.calfacade.BwCategory) BwString(org.bedework.calfacade.BwString)

Aggregations

BwCategory (org.bedework.calfacade.BwCategory)42 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)13 BwContact (org.bedework.calfacade.BwContact)11 BwString (org.bedework.calfacade.BwString)11 BwCalendar (org.bedework.calfacade.BwCalendar)10 BwEvent (org.bedework.calfacade.BwEvent)10 BwLocation (org.bedework.calfacade.BwLocation)8 BwXproperty (org.bedework.calfacade.BwXproperty)7 ArrayList (java.util.ArrayList)6 EventInfo (org.bedework.calfacade.svc.EventInfo)6 BwDateTime (org.bedework.calfacade.BwDateTime)5 TreeSet (java.util.TreeSet)4 BwAttendee (org.bedework.calfacade.BwAttendee)4 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)4 PropertyInfoIndex (org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex)4 Period (net.fortuna.ical4j.model.Period)3 BwEventProxy (org.bedework.calfacade.BwEventProxy)3 BwIcalPropertyInfoEntry (org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry)3 FilterBase (org.bedework.caldav.util.filter.FilterBase)2 ObjectFilter (org.bedework.caldav.util.filter.ObjectFilter)2