Search in sources :

Example 1 with CalPrincipalInfo

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

the class BwSysIntfImpl method getCalPrincipalInfo.

@Override
public CalPrincipalInfo getCalPrincipalInfo(final AccessPrincipal principal) throws WebdavException {
    try {
        if (principal == null) {
            return null;
        }
        final boolean thisPrincipal = principal.equals(getSvci().getPrincipal());
        if (thisPrincipal && (principalInfo != null)) {
            return principalInfo;
        }
        final BwPrincipal p = getSvci().getUsersHandler().getPrincipal(principal.getPrincipalRef());
        if (p == null) {
            return null;
        }
        if (p.getKind() != WhoDefs.whoTypeUser) {
            // XXX Cannot handle this yet
            return null;
        }
        // SCHEDULE - just get home path and get default cal from user prefs.
        final String userHomePath = Util.buildPath(true, getSvci().getPrincipalInfo().getCalendarHomePath(p));
        final String defaultCalendarPath = Util.buildPath(true, userHomePath + basicSysProperties.getUserDefaultCalendar());
        final String inboxPath = Util.buildPath(true, userHomePath, "/", basicSysProperties.getUserInbox());
        ;
        final String outboxPath = Util.buildPath(true, userHomePath, "/", basicSysProperties.getUserOutbox());
        final String notificationsPath = Util.buildPath(true, userHomePath, "/", basicSysProperties.getDefaultNotificationsName());
        final CalPrincipalInfo pi = new CalPrincipalInfo(p, null, null, userHomePath, defaultCalendarPath, inboxPath, outboxPath, notificationsPath, p.getQuota());
        if (thisPrincipal) {
            principalInfo = pi;
        }
        return pi;
    } catch (final Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) CalPrincipalInfo(org.bedework.caldav.server.sysinterface.CalPrincipalInfo)

Example 2 with CalPrincipalInfo

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

the class BwSysIntfImpl method getCalPrincipalInfo.

private CalPrincipalInfo getCalPrincipalInfo(final BwPrincipalInfo pi) throws WebdavException {
    try {
        // SCHEDULE - just get home path and get default cal from user prefs.
        String userHomePath = Util.buildPath(false, "/", basicSysProperties.getUserCalendarRoot());
        if (pi.getPrincipalHref() == null) {
            return new CalPrincipalInfo(null, pi.getCard(), pi.getCardStr(), // userHomePath,
            null, // defaultCalendarPath,
            null, // inboxPath,
            null, // outboxPath,
            null, // notificationsPath,
            null, 0);
        }
        final BwPrincipal p = getSvci().getDirectories().getPrincipal(pi.getPrincipalHref());
        if (pi.getPrincipalHref().startsWith(BwPrincipal.userPrincipalRoot)) {
            userHomePath = Util.buildPath(true, userHomePath, pi.getPrincipalHref().substring(BwPrincipal.userPrincipalRoot.length()));
        } else {
            userHomePath = Util.buildPath(true, userHomePath, pi.getPrincipalHref());
        }
        final String defaultCalendarPath = Util.buildPath(true, userHomePath + basicSysProperties.getUserDefaultCalendar());
        final String inboxPath = Util.buildPath(true, userHomePath, "/", basicSysProperties.getUserInbox());
        final String outboxPath = Util.buildPath(true, userHomePath, "/", basicSysProperties.getUserOutbox());
        final String notificationsPath = Util.buildPath(true, userHomePath, "/", basicSysProperties.getDefaultNotificationsName());
        return new CalPrincipalInfo(p, pi.getCard(), pi.getCardStr(), userHomePath, defaultCalendarPath, inboxPath, outboxPath, notificationsPath, 0);
    } catch (final Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) CalPrincipalInfo(org.bedework.caldav.server.sysinterface.CalPrincipalInfo)

Example 3 with CalPrincipalInfo

use of org.bedework.caldav.server.sysinterface.CalPrincipalInfo 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)

Example 4 with CalPrincipalInfo

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

the class BwSysIntfImpl method and.

private List<CalPrincipalInfo> and(final List<CalPrincipalInfo> pis, final CalPrincipalInfo pi) {
    if (pis == null) {
        final List<CalPrincipalInfo> newPis = new ArrayList<>();
        newPis.add(pi);
        return newPis;
    }
    if (pis.size() == 0) {
        return pis;
    }
    for (final CalPrincipalInfo listPi : pis) {
        if (pi.principal.equals(listPi.principal)) {
            if (pis.size() == 1) {
                return pis;
            }
            final List<CalPrincipalInfo> newPis = new ArrayList<>();
            newPis.add(pi);
            return newPis;
        }
    }
    return new ArrayList<>();
}
Also used : ArrayList(java.util.ArrayList) CalPrincipalInfo(org.bedework.caldav.server.sysinterface.CalPrincipalInfo)

Aggregations

CalPrincipalInfo (org.bedework.caldav.server.sysinterface.CalPrincipalInfo)4 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)3 ArrayList (java.util.ArrayList)2 BwPrincipal (org.bedework.calfacade.BwPrincipal)2 Holder (javax.xml.ws.Holder)1 CalDAVCollection (org.bedework.caldav.server.CalDAVCollection)1 BwPrincipalInfo (org.bedework.calfacade.BwPrincipalInfo)1 WebdavProperty (org.bedework.webdav.servlet.shared.WebdavProperty)1