use of org.bedework.calfacade.RecurringRetrievalMode in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method getRrm.
private RecurringRetrievalMode getRrm(final RetrievalMode rm) throws WebdavException {
if (rm == null) {
return RecurringRetrievalMode.overrides;
}
try {
if (rm.getExpand() != null) {
/* expand with time range */
ExpandType ex = rm.getExpand();
DateTime s = new DateTime(XcalUtil.getIcalFormatDateTime(ex.getStart()));
DateTime e = new DateTime(XcalUtil.getIcalFormatDateTime(ex.getEnd()));
return new RecurringRetrievalMode(Rmode.expanded, getBwDt(s), getBwDt(e));
}
if (rm.getLimitRecurrenceSet() != null) {
/* Only return master event and overrides in range */
LimitRecurrenceSetType l = rm.getLimitRecurrenceSet();
DateTime s = new DateTime(XcalUtil.getIcalFormatDateTime(l.getStart()));
DateTime e = new DateTime(XcalUtil.getIcalFormatDateTime(l.getEnd()));
return new RecurringRetrievalMode(Rmode.overrides, getBwDt(s), getBwDt(e));
}
} catch (Throwable t) {
throw new WebdavBadRequest(CaldavTags.validFilter, "Invalid time-range");
}
/* Return master + overrides */
return RecurringRetrievalMode.overrides;
}
use of org.bedework.calfacade.RecurringRetrievalMode 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;
}
use of org.bedework.calfacade.RecurringRetrievalMode in project bw-calendar-engine by Bedework.
the class CalintfImpl method getFreeBusyEntities.
private Collection<CoreEventInfo> getFreeBusyEntities(final Collection<BwCalendar> cals, final BwDateTime start, final BwDateTime end, final boolean ignoreTransparency) throws CalFacadeException {
/* Only events and freebusy for freebusy reports. */
final FilterBase filter = new OrFilter();
try {
filter.addChild(EntityTypeFilter.makeEntityTypeFilter(null, "event", false));
filter.addChild(EntityTypeFilter.makeEntityTypeFilter(null, "freeAndBusy", false));
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
final RecurringRetrievalMode rrm = new RecurringRetrievalMode(Rmode.expanded, start, end);
final Collection<CoreEventInfo> evs = getEvents(cals, filter, start, end, null, DeletedState.noDeleted, rrm, true);
// Filter out transparent and cancelled events
final Collection<CoreEventInfo> events = new TreeSet<>();
for (final CoreEventInfo cei : evs) {
final BwEvent ev = cei.getEvent();
if (!ignoreTransparency && IcalDefs.transparencyTransparent.equals(ev.getPeruserTransparency(this.getPrincipal().getPrincipalRef()))) {
// Ignore this one.
continue;
}
if (ev.getSuppressed() || BwEvent.statusCancelled.equals(ev.getStatus())) {
// Ignore this one.
continue;
}
events.add(cei);
}
return events;
}
Aggregations