Microsoft Graph — как создать запрос findMeetingTimes в Java?

Я пытаюсь реализовать запрос findMeetingTimes в своем приложении. Проблема в том, что точный код из документации Microsoft не работает (https://docs.microsoft.com/en-us/graph/api/user-findmeetingtimes?view=graph-rest-1.0&tabs=java). Здесь мы передаем MeetingDuration в виде строки, но требуемый тип — javax.xml.datatype.Duration, что сбивает с толку, поскольку это абстрактный класс и явно не соответствует документации от Microsoft. Как должна выглядеть правильная реализация?

  IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();

LinkedList<Option> requestOptions = new LinkedList<Option>();
requestOptions.add(new HeaderOption("Prefer", "outlook.timezone=\"Pacific Standard Time\""));

LinkedList<AttendeeBase> attendeesList = new LinkedList<AttendeeBase>();
AttendeeBase attendees = new AttendeeBase();
attendees.type = AttendeeType.REQUIRED;
EmailAddress emailAddress = new EmailAddress();
emailAddress.name = "Alex Wilbur";
emailAddress.address = "[email protected]";
attendees.emailAddress = emailAddress;

attendeesList.add(attendees);

LocationConstraint locationConstraint = new LocationConstraint();
locationConstraint.isRequired = "false";
locationConstraint.suggestLocation = "false";
LinkedList<LocationConstraintItem> locationsList = new LinkedList<LocationConstraintItem>();
LocationConstraintItem locations = new LocationConstraintItem();
locations.resolveAvailability = "false";
locations.displayName = "Conf room Hood";
locationsList.add(locations);
locationConstraint.locations = locationsList;

TimeConstraint timeConstraint = new TimeConstraint();
timeConstraint.activityDomain = ActivityDomain.WORK;
LinkedList<TimeSlot> timeSlotsList = new LinkedList<TimeSlot>();
TimeSlot timeSlots = new TimeSlot();
DateTimeTimeZone start = new DateTimeTimeZone();
start.dateTime = "2019-04-16T09:00:00";
start.timeZone = "Pacific Standard Time";
timeSlots.start = start;
DateTimeTimeZone end = new DateTimeTimeZone();
end.dateTime = "2019-04-18T17:00:00";
end.timeZone = "Pacific Standard Time";
timeSlots.end = end;
timeSlotsList.add(timeSlots);
timeConstraint.timeSlots = timeSlotsList;

boolean isOrganizerOptional = false;

String meetingDuration = "PT1H";

boolean returnSuggestionReasons = true;

String minimumAttendeePercentage = "100";

graphClient.me()
    .findMeetingTimes(attendeesList,locationConstraint,timeConstraint,meetingDuration,null,isOrganizerOptional,returnSuggestionReasons,minimumAttendeePercentage)
    .buildRequest( requestOptions )
    .post();

person SaintNick    schedule 08.09.2020    source источник


Ответы (1)


Мне удалось заменить meetingDuration правильным объектом:

 DatatypeFactory factory = DatatypeFactory.newInstance();
        javax.xml.datatype.Duration meetingDuration = factory.newDuration("PT1H");
        
        graphClient.me()
                .findMeetingTimes(attendeesList, null, timeConstraint, meetingDuration, null, true, true, 100.0)
                .buildRequest(requestOptions)
                .post();

Вопрос в том, как теперь поймать ответ сервера? Опять же, ни слова в документах MS :/

person SaintNick    schedule 09.09.2020