Search in sources :

Example 1 with CalDAVCollection

use of org.bedework.caldav.server.CalDAVCollection in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method getCollections.

@Override
public Collection<CalDAVCollection> getCollections(final CalDAVCollection col) throws WebdavException {
    try {
        final BwCalendar bwCol = unwrap(col);
        boolean isUserHome = false;
        List<Integer> provisionedTypes = null;
        /* Is this the calendar home? If so we have to ensure all
         provisioned collections exist */
        if (getPrincipal() != null) {
            final String userHomePath = Util.buildPath(true, getSvci().getPrincipalInfo().getCalendarHomePath(getPrincipal()));
            if (Util.buildPath(true, bwCol.getPath()).equals(userHomePath)) {
                isUserHome = true;
                provisionedTypes = new ArrayList<>();
                for (final BwCalendar.CollectionInfo ci : BwCalendar.getAllCollectionInfo()) {
                    if (ci.provision) {
                        provisionedTypes.add(ci.collectionType);
                    }
                }
            }
        }
        final CalendarsI ci = getSvci().getCalendarsHandler();
        final Collection<BwCalendar> bwch = ci.getChildren(bwCol);
        final Collection<CalDAVCollection> ch = new ArrayList<>();
        if (bwch == null) {
            return ch;
        }
        for (final BwCalendar c : bwch) {
            if (bedeworkExtensionsEnabled() || !c.getName().startsWith(".")) {
                ci.resolveAlias(c, true, false);
                ch.add(new BwCalDAVCollection(this, c));
            }
            if (isUserHome && !c.getAlias()) {
                provisionedTypes.remove(new Integer(c.getCalType()));
            }
        }
        if (isUserHome && !provisionedTypes.isEmpty()) {
            // Need to add some
            for (final int colType : provisionedTypes) {
                final BwCalendar pcol = ci.getSpecial(currentPrincipal, colType, true, PrivilegeDefs.privAny);
                ch.add(new BwCalDAVCollection(this, pcol));
            }
        }
        return ch;
    } catch (final CalFacadeAccessException cfae) {
        throw new WebdavForbidden();
    } catch (final Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) ArrayList(java.util.ArrayList) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwCalendar(org.bedework.calfacade.BwCalendar) CalendarsI(org.bedework.calsvci.CalendarsI) CalDAVCollection(org.bedework.caldav.server.CalDAVCollection) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException)

Example 2 with CalDAVCollection

use of org.bedework.caldav.server.CalDAVCollection in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method getPrincipals.

@Override
public Collection<CalPrincipalInfo> getPrincipals(String resourceUri, final PrincipalPropertySearch pps) throws WebdavException {
    List<CalPrincipalInfo> principals = null;
    if (pps.applyToPrincipalCollectionSet) {
        /* I believe it's valid (if unhelpful) to return nothing
       */
        return new ArrayList<>();
    }
    if (!resourceUri.endsWith("/")) {
        resourceUri += "/";
    }
    try {
        String proot = BwPrincipal.principalRoot;
        if (!proot.endsWith("/")) {
            proot += "/";
        }
        if (!resourceUri.equals(proot)) {
            return new ArrayList<>();
        }
    } catch (final Throwable t) {
        throw new WebdavException(t);
    }
    /* If we don't support any of the properties in the searches we don't match.
     *
     * Currently we only support calendarUserAddressSet or calendarHomeSet.
     *
     * For calendarUserAddressSet the value to match must be a valid CUA
     *
     * For calendarHomeSet it must be a valid home uri
     */
    final List<WebdavProperty> props = new ArrayList<>();
    String cutype = null;
    for (final WebdavProperty prop : pps.props) {
        if (debug) {
            debug("Try to match " + prop);
        }
        final String pval = prop.getPval();
        if (CaldavTags.calendarUserAddressSet.equals(prop.getTag())) {
            principals = and(principals, getCalPrincipalInfo(caladdrToPrincipal(pval)));
        } else if (CaldavTags.calendarHomeSet.equals(prop.getTag())) {
            final String path = getUrlHandler().unprefix(pval);
            final CalDAVCollection col = getCollection(path);
            if (col != null) {
                principals = and(principals, getCalPrincipalInfo(col.getOwner()));
            }
        } else if (CaldavTags.calendarUserType.equals(prop.getTag())) {
            cutype = pval;
        } else if (WebdavTags.displayname.equals(prop.getTag())) {
            // Store for directory search
            props.add(prop);
        }
    }
    try {
        if (props.size() != 0) {
            // Directory search
            final Holder<Boolean> truncated = new Holder<>();
            if (principals == null) {
                principals = new ArrayList<>();
            }
            final List<BwPrincipalInfo> pis = getSvci().getDirectories().find(props, pps.pr.props, cutype, truncated);
            if (pis != null) {
                for (final BwPrincipalInfo pi : pis) {
                    principals.add(getCalPrincipalInfo(pi));
                }
            }
        }
    } catch (final Throwable t) {
        throw new WebdavException(t);
    }
    if (principals == null) {
        return new ArrayList<>();
    }
    return principals;
}
Also used : Holder(javax.xml.ws.Holder) ArrayList(java.util.ArrayList) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) CalDAVCollection(org.bedework.caldav.server.CalDAVCollection) WebdavProperty(org.bedework.webdav.servlet.shared.WebdavProperty) CalPrincipalInfo(org.bedework.caldav.server.sysinterface.CalPrincipalInfo) BwPrincipalInfo(org.bedework.calfacade.BwPrincipalInfo)

Aggregations

ArrayList (java.util.ArrayList)2 CalDAVCollection (org.bedework.caldav.server.CalDAVCollection)2 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)2 Holder (javax.xml.ws.Holder)1 CalPrincipalInfo (org.bedework.caldav.server.sysinterface.CalPrincipalInfo)1 BwCalendar (org.bedework.calfacade.BwCalendar)1 BwPrincipalInfo (org.bedework.calfacade.BwPrincipalInfo)1 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)1 CalendarsI (org.bedework.calsvci.CalendarsI)1 WebdavForbidden (org.bedework.webdav.servlet.shared.WebdavForbidden)1 WebdavProperty (org.bedework.webdav.servlet.shared.WebdavProperty)1