Search in sources :

Example 71 with BwCalendar

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

the class BwSysIntfImpl method getFreeBusy.

/* (non-Javadoc)
   * @see org.bedework.caldav.server.sysinterface.SysIntf#getFreeBusy(org.bedework.caldav.server.CalDAVCollection, int, org.bedework.caldav.util.TimeRange)
   */
@Override
public CalDAVEvent getFreeBusy(final CalDAVCollection col, final int depth, final TimeRange timeRange) throws WebdavException {
    try {
        BwCalendar bwCol = unwrap(col);
        int calType = bwCol.getCalType();
        if (!bwCol.getCollectionInfo().allowFreeBusy) {
            throw new WebdavForbidden(WebdavTags.supportedReport);
        }
        Collection<BwCalendar> cals = new ArrayList<BwCalendar>();
        if (calType == BwCalendar.calTypeCalendarCollection) {
            cals.add(bwCol);
        } else if (depth == 0) {
        /* Cannot return anything */
        } else {
            for (BwCalendar ch : getSvci().getCalendarsHandler().getChildren(bwCol)) {
                // For depth 1 we only add calendar collections
                if ((depth > 1) || (ch.getCalType() == BwCalendar.calTypeCalendarCollection)) {
                    cals.add(ch);
                }
            }
        }
        AccessPrincipal owner = col.getOwner();
        String orgUri;
        if (owner instanceof BwPrincipal) {
            orgUri = getSvci().getDirectories().principalToCaladdr((BwPrincipal) owner);
        } else {
            BwPrincipal p = BwPrincipal.makeUserPrincipal();
            p.setAccount(owner.getAccount());
            orgUri = getSvci().getDirectories().principalToCaladdr(p);
        }
        BwOrganizer org = new BwOrganizer();
        org.setOrganizerUri(orgUri);
        BwEvent fb;
        if (cals.isEmpty()) {
            // Return an empty object
            fb = new BwEventObj();
            fb.setEntityType(IcalDefs.entityTypeFreeAndBusy);
            fb.setDtstart(getBwDt(timeRange.getStart()));
            fb.setDtend(getBwDt(timeRange.getEnd()));
        } else {
            fb = getSvci().getScheduler().getFreeBusy(cals, (BwPrincipal) currentPrincipal, getBwDt(timeRange.getStart()), getBwDt(timeRange.getEnd()), org, // uid
            null, null);
        }
        EventInfo ei = new EventInfo(fb);
        return new BwCalDAVEvent(this, ei);
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    } catch (WebdavException wde) {
        throw wde;
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) ArrayList(java.util.ArrayList) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) BwCalendar(org.bedework.calfacade.BwCalendar) AccessPrincipal(org.bedework.access.AccessPrincipal) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) BwPrincipal(org.bedework.calfacade.BwPrincipal) BwEventObj(org.bedework.calfacade.BwEventObj) BwOrganizer(org.bedework.calfacade.BwOrganizer)

Example 72 with BwCalendar

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

the class BwSysIntfImpl method fromIcal.

@Override
public SysiIcalendar fromIcal(final CalDAVCollection col, final IcalendarType ical, final IcalResultType rtype) throws WebdavException {
    // Ensure open
    getSvci();
    boolean rollback = true;
    try {
        BwCalendar bwcol = null;
        if (col != null) {
            bwcol = unwrap(col.resolveAlias(true));
        }
        Icalendar ic = trans.fromIcal(bwcol, ical, // diff the contents
        true);
        if (rtype == IcalResultType.OneComponent) {
            if (ic.getComponents().size() != 1) {
                throw new WebdavBadRequest(CaldavTags.validCalendarObjectResource);
            }
            if (!(ic.getComponents().iterator().next() instanceof EventInfo)) {
                throw new WebdavBadRequest(CaldavTags.validCalendarObjectResource);
            }
        } else if (rtype == IcalResultType.TimeZone) {
            if (ic.getTimeZones().size() != 1) {
                throw new WebdavBadRequest("Expected one timezone");
            }
        }
        SysiIcalendar sic = new MySysiIcalendar(this, ic);
        rollback = false;
        return sic;
    } catch (WebdavException wde) {
        throw wde;
    } catch (IcalMalformedException ime) {
        throw new WebdavForbidden(CaldavTags.validCalendarData, ime.getMessage());
    } catch (Throwable t) {
        if (debug) {
            error(t);
        }
        // Assume bad data in some way
        throw new WebdavForbidden(CaldavTags.validCalendarObjectResource, t.getMessage());
    } finally {
        if (rollback) {
            try {
                getSvci().rollbackTransaction();
            } catch (Throwable t) {
            }
        }
    }
}
Also used : WebdavBadRequest(org.bedework.webdav.servlet.shared.WebdavBadRequest) EventInfo(org.bedework.calfacade.svc.EventInfo) Icalendar(org.bedework.icalendar.Icalendar) SysiIcalendar(org.bedework.caldav.server.SysiIcalendar) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwCalendar(org.bedework.calfacade.BwCalendar) SysiIcalendar(org.bedework.caldav.server.SysiIcalendar) IcalMalformedException(org.bedework.icalendar.IcalMalformedException)

Example 73 with BwCalendar

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

the class CoreCalendars method moveCalendar.

@Override
public void moveCalendar(BwCalendar val, final BwCalendar newParent) throws CalFacadeException {
    colCache.flush();
    /* check access - privbind on new parent privunbind on val?
     */
    ac.checkAccess(val, privUnbind, false);
    ac.checkAccess(newParent, privBind, false);
    if (newParent.getCalType() != BwCalendar.calTypeFolder) {
        throw new CalFacadeException(CalFacadeException.illegalCalendarCreation);
    }
    val = unwrap(val);
    val.setColPath(newParent.getPath());
    val.updateLastmod(getCurrentTimestamp());
    final BwCalendar tombstoned = val.makeTombstoneCopy();
    tombstoned.tombstone();
    dao.save(tombstoned);
    /* This triggers off a cascade of updates down the tree as we are storing the
     * path in the calendar objects. This may be preferable to calculating the
     * path at every access
     */
    updatePaths(val, newParent);
    /* Remove any tombstoned collection with the same name */
    dao.removeTombstonedVersion(val);
    // Flush it again
    colCache.flush();
}
Also used : BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 74 with BwCalendar

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

the class CoreCalendars method addNewCalendars.

@Override
public void addNewCalendars(final BwPrincipal user) throws CalFacadeException {
    /* Add a user collection to the userCalendarRoot and then a default
       calendar collection. */
    String path = userCalendarRootPath;
    final BwCalendar userrootcal = dao.getCollection(path);
    if (userrootcal == null) {
        throw new CalFacadeException("No user root at " + path);
    }
    BwCalendar parentCal = userrootcal;
    BwCalendar usercal = null;
    /* We may have a principal e.g. /principals/resources/vcc311
     * All except the last may exist already.
     */
    final String[] upath = user.getAccountSplit();
    for (int i = 0; i < upath.length; i++) {
        final String pathSeg = upath[i];
        if ((pathSeg == null) || (pathSeg.length() == 0)) {
            // Leading or double slash - skip it
            continue;
        }
        path = Util.buildPath(colPathEndsWithSlash, path, "/", pathSeg);
        usercal = dao.getCollection(path);
        if (i == (upath.length - 1)) {
            if (usercal != null) {
                throw new CalFacadeException("User calendar already exists at " + path);
            }
            /* Create a folder for the user */
            usercal = new BwCalendar();
            usercal.setName(pathSeg);
            usercal.setCreatorHref(user.getPrincipalRef());
            usercal.setOwnerHref(user.getPrincipalRef());
            usercal.setPublick(false);
            usercal.setPath(path);
            usercal.setColPath(parentCal.getPath());
            dao.saveCollection(usercal);
            notify(SysEvent.SysCode.COLLECTION_ADDED, usercal);
        } else if (usercal == null) {
            /* Create a new system owned folder for part of the principal
         * hierarchy
         */
            usercal = new BwCalendar();
            usercal.setName(pathSeg);
            usercal.setCreatorHref(userrootcal.getCreatorHref());
            usercal.setOwnerHref(userrootcal.getOwnerHref());
            usercal.setPublick(false);
            usercal.setPath(path);
            usercal.setColPath(parentCal.getPath());
            dao.saveCollection(usercal);
            notify(SysEvent.SysCode.COLLECTION_ADDED, usercal);
        }
        parentCal = usercal;
    }
    if (usercal == null) {
        throw new CalFacadeException("Invalid user " + user);
    }
    /* Create a default calendar */
    final BwCalendar cal = new BwCalendar();
    cal.setName(getSyspars().getUserDefaultCalendar());
    cal.setCreatorHref(user.getPrincipalRef());
    cal.setOwnerHref(user.getPrincipalRef());
    cal.setPublick(false);
    cal.setPath(Util.buildPath(colPathEndsWithSlash, path, "/", cal.getName()));
    cal.setColPath(usercal.getPath());
    cal.setCalType(BwCalendar.calTypeCalendarCollection);
    cal.setAffectsFreeBusy(true);
    dao.saveCollection(cal);
    notify(SysEvent.SysCode.COLLECTION_ADDED, cal);
}
Also used : BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 75 with BwCalendar

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

the class CoreCalendars method getCollection.

@Override
public BwCalendar getCollection(final String path) throws CalFacadeException {
    if (path == null) {
        return null;
    }
    BwCalendar col = colCache.get(path);
    if (col != null) {
        return col;
    }
    col = dao.getCollection(path);
    if (col == null) {
        if (path.equals("/")) {
            // Fake a root collection
            col = new BwCalendar();
            col.setPath("/");
            // Use this for owner/creator
            final BwCalendar userRoot = getCollection(userCalendarRootPath);
            if (userRoot == null) {
                return null;
            }
            col.setOwnerHref(userRoot.getOwnerHref());
            col.setCreatorHref(userRoot.getCreatorHref());
            col.setAccess(Access.getDefaultPublicAccess());
        } else if (!getPrincipal().getUnauthenticated()) {
            /* Didn't find it. Is this a special collection we should create,
           Only try this if authenticated.
         */
            final GetSpecialCalendarResult gscr = getIfSpecial(getPrincipal(), path);
            if (gscr == null) {
                return null;
            }
            col = gscr.cal;
        } else {
            return null;
        }
    }
    final CalendarWrapper wcol = wrap(col);
    if (wcol != null) {
        colCache.put(wcol);
    }
    return wcol;
}
Also used : BwCalendar(org.bedework.calfacade.BwCalendar) CalendarWrapper(org.bedework.calfacade.wrappers.CalendarWrapper)

Aggregations

BwCalendar (org.bedework.calfacade.BwCalendar)134 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)46 EventInfo (org.bedework.calfacade.svc.EventInfo)23 BwEvent (org.bedework.calfacade.BwEvent)19 ArrayList (java.util.ArrayList)18 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)18 BwPrincipal (org.bedework.calfacade.BwPrincipal)15 TreeSet (java.util.TreeSet)10 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)10 BwCategory (org.bedework.calfacade.BwCategory)10 BwResource (org.bedework.calfacade.BwResource)10 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)9 FilterBase (org.bedework.caldav.util.filter.FilterBase)8 BwPreferences (org.bedework.calfacade.svc.BwPreferences)8 BwEventProxy (org.bedework.calfacade.BwEventProxy)7 CalendarWrapper (org.bedework.calfacade.wrappers.CalendarWrapper)7 CurrentAccess (org.bedework.access.Acl.CurrentAccess)6 CalendarsI (org.bedework.calsvci.CalendarsI)6 Acl (org.bedework.access.Acl)5 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)5