@FreeBusyQuery public List<SchedulingResponseItem> freeBusyQuery(Profile profile, String icalQuery) throws NotAuthorizedException { ICalFormatter.FreeBusyRequest r = formatter.parseFreeBusyRequest(icalQuery); log.info( "queryFreeBusy: attendees=" + r.getAttendeeLines().size() + " - " + r.getAttendeeMailtos().size()); List<SchedulingResponseItem> list = new ArrayList<>(); try { for (String attendeeMailto : r.getAttendeeMailtos()) { MailboxAddress add = MailboxAddress.parse(attendeeMailto); Profile attendee = findUserFromMailto(add); if (attendee == null) { log.warn("Attendee not found: " + attendeeMailto); SchedulingResponseItem item = new SchedulingResponseItem( "mailto:" + attendeeMailto, ITip.StatusResponse.RS_INVALID_37, null); list.add(item); } else { log.info("Found attendee: " + attendee.getName()); // Now locate events and build an ical response String ical = buildFreeBusyAttendeeResponse(attendee, r, add.domain, attendeeMailto); SchedulingResponseItem item = new SchedulingResponseItem( "mailto:" + attendeeMailto, ITip.StatusResponse.RS_SUCCESS_20, ical); list.add(item); } } } catch (NotAuthorizedException ex) { throw ex; } catch (BadRequestException ex) { throw new RuntimeException(ex); } return list; }
/** * @param add * @return * @throws NotAuthorizedException * @throws BadRequestException */ private Profile findUserFromMailto(MailboxAddress add) throws NotAuthorizedException, BadRequestException { return Profile.findByEmail(add.toPlainAddress(), SessionManager.session()); }