Search in sources :

Example 1 with FreeBusyResponseType

use of com.microsoft.schemas.exchange.services._2006.messages.FreeBusyResponseType 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);
        // Request for highest hierarchy view. The rest hierarchy will be Detailed->FreeBusy->MergedOnly->None
        availabilityOpts.getRequestedView().add("DetailedMerged");
        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>();
        TimeZoneDefinitionType tzdt = new TimeZoneDefinitionType();
        tzdt.setId("Greenwich Standard Time");
        TimeZoneContextType tzct = new TimeZoneContextType();
        tzct.setTimeZoneDefinition(tzdt);
        service.getUserAvailability(availabilityRequest, tzct, serverVersion, 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) {
        int i = 0;
        long startTime = req.get(0).start;
        long endTime = req.get(0).end;
        for (FreeBusyResponseType attendeeAvailability : results) {
            if (attendeeAvailability.getFreeBusyView() != null) {
                String fbResponseViewType = attendeeAvailability.getFreeBusyView().getFreeBusyViewType().get(0);
                String emailAddress = attendees.getMailboxData().get(i).getEmail().getAddress();
                ZimbraLog.fb.debug("For user :%s free busy response type received is : %s", emailAddress, fbResponseViewType);
                if (re.email == emailAddress) {
                    if (ResponseClassType.ERROR == attendeeAvailability.getResponseMessage().getResponseClass()) {
                        ZimbraLog.fb.debug("Unable to fetch free busy for %s  error code %s :: %s", emailAddress, attendeeAvailability.getResponseMessage().getResponseCode(), attendeeAvailability.getResponseMessage().getMessageText());
                        FreeBusy npFreeBusy = FreeBusy.nodataFreeBusy(emailAddress, startTime, endTime);
                        ret.add(npFreeBusy);
                        if (attendeeAvailability.getResponseMessage().getResponseCode().equals(ResponseCodeType.ERROR_NO_FREE_BUSY_ACCESS)) {
                            npFreeBusy.mList.getHead().hasPermission = false;
                        }
                        ZimbraLog.fb.info("Error in response. continuing to next one sending nodata as response");
                        i++;
                        continue;
                    }
                    String fb = attendeeAvailability.getFreeBusyView().getMergedFreeBusy();
                    ZimbraLog.fb.info("Merged view Free Busy info received for user:%s is %s: ", emailAddress, fb);
                    ArrayList<FreeBusy> userIntervals = new ArrayList<FreeBusy>();
                    if (fb == null) {
                        ZimbraLog.fb.warn("Merged view Free Busy info not avaiable for the user");
                        // Avoid NPE.
                        fb = "";
                    } else {
                        userIntervals.add(new ExchangeFreeBusyProvider.ExchangeUserFreeBusy(fb, re.email, fb_interval, startTime, endTime));
                        ret.addAll(userIntervals);
                    }
                    // Parsing Detailed fb view response
                    if ("DetailedMerged".equals(fbResponseViewType) || "FreeBusyMerged".equals(fbResponseViewType)) {
                        parseDetailedFreeBusyResponse(emailAddress, startTime, endTime, attendeeAvailability, userIntervals);
                        ret.addAll(userIntervals);
                    } else {
                        // No FreeBusy view information available. returning nodata freebusy in response
                        ZimbraLog.fb.debug("No Free Busy view info avaiable for [%s], free busy view type from response : %s", emailAddress, fbResponseViewType);
                        ret.add(FreeBusy.nodataFreeBusy(emailAddress, startTime, endTime));
                    }
                }
                i++;
            }
        }
    }
    return ret;
}
Also used : ServerInfo(com.zimbra.cs.fb.ExchangeFreeBusyProvider.ServerInfo) TimeZoneContextType(com.microsoft.schemas.exchange.services._2006.types.TimeZoneContextType) ArrayList(java.util.ArrayList) RequestServerVersion(com.microsoft.schemas.exchange.services._2006.types.RequestServerVersion) TimeZoneDefinitionType(com.microsoft.schemas.exchange.services._2006.types.TimeZoneDefinitionType) GetUserAvailabilityResponseType(com.microsoft.schemas.exchange.services._2006.messages.GetUserAvailabilityResponseType) ServerVersionInfo(com.microsoft.schemas.exchange.services._2006.types.ServerVersionInfo) FreeBusyResponseType(com.microsoft.schemas.exchange.services._2006.messages.FreeBusyResponseType) FreeBusyViewOptionsType(com.microsoft.schemas.exchange.services._2006.types.FreeBusyViewOptionsType) SerializableTimeZoneTime(com.microsoft.schemas.exchange.services._2006.types.SerializableTimeZoneTime) DatatypeFactory(javax.xml.datatype.DatatypeFactory) ArrayOfMailboxData(com.microsoft.schemas.exchange.services._2006.types.ArrayOfMailboxData) Holder(javax.xml.ws.Holder) MailboxData(com.microsoft.schemas.exchange.services._2006.types.MailboxData) ArrayOfMailboxData(com.microsoft.schemas.exchange.services._2006.types.ArrayOfMailboxData) GregorianCalendar(java.util.GregorianCalendar) Duration(com.microsoft.schemas.exchange.services._2006.types.Duration) SerializableTimeZone(com.microsoft.schemas.exchange.services._2006.types.SerializableTimeZone) EmailAddress(com.microsoft.schemas.exchange.services._2006.types.EmailAddress) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) MalformedURLException(java.net.MalformedURLException) CertificateException(java.security.cert.CertificateException) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) GetUserAvailabilityRequestType(com.microsoft.schemas.exchange.services._2006.messages.GetUserAvailabilityRequestType)

Example 2 with FreeBusyResponseType

use of com.microsoft.schemas.exchange.services._2006.messages.FreeBusyResponseType in project zm-mailbox by Zimbra.

the class ExchangeEWSFreeBusyProvider method parseDetailedFreeBusyResponse.

/*
    * This method parse the Detailed and FreeBusy view response information for each individual user,
    * who has those view information.
    */
private static void parseDetailedFreeBusyResponse(String name, long start, long end, FreeBusyResponseType freeBusyResponse, ArrayList<FreeBusy> ret) {
    ArrayOfCalendarEvent arrayOfCalendarEvent = null;
    List<CalendarEvent> calendarEvents = null;
    if (freeBusyResponse.getFreeBusyView() != null) {
        arrayOfCalendarEvent = freeBusyResponse.getFreeBusyView().getCalendarEventArray();
        if (arrayOfCalendarEvent != null) {
            calendarEvents = arrayOfCalendarEvent.getCalendarEvent();
            LegacyFreeBusyType legacyType;
            if (calendarEvents != null && calendarEvents.size() > 0) {
                for (CalendarEvent event : calendarEvents) {
                    legacyType = event.getBusyType();
                    FreeBusy.Interval interval = getFreeBusyInterval(ret, event);
                    ZimbraLog.fb.debug("For user %s FB data received is: legacyType : %s, startTime : %s, " + "endTime : %s", name, legacyType, event.getStartTime(), event.getEndTime());
                    if (event.getCalendarEventDetails() != null && interval != null) {
                        CalendarEventDetails calendarEventDetails = event.getCalendarEventDetails();
                        interval.id = calendarEventDetails.getID();
                        interval.location = calendarEventDetails.getLocation();
                        interval.subject = calendarEventDetails.getSubject();
                        interval.isMeeting = calendarEventDetails.isIsMeeting();
                        interval.isRecurring = calendarEventDetails.isIsRecurring();
                        interval.isException = calendarEventDetails.isIsException();
                        interval.isReminderSet = calendarEventDetails.isIsReminderSet();
                        interval.isPrivate = calendarEventDetails.isIsPrivate();
                        interval.detailsExist = true;
                        ZimbraLog.fb.debug("eventID : %s, location : %s, subject : %s, isMeeting : %b, " + "isRecurring : %b, isException : %b, isReminderSet : %b, isPrivate : %b", interval.id, interval.location, interval.subject, interval.isMeeting, interval.isRecurring, interval.isException, interval.isReminderSet, interval.isPrivate);
                    } else {
                        ZimbraLog.fb.debug("Calendar Event details not found for the user %s", name);
                    }
                }
            } else {
                ZimbraLog.fb.debug("No Calendar Information available for the user : %s", name);
            }
        }
    }
}
Also used : CalendarEventDetails(com.microsoft.schemas.exchange.services._2006.types.CalendarEventDetails) ArrayOfCalendarEvent(com.microsoft.schemas.exchange.services._2006.types.ArrayOfCalendarEvent) CalendarEvent(com.microsoft.schemas.exchange.services._2006.types.CalendarEvent) ArrayOfCalendarEvent(com.microsoft.schemas.exchange.services._2006.types.ArrayOfCalendarEvent) LegacyFreeBusyType(com.microsoft.schemas.exchange.services._2006.types.LegacyFreeBusyType)

Aggregations

FreeBusyResponseType (com.microsoft.schemas.exchange.services._2006.messages.FreeBusyResponseType)1 GetUserAvailabilityRequestType (com.microsoft.schemas.exchange.services._2006.messages.GetUserAvailabilityRequestType)1 GetUserAvailabilityResponseType (com.microsoft.schemas.exchange.services._2006.messages.GetUserAvailabilityResponseType)1 ArrayOfCalendarEvent (com.microsoft.schemas.exchange.services._2006.types.ArrayOfCalendarEvent)1 ArrayOfMailboxData (com.microsoft.schemas.exchange.services._2006.types.ArrayOfMailboxData)1 CalendarEvent (com.microsoft.schemas.exchange.services._2006.types.CalendarEvent)1 CalendarEventDetails (com.microsoft.schemas.exchange.services._2006.types.CalendarEventDetails)1 Duration (com.microsoft.schemas.exchange.services._2006.types.Duration)1 EmailAddress (com.microsoft.schemas.exchange.services._2006.types.EmailAddress)1 FreeBusyViewOptionsType (com.microsoft.schemas.exchange.services._2006.types.FreeBusyViewOptionsType)1 LegacyFreeBusyType (com.microsoft.schemas.exchange.services._2006.types.LegacyFreeBusyType)1 MailboxData (com.microsoft.schemas.exchange.services._2006.types.MailboxData)1 RequestServerVersion (com.microsoft.schemas.exchange.services._2006.types.RequestServerVersion)1 SerializableTimeZone (com.microsoft.schemas.exchange.services._2006.types.SerializableTimeZone)1 SerializableTimeZoneTime (com.microsoft.schemas.exchange.services._2006.types.SerializableTimeZoneTime)1 ServerVersionInfo (com.microsoft.schemas.exchange.services._2006.types.ServerVersionInfo)1 TimeZoneContextType (com.microsoft.schemas.exchange.services._2006.types.TimeZoneContextType)1 TimeZoneDefinitionType (com.microsoft.schemas.exchange.services._2006.types.TimeZoneDefinitionType)1 ServiceException (com.zimbra.common.service.ServiceException)1 ServerInfo (com.zimbra.cs.fb.ExchangeFreeBusyProvider.ServerInfo)1