Search in sources :

Example 1 with BasicSystemProperties

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

the class Views method find.

@Override
public BwView find(String val) throws CalFacadeException {
    if (val == null) {
        BwPreferences prefs = getSvc().getPrefsHandler().get();
        val = prefs.getPreferredView();
        if (val == null) {
            return null;
        }
    }
    /* val may be a name in which case it's for the current user or it
     * may be a fully qualified path referencing another users views.
     */
    if (!val.startsWith("/")) {
        // This user
        Collection<BwView> views = getAll();
        for (BwView view : views) {
            if (view.getName().equals(val)) {
                return view;
            }
        }
        return null;
    }
    /* Other user - we expect a path of th eform
     *  /user/<id>/<bedework-resource-name>/views/<view-name>
     */
    String[] pathEls = val.split("/");
    BasicSystemProperties bsp = getBasicSyspars();
    if ((pathEls.length != 5) || !bsp.getBedeworkResourceDirectory().equals(pathEls[2]) || !"views".equals(pathEls[3])) {
        return null;
    }
    StringBuilder sb = new StringBuilder();
    if (bsp.getUserCalendarRoot().equals(pathEls[0])) {
        sb.append(BwPrincipal.userPrincipalRoot);
    } else {
        return null;
    }
    // user id
    sb.append(pathEls[1]);
    BwPrincipal pr = getPrincipal(sb.toString());
    if (pr == null) {
        return null;
    }
    Collection<BwView> views = getAll(pr);
    String viewName = pathEls[4];
    for (BwView view : views) {
        if (view.getName().equals(viewName)) {
            return view;
        }
    }
    return null;
}
Also used : BwPreferences(org.bedework.calfacade.svc.BwPreferences) BwPrincipal(org.bedework.calfacade.BwPrincipal) BasicSystemProperties(org.bedework.calfacade.configs.BasicSystemProperties) BwView(org.bedework.calfacade.svc.BwView)

Example 2 with BasicSystemProperties

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

the class CoreCalendars method checkNewCalendarName.

private void checkNewCalendarName(final String name, final boolean special, final BwCalendar parent) throws CalFacadeException {
    // XXX This should be accessible to all implementations.
    if (!special) {
        final BasicSystemProperties sys = getSyspars();
        if (name.equals(sys.getUserInbox())) {
            throw new CalFacadeException(CalFacadeException.illegalCalendarCreation);
        }
        if (name.equals(sys.getUserOutbox())) {
            throw new CalFacadeException(CalFacadeException.illegalCalendarCreation);
        }
        if (name.equals(sys.getDefaultNotificationsName())) {
            throw new CalFacadeException(CalFacadeException.illegalCalendarCreation);
        }
    }
    /* Ensure the name is not-null and contains no invalid characters
     */
    if ((name == null) || name.contains("/")) {
        throw new CalFacadeException(CalFacadeException.illegalCalendarCreation);
    }
    /* Ensure the new path is unique */
    String path;
    if (parent == null) {
        path = "";
    } else {
        path = parent.getPath();
    }
    path = Util.buildPath(colPathEndsWithSlash, path, "/", name);
    final BwCalendar col = dao.getCollection(path);
    if (col != null) {
        if (!col.getTombstoned()) {
            throw new CalFacadeException(CalFacadeException.duplicateCalendar);
        }
        dao.deleteCalendar(unwrap(col));
    }
}
Also used : BasicSystemProperties(org.bedework.calfacade.configs.BasicSystemProperties) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 3 with BasicSystemProperties

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

the class CoreCalendars method getSpecialCalendar.

private GetSpecialCalendarResult getSpecialCalendar(final BwPrincipal owner, final int calType, final boolean create, final boolean tryFetch, final int access) throws CalFacadeException {
    final String name;
    final BasicSystemProperties sys = getSyspars();
    int ctype = calType;
    if (calType == BwCalendar.calTypeInbox) {
        name = sys.getUserInbox();
    } else if (calType == BwCalendar.calTypePendingInbox) {
        // sys.getUserInbox();
        name = ".pendingInbox";
    } else if (calType == BwCalendar.calTypeOutbox) {
        name = sys.getUserOutbox();
    } else if (calType == BwCalendar.calTypeNotifications) {
        name = sys.getDefaultNotificationsName();
    } else if (calType == BwCalendar.calTypeEventList) {
        name = sys.getDefaultReferencesName();
    } else if (calType == BwCalendar.calTypePoll) {
        name = sys.getUserDefaultPollsCalendar();
    } else if (calType == BwCalendar.calTypeAttachments) {
        name = sys.getDefaultAttachmentsName();
    } else if (calType == BwCalendar.calTypeCalendarCollection) {
        name = sys.getUserDefaultCalendar();
    } else if (calType == BwCalendar.calTypeTasks) {
        name = sys.getUserDefaultTasksCalendar();
        ctype = BwCalendar.calTypeTasks;
    } else {
        // Not supported
        return null;
    }
    final List<String> entityTypes = BwCalendar.entityTypes.get(calType);
    final String pathTo = cb.getPrincipalInfo().getCalendarHomePath(owner);
    final GetSpecialCalendarResult gscr = new GetSpecialCalendarResult();
    if (!dao.collectionExists(pathTo)) {
        gscr.noUserHome = true;
        return gscr;
    }
    if (tryFetch) {
        gscr.cal = getCalendar(Util.buildPath(colPathEndsWithSlash, pathTo, "/", name), access, false);
        if ((gscr.cal != null) || !create) {
            return gscr;
        }
    }
    /*
    BwCalendar parent = getCalendar(pathTo, privRead);

    if (parent == null) {
      throw new CalFacadeException("org.bedework.calcore.calendars.unabletocreate");
    }
    */
    gscr.cal = new BwCalendar();
    gscr.cal.setName(name);
    gscr.cal.setCreatorHref(owner.getPrincipalRef());
    gscr.cal.setOwnerHref(owner.getPrincipalRef());
    gscr.cal.setCalType(ctype);
    if (entityTypes != null) {
        gscr.cal.setSupportedComponents(entityTypes);
    }
    /* I think we're allowing privNone here because we don't mind if the
     * calendar gets created even if the caller has no access.
     */
    gscr.cal = add(gscr.cal, pathTo, true, access);
    gscr.created = true;
    return gscr;
}
Also used : BasicSystemProperties(org.bedework.calfacade.configs.BasicSystemProperties) BwCalendar(org.bedework.calfacade.BwCalendar)

Example 4 with BasicSystemProperties

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

the class CoreCalendars method getIfSpecial.

/* ====================================================================
   *                   Private methods
   * ==================================================================== */
private GetSpecialCalendarResult getIfSpecial(final BwPrincipal owner, final String path) throws CalFacadeException {
    final String pathTo = cb.getPrincipalInfo().getCalendarHomePath(owner);
    final BasicSystemProperties sys = getSyspars();
    if (Util.buildPath(colPathEndsWithSlash, pathTo, "/", sys.getUserInbox()).equals(path)) {
        return getSpecialCalendar(owner, BwCalendar.calTypeInbox, true, false, PrivilegeDefs.privAny);
    }
    if (Util.buildPath(colPathEndsWithSlash, pathTo, "/", ".pendingInbox").equals(path)) {
        return getSpecialCalendar(owner, BwCalendar.calTypePendingInbox, true, false, PrivilegeDefs.privAny);
    }
    if (Util.buildPath(colPathEndsWithSlash, pathTo, "/", sys.getUserOutbox()).equals(path)) {
        return getSpecialCalendar(owner, BwCalendar.calTypeOutbox, true, false, PrivilegeDefs.privAny);
    }
    if (Util.buildPath(colPathEndsWithSlash, pathTo, "/", sys.getDefaultNotificationsName()).equals(path)) {
        return getSpecialCalendar(owner, BwCalendar.calTypeNotifications, true, false, PrivilegeDefs.privAny);
    }
    if (Util.buildPath(colPathEndsWithSlash, pathTo, "/", sys.getDefaultReferencesName()).equals(path)) {
        return getSpecialCalendar(owner, BwCalendar.calTypeEventList, true, false, PrivilegeDefs.privAny);
    }
    if (Util.buildPath(colPathEndsWithSlash, pathTo, "/", sys.getUserDefaultPollsCalendar()).equals(path)) {
        return getSpecialCalendar(owner, BwCalendar.calTypePoll, true, false, PrivilegeDefs.privAny);
    }
    return null;
}
Also used : BasicSystemProperties(org.bedework.calfacade.configs.BasicSystemProperties)

Aggregations

BasicSystemProperties (org.bedework.calfacade.configs.BasicSystemProperties)4 BwCalendar (org.bedework.calfacade.BwCalendar)2 BwPrincipal (org.bedework.calfacade.BwPrincipal)1 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)1 BwPreferences (org.bedework.calfacade.svc.BwPreferences)1 BwView (org.bedework.calfacade.svc.BwView)1