use of org.bedework.calsvc.scheduling.hosts.Response in project bw-calendar-engine by Bedework.
the class IScheduleHandler method sendExternalRequest.
/* External iSchedule requests */
protected void sendExternalRequest(final ScheduleResult sr, final EventInfo ei, final Collection<UserInbox> inboxes) throws CalFacadeException {
/* Each entry in inboxes should have the same hostinfo */
HostInfo hi = null;
final BwEvent ev = ei.getEvent();
final boolean freeBusyRequest = ev.getEntityType() == IcalDefs.entityTypeFreeAndBusy;
Set<String> recipients = null;
/*
class Request {
HostInfo hi;
String url;
String content;
}
*/
final HashMap<String, UserInbox> uimap = new HashMap<>();
/* For realtime or caldav we make up a single meeting request or freebusy request.
* For freebusy url we just execute one url at a time
*/
for (final UserInbox ui : inboxes) {
if (hi == null) {
// First time
hi = ui.host;
if (hi.getSupportsBedework() || hi.getSupportsCaldav() || hi.getSupportsISchedule()) {
recipients = new TreeSet<>();
}
}
if (recipients == null) {
// request per recipient - only freebusy
if (debug) {
trace("freebusy request to " + hi.getFbUrl() + " for " + ui.recipient);
}
} else {
recipients.add(ui.recipient);
uimap.put(ui.recipient, ui);
}
}
if (recipients == null) {
// No ischedule requests
return;
}
if (debug) {
final String meth;
if (freeBusyRequest) {
meth = "freebusy";
} else {
meth = "meeting";
}
trace(meth + " request to " + hi.getFbUrl() + " for " + recipients);
}
final EventInfo cei = copyEventInfo(ei, getPrincipal());
cei.getEvent().setRecipients(recipients);
final Response r;
if (freeBusyRequest) {
try {
r = getCalDavClient().getFreeBusy(hi, cei);
} catch (final CalFacadeException cfe) {
error(cfe);
return;
}
for (final ResponseElement re : r.getResponses()) {
final UserInbox ui = uimap.get(re.getRecipient());
if (ui == null) {
continue;
}
if (re.getCalData() == null) {
ui.setStatus(ScheduleStates.scheduleUnprocessed);
continue;
}
ui.freeBusy = re.getCalData().getEvent();
ui.setStatus(ScheduleStates.scheduleOk);
sr.externalRcs.remove(ui.recipient);
}
return;
}
try {
r = getCalDavClient().scheduleMeeting(hi, cei);
} catch (final CalFacadeException cfe) {
error(cfe);
return;
}
for (final ResponseElement re : r.getResponses()) {
final UserInbox ui = uimap.get(re.getRecipient());
if (ui == null) {
continue;
}
ui.setStatus(ScheduleStates.scheduleOk);
sr.externalRcs.remove(ui.recipient);
}
}
Aggregations