Search in sources :

Example 1 with ScheduleRecipientResult

use of org.bedework.calfacade.ScheduleResult.ScheduleRecipientResult in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method checkStatus.

/**
 * @param sr schedule result
 * @return recipient results
 * @throws WebdavException
 */
private Collection<SchedRecipientResult> checkStatus(final ScheduleResult sr) throws WebdavException {
    if ((sr.errorCode == null) || (sr.errorCode.equals(CalFacadeException.schedulingNoRecipients))) {
        final Collection<SchedRecipientResult> srrs = new ArrayList<>();
        for (final ScheduleRecipientResult bwsrr : sr.recipientResults.values()) {
            final SchedRecipientResult srr = new SchedRecipientResult();
            srr.recipient = bwsrr.recipient;
            srr.status = bwsrr.getStatus();
            if (bwsrr.freeBusy != null) {
                srr.freeBusy = new BwCalDAVEvent(this, new EventInfo(bwsrr.freeBusy));
            }
            srrs.add(srr);
        }
        return srrs;
    }
    if (sr.errorCode.equals(CalFacadeException.schedulingBadMethod)) {
        throw new WebdavForbidden(CaldavTags.validCalendarData, "Bad METHOD");
    }
    if (sr.errorCode.equals(CalFacadeException.schedulingBadAttendees)) {
        throw new WebdavForbidden(CaldavTags.attendeeAllowed, "Bad attendees");
    }
    if (sr.errorCode.equals(CalFacadeException.schedulingAttendeeAccessDisallowed)) {
        throw new WebdavForbidden(CaldavTags.attendeeAllowed, "attendeeAccessDisallowed");
    }
    throw new WebdavForbidden(sr.errorCode);
}
Also used : ScheduleRecipientResult(org.bedework.calfacade.ScheduleResult.ScheduleRecipientResult) EventInfo(org.bedework.calfacade.svc.EventInfo) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) ArrayList(java.util.ArrayList)

Example 2 with ScheduleRecipientResult

use of org.bedework.calfacade.ScheduleResult.ScheduleRecipientResult in project bw-calendar-engine by Bedework.

the class OutboundSchedulingHandler method sendSchedule.

/* Send the meeting request. If recipient is non-null send only to that recipient
   * (used for REFRESH handling), otherwise send to recipients in event.
   */
protected void sendSchedule(final ScheduleResult sr, final EventInfo ei, final String recipient, final String fromAttUri, final boolean fromOrganizer) throws CalFacadeException {
    /* Recipients external to the system. */
    final BwEvent ev = ei.getEvent();
    final boolean freeBusyRequest = ev.getEntityType() == IcalDefs.entityTypeFreeAndBusy;
    ev.updateDtstamp();
    if (recipient != null) {
        getRecipientInbox(ei, recipient, fromAttUri, sr, freeBusyRequest);
    } else if (ev.getRecipients() == null) {
        return;
    } else {
        for (final String recip : ev.getRecipients()) {
            getRecipientInbox(ei, recip, fromAttUri, sr, freeBusyRequest);
        }
    }
    /* As we go through the inbox info, we gather together those for the same
     * host but external to this system.
     *
     * We then send off one request to each external host.
     */
    final Map<String, Collection<UserInbox>> hostMap = new HashMap<>();
    for (final ScheduleRecipientResult sres : sr.recipientResults.values()) {
        final UserInbox ui = (UserInbox) sres;
        if (sr.ignored) {
            ui.setStatus(ScheduleStates.scheduleIgnored);
            continue;
        }
        if (ui.getStatus() == ScheduleStates.scheduleUnprocessed) {
            if (ui.getHost() != null) {
                /* Needs to be sent to an external destination. Add it
           * to the list of inboxes for that host.
           */
                Collection<UserInbox> inboxes = hostMap.get(ui.getHost().getHostname());
                if (inboxes == null) {
                    inboxes = new ArrayList<>();
                    hostMap.put(ui.getHost().getHostname(), inboxes);
                }
                inboxes.add(ui);
                continue;
            }
            /* Going to an internal destination */
            String deliveryStatus = null;
            try {
                if (freeBusyRequest) {
                    sres.freeBusy = getFreeBusy(null, ui.principal, ev.getDtstart(), ev.getDtend(), ev.getOrganizer(), ev.getUid(), null);
                    ui.setStatus(ScheduleStates.scheduleOk);
                } else if (!ui.principal.getPrincipalRef().equals(getPrincipal().getPrincipalRef())) {
                    if (addToInbox(ui.inboxPath, ui.principal, ei, fromOrganizer) == null) {
                        ui.setStatus(ScheduleStates.scheduleOk);
                        deliveryStatus = IcalDefs.deliveryStatusDelivered;
                    } else {
                        ui.setStatus(ScheduleStates.scheduleError);
                        deliveryStatus = IcalDefs.deliveryStatusFailed;
                    }
                } else {
                    // That's us
                    ui.setAttendeeScheduleStatus(null);
                    ui.setStatus(ScheduleStates.scheduleOk);
                }
            } catch (CalFacadeAccessException cae) {
                ui.setStatus(ScheduleStates.scheduleNoAccess);
                deliveryStatus = IcalDefs.deliveryStatusNoAccess;
            }
            if (fromOrganizer) {
                if (deliveryStatus != null) {
                    ui.setAttendeeScheduleStatus(deliveryStatus);
                }
            } else {
            // ev.getOrganizer().setScheduleStatus(deliveryStatus);
            }
        }
        if (debug) {
            trace("added recipient " + ui.recipient + " status = " + ui.getStatus());
        }
    }
    for (final Collection<UserInbox> inboxes : hostMap.values()) {
        /* Send any ischedule requests to external servers. */
        sendExternalRequest(sr, ei, inboxes);
    }
}
Also used : ScheduleRecipientResult(org.bedework.calfacade.ScheduleResult.ScheduleRecipientResult) HashMap(java.util.HashMap) Collection(java.util.Collection) BwEvent(org.bedework.calfacade.BwEvent) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException)

Example 3 with ScheduleRecipientResult

use of org.bedework.calfacade.ScheduleResult.ScheduleRecipientResult in project bw-calendar-engine by Bedework.

the class FreeAndBusyHandler method aggregateFreeBusy.

/* (non-Javadoc)
   * @see org.bedework.calsvci.SchedulingI#aggregateFreeBusy(org.bedework.calfacade.ScheduleResult, org.bedework.calfacade.BwDateTime, org.bedework.calfacade.BwDateTime, org.bedework.calfacade.BwDuration)
   */
@Override
public FbResponses aggregateFreeBusy(final ScheduleResult sr, final BwDateTime start, final BwDateTime end, final BwDuration granularity) throws CalFacadeException {
    FbResponses resps = new FbResponses();
    if (start.getDateType() || end.getDateType()) {
        throw new CalFacadeException(CalFacadeException.schedulingBadGranulatorDt);
    }
    resps.setResponses(new ArrayList<FbGranulatedResponse>());
    /* Combine the responses into one big collection */
    FbGranulatedResponse allResponses = new FbGranulatedResponse();
    allResponses.setStart(start);
    allResponses.setEnd(end);
    resps.setAggregatedResponse(allResponses);
    for (ScheduleRecipientResult srr : sr.recipientResults.values()) {
        FbGranulatedResponse fb = new FbGranulatedResponse();
        resps.getResponses().add(fb);
        fb.setRespCode(srr.getStatus());
        fb.setNoResponse(srr.freeBusy == null);
        fb.setRecipient(srr.recipient);
        if (!fb.okResponse()) {
            continue;
        }
        if (srr.freeBusy.getNumAttendees() == 1) {
            fb.setAttendee(srr.freeBusy.getAttendees().iterator().next());
        }
        granulateFreeBusy(fb, srr.freeBusy, start, end, granularity);
        if (fb.getStart() == null) {
            continue;
        }
        boolean first = false;
        if (allResponses.eps.isEmpty()) {
            first = true;
        }
        // Merge resp into allResponses - they should have the same start/end
        Iterator<EventPeriod> allIt = allResponses.eps.iterator();
        for (EventPeriod respEp : fb.eps) {
            EventPeriod allEp;
            if (first) {
                // Just set the event period from this first response.
                allResponses.eps.add(respEp);
                allEp = respEp;
                continue;
            }
            // Merge this response period into the corresponding aggregated response
            allEp = allIt.next();
            // Validity check
            if (!allEp.getStart().equals(respEp.getStart()) || !allEp.getEnd().equals(respEp.getEnd())) {
                throw new CalFacadeException(CalFacadeException.schedulingBadResponse);
            }
            if ((respEp.getType() == BwFreeBusyComponent.typeBusy) || (respEp.getType() == BwFreeBusyComponent.typeBusyUnavailable)) {
                allEp.setNumBusy(allEp.getNumBusy() + 1);
            } else if (respEp.getType() == BwFreeBusyComponent.typeBusyTentative) {
                allEp.setNumTentative(allEp.getNumTentative() + 1);
            }
            allEp.setType(typeTable[allEp.getType()][respEp.getType()]);
        }
    }
    return resps;
}
Also used : ScheduleRecipientResult(org.bedework.calfacade.ScheduleResult.ScheduleRecipientResult) EventPeriod(org.bedework.calfacade.util.Granulator.EventPeriod) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

ScheduleRecipientResult (org.bedework.calfacade.ScheduleResult.ScheduleRecipientResult)3 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 BwEvent (org.bedework.calfacade.BwEvent)1 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)1 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)1 EventInfo (org.bedework.calfacade.svc.EventInfo)1 EventPeriod (org.bedework.calfacade.util.Granulator.EventPeriod)1 WebdavForbidden (org.bedework.webdav.servlet.shared.WebdavForbidden)1