use of org.bedework.calsvc.scheduling.hosts.Response.ResponseElement 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);
}
}
use of org.bedework.calsvc.scheduling.hosts.Response.ResponseElement in project bw-calendar-engine by Bedework.
the class IscheduleClient method parseResponse.
private void parseResponse(final HostInfo hi, final Response resp) throws CalFacadeException {
try {
final Document doc = parseContent(resp);
if (doc == null) {
throw new CalFacadeException(CalFacadeException.badResponse);
}
final QName sresponseTag;
final QName responseTag;
final QName recipientTag;
final QName requestStatusTag;
final QName calendarDataTag;
final QName errorTag;
final QName descriptionTag;
if (hi.getSupportsISchedule()) {
sresponseTag = IscheduleTags.scheduleResponse;
responseTag = IscheduleTags.response;
recipientTag = IscheduleTags.recipient;
requestStatusTag = IscheduleTags.requestStatus;
calendarDataTag = IscheduleTags.calendarData;
errorTag = IscheduleTags.error;
descriptionTag = IscheduleTags.responseDescription;
} else {
sresponseTag = CaldavTags.scheduleResponse;
responseTag = CaldavTags.response;
recipientTag = CaldavTags.recipient;
requestStatusTag = CaldavTags.requestStatus;
calendarDataTag = CaldavTags.calendarData;
errorTag = WebdavTags.error;
descriptionTag = WebdavTags.responseDescription;
}
final Element root = doc.getDocumentElement();
if (!XmlUtil.nodeMatches(root, sresponseTag)) {
throw new CalFacadeException(CalFacadeException.badResponse);
}
for (final Element el : getChildren(root)) {
final ResponseElement fbel = new ResponseElement();
if (!XmlUtil.nodeMatches(el, responseTag)) {
throw new CalFacadeException(CalFacadeException.badResponse);
}
/* ================================================================
11.2. CALDAV/ISCHEDULE:response XML Element
Name: response
Namespace: urn:ietf:params:xml:ns:caldav or
urn:ietf:params:xml:ns:ischedule or
Purpose: Contains a single response for a POST method request.
Description: See Section 6.1.4.
Definition:
<!ELEMENT response (recipient,
request-status,
calendar-data?,
error?,
response-description?)>
================================================================ */
final Iterator<Element> respels = getChildren(el).iterator();
Element respel = respels.next();
if (!XmlUtil.nodeMatches(respel, recipientTag)) {
throw new CalFacadeException(CalFacadeException.badResponse);
}
fbel.setRecipient(getElementContent(respel));
respel = respels.next();
if (!XmlUtil.nodeMatches(respel, requestStatusTag)) {
throw new CalFacadeException(CalFacadeException.badResponse);
}
fbel.setReqStatus(getElementContent(respel));
if (respels.hasNext()) {
respel = respels.next();
if (XmlUtil.nodeMatches(respel, calendarDataTag)) {
final String calData = getElementContent(respel);
final Reader rdr = new StringReader(calData);
final Icalendar ical = trans.fromIcal(null, rdr);
fbel.setCalData(ical.getEventInfo());
} else if (XmlUtil.nodeMatches(respel, errorTag)) {
fbel.setDavError(respel.getFirstChild().getLocalName());
} else if (XmlUtil.nodeMatches(respel, descriptionTag)) {
// XXX Not processed yet
} else {
throw new CalFacadeException(CalFacadeException.badResponse);
}
}
resp.addResponse(fbel);
}
} catch (final Throwable t) {
if (debug) {
error(t);
}
resp.setException(t);
}
}
Aggregations