use of org.bedework.calfacade.BwEventObj in project bw-calendar-engine by Bedework.
the class CalintfImpl method getFreeBusy.
/* ====================================================================
* Free busy
* ==================================================================== */
@Override
public BwEvent getFreeBusy(final Collection<BwCalendar> cals, final BwPrincipal who, final BwDateTime start, final BwDateTime end, final boolean returnAll, final boolean ignoreTransparency) throws CalFacadeException {
if (who.getKind() != WhoDefs.whoTypeUser) {
throw new CalFacadeException("Unsupported: non user principal for free-busy");
}
final Collection<CoreEventInfo> events = getFreeBusyEntities(cals, start, end, ignoreTransparency);
final BwEvent fb = new BwEventObj();
fb.setEntityType(IcalDefs.entityTypeFreeAndBusy);
fb.setOwnerHref(who.getPrincipalRef());
fb.setDtstart(start);
fb.setDtend(end);
try {
final TreeSet<EventPeriod> eventPeriods = new TreeSet<>();
for (final CoreEventInfo ei : events) {
final BwEvent ev = ei.getEvent();
// Ignore if times were specified and this event is outside the times
final BwDateTime estart = ev.getDtstart();
final BwDateTime eend = ev.getDtend();
/* Don't report out of the requested period */
final String dstart;
final String dend;
if (estart.before(start)) {
dstart = start.getDtval();
} else {
dstart = estart.getDtval();
}
if (eend.after(end)) {
dend = end.getDtval();
} else {
dend = eend.getDtval();
}
final DateTime psdt = new DateTime(dstart);
final DateTime pedt = new DateTime(dend);
psdt.setUtc(true);
pedt.setUtc(true);
int type = BwFreeBusyComponent.typeBusy;
if (BwEvent.statusTentative.equals(ev.getStatus())) {
type = BwFreeBusyComponent.typeBusyTentative;
}
eventPeriods.add(new EventPeriod(psdt, pedt, type));
}
/* iterate through the sorted periods combining them where they are
adjacent or overlap */
Period p = null;
/* For the moment just build a single BwFreeBusyComponent
*/
BwFreeBusyComponent fbc = null;
int lastType = 0;
for (final EventPeriod ep : eventPeriods) {
if (debug) {
debug(ep.toString());
}
if (p == null) {
p = new Period(ep.getStart(), ep.getEnd());
lastType = ep.getType();
} else if ((lastType != ep.getType()) || ep.getStart().after(p.getEnd())) {
// Non adjacent periods
if (fbc == null) {
fbc = new BwFreeBusyComponent();
fbc.setType(lastType);
fb.addFreeBusyPeriod(fbc);
}
fbc.addPeriod(p.getStart(), p.getEnd());
if (lastType != ep.getType()) {
fbc = null;
}
p = new Period(ep.getStart(), ep.getEnd());
lastType = ep.getType();
} else if (ep.getEnd().after(p.getEnd())) {
// Extend the current period
p = new Period(p.getStart(), ep.getEnd());
}
// else it falls within the existing period
}
if (p != null) {
if ((fbc == null) || (lastType != fbc.getType())) {
fbc = new BwFreeBusyComponent();
fbc.setType(lastType);
fb.addFreeBusyPeriod(fbc);
}
fbc.addPeriod(p.getStart(), p.getEnd());
}
} catch (final Throwable t) {
if (debug) {
error(t);
}
throw new CalFacadeException(t);
}
return fb;
}
use of org.bedework.calfacade.BwEventObj in project bw-calendar-engine by Bedework.
the class Events method getInstances.
@Override
public InstancesResponse getInstances(final GetInstancesRequest req) {
final InstancesResponse resp = new InstancesResponse();
resp.setId(req.getId());
if (!req.validate(resp)) {
return resp;
}
// Use a BwEvent to build the instance set
final BwEvent ev = new BwEventObj();
try {
final BwDateTime st = req.getStartDt();
ev.setDtstart(st);
ev.setDtend(req.getEndDt());
ev.addRrule(req.getRrule());
if (!Util.isEmpty(req.getExdates())) {
for (final String dt : req.getExdates()) {
ev.addExdate(BwDateTime.makeBwDateTime(st.getDateType(), dt, st.getTzid()));
}
}
if (!Util.isEmpty(req.getRdates())) {
for (final String dt : req.getRdates()) {
ev.addRdate(BwDateTime.makeBwDateTime(st.getDateType(), dt, st.getTzid()));
}
}
final RecurPeriods rp = RecurUtil.getPeriods(ev, getAuthpars().getMaxYears(), getAuthpars().getMaxInstances(), req.getBegin(), req.getEnd());
resp.setInstances(rp.instances);
return resp;
} catch (final Throwable t) {
return Response.error(resp, t);
}
}
use of org.bedework.calfacade.BwEventObj in project bw-calendar-engine by Bedework.
the class ImplicitSchedulingHandler method sendReply.
/* (non-Javadoc)
* @see org.bedework.calsvci.SchedulingI#sendReply(org.bedework.calfacade.svc.EventInfo, int, java.lang.String)
*/
@Override
public ScheduleResult sendReply(final EventInfo ei, final int partstat, final String comment) throws CalFacadeException {
ScheduleResult sr = new ScheduleResult();
BwEvent ev = ei.getEvent();
if (!ev.getAttendeeSchedulingObject()) {
sr.errorCode = CalFacadeException.schedulingBadMethod;
return sr;
}
BwAttendee att = findUserAttendee(ev);
if (att == null) {
sr.errorCode = CalFacadeException.schedulingNotAttendee;
return sr;
}
att = (BwAttendee) att.clone();
att.setPartstat(IcalDefs.partstats[partstat]);
att.setRsvp(partstat == IcalDefs.partstatNeedsAction);
BwEvent outEv = new BwEventObj();
EventInfo outEi = new EventInfo(outEv);
outEv.setScheduleMethod(ScheduleMethods.methodTypeReply);
outEv.addRequestStatus(new BwRequestStatus(IcalDefs.requestStatusSuccess.getCode(), IcalDefs.requestStatusSuccess.getDescription()));
outEv.addRecipient(ev.getOrganizer().getOrganizerUri());
outEv.setOriginator(att.getAttendeeUri());
outEv.updateDtstamp();
outEv.setOrganizer((BwOrganizer) ev.getOrganizer().clone());
outEv.getOrganizer().setDtstamp(outEv.getDtstamp());
outEv.addAttendee(att);
outEv.setUid(ev.getUid());
outEv.setRecurrenceId(ev.getRecurrenceId());
outEv.setDtstart(ev.getDtstart());
outEv.setDtend(ev.getDtend());
outEv.setDuration(ev.getDuration());
outEv.setNoStart(ev.getNoStart());
outEv.setSummary(ev.getSummary());
outEv.setRecurring(false);
if (comment != null) {
outEv.addComment(new BwString(null, comment));
}
sr = scheduleResponse(outEi);
outEv.setScheduleState(BwEvent.scheduleStateProcessed);
return sr;
}
use of org.bedework.calfacade.BwEventObj in project bw-calendar-engine by Bedework.
the class AttendeeSchedulingHandler method requestRefresh.
@Override
public ScheduleResult requestRefresh(final EventInfo ei, final String comment) throws CalFacadeException {
ScheduleResult sr = new ScheduleResult();
BwEvent ev = ei.getEvent();
if (ev.getScheduleMethod() != ScheduleMethods.methodTypeRequest) {
sr.errorCode = CalFacadeException.schedulingBadMethod;
return sr;
}
BwAttendee att = findUserAttendee(ev);
if (att == null) {
throw new CalFacadeException(CalFacadeException.schedulingNotAttendee);
}
BwEvent outEv = new BwEventObj();
EventInfo outEi = new EventInfo(outEv);
outEv.setScheduleMethod(ScheduleMethods.methodTypeRefresh);
outEv.addRecipient(ev.getOrganizer().getOrganizerUri());
outEv.setOriginator(att.getAttendeeUri());
outEv.updateDtstamp();
outEv.setOrganizer((BwOrganizer) ev.getOrganizer().clone());
outEv.getOrganizer().setDtstamp(outEv.getDtstamp());
outEv.addAttendee((BwAttendee) att.clone());
outEv.setUid(ev.getUid());
outEv.setRecurrenceId(ev.getRecurrenceId());
outEv.setDtstart(ev.getDtstart());
outEv.setDtend(ev.getDtend());
outEv.setDuration(ev.getDuration());
outEv.setNoStart(ev.getNoStart());
outEv.setRecurring(false);
if (comment != null) {
outEv.addComment(new BwString(null, comment));
}
sr = scheduleResponse(outEi);
outEv.setScheduleState(BwEvent.scheduleStateProcessed);
return sr;
}
Aggregations