Search in sources :

Example 46 with BwPrincipal

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

the class CalSuites method getResourcesPath.

/* ====================================================================
   *                   Resource methods
   *  =================================================================== */
public String getResourcesPath(final BwCalSuite suite, final ResourceClass cl) throws CalFacadeException {
    if (cl == ResourceClass.global) {
        return getBasicSyspars().getGlobalResourcesPath();
    }
    final BwPrincipal eventsOwner = getPrincipal(suite.getGroup().getOwnerHref());
    final String home = getSvc().getPrincipalInfo().getCalendarHomePath(eventsOwner);
    final BwPreferences prefs = getSvc().getPrefsHandler().get(eventsOwner);
    String col = null;
    if (cl == ResourceClass.admin) {
        col = prefs.getAdminResourcesDirectory();
        if (col == null) {
            col = ".adminResources";
        }
    } else if (cl == ResourceClass.calsuite) {
        col = prefs.getSuiteResourcesDirectory();
        if (col == null) {
            col = ".csResources";
        }
    }
    if (col != null) {
        return Util.buildPath(colPathEndsWithSlash, home, "/", col);
    }
    throw new RuntimeException("System error");
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) BwPreferences(org.bedework.calfacade.svc.BwPreferences)

Example 47 with BwPrincipal

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

the class CalSvc method pushPrincipal.

/**
 * Switch to the given principal to allow us to update their stuff - for
 * example - send a notification.
 *
 * @param principal a principal object
 */
void pushPrincipal(final BwPrincipal principal) throws CalFacadeException {
    BwPrincipal pr = getUsersHandler().getUser(principal.getPrincipalRef());
    if (pr == null) {
        pr = addUser(principal.getPrincipalRef());
    }
    ((SvciPrincipalInfo) principalInfo).pushPrincipal(pr);
    getCal().principalChanged();
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal)

Example 48 with BwPrincipal

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

the class CalSvc method addUser.

/* Create the user. Get a new CalSvc object for that purpose.
   *
   */
BwPrincipal addUser(final String val) throws CalFacadeException {
    final Users users = (Users) getUsersHandler();
    /* Run this in a separate transaction to ensure we don't fail if the user
     * gets created by a concurrent process.
     */
    // if (creating) {
    // // Get a fake user
    // return users.initUserObject(val);
    // }
    // In case we need to replace the session
    getCal().flush();
    try {
        users.createUser(val);
    } catch (final CalFacadeException cfe) {
        if (cfe.getCause() instanceof ConstraintViolationException) {
            // We'll assume it was created by another process.
            warn("ConstraintViolationException trying to create " + val);
        // Does this session still work?
        } else {
            rollbackTransaction();
            if (debug) {
                cfe.printStackTrace();
            }
            throw cfe;
        }
    } catch (final Throwable t) {
        rollbackTransaction();
        if (debug) {
            t.printStackTrace();
        }
        throw new CalFacadeException(t);
    }
    final BwPrincipal principal = users.getUser(val);
    if (principal == null) {
        return null;
    }
    final String caladdr = getDirectories().userToCaladdr(principal.getPrincipalRef());
    if (caladdr != null) {
        final List<String> emails = Collections.singletonList(caladdr.substring("mailto:".length()));
        final Notifications notify = (Notifications) getNotificationsHandler();
        notify.subscribe(principal, emails);
    }
    return principal;
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) BwString(org.bedework.calfacade.BwString) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 49 with BwPrincipal

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

the class CalSvcDb method pushPrincipal.

protected void pushPrincipal(final String href) throws CalFacadeException {
    final BwPrincipal pr = caladdrToPrincipal(href);
    if (pr == null) {
        throw new CalFacadeException(CalFacadeException.badRequest, "unknown principal");
    }
    getSvc().pushPrincipal(pr);
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 50 with BwPrincipal

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

the class CalSvcDb method pushPrincipalReturn.

protected boolean pushPrincipalReturn(final String href) throws CalFacadeException {
    final BwPrincipal pr = caladdrToPrincipal(href);
    if (pr == null) {
        return false;
    }
    getSvc().pushPrincipal(pr);
    return true;
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal)

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