Search in sources :

Example 11 with BwEventObj

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;
}
Also used : EventPeriod(org.bedework.calfacade.util.Granulator.EventPeriod) BwFreeBusyComponent(org.bedework.calfacade.BwFreeBusyComponent) BwDateTime(org.bedework.calfacade.BwDateTime) CoreEventInfo(org.bedework.calcorei.CoreEventInfo) Period(net.fortuna.ical4j.model.Period) EventPeriod(org.bedework.calfacade.util.Granulator.EventPeriod) BwEvent(org.bedework.calfacade.BwEvent) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) DateTime(net.fortuna.ical4j.model.DateTime) BwDateTime(org.bedework.calfacade.BwDateTime) TreeSet(java.util.TreeSet) BwEventObj(org.bedework.calfacade.BwEventObj)

Example 12 with BwEventObj

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);
    }
}
Also used : BwDateTime(org.bedework.calfacade.BwDateTime) BwEvent(org.bedework.calfacade.BwEvent) InstancesResponse(org.bedework.calfacade.responses.InstancesResponse) RecurPeriods(org.bedework.icalendar.RecurUtil.RecurPeriods) BwEventObj(org.bedework.calfacade.BwEventObj)

Example 13 with BwEventObj

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;
}
Also used : ScheduleResult(org.bedework.calfacade.ScheduleResult) EventInfo(org.bedework.calfacade.svc.EventInfo) BwRequestStatus(org.bedework.calfacade.BwRequestStatus) BwEvent(org.bedework.calfacade.BwEvent) BwString(org.bedework.calfacade.BwString) BwAttendee(org.bedework.calfacade.BwAttendee) BwEventObj(org.bedework.calfacade.BwEventObj)

Example 14 with BwEventObj

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;
}
Also used : ScheduleResult(org.bedework.calfacade.ScheduleResult) EventInfo(org.bedework.calfacade.svc.EventInfo) BwEvent(org.bedework.calfacade.BwEvent) BwString(org.bedework.calfacade.BwString) BwAttendee(org.bedework.calfacade.BwAttendee) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) BwEventObj(org.bedework.calfacade.BwEventObj)

Aggregations

BwEventObj (org.bedework.calfacade.BwEventObj)14 BwEvent (org.bedework.calfacade.BwEvent)13 EventInfo (org.bedework.calfacade.svc.EventInfo)10 BwAttendee (org.bedework.calfacade.BwAttendee)5 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)5 Period (net.fortuna.ical4j.model.Period)3 BwEventProxy (org.bedework.calfacade.BwEventProxy)3 BwFreeBusyComponent (org.bedework.calfacade.BwFreeBusyComponent)3 BwOrganizer (org.bedework.calfacade.BwOrganizer)3 BwString (org.bedework.calfacade.BwString)3 ArrayList (java.util.ArrayList)2 TreeSet (java.util.TreeSet)2 VFreeBusy (net.fortuna.ical4j.model.component.VFreeBusy)2 BwCalendar (org.bedework.calfacade.BwCalendar)2 BwDateTime (org.bedework.calfacade.BwDateTime)2 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)2 ScheduleResult (org.bedework.calfacade.ScheduleResult)2 ChangeTable (org.bedework.calfacade.util.ChangeTable)2 EventPeriod (org.bedework.calfacade.util.Granulator.EventPeriod)2 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)2