[Bedework-commit] calendarapi r311 - in trunk:
calCore/src/org/bedework/calcore/hibernate
calsvc/src/org/bedework/calsvc calsvci/src/org/bedework/calsvci
svnadmin at bedework.org
svnadmin at bedework.org
Wed Jun 13 14:58:32 EDT 2007
Author: douglm
Date: 2007-06-13 14:58:31 -0400 (Wed, 13 Jun 2007)
New Revision: 311
Modified:
trunk/calCore/src/org/bedework/calcore/hibernate/CalintfImpl.java
trunk/calsvc/src/org/bedework/calsvc/AutoScheduler.java
trunk/calsvc/src/org/bedework/calsvc/CalSvc.java
trunk/calsvc/src/org/bedework/calsvc/Scheduling.java
trunk/calsvci/src/org/bedework/calsvci/CalSvcI.java
trunk/calsvci/src/org/bedework/calsvci/SchedulingI.java
Log:
Move remaining freebusy code out of CalSvc into Scheduling
Change other classes to use schduling class.
Delete unused code.
Use common jsp for displaying users own freebusy. At the moment that freebusy display is broken. Will fix soon
Modified: trunk/calCore/src/org/bedework/calcore/hibernate/CalintfImpl.java
===================================================================
--- trunk/calCore/src/org/bedework/calcore/hibernate/CalintfImpl.java 2007-06-13 14:26:57 UTC (rev 310)
+++ trunk/calCore/src/org/bedework/calcore/hibernate/CalintfImpl.java 2007-06-13 18:58:31 UTC (rev 311)
@@ -82,7 +82,6 @@
import org.bedework.calfacade.BwSystem;
import org.bedework.calfacade.BwTimeZone;
import org.bedework.calfacade.BwUser;
-import org.bedework.calfacade.CalFacadeDefs;
import org.bedework.calfacade.RecurringRetrievalMode;
import org.bedework.calfacade.TimeZoneInfo;
import org.bedework.calfacade.BwStats.StatsEntry;
Modified: trunk/calsvc/src/org/bedework/calsvc/AutoScheduler.java
===================================================================
--- trunk/calsvc/src/org/bedework/calsvc/AutoScheduler.java 2007-06-13 14:26:57 UTC (rev 310)
+++ trunk/calsvc/src/org/bedework/calsvc/AutoScheduler.java 2007-06-13 18:58:31 UTC (rev 311)
@@ -173,10 +173,8 @@
if (!scheduleDoubleBook) {
// See if there are any events booked during this time.
- BwFreeBusy fb = svci.getFreeBusy(null, null,
- svci.getUser(),
- ev.getDtstart(), ev.getDtend(),
- null, false);
+ BwFreeBusy fb = sched.getFreeBusy(null, svci.getUser(),
+ ev.getDtstart(), ev.getDtend());
Collection<BwFreeBusyComponent> times = fb.getTimes();
Modified: trunk/calsvc/src/org/bedework/calsvc/CalSvc.java
===================================================================
--- trunk/calsvc/src/org/bedework/calsvc/CalSvc.java 2007-06-13 14:26:57 UTC (rev 310)
+++ trunk/calsvc/src/org/bedework/calsvc/CalSvc.java 2007-06-13 18:58:31 UTC (rev 311)
@@ -64,18 +64,14 @@
import org.bedework.calfacade.base.BwShareableDbentity;
import org.bedework.calfacade.base.UpdateFromTimeZonesInfo;
import org.bedework.calfacade.BwAlarm;
-import org.bedework.calfacade.BwAttendee;
import org.bedework.calfacade.BwCalendar;
import org.bedework.calfacade.BwCategory;
import org.bedework.calfacade.BwDateTime;
-import org.bedework.calfacade.BwDuration;
import org.bedework.calfacade.BwEvent;
import org.bedework.calfacade.BwEventAnnotation;
import org.bedework.calfacade.BwEventProxy;
import org.bedework.calfacade.BwFreeBusy;
-import org.bedework.calfacade.BwFreeBusyComponent;
import org.bedework.calfacade.BwLocation;
-import org.bedework.calfacade.BwPrincipal;
import org.bedework.calfacade.BwContact;
import org.bedework.calfacade.BwStats;
import org.bedework.calfacade.BwString;
@@ -89,9 +85,7 @@
import org.bedework.calfacade.exc.CalFacadeAccessException;
import org.bedework.calfacade.exc.CalFacadeDupNameException;
import org.bedework.calfacade.exc.CalFacadeException;
-import org.bedework.calfacade.filter.BwEntityTypeFilter;
import org.bedework.calfacade.filter.BwFilter;
-import org.bedework.calfacade.filter.BwOrFilter;
import org.bedework.calfacade.ifs.Directories;
import org.bedework.calfacade.mail.MailerIntf;
import org.bedework.calfacade.svc.BwAdminGroup;
@@ -113,9 +107,6 @@
import org.bedework.calfacade.timezones.CalTimezones;
import org.bedework.calfacade.util.CalFacadeUtil;
import org.bedework.calfacade.util.ChangeTable;
-import org.bedework.calfacade.util.EventPeriods;
-import org.bedework.calfacade.util.Granulator;
-import org.bedework.calfacade.util.Granulator.GetPeriodsPars;
import org.bedework.calsvc.indexing.BwIndexKey;
import org.bedework.calsvc.indexing.BwIndexLuceneImpl;
import org.bedework.calsvci.BwIndexSearchResultEntry;
@@ -137,14 +128,11 @@
import edu.rpi.cmt.access.Acl.CurrentAccess;
import net.fortuna.ical4j.model.component.VTimeZone;
-import net.fortuna.ical4j.model.DateTime;
-import net.fortuna.ical4j.model.Period;
import net.fortuna.ical4j.model.TimeZone;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.TreeSet;
@@ -1382,20 +1370,6 @@
return c;
}
- public Collection<BwSubscription> getSubscriptions(BwUser user)
- throws CalFacadeException {
- Collection<BwSubscription> c = getUserPrefs(user).getSubscriptions();
- if (c == null) {
- return new TreeSet<BwSubscription>();
- }
-
- for (BwSubscription sub: c) {
- getSubCalendar(sub);
- }
-
- return c;
- }
-
public BwSubscription getSubscription(int id) throws CalFacadeException {
return dbi.getSubscription(id);
}
@@ -1405,274 +1379,6 @@
}
/* ====================================================================
- * Free busy
- * ==================================================================== */
-
- /* (non-Javadoc)
- * @see org.bedework.calsvci.CalSvcI#getFreeBusy(java.util.Collection, org.bedework.calfacade.BwCalendar, org.bedework.calfacade.BwPrincipal, org.bedework.calfacade.BwDateTime, org.bedework.calfacade.BwDateTime, org.bedework.calfacade.BwDuration, boolean)
- */
- public BwFreeBusy getFreeBusy(Collection<BwSubscription> subs,
- BwCalendar cal, BwPrincipal who,
- BwDateTime start, BwDateTime end,
- BwDuration granularity,
- boolean returnAll)
- throws CalFacadeException {
- if (!(who instanceof BwUser)) {
- throw new CalFacadeException("Unsupported: non user principal for free-busy");
- }
-
- BwUser u = (BwUser)who;
-
- if (subs != null) {
- // Use these
- } else if (cal != null) {
- /* Don't check - we do so at the fetch of events
- getCal().checkAccess(cal, PrivilegeDefs.privReadFreeBusy, false);
- */
-
- BwSubscription sub = BwSubscription.makeSubscription(cal);
-
- subs = new ArrayList<BwSubscription>();
- subs.add(sub);
- } else if (currentUser().equals(who)) {
- subs = getSubscriptions();
- } else {
- /* First see if we have free busy access to the users calendar */
-
- /* XXX This needs to be brought into line with CalDAV.
-
- cal = getCal().getCalendars(u, PrivilegeDefs.privReadFreeBusy);
- if (cal == null) {
- throw new CalFacadeAccessException();
- }
-
- getCal().checkAccess(cal, PrivilegeDefs.privReadFreeBusy, false);
- */
- /* CalDAV uses Inbox to determine scheduling acccess */
- try {
- getCal().getSpecialCalendar(u,
- BwCalendar.calTypeInbox,
- true,
- PrivilegeDefs.privReadFreeBusy);
- } catch (CalFacadeAccessException cae) {
- getCal().getSpecialCalendar(u,
- BwCalendar.calTypeInbox,
- true,
- PrivilegeDefs.privScheduleFreeBusy);
- }
-
- subs = dbi.fetchPreferences(u).getSubscriptions();
- }
-
- BwFreeBusy fb = new BwFreeBusy(who, start, end);
- assignGuid(fb);
-
- BwAttendee att = new BwAttendee();
- att.setAttendeeUri(getDirectories().userToCaladdr(who.getAccount()));
- fb.addAttendee(att);
-
- Collection<EventInfo> events = new TreeSet<EventInfo>();
- /* Only events and freebusy for freebusy reports. */
- BwFilter filter = new BwOrFilter();
- filter.addChild(BwEntityTypeFilter.eventFilter(null, false));
- filter.addChild(BwEntityTypeFilter.freebusyFilter(null, false));
-
- for (BwSubscription sub: subs) {
- if (!sub.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<EventInfo> evs = getEvents(sub, filter, start, end, rrm, true);
-
- // Filter out transparent events
- for (EventInfo ei : evs) {
- BwEvent ev = ei.getEvent();
-
- if (!sub.getIgnoreTransparency() &&
- BwEvent.transparencyTransparent.equals(ev.getTransparency())) {
- // Ignore this one.
- continue;
- }
-
- if (BwEvent.statusCancelled.equals(ev.getStatus())) {
- // Ignore this one.
- continue;
- }
-
- events.add(ei);
- }
- }
-
- try {
- if (granularity != null) {
- // chunked.
- GetPeriodsPars gpp = new GetPeriodsPars();
-
- gpp.periods = events;
- gpp.startDt = start;
- gpp.dur = granularity;
- gpp.tzcache = getTimezones();
-
- BwFreeBusyComponent fbc = null;
-
- if (!returnAll) {
- // One component
- fbc = new BwFreeBusyComponent();
- fb.addTime(fbc);
- }
-
- int limit = 10000; // XXX do this better
-
- /* endDt is null first time through, then represents end of last
- * segment.
- */
- while ((gpp.endDt == null) || (gpp.endDt.before(end))) {
- //if (debug) {
- // trace("gpp.startDt=" + gpp.startDt + " end=" + end);
- //}
- if (limit < 0) {
- throw new CalFacadeException("org.bedework.svci.limit.exceeded");
- }
- limit--;
-
- Collection periodEvents = Granulator.getPeriodsEvents(gpp);
-
- if (returnAll) {
- fbc = new BwFreeBusyComponent();
- fb.addTime(fbc);
-
- DateTime psdt = new DateTime(gpp.startDt.getDtval());
- DateTime pedt = new DateTime(gpp.endDt.getDtval());
-
- psdt.setUtc(true);
- pedt.setUtc(true);
- fbc.addPeriod(psdt, pedt);
- if (periodEvents.size() == 0) {
- fbc.setType(BwFreeBusyComponent.typeFree);
- } else {
- fbc.setType(getFreeBusyType(periodEvents));
- }
- } else if (periodEvents.size() != 0) {
- /* Some events fall in the period. Add an entry.
- * We eliminated cancelled events earler. Now we should set the
- * free/busy type based on the events status.
- */
-
- DateTime psdt = new DateTime(gpp.startDt.getDtval());
- DateTime pedt = new DateTime(gpp.endDt.getDtval());
-
- psdt.setUtc(true);
- pedt.setUtc(true);
-
- if (fbc == null) {
- fbc = new BwFreeBusyComponent();
- fb.addTime(fbc);
- }
-
- fbc.addPeriod(psdt, pedt);
- fbc.setType(getFreeBusyType(periodEvents));
- }
- }
-
- return fb;
- }
-
- /* No granularity specified - more rfc like */
- EventPeriods eventPeriods = new EventPeriods(getTimezones(), start, end,
- debug);
-
- for (EventInfo ei: events) {
- BwEvent ev = ei.getEvent();
- int type;
-
- if (ev.getEntityType() == CalFacadeDefs.entityTypeEvent) {
- if (BwEvent.statusCancelled.equals(ev.getStatus())) {
- // Ignore this one.
- continue;
- }
-
- type = BwFreeBusyComponent.typeBusy;
-
- 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(), ev.getOwner(),
- type);
- } else if (ev.getEntityType() == CalFacadeDefs.entityTypeFreeAndBusy) {
- Collection<BwFreeBusyComponent> fbcs = ev.getFreeBusyPeriods();
-
- for (BwFreeBusyComponent fbc: fbcs) {
- type = fbc.getType();
-
- for (Period p: fbc.getPeriods()) {
- eventPeriods.addPeriod(p.getStart(), p.getEnd(), ev.getOwner(),
- type);
- }
- }
- }
- }
-
- /* iterate through the sorted periods combining them where they are
- adjacent or overlap */
-
- BwFreeBusyComponent fbc = eventPeriods.makeFreeBusyComponent(BwFreeBusyComponent.typeBusy);
- if (fbc != null) {
- fb.addTime(fbc);
- }
-
- fbc = eventPeriods.makeFreeBusyComponent(BwFreeBusyComponent.typeBusyUnavailable);
- if (fbc != null) {
- fb.addTime(fbc);
- }
-
- fbc = eventPeriods.makeFreeBusyComponent(BwFreeBusyComponent.typeBusyTentative);
- if (fbc != null) {
- fb.addTime(fbc);
- }
- } catch (Throwable t) {
- if (debug) {
- error(t);
- }
- throw new CalFacadeException(t);
- }
-
- return fb;
- }
-
- private int getFreeBusyType(Collection periodEvents) {
- int fbtype = BwFreeBusyComponent.typeFree;
-
- Iterator it = periodEvents.iterator();
- while (it.hasNext()) {
- EventInfo ei = (EventInfo)it.next();
-
- String status = ei.getEvent().getStatus();
- if (status == null) {
- // FREEBUSY - is this OK?
- return BwFreeBusyComponent.typeBusy;
- }
-
- if (status.equals(BwEvent.statusConfirmed)) {
- return BwFreeBusyComponent.typeBusy;
- }
-
- if (status.equals(BwEvent.statusTentative)) {
- fbtype = BwFreeBusyComponent.typeBusyTentative;
- }
- }
-
- return fbtype;
- }
-
- /* ====================================================================
* Categories
* ==================================================================== */
@@ -2547,127 +2253,9 @@
}
/* ====================================================================
- * Package and protected methods
- * ==================================================================== */
-
- /** Get the current db session
- *
- * @return Object
- * @throws CalFacadeException
- */
- Object getDbSession() throws CalFacadeException {
- return getCal().getDbSession();
- }
-
- /* ====================================================================
* Private methods
* ==================================================================== */
- private Collection<EventInfo> getEvents(BwSubscription sub, BwFilter filter,
- BwDateTime startDate, BwDateTime endDate,
- RecurringRetrievalMode recurRetrieval,
- boolean freeBusy) throws CalFacadeException {
- TreeSet<EventInfo> ts = new TreeSet<EventInfo>();
- boolean showAllCalendars = true;
-
- if (sub != null) {
- // Explicitly selected calendar - via a subscription.
- getSubCalendar(sub, freeBusy);
-
- return postProcess(getCal(sub).getEvents(sub.getCalendar(), filter,
- startDate, endDate,
- recurRetrieval, freeBusy,
- !freeBusy),
- sub);
- }
-
- Collection<BwSubscription> subs = null;
-
- /* Through a view or the complete set of subscriptions. Do not include
- * 'special' calendars.
- */
-
- if (!isPublicAdmin() && currentView != null) {
- if (debug) {
- trace("Use current view \"" + currentView.getName() + "\"");
- }
-
- /* Don't show special calendars in views */
- showAllCalendars = false;
- subs = currentView.getSubscriptions();
- if (subs == null) {
- subs = new TreeSet<BwSubscription>();
- }
- } else {
- subs = getCurrentSubscriptions();
- if (subs == null) {
- // Try set of users subscriptions.
- if (debug) {
- trace("Use user subscriptions");
- }
-
- subs = getSubscriptions();
- } else if (debug) {
- trace("Use current subscriptions");
- }
-
- if (subs == null) {
- if (debug) {
- trace("Make up ALL events");
- }
-
- sub = new BwSubscription();
- sub.setName("All events"); // XXX property?
- sub.setDisplay(true);
- sub.setInternalSubscription(true);
-
- return postProcess(getCal().getEvents(null, filter, startDate,
- endDate, recurRetrieval,
- freeBusy, false),
- sub);
- }
- }
-
- /* Iterate over the subscriptions and merge the results.
- *
- * First we iterate over the subscriptions looking for internal calendars.
- * These we accumulate as children of a single calendar allowing a single
- * query for all calendars.
- *
- * We will then iterate again to handle external calendars. (Not implemented)
- */
- BwCalendar internal = new BwCalendar();
- setupSharableEntity(internal);
-
- // For locating subscriptions from calendar
- HashMap<Integer, BwSubscription> sublookup =
- new HashMap<Integer, BwSubscription>();
-
- for (BwSubscription s: subs) {
- BwCalendar calendar = getSubCalendar(s, freeBusy);
-
- if (calendar != null) {
- internal.addChild(calendar);
- putSublookup(sublookup, s, calendar);
- }
- }
-
- if (!internal.hasChildren()) {
- if (debug) {
- trace("No children for internal calendar");
- }
-
- return ts;
- }
-
- ts.addAll(postProcess(getCal().getEvents(internal, filter,
- startDate, endDate,
- recurRetrieval, freeBusy, showAllCalendars),
- sublookup));
-
- return ts;
- }
-
private BwCalendar getSubCalendar(BwSubscription val,
boolean freeBusy) throws CalFacadeException {
int desiredAccess = PrivilegeDefs.privRead;
@@ -3234,6 +2822,134 @@
* Package private methods
* ==================================================================== */
+ /** Get the current db session
+ *
+ * @return Object
+ * @throws CalFacadeException
+ */
+ Object getDbSession() throws CalFacadeException {
+ return getCal().getDbSession();
+ }
+
+ Collection<BwSubscription> getSubscriptions(BwUser user)
+ throws CalFacadeException {
+ Collection<BwSubscription> c = getUserPrefs(user).getSubscriptions();
+ if (c == null) {
+ return new TreeSet<BwSubscription>();
+ }
+
+ for (BwSubscription sub: c) {
+ getSubCalendar(sub);
+ }
+
+ return c;
+ }
+
+ Collection<EventInfo> getEvents(BwSubscription sub, BwFilter filter,
+ BwDateTime startDate, BwDateTime endDate,
+ RecurringRetrievalMode recurRetrieval,
+ boolean freeBusy) throws CalFacadeException {
+ TreeSet<EventInfo> ts = new TreeSet<EventInfo>();
+ boolean showAllCalendars = true;
+
+ if (sub != null) {
+ // Explicitly selected calendar - via a subscription.
+ getSubCalendar(sub, freeBusy);
+
+ return postProcess(getCal(sub).getEvents(sub.getCalendar(), filter,
+ startDate, endDate,
+ recurRetrieval, freeBusy,
+ !freeBusy),
+ sub);
+ }
+
+ Collection<BwSubscription> subs = null;
+
+ /* Through a view or the complete set of subscriptions. Do not include
+ * 'special' calendars.
+ */
+
+ if (!isPublicAdmin() && currentView != null) {
+ if (debug) {
+ trace("Use current view \"" + currentView.getName() + "\"");
+ }
+
+ /* Don't show special calendars in views */
+ showAllCalendars = false;
+ subs = currentView.getSubscriptions();
+ if (subs == null) {
+ subs = new TreeSet<BwSubscription>();
+ }
+ } else {
+ subs = getCurrentSubscriptions();
+ if (subs == null) {
+ // Try set of users subscriptions.
+ if (debug) {
+ trace("Use user subscriptions");
+ }
+
+ subs = getSubscriptions();
+ } else if (debug) {
+ trace("Use current subscriptions");
+ }
+
+ if (subs == null) {
+ if (debug) {
+ trace("Make up ALL events");
+ }
+
+ sub = new BwSubscription();
+ sub.setName("All events"); // XXX property?
+ sub.setDisplay(true);
+ sub.setInternalSubscription(true);
+
+ return postProcess(getCal().getEvents(null, filter, startDate,
+ endDate, recurRetrieval,
+ freeBusy, false),
+ sub);
+ }
+ }
+
+ /* Iterate over the subscriptions and merge the results.
+ *
+ * First we iterate over the subscriptions looking for internal calendars.
+ * These we accumulate as children of a single calendar allowing a single
+ * query for all calendars.
+ *
+ * We will then iterate again to handle external calendars. (Not implemented)
+ */
+ BwCalendar internal = new BwCalendar();
+ setupSharableEntity(internal);
+
+ // For locating subscriptions from calendar
+ HashMap<Integer, BwSubscription> sublookup =
+ new HashMap<Integer, BwSubscription>();
+
+ for (BwSubscription s: subs) {
+ BwCalendar calendar = getSubCalendar(s, freeBusy);
+
+ if (calendar != null) {
+ internal.addChild(calendar);
+ putSublookup(sublookup, s, calendar);
+ }
+ }
+
+ if (!internal.hasChildren()) {
+ if (debug) {
+ trace("No children for internal calendar");
+ }
+
+ return ts;
+ }
+
+ ts.addAll(postProcess(getCal().getEvents(internal, filter,
+ startDate, endDate,
+ recurRetrieval, freeBusy, showAllCalendars),
+ sublookup));
+
+ return ts;
+ }
+
EventUpdateResult addEvent(BwCalendar cal,
BwEvent event,
Collection<BwEventProxy> overrides,
@@ -3516,9 +3232,5 @@
private void error(String msg) {
getLogger().error(msg);
}
-
- private void error(Throwable t) {
- getLogger().error(this, t);
- }
}
Modified: trunk/calsvc/src/org/bedework/calsvc/Scheduling.java
===================================================================
--- trunk/calsvc/src/org/bedework/calsvc/Scheduling.java 2007-06-13 14:26:57 UTC (rev 310)
+++ trunk/calsvc/src/org/bedework/calsvc/Scheduling.java 2007-06-13 18:58:31 UTC (rev 311)
@@ -35,6 +35,7 @@
import org.bedework.calfacade.BwFreeBusy;
import org.bedework.calfacade.BwFreeBusyComponent;
import org.bedework.calfacade.BwLocation;
+import org.bedework.calfacade.BwPrincipal;
import org.bedework.calfacade.BwUser;
import org.bedework.calfacade.CalFacadeDefs;
import org.bedework.calfacade.RecurringRetrievalMode;
@@ -43,10 +44,14 @@
import org.bedework.calfacade.ScheduleResult.ScheduleRecipientResult;
import org.bedework.calfacade.exc.CalFacadeAccessException;
import org.bedework.calfacade.exc.CalFacadeException;
+import org.bedework.calfacade.filter.BwEntityTypeFilter;
+import org.bedework.calfacade.filter.BwFilter;
+import org.bedework.calfacade.filter.BwOrFilter;
import org.bedework.calfacade.svc.BwSubscription;
import org.bedework.calfacade.svc.EventInfo;
import org.bedework.calfacade.svc.prefs.BwPreferences;
import org.bedework.calfacade.util.CalFacadeUtil;
+import org.bedework.calfacade.util.EventPeriods;
import org.bedework.calfacade.util.Granulator;
import org.bedework.calfacade.util.Granulator.EventPeriod;
import org.bedework.calfacade.util.Granulator.GetPeriodsPars;
@@ -567,13 +572,174 @@
throw new CalFacadeException(t);
}
}
+ /* (non-Javadoc)
+ * @see org.bedework.calsvci.SchedulingI#getFreeBusy(java.util.Collection, org.bedework.calfacade.BwCalendar, org.bedework.calfacade.BwPrincipal, org.bedework.calfacade.BwDateTime, org.bedework.calfacade.BwDateTime)
+ */
+ public BwFreeBusy getFreeBusy(BwCalendar cal, BwPrincipal who,
+ BwDateTime start, BwDateTime end)
+ throws CalFacadeException {
+ if (!(who instanceof BwUser)) {
+ throw new CalFacadeException("Unsupported: non user principal for free-busy");
+ }
+ BwUser u = (BwUser)who;
+ Collection<BwSubscription> subs;
+
+ if (cal != null) {
+ /* Don't check - we do so at the fetch of events
+ getCal().checkAccess(cal, PrivilegeDefs.privReadFreeBusy, false);
+ */
+
+ BwSubscription sub = BwSubscription.makeSubscription(cal);
+
+ subs = new ArrayList<BwSubscription>();
+ subs.add(sub);
+ } else if (svci.getUser().equals(who)) {
+ subs = svci.getSubscriptions();
+ } else {
+ /* First see if we have free busy access to the users calendar */
+
+ /* XXX This needs to be brought into line with CalDAV.
+
+ cal = getCal().getCalendars(u, PrivilegeDefs.privReadFreeBusy);
+ if (cal == null) {
+ throw new CalFacadeAccessException();
+ }
+
+ getCal().checkAccess(cal, PrivilegeDefs.privReadFreeBusy, false);
+ */
+ /* CalDAV uses Inbox to determine scheduling acccess */
+ try {
+ svci.getSpecialCalendar(u,
+ BwCalendar.calTypeInbox,
+ true,
+ PrivilegeDefs.privReadFreeBusy);
+ } catch (CalFacadeAccessException cae) {
+ svci.getSpecialCalendar(u,
+ BwCalendar.calTypeInbox,
+ true,
+ PrivilegeDefs.privScheduleFreeBusy);
+ }
+
+ subs = svci.getSubscriptions(u);
+ }
+
+ BwFreeBusy fb = new BwFreeBusy(who, start, end);
+ svci.assignGuid(fb);
+
+ BwAttendee att = new BwAttendee();
+ att.setAttendeeUri(svci.getDirectories().userToCaladdr(who.getAccount()));
+ fb.addAttendee(att);
+
+ Collection<EventInfo> events = new TreeSet<EventInfo>();
+ /* Only events and freebusy for freebusy reports. */
+ BwFilter filter = new BwOrFilter();
+ filter.addChild(BwEntityTypeFilter.eventFilter(null, false));
+ filter.addChild(BwEntityTypeFilter.freebusyFilter(null, false));
+
+ for (BwSubscription sub: subs) {
+ if (!sub.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<EventInfo> evs = svci.getEvents(sub, filter, start, end, rrm, true);
+
+ // Filter out transparent events
+ for (EventInfo ei : evs) {
+ BwEvent ev = ei.getEvent();
+
+ if (!sub.getIgnoreTransparency() &&
+ BwEvent.transparencyTransparent.equals(ev.getTransparency())) {
+ // Ignore this one.
+ continue;
+ }
+
+ if (BwEvent.statusCancelled.equals(ev.getStatus())) {
+ // Ignore this one.
+ continue;
+ }
+
+ events.add(ei);
+ }
+ }
+
+ try {
+ EventPeriods eventPeriods = new EventPeriods(svci.getTimezones(),
+ start, end,
+ debug);
+
+ for (EventInfo ei: events) {
+ BwEvent ev = ei.getEvent();
+ int type;
+
+ if (ev.getEntityType() == CalFacadeDefs.entityTypeEvent) {
+ if (BwEvent.statusCancelled.equals(ev.getStatus())) {
+ // Ignore this one.
+ continue;
+ }
+
+ type = BwFreeBusyComponent.typeBusy;
+
+ 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(), ev.getOwner(),
+ type);
+ } else if (ev.getEntityType() == CalFacadeDefs.entityTypeFreeAndBusy) {
+ Collection<BwFreeBusyComponent> fbcs = ev.getFreeBusyPeriods();
+
+ for (BwFreeBusyComponent fbc: fbcs) {
+ type = fbc.getType();
+
+ for (Period p: fbc.getPeriods()) {
+ eventPeriods.addPeriod(p.getStart(), p.getEnd(), ev.getOwner(),
+ type);
+ }
+ }
+ }
+ }
+
+ /* iterate through the sorted periods combining them where they are
+ adjacent or overlap */
+
+ BwFreeBusyComponent fbc = eventPeriods.makeFreeBusyComponent(BwFreeBusyComponent.typeBusy);
+ if (fbc != null) {
+ fb.addTime(fbc);
+ }
+
+ fbc = eventPeriods.makeFreeBusyComponent(BwFreeBusyComponent.typeBusyUnavailable);
+ if (fbc != null) {
+ fb.addTime(fbc);
+ }
+
+ fbc = eventPeriods.makeFreeBusyComponent(BwFreeBusyComponent.typeBusyTentative);
+ if (fbc != null) {
+ fb.addTime(fbc);
+ }
+ } catch (Throwable t) {
+ if (debug) {
+ error(t);
+ }
+ throw new CalFacadeException(t);
+ }
+
+ return fb;
+ }
+
/* (non-Javadoc)
- * @see org.bedework.calsvci.SchedulingI#getFreeBusy(org.bedework.calfacade.ScheduleResult, org.bedework.calfacade.BwDateTime, org.bedework.calfacade.BwDateTime, org.bedework.calfacade.BwDuration)
+ * @see org.bedework.calsvci.SchedulingI#aggregateFreeBusy(org.bedework.calfacade.ScheduleResult, org.bedework.calfacade.BwDateTime, org.bedework.calfacade.BwDateTime, org.bedework.calfacade.BwDuration)
*/
- public FbResponses getFreeBusy(ScheduleResult sr,
- BwDateTime start, BwDateTime end,
- BwDuration granularity) throws CalFacadeException {
+ public FbResponses aggregateFreeBusy(ScheduleResult sr,
+ BwDateTime start, BwDateTime end,
+ BwDuration granularity) throws CalFacadeException {
FbResponses resps = new FbResponses();
if (start.getDateType() || end.getDateType()) {
@@ -707,9 +873,7 @@
fbresp.setStart(start);
fbresp.setEnd(end);
- GetPeriodsPars gpp = new GetPeriodsPars();
Collection<EventPeriod> periods = new ArrayList<EventPeriod>();
- gpp.periods = periods;
if (fb.getTimes() != null) {
for (BwFreeBusyComponent fbcomp: fb.getTimes()) {
@@ -737,6 +901,9 @@
}
}
+ GetPeriodsPars gpp = new GetPeriodsPars();
+
+ gpp.periods = periods;
gpp.startDt = start;
gpp.dur = granularity;
gpp.tzcache = svci.getTimezones();
@@ -875,20 +1042,15 @@
if (ui.status == ScheduleRecipientResult.scheduleUnprocessed) {
try {
if (freeBusyRequest) {
- sres.freeBusy = svci.getFreeBusy(null, null, ui.user,
- event.getDtstart(), event.getDtend(),
- null, false);
+ sres.freeBusy = getFreeBusy(null, ui.user,
+ event.getDtstart(), event.getDtend());
} else if (!ui.account.equals(svci.getUser().getAccount())) {
addToInbox(ui, event);
}
ui.status = ScheduleRecipientResult.scheduleOk;
} catch (CalFacadeAccessException cae) {
- // Changed on us
ui.status = ScheduleRecipientResult.scheduleNoAccess;
- sr.errorCode = CalFacadeException.schedulingAttendeeAccessDisallowed;
- svci.rollbackTransaction();
- return externalRcs;
}
}
Modified: trunk/calsvci/src/org/bedework/calsvci/CalSvcI.java
===================================================================
--- trunk/calsvci/src/org/bedework/calsvci/CalSvcI.java 2007-06-13 14:26:57 UTC (rev 310)
+++ trunk/calsvci/src/org/bedework/calsvci/CalSvcI.java 2007-06-13 18:58:31 UTC (rev 311)
@@ -58,12 +58,9 @@
import org.bedework.calfacade.BwCalendar;
import org.bedework.calfacade.BwCategory;
import org.bedework.calfacade.BwDateTime;
-import org.bedework.calfacade.BwDuration;
import org.bedework.calfacade.BwEvent;
import org.bedework.calfacade.BwEventProxy;
-import org.bedework.calfacade.BwFreeBusy;
import org.bedework.calfacade.BwLocation;
-import org.bedework.calfacade.BwPrincipal;
import org.bedework.calfacade.BwContact;
import org.bedework.calfacade.BwStats;
import org.bedework.calfacade.BwString;
@@ -1016,15 +1013,6 @@
*/
public abstract Collection<BwSubscription> getSubscriptions() throws CalFacadeException;
- /** Get the given users subscription.
- *
- * @param user BwUser
- * @return Collection of subscriptions
- * @throws CalFacadeException
- */
- public abstract Collection<BwSubscription> getSubscriptions(BwUser user)
- throws CalFacadeException;
-
/** Fetch the subscription from the db given an id
*
* @param id
@@ -1050,38 +1038,6 @@
public abstract BwCalendar getSubCalendar(BwSubscription val) throws CalFacadeException;
/* ====================================================================
- * Free busy
- * ==================================================================== */
-
- /** Get the free busy for the given principal. A granularity of null results
- * in a list of busy periods. Otherwise the start to end time is divided up
- * into granularity sized chunks which will only be reported if one or more
- * events fall in the segment.
- *
- * @param subs If non-null use these as the subscriptions.
- * @param cal Calendar to provide free-busy for. Null for the user root
- * for default collection (as specified by user).
- * Used for local access to a given calendar via e.g. caldav
- * @param who If sub and cal are null get the info for this user, otherwise
- * this is used as the free/busy result owner
- * @param start
- * @param end
- * @param granularity BwDuration object defining how to divide free/busy
- * null for one big glob. or set to e.g. 1 hour for
- * hourly chunks.
- * @param returnAll if true return entries for free time otherwise just for busy
- * (only for granularity not null)
- * @return BwFreeBusy
- * @throws CalFacadeException
- */
- public abstract BwFreeBusy getFreeBusy(Collection<BwSubscription> subs,
- BwCalendar cal, BwPrincipal who,
- BwDateTime start, BwDateTime end,
- BwDuration granularity,
- boolean returnAll)
- throws CalFacadeException;
-
- /* ====================================================================
* Categories
* ==================================================================== */
Modified: trunk/calsvci/src/org/bedework/calsvci/SchedulingI.java
===================================================================
--- trunk/calsvci/src/org/bedework/calsvci/SchedulingI.java 2007-06-13 14:26:57 UTC (rev 310)
+++ trunk/calsvci/src/org/bedework/calsvci/SchedulingI.java 2007-06-13 18:58:31 UTC (rev 311)
@@ -31,6 +31,7 @@
import org.bedework.calfacade.BwDuration;
import org.bedework.calfacade.BwEvent;
import org.bedework.calfacade.BwFreeBusy;
+import org.bedework.calfacade.BwPrincipal;
import org.bedework.calfacade.ScheduleResult;
import org.bedework.calfacade.exc.CalFacadeException;
import org.bedework.calfacade.util.Granulator.EventPeriod;
@@ -121,6 +122,22 @@
*/
public ScheduleResult scheduleResponse(BwEvent event) throws CalFacadeException;
+ /** Get the free busy for the given principal as a list of busy periods.
+ *
+ * @param cal Calendar to provide free-busy for. Null for the user root
+ * for default collection (as specified by user).
+ * Used for local access to a given calendar via e.g. caldav
+ * @param who If cal is null get the info for this user, otherwise
+ * this is used as the free/busy result owner
+ * @param start
+ * @param end
+ * @return BwFreeBusy
+ * @throws CalFacadeException
+ */
+ public BwFreeBusy getFreeBusy(BwCalendar cal, BwPrincipal who,
+ BwDateTime start, BwDateTime end)
+ throws CalFacadeException;
+
/** Used for user interface. Result of dividing VFREEBUSY into equal sized
* chunks.
*
@@ -271,9 +288,9 @@
* @return FbResponses
* @throws CalFacadeException
*/
- public FbResponses getFreeBusy(ScheduleResult sr,
- BwDateTime start, BwDateTime end,
- BwDuration granularity) throws CalFacadeException;
+ public FbResponses aggregateFreeBusy(ScheduleResult sr,
+ BwDateTime start, BwDateTime end,
+ BwDuration granularity) throws CalFacadeException;
/** Granulate (divide into equal chunks and return the result. The response
* from the original request may be for a different time range than requested.
More information about the Bedework-commit
mailing list