List of usage examples for org.joda.time LocalDate LocalDate
public LocalDate()
From source file:de.appsolve.padelcampus.admin.controller.bookings.AdminBookingsReservationsController.java
@RequestMapping(method = POST, value = "booking/{bookingId}") public ModelAndView postEditBooking(@PathVariable("bookingId") Long bookingId, @Valid @ModelAttribute("Model") ReservationRequest model, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return getEditView(model); }// w ww . j av a 2s . c om try { LocalDate today = new LocalDate(); LocalTime now = new LocalTime(); if (model.getStartDate().compareTo(today) < 0 || (model.getStartDate().equals(today) && model.getStartTime().compareTo(now) < 0)) { throw new Exception(msg.get("RequestedTimeIsInThePast")); } /* only one offer possible */ Offer offer = model.getOffers().iterator().next(); /* make sure to not modify booking before we know it can be changed b/c auf auto transaction commit */ Booking booking = bookingDAO.findById(bookingId); List<CalendarConfig> calendarConfigs = calendarConfigDAO.findFor(model.getStartDate()); //throws CalendarConfigException Iterator<CalendarConfig> iterator = calendarConfigs.iterator(); while (iterator.hasNext()) { CalendarConfig calendarConfig = iterator.next(); if (!bookingUtil.isHoliday(model.getStartDate(), calendarConfig)) { List<Booking> confirmedBookings = bookingDAO.findBlockedBookingsForDate(model.getStartDate()); //remove the current booking as we want to update it confirmedBookings.remove(booking); OfferDurationPrice offerDurationPrice = bookingUtil.getOfferDurationPrice(calendarConfigs, confirmedBookings, model.getStartDate(), model.getStartTime(), offer); if (offerDurationPrice != null) { TimeSlot timeSlot = new TimeSlot(); timeSlot.setDate(model.getStartDate()); timeSlot.setStartTime(model.getStartTime()); timeSlot.setEndTime(model.getEndTime()); timeSlot.setConfig(calendarConfig); Long bookingSlotsLeft = bookingUtil.getBookingSlotsLeft(timeSlot, offer, confirmedBookings); if (bookingSlotsLeft >= 1) { BigDecimal price = offerDurationPrice.getDurationPriceMap() .get(booking.getDuration().intValue()); booking.setAmount(price); booking.setBlockingTime(new LocalDateTime()); booking.setBookingDate(model.getStartDate()); booking.setBookingTime(model.getStartTime()); booking.setComment(model.getComment()); booking.setDuration(getDuration(model, calendarConfig)); booking.setOffer(offer); booking.setOfferOptions(model.getOfferOptions()); booking.setPaymentConfirmed(model.getPaymentConfirmed()); booking.setPaymentMethod(PaymentMethod.Reservation); booking.setPublicBooking(model.getPublicBooking()); bookingDAO.saveOrUpdate(booking); return redirectToIndex(); } } } } throw new Exception(msg.get("NoCourtReservationsForSelectedDateTime")); } catch (Exception e) { LOG.error(e); bindingResult.addError(new ObjectError("id", e.getMessage())); return getEditView(model); } }
From source file:de.appsolve.padelcampus.admin.controller.reports.AdminReportsTimesController.java
@RequestMapping(method = GET) public ModelAndView getIndex() throws JsonProcessingException { LocalDate endDate = new LocalDate(); LocalDate startDate = endDate.minusYears(1); DateRange dateRange = new DateRange(); dateRange.setStartDate(startDate);//from w w w.j a v a2 s .c om dateRange.setEndDate(endDate); return getIndexView(dateRange); }
From source file:de.appsolve.padelcampus.admin.controller.reports.AdminReportsUtilizationController.java
@RequestMapping() public ModelAndView getIndex() throws JsonProcessingException { LocalDate endDate = new LocalDate(); LocalDate startDate = endDate.minusMonths(3); DateRange dateRange = new DateRange(); dateRange.setStartDate(startDate);// w w w . j av a2 s. co m dateRange.setEndDate(endDate); return getIndexView(dateRange); }
From source file:de.appsolve.padelcampus.controller.bookings.BookingsController.java
private void validateAndAddObjectsToView(ModelAndView mav, HttpServletRequest request, Booking booking, String day, String time, Offer offer) throws Exception { LocalDate selectedDate = FormatUtils.DATE_HUMAN_READABLE.parseLocalDate(day); LocalTime selectedTime = FormatUtils.TIME_HUMAN_READABLE.parseLocalTime(time); LocalDate today = new LocalDate(); LocalTime now = new LocalTime(); if (selectedDate.compareTo(today) < 0 || (selectedDate.equals(today) && selectedTime.compareTo(now) < 0)) { throw new Exception(msg.get("RequestedTimeIsInThePast")); }/* w w w . j a v a 2 s .c o m*/ LocalDate lastDay = bookingUtil.getLastBookableDay(request); if (selectedDate.isAfter(lastDay)) { throw new Exception(msg.get("RequestedTimeIsInTheFuture")); } //create a list of possible booking durations taking into account calendar configurations and confirmed bookings List<CalendarConfig> configs = calendarConfigDAO.findFor(selectedDate); List<Booking> confirmedBookings = bookingDAO.findBlockedBookingsForDate(selectedDate); OfferDurationPrice offerDurationPrice = bookingUtil.getOfferDurationPrice(configs, confirmedBookings, selectedDate, selectedTime, offer); //notify the user in case there are no durations bookable if (offerDurationPrice == null) { throw new Exception(msg.get("NoFreeCourtsForSelectedTimeAndDate")); } //store user provided data in the session booking booking.setBookingDate(selectedDate); booking.setBookingTime(selectedTime); //set currency and price if offer and duration have been selected if (booking.getOffer() != null && booking.getDuration() != null) { if (offerDurationPrice.getOffer().equals(booking.getOffer())) { BigDecimal price; switch (booking.getPaymentMethod()) { case Subscription: price = BigDecimal.ZERO; break; default: price = offerDurationPrice.getDurationPriceMap().get(booking.getDuration().intValue()); } booking.setAmount(price); booking.setCurrency(offerDurationPrice.getConfig().getCurrency()); } } sessionUtil.setBooking(request, booking); if (mav != null) { mav.addObject("Booking", booking); mav.addObject("OfferDurationPrice", offerDurationPrice); mav.addObject("SelectedOffer", offer); } }
From source file:de.appsolve.padelcampus.controller.bookings.BookingsPayMillController.java
private void addPublicApiKeyToModel(ModelAndView directDebitView) { PayMillConfig config = payMillConfigDAO.findFirst(); directDebitView.addObject("PAYMILL_PUBLIC_KEY", config.getPublicApiKey()); List<String> years = new ArrayList<>(); LocalDate date = new LocalDate(); years.add(date.toString("yyyy")); int i = 0;/* w w w . j a v a 2s . co m*/ while (i < 10) { date = date.plusYears(1); years.add(date.toString("yyyy")); i++; } directDebitView.addObject("Years", years); }
From source file:de.appsolve.padelcampus.controller.bookings.BookingsVoucherController.java
@RequestMapping(value = "booking/{UUID}/voucher", method = POST) public ModelAndView onPostVoucher(@PathVariable("UUID") String UUID, @RequestParam(required = false) String voucherUUID) { Booking booking = bookingDAO.findByUUID(UUID); ModelAndView mav = getVoucherView(booking); try {//from w ww .j ava 2s . com if (booking.getConfirmed()) { throw new Exception(msg.get("BookingAlreadyConfirmed")); } if (StringUtils.isEmpty(voucherUUID)) { throw new Exception(msg.get("MissingRequiredVoucher")); } Voucher voucher = voucherDAO.findByUUID(voucherUUID); LocalDate now = new LocalDate(); if (voucher == null) { throw new Exception(msg.get("VoucherDoesNotExist")); } if (voucher.getUsed()) { throw new Exception(msg.get("VoucherHasAlreadyBeenUsed")); } if (now.isAfter(voucher.getValidUntil())) { throw new Exception(msg.get("VoucherHasExpired")); } if (voucher.getDuration().compareTo(booking.getDuration()) < 0) { throw new Exception( msg.get("VoucherIsOnlyValidForDuration", new Object[] { voucher.getDuration() })); } if (!voucher.getOffers().contains(booking.getOffer())) { throw new Exception(msg.get("VoucherIsOnlyValidForOffer", new Object[] { voucher.getOffers() })); } LocalTime validUntilTime = voucher.getValidUntilTime(); LocalTime bookingEndTime = booking.getBookingEndTime(); if (bookingEndTime.isAfter(validUntilTime)) { throw new Exception(msg.get("VoucherIsOnlyValidForBookingsBefore", new Object[] { validUntilTime.toString(TIME_HUMAN_READABLE) })); } //update legacy vouchers if (voucher.getCalendarWeekDays().isEmpty()) { voucher.setCalendarWeekDays(new HashSet<>(Arrays.asList(CalendarWeekDay.values()))); } Set<CalendarWeekDay> validWeekDays = voucher.getCalendarWeekDays(); CalendarWeekDay bookingWeekDay = CalendarWeekDay.values()[booking.getBookingDate().getDayOfWeek() - 1]; if (!validWeekDays.contains(bookingWeekDay)) { throw new Exception(msg.get("VoucherIsOnlyValidForBookingsOn", new Object[] { validWeekDays })); } voucher.setUsed(true); voucherDAO.saveOrUpdate(voucher); booking.setPaymentConfirmed(true); booking.setVoucher(voucher); bookingDAO.saveOrUpdate(booking); return BookingsController.getRedirectToSuccessView(booking); } catch (Exception e) { log.error(e); mav.addObject("error", e.getMessage()); return mav; } }
From source file:de.appsolve.padelcampus.controller.events.EventsController.java
private void saveGame(Event event, List<Participant> teams, HttpServletRequest request) { Game game = new Game(); game.setEvent(event);/*from w ww . j ava 2 s.c om*/ game.setParticipants(new HashSet<>(teams)); game = gameDAO.saveOrUpdate(game); Set<GameSet> gameSets = new HashSet<>(); for (int setNumber = 1; setNumber <= event.getNumberOfSets(); setNumber++) { for (int teamNumber = 0; teamNumber < teams.size(); teamNumber++) { try { LOG.info("set-" + setNumber + "-team-" + teamNumber); Integer setGames = Integer .parseInt(request.getParameter("set-" + setNumber + "-team-" + teamNumber)); if (setGames != -1) { GameSet gameSet = new GameSet(); gameSet.setEvent(event); gameSet.setGame(game); gameSet.setSetGames(setGames); gameSet.setSetNumber(setNumber); gameSet.setParticipant(teams.get(teamNumber)); gameSet = gameSetDAO.saveOrUpdate(gameSet); gameSets.add(gameSet); } } catch (NumberFormatException e) { LOG.info(e); } } } game.setGameSets(new HashSet<>(gameSets)); if (gameSets.isEmpty()) { //we use score reporter as an indicator that the game has been played game.setScoreReporter(null); } else { game.setScoreReporter(sessionUtil.getUser(request)); } game.setGameSets(gameSets); game.setStartDate(new LocalDate()); gameDAO.saveOrUpdate(game); }
From source file:de.appsolve.padelcampus.controller.matchoffers.MatchOffersController.java
@RequestMapping(value = "add") public ModelAndView getEdit(HttpServletRequest request) { Player user = sessionUtil.getUser(request); if (user == null) { return getLoginRequiredView(request, msg.get("NewMatchOffer")); }/*from w w w. j a v a 2s . c o m*/ MatchOffer matchOffer = new MatchOffer(); matchOffer.setStartDate(new LocalDate().plusDays(1)); matchOffer.setStartTimeHour(BOOKING_DEFAULT_VALID_FROM_HOUR); matchOffer.setMinPlayersCount(4); matchOffer.setMaxPlayersCount(4); Set<Player> players = new HashSet<>(); players.add(user); matchOffer.setPlayers(players); return getEditView(matchOffer); }
From source file:de.appsolve.padelcampus.controller.matchoffers.MatchOffersController.java
private ModelAndView getShowView(HttpServletRequest request, MatchOffer model) { LocalDate today = new LocalDate(); LocalTime now = new LocalTime(Constants.DEFAULT_TIMEZONE); if (model == null) { return new ModelAndView("matchoffers/invalid"); } else if (model.getStartDate().isBefore(today) || (model.getStartDate().equals(today) && model.getStartTime().isBefore(now))) { return new ModelAndView("matchoffers/expired", "Model", model); } else {/*from w w w . ja v a2s.c o m*/ ModelAndView mav = new ModelAndView("matchoffers/offer", "Model", model); mav.addObject("OfferURL", getOfferURL(request, model)); mav.addObject("NewMatchOfferMailSubject", msg.get("NewMatchOfferMailSubject")); mav.addObject("NewMatchOfferMailBody", getNewMatchOfferMailBody(request, model).replace("\n", "%0A")); mav.addObject("PageTitle", String.format("%s %s", FormatUtils.DATE_WITH_DAY.print(model.getStartDate()), FormatUtils.TIME_HUMAN_READABLE.print(model.getStartTime()))); return mav; } }
From source file:de.appsolve.padelcampus.controller.players.PlayersController.java
private ModelAndView getPlayersView(Event event, Collection<Player> players, String title) { List<Ranking> ranking = rankingUtil.getPlayerRanking(players, new LocalDate()); ModelAndView mav = new ModelAndView("players/players"); mav.addObject("RankingMap", ranking); mav.addObject("title", title); mav.addObject("Model", event); return mav;/*w ww . jav a 2 s . c o m*/ }