Search in sources :

Example 31 with BwPrincipal

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

use of org.bedework.calfacade.BwPrincipal 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 33 with BwPrincipal

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

the class PrincipalsAndPrefsDAO method getPrincipal.

public BwPrincipal getPrincipal(final String href) throws CalFacadeException {
    final HibSession sess = getSess();
    if (href == null) {
        return null;
    }
    if (sess == null) {
        warn("Null sesssion");
        throw new NullPointerException("No session");
    }
    sess.createQuery(getPrincipalQuery);
    sess.setString("href", href);
    return (BwPrincipal) sess.getUnique();
}
Also used : HibSession(org.bedework.calcorei.HibSession) BwPrincipal(org.bedework.calfacade.BwPrincipal)

Example 34 with BwPrincipal

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

the class PrincipalsAndPrefsDAO method getMembers.

@SuppressWarnings("unchecked")
public Collection<BwPrincipal> getMembers(final BwGroup group, final boolean admin) throws CalFacadeException {
    final HibSession sess = getSess();
    if (admin) {
        sess.createQuery(getAdminGroupUserMembersQuery);
    } else {
        sess.createQuery(getGroupUserMembersQuery);
    }
    sess.setEntity("gr", group);
    final Collection<BwPrincipal> ms = new TreeSet<>();
    ms.addAll(sess.getList());
    if (admin) {
        sess.createQuery(getAdminGroupGroupMembersQuery);
    } else {
        sess.createQuery(getGroupGroupMembersQuery);
    }
    sess.setEntity("gr", group);
    ms.addAll(sess.getList());
    return ms;
}
Also used : HibSession(org.bedework.calcorei.HibSession) BwPrincipal(org.bedework.calfacade.BwPrincipal) TreeSet(java.util.TreeSet)

Example 35 with BwPrincipal

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

the class RestorePrincipal method doRestore.

/**
 * Restore everything owned by this principal
 *
 * @throws CalFacadeException on error
 */
public boolean doRestore() throws CalFacadeException {
    try {
        final String prPath = topPath();
        final File pdir = Utils.directory(prPath);
        if (pdir == null) {
            addInfo("No user data found at " + prPath);
            return false;
        }
        final XmlFile prXml = new XmlFile(pdir, "principal.xml", false);
        final XmlFile prefsXml = new XmlFile(pdir, "preferences.xml", false);
        final BwPrincipal pr = fxml.fromXml(prXml.getRoot(), BwUser.class, BwPrincipal.getRestoreCallback());
        final BwPreferences prefs = fxml.fromXml(prefsXml.getRoot(), BwPreferences.class, BwPreferences.getRestoreCallback());
        incCount(Counters.users);
        incCount(Counters.userPrefs);
        if (getGlobals().getDryRun()) {
            info(pr.toString());
            info(prefs.toString());
        } else {
            getRi().restorePrincipal(pr);
            getRi().restoreUserPrefs(prefs);
        }
        restoreCategories();
        restoreContacts();
        restoreLocations();
        restoreCollections();
    } catch (final CalFacadeException ce) {
        throw ce;
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
    return true;
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) BwPreferences(org.bedework.calfacade.svc.BwPreferences) XmlFile(org.bedework.dumprestore.restore.XmlFile) File(java.io.File) XmlFile(org.bedework.dumprestore.restore.XmlFile) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

BwPrincipal (org.bedework.calfacade.BwPrincipal)59 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)22 BwCalendar (org.bedework.calfacade.BwCalendar)16 BwAdminGroup (org.bedework.calfacade.svc.BwAdminGroup)10 EventInfo (org.bedework.calfacade.svc.EventInfo)9 BwEvent (org.bedework.calfacade.BwEvent)7 ArrayList (java.util.ArrayList)6 BwPreferences (org.bedework.calfacade.svc.BwPreferences)6 Acl (org.bedework.access.Acl)5 BwGroup (org.bedework.calfacade.BwGroup)4 Component (net.fortuna.ical4j.model.Component)3 AccessException (org.bedework.access.AccessException)3 Ace (org.bedework.access.Ace)3 Privilege (org.bedework.access.Privilege)3 BwOrganizer (org.bedework.calfacade.BwOrganizer)3 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)3 File (java.io.File)2 Collection (java.util.Collection)2 NamingEnumeration (javax.naming.NamingEnumeration)2 Attribute (javax.naming.directory.Attribute)2