Search in sources :

Example 1 with CalendarsI

use of org.bedework.calsvci.CalendarsI 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 CalendarsI

use of org.bedework.calsvci.CalendarsI in project bw-calendar-engine by Bedework.

the class DumpPrincipal method dumpCol.

protected void dumpCol(final BwCalendar col, final boolean doChildren) throws CalFacadeException {
    final CalendarsI colsI = getSvc().getCalendarsHandler();
    try {
        incCount(DumpGlobals.collections);
        makeDir(col.getName(), false);
        col.dump(makeFile(col.getName() + ".xml"));
        /* Dump any events in this collection */
        final Iterable<EventInfo> eis = getDi().getEventInfos(col.getPath());
        eis.forEach(new EventConsumer());
        if (!doChildren || !col.getCollectionInfo().childrenAllowed) {
            return;
        }
        final Collection<BwCalendar> cols = colsI.getChildren(col);
        if (Util.isEmpty(cols)) {
            return;
        }
        for (final BwCalendar ch : cols) {
            dumpCol(ch, true);
        }
    } finally {
        popPath();
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) CalendarsI(org.bedework.calsvci.CalendarsI) BwCalendar(org.bedework.calfacade.BwCalendar)

Example 3 with CalendarsI

use of org.bedework.calsvci.CalendarsI in project bw-calendar-engine by Bedework.

the class DumpSystem method doDump.

/**
 * Dump everything owned by this principal
 *
 * @throws CalFacadeException on error
 */
public void doDump() throws CalFacadeException {
    try {
        makeDir(Defs.collectionsDirName, false);
        final CalendarsI cols = getSvc().getCalendarsHandler();
        final BwCalendar usercal = cols.get(getSysRoots().getUserCalendarRoot());
        if (usercal == null) {
            warn("Unable to fetch user calendar root");
            return;
        }
        dumpCol(usercal, false);
    } finally {
        popPath();
    }
}
Also used : CalendarsI(org.bedework.calsvci.CalendarsI) BwCalendar(org.bedework.calfacade.BwCalendar)

Example 4 with CalendarsI

use of org.bedework.calsvci.CalendarsI in project bw-calendar-engine by Bedework.

the class FreeAndBusyHandler method getFreeBusy.

/* (non-Javadoc)
   * @see org.bedework.calsvci.SchedulingI#getFreeBusy(java.util.Collection, org.bedework.calfacade.BwPrincipal, org.bedework.calfacade.BwDateTime, org.bedework.calfacade.BwDateTime, org.bedework.calfacade.BwOrganizer, java.lang.String)
   */
@Override
public BwEvent getFreeBusy(final Collection<BwCalendar> fbset, final BwPrincipal who, final BwDateTime start, final BwDateTime end, final BwOrganizer org, final String uid, final String exceptUid) throws CalFacadeException {
    CalendarsI colHandler = getSvc().getCalendarsHandler();
    Collection<BwCalendar> cals = null;
    if (fbset != null) {
        /* Don't check - we do so at the fetch of events
      getCal().checkAccess(cal, PrivilegeDefs.privReadFreeBusy, false);
      */
        cals = addToFreeBusySet(cals, fbset);
    } else if (getPrincipal().equals(who)) {
        cals = getFreebusySet();
    } else {
        /* CalDAV uses Inbox to determine scheduling acccess */
        try {
            getSpecialCalendar(who, BwCalendar.calTypeInbox, true, PrivilegeDefs.privReadFreeBusy);
        } catch (CalFacadeAccessException cae) {
            getSpecialCalendar(who, BwCalendar.calTypeInbox, true, PrivilegeDefs.privScheduleFreeBusy);
        }
        cals = addToFreeBusySet(cals, colHandler.getChildren(colHandler.getHome(who, true)));
    }
    if (cals == null) {
        throw new CalFacadeAccessException();
    }
    BwEvent fb = new BwEventObj();
    fb.setEntityType(IcalDefs.entityTypeFreeAndBusy);
    fb.setOwnerHref(who.getPrincipalRef());
    fb.setDtstart(start);
    fb.setDtend(end);
    fb.setEndType(StartEndComponent.endTypeDate);
    if (uid == null) {
        assignGuid(fb);
    } else {
        fb.setUid(uid);
    }
    fb.setDtstamps(getCurrentTimestamp());
    String uri = getSvc().getDirectories().principalToCaladdr(who);
    BwAttendee att = new BwAttendee();
    att.setAttendeeUri(uri);
    fb.addAttendee(att);
    fb.setOrganizer((BwOrganizer) org.clone());
    Collection<EventInfo> events = new TreeSet<EventInfo>();
    /* Only events and freebusy for freebusy reports. */
    FilterBase filter = new OrFilter();
    try {
        filter.addChild(EntityTypeFilter.makeEntityTypeFilter(null, "event", false));
        filter.addChild(EntityTypeFilter.makeEntityTypeFilter(null, "freeAndBusy", false));
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
    String userHref = who.getPrincipalRef();
    for (BwCalendar c : cals) {
        if (!c.getAffectsFreeBusy()) {
            continue;
        }
        // XXX If it's an external subscription we probably just get free busy and
        // merge it in.
        RecurringRetrievalMode rrm = new RecurringRetrievalMode(Rmode.expanded, start, end);
        Collection<BwCalendar> cs = new ArrayList<BwCalendar>();
        cs.add(c);
        Collection<EventInfo> evs = getEvents(cs, filter, start, end, // retrieveList
        null, rrm, true);
        // Filter out transparent events
        for (EventInfo ei : evs) {
            BwEvent ev = ei.getEvent();
            if ((exceptUid != null) && exceptUid.equals(ev.getUid())) {
                continue;
            }
            if (!c.getIgnoreTransparency() && IcalDefs.transparencyTransparent.equals(ev.getPeruserTransparency(userHref))) {
                // Ignore this one.
                continue;
            }
            if (BwEvent.statusCancelled.equals(ev.getStatus())) {
                // Ignore this one.
                continue;
            }
            if (ev.getAttendeeSchedulingObject()) {
                att = ev.findAttendee(uri);
                if (att != null) {
                    int pstat = IcalDefs.checkPartstat(att.getPartstat());
                    if (pstat == IcalDefs.partstatDeclined) {
                        continue;
                    }
                    if (pstat == IcalDefs.partstatNeedsAction) {
                        continue;
                    }
                }
            }
            events.add(ei);
        }
    }
    try {
        EventPeriods eventPeriods = new EventPeriods(start, end);
        for (EventInfo ei : events) {
            BwEvent ev = ei.getEvent();
            int type;
            if (ev.getEntityType() == IcalDefs.entityTypeEvent) {
                if (BwEvent.statusCancelled.equals(ev.getStatus())) {
                    // Ignore this one.
                    continue;
                }
                type = BwFreeBusyComponent.typeBusy;
                if (ev.getAttendeeSchedulingObject()) {
                    att = ev.findAttendee(uri);
                    if (att != null) {
                        if (IcalDefs.checkPartstat(att.getPartstat()) == IcalDefs.partstatTentative) {
                            type = BwFreeBusyComponent.typeBusyTentative;
                        }
                    }
                }
                if (BwEvent.statusTentative.equals(ev.getStatus())) {
                    type = BwFreeBusyComponent.typeBusyTentative;
                } else if (BwEvent.statusUnavailable.equals(ev.getStatus())) {
                    type = BwFreeBusyComponent.typeBusyUnavailable;
                }
                eventPeriods.addPeriod(ev.getDtstart(), ev.getDtend(), type);
            } else if (ev.getEntityType() == IcalDefs.entityTypeFreeAndBusy) {
                Collection<BwFreeBusyComponent> fbcs = ev.getFreeBusyPeriods();
                for (BwFreeBusyComponent fbc : fbcs) {
                    type = fbc.getType();
                    for (Period p : fbc.getPeriods()) {
                        eventPeriods.addPeriod(p.getStart(), p.getEnd(), type);
                    }
                }
            }
        }
        /* iterate through the sorted periods combining them where they are
       adjacent or overlap */
        BwFreeBusyComponent fbc = eventPeriods.makeFreeBusyComponent(BwFreeBusyComponent.typeBusy);
        if (fbc != null) {
            fb.addFreeBusyPeriod(fbc);
        }
        fbc = eventPeriods.makeFreeBusyComponent(BwFreeBusyComponent.typeBusyUnavailable);
        if (fbc != null) {
            fb.addFreeBusyPeriod(fbc);
        }
        fbc = eventPeriods.makeFreeBusyComponent(BwFreeBusyComponent.typeBusyTentative);
        if (fbc != null) {
            fb.addFreeBusyPeriod(fbc);
        }
    } catch (Throwable t) {
        if (debug) {
            error(t);
        }
        throw new CalFacadeException(t);
    }
    return fb;
}
Also used : EventPeriods(org.bedework.calfacade.util.EventPeriods) BwFreeBusyComponent(org.bedework.calfacade.BwFreeBusyComponent) EventInfo(org.bedework.calfacade.svc.EventInfo) RecurringRetrievalMode(org.bedework.calfacade.RecurringRetrievalMode) ArrayList(java.util.ArrayList) Period(net.fortuna.ical4j.model.Period) EventPeriod(org.bedework.calfacade.util.Granulator.EventPeriod) BwEvent(org.bedework.calfacade.BwEvent) CalendarsI(org.bedework.calsvci.CalendarsI) BwCalendar(org.bedework.calfacade.BwCalendar) OrFilter(org.bedework.caldav.util.filter.OrFilter) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) TreeSet(java.util.TreeSet) Collection(java.util.Collection) BwAttendee(org.bedework.calfacade.BwAttendee) BwEventObj(org.bedework.calfacade.BwEventObj) FilterBase(org.bedework.caldav.util.filter.FilterBase)

Example 5 with CalendarsI

use of org.bedework.calsvci.CalendarsI in project bw-calendar-engine by Bedework.

the class DumpPrincipal method doDump.

/**
 * Dump everything owned by this principal
 *
 * @throws CalFacadeException on error
 */
public void doDump() throws CalFacadeException {
    final File f = makeFile("principal.xml");
    pr.dump(f);
    final BwPreferences prefs = getSvc().getPrefsHandler().get();
    if (prefs == null) {
        warn("No preferences for " + pr.getPrincipalRef());
    } else {
        incCount(DumpGlobals.userPrefs);
        prefs.dump(makeFile("preferences.xml"));
    }
    dumpCategories(false);
    dumpContacts(false);
    dumpLocations(false);
    try {
        makeDir(Defs.collectionsDirName, false);
        final CalendarsI cols = getSvc().getCalendarsHandler();
        final BwCalendar home = cols.getHome();
        if (home == null) {
            warn("No home for " + pr.getPrincipalRef());
            return;
        }
        dumpCol(home, true);
    } finally {
        popPath();
    }
}
Also used : BwPreferences(org.bedework.calfacade.svc.BwPreferences) CalendarsI(org.bedework.calsvci.CalendarsI) BwCalendar(org.bedework.calfacade.BwCalendar) File(java.io.File)

Aggregations

BwCalendar (org.bedework.calfacade.BwCalendar)6 CalendarsI (org.bedework.calsvci.CalendarsI)6 ArrayList (java.util.ArrayList)2 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)2 EventInfo (org.bedework.calfacade.svc.EventInfo)2 File (java.io.File)1 Collection (java.util.Collection)1 TreeSet (java.util.TreeSet)1 Period (net.fortuna.ical4j.model.Period)1 CalDAVCollection (org.bedework.caldav.server.CalDAVCollection)1 FilterBase (org.bedework.caldav.util.filter.FilterBase)1 OrFilter (org.bedework.caldav.util.filter.OrFilter)1 BwAttendee (org.bedework.calfacade.BwAttendee)1 BwEvent (org.bedework.calfacade.BwEvent)1 BwEventObj (org.bedework.calfacade.BwEventObj)1 BwFreeBusyComponent (org.bedework.calfacade.BwFreeBusyComponent)1 RecurringRetrievalMode (org.bedework.calfacade.RecurringRetrievalMode)1 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)1 BwPreferences (org.bedework.calfacade.svc.BwPreferences)1 EventPeriods (org.bedework.calfacade.util.EventPeriods)1