use of com.microsoft.schemas.exchange.services._2006.types.ArrayOfMailboxData in project zm-mailbox by Zimbra.
the class ExchangeEWSFreeBusyProvider method getFreeBusyForHost.
public List<FreeBusy> getFreeBusyForHost(String host, ArrayList<Request> req) throws IOException {
int fb_interval = LC.exchange_free_busy_interval_min.intValueWithinRange(5, 1444);
List<FreeBusyResponseType> results = null;
ArrayList<FreeBusy> ret = new ArrayList<FreeBusy>();
Request r = req.get(0);
long start = Request.offsetInterval(req.get(0).start, fb_interval);
ServerInfo serverInfo = (ServerInfo) r.data;
if (serverInfo == null) {
ZimbraLog.fb.warn("no exchange server info for user " + r.email);
return ret;
}
if (!serverInfo.enabled)
return ret;
ArrayOfMailboxData attendees = new ArrayOfMailboxData();
for (Request request : req) {
EmailAddress email = new EmailAddress();
email.setAddress(request.email);
MailboxData mailbox = new MailboxData();
mailbox.setEmail(email);
mailbox.setAttendeeType(MeetingAttendeeType.REQUIRED);
attendees.getMailboxData().add(mailbox);
}
try {
Duration duration = new Duration();
DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
GregorianCalendar gregorianCalStart = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
gregorianCalStart.setTimeInMillis(start);
duration.setStartTime(datatypeFactory.newXMLGregorianCalendar(gregorianCalStart));
GregorianCalendar gregorianCalEnd = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
gregorianCalEnd.setTimeInMillis(req.get(0).end);
duration.setEndTime(datatypeFactory.newXMLGregorianCalendar(gregorianCalEnd));
FreeBusyViewOptionsType availabilityOpts = new FreeBusyViewOptionsType();
availabilityOpts.setMergedFreeBusyIntervalInMinutes(fb_interval);
availabilityOpts.getRequestedView().add("MergedOnly");
availabilityOpts.setTimeWindow(duration);
GetUserAvailabilityRequestType availabilityRequest = new GetUserAvailabilityRequestType();
// TODO: check if we need to set request timezone
SerializableTimeZone timezone = new SerializableTimeZone();
timezone.setBias(0);
SerializableTimeZoneTime standardTime = new SerializableTimeZoneTime();
standardTime.setTime("00:00:00");
standardTime.setDayOrder((short) 1);
standardTime.setDayOfWeek(DayOfWeekType.SUNDAY);
timezone.setStandardTime(standardTime);
timezone.setDaylightTime(standardTime);
availabilityRequest.setTimeZone(timezone);
availabilityRequest.setFreeBusyViewOptions(availabilityOpts);
availabilityRequest.setMailboxDataArray(attendees);
RequestServerVersion serverVersion = new RequestServerVersion();
serverVersion.setVersion(ExchangeVersionType.EXCHANGE_2010_SP_1);
Holder<GetUserAvailabilityResponseType> availabilityResponse = new Holder<GetUserAvailabilityResponseType>();
Holder<ServerVersionInfo> gfversionInfo = new Holder<ServerVersionInfo>();
service.getUserAvailability(availabilityRequest, availabilityResponse, gfversionInfo);
results = availabilityResponse.value.getFreeBusyResponseArray().getFreeBusyResponse();
} catch (DatatypeConfigurationException dce) {
ZimbraLog.fb.warn("getFreeBusyForHost DatatypeConfiguration failure", dce);
return getEmptyList(req);
} catch (Exception e) {
ZimbraLog.fb.warn("getFreeBusyForHost failure", e);
return getEmptyList(req);
}
for (Request re : req) {
String fb = "";
int i = 0;
for (FreeBusyResponseType attendeeAvailability : results) {
if (re.email == attendees.getMailboxData().get(i).getEmail().getAddress()) {
if (ResponseClassType.SUCCESS != attendeeAvailability.getResponseMessage().getResponseClass()) {
ZimbraLog.fb.warn(attendeeAvailability.getResponseMessage().getMessageText());
ZimbraLog.fb.warn("Error in response. continuing to next one");
i++;
continue;
}
ZimbraLog.fb.debug("Availability for " + attendees.getMailboxData().get(i).getEmail().getAddress() + " [" + attendeeAvailability.getFreeBusyView().getMergedFreeBusy() + "]");
fb = attendeeAvailability.getFreeBusyView().getMergedFreeBusy();
if (fb == null) {
ZimbraLog.fb.warn("Merged view Free Busy info not avaiable");
//Avoid NPE.
fb = "";
}
break;
}
i++;
}
ret.add(new ExchangeFreeBusyProvider.ExchangeUserFreeBusy(fb, re.email, fb_interval, req.get(0).start, req.get(0).end));
}
return ret;
}
Aggregations