/** * @param ownerIdentifier * @param model * @param fbo * @param bindingResult * @return * @throws NotAVisitorException * @throws OwnerNotFoundException * @throws SchedulingException */ @RequestMapping(method = RequestMethod.POST) protected String createAppointment( final ModelMap model, @PathVariable("ownerIdentifier") final String ownerIdentifier, @Valid @ModelAttribute(COMMAND_ATTR_NAME) final CreateAppointmentFormBackingObject fbo, BindingResult bindingResult) throws NotAVisitorException, OwnerNotFoundException, SchedulingException { CalendarAccountUserDetailsImpl currentUser = (CalendarAccountUserDetailsImpl) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); IScheduleVisitor visitor = currentUser.getScheduleVisitor(); if (bindingResult.hasErrors()) { return "visitor/create-appointment-form"; } IScheduleOwner selectedOwner = null; if (StringUtils.isNumeric(ownerIdentifier)) { Long ownerId = Long.parseLong(ownerIdentifier); selectedOwner = findOwnerForVisitor(visitor, ownerId); } else { PublicProfile profile = publicProfileDao.locatePublicProfileByKey(ownerIdentifier); if (null != profile) { selectedOwner = ownerDao.locateOwnerByAvailableId(profile.getOwnerId()); } } if (null == selectedOwner) { throw new OwnerNotFoundException("no owner found for " + ownerIdentifier); } validateChosenStartTime( selectedOwner.getPreferredVisibleWindow(), fbo.getTargetBlock().getStartTime()); AvailableBlock finalAppointmentBlock = fbo.getTargetBlock(); if (fbo.isDoubleLengthAvailable()) { // check if selected meeting duration matches meeting durations maxLength // if it's greater, then we need to look up the next block in the schedule and attempt to // combine if (fbo.getSelectedDuration() == fbo.getMeetingDurations().getMaxLength()) { finalAppointmentBlock = availableScheduleDao.retrieveTargetDoubleLengthBlock( selectedOwner, finalAppointmentBlock.getStartTime()); } } if (null == finalAppointmentBlock) { throw new SchedulingException("requested time is not available"); } VEvent event = schedulingAssistantService.scheduleAppointment( visitor, selectedOwner, finalAppointmentBlock, fbo.getReason()); model.put("event", event); model.put("owner", selectedOwner); model.put("ownerRemindersPreference", selectedOwner.getRemindersPreference()); return "visitor/create-appointment-success"; }
/** * @param ownerIdentifier * @param weekStart * @param visitorUsername * @param model * @return * @throws NotAVisitorException * @throws CalendarUserNotFoundException */ @RequestMapping( value = "/admin/schedule-debug/{ownerIdentifier}/visitor-conflicts.json", method = RequestMethod.GET) public View visitorConflicts( @PathVariable("ownerIdentifier") long ownerIdentifier, @RequestParam(value = "weekStart", required = false, defaultValue = "1") int weekStart, @RequestParam(value = "visitorUsername", required = true) String visitorUsername, final ModelMap model) throws NotAVisitorException, CalendarAccountNotFoundException { ICalendarAccount visitorAccount = this.calendarAccountDao.getCalendarAccount(visitorUsername); if (visitorAccount == null) { throw new NotAVisitorException(visitorUsername + " not found"); } IScheduleVisitor visitor = this.visitorDao.toVisitor(visitorAccount); IScheduleOwner owner = ownerDao.locateOwnerByAvailableId(ownerIdentifier); if (owner == null) { throw new CalendarAccountNotFoundException("no owner found for id " + ownerIdentifier); } VisibleScheduleRequestConstraints requestConstraints = VisibleScheduleRequestConstraints.newInstance(owner, weekStart); List<AvailableBlock> visitorConflicts = this.schedulingAssistantService.calculateVisitorConflicts( visitor, owner, requestConstraints.getTargetStartDate(), requestConstraints.getTargetEndDate()); List<String> conflictBlocks = new ArrayList<String>(); SimpleDateFormat df = CommonDateOperations.getDateTimeFormat(); for (AvailableBlock b : visitorConflicts) { conflictBlocks.add(df.format(b.getStartTime())); } model.addAttribute("conflicts", conflictBlocks); Calendar visitorCalendar = this.calendarDataDao.getCalendar( visitorAccount, requestConstraints.getTargetStartDate(), requestConstraints.getTargetEndDate()); model.addAttribute("visitorCalendarData", visitorCalendar.toString()); return new MappingJacksonJsonView(); }