@Test public void getMonthWithFullWeeks() throws Exception { Calendar give = Calendar.getInstance(); give.add(Calendar.MONTH, 3); TimeFrameFactory tff = new TimeFrameFactory(give); TimeFrame got = tff.getMonthWithFullWeeks(); // assert "first day of week" and more or equal units as the pure month assertEquals(got.getCalendarStart().get(Calendar.DAY_OF_WEEK), give.getFirstDayOfWeek()); assertEquals(got.getCalendarEnd().get(Calendar.DAY_OF_WEEK), give.getFirstDayOfWeek()); assertTrue(got.getDuration() >= tff.getMonth().getDuration()); }
private HtmlElement getSummary(HttpServletRequest request) { HtmlElement result = HtmlFactory.get("ul").addClassName("asList"); HtmlElement warningSpan = HtmlFactory.get("span").addClassName("warning"); // summary availability Integer availability = RequestInterpreter.getAvailability(request); // is valid availability if (availability != null && (availability == COMPLETE_AVAILABLE || availability == GENERAL_NOT_AVAILABLE || availability == BOOKED_NOT_AVAILABLE || availability == MAINTENANCE_NOT_AVAILABLE || availability == BOOKING_MUST_NOT_START_HERE)) { result.add( HtmlFactory.get("li") .add(HtmlFactory.get("strong").add("Availability")) .add(": ") .add(FamText.facilityAvailability(availability))); // INTLANG; } // summary interval Integer interval = RequestInterpreter.getInterval(request); if (interval != null) { result.add( HtmlFactory.get("li") .add(HtmlFactory.get("strong").add("Interval")) .add(": ") .add(FamText.message("calendar.iteration." + interval))); // INTLANG; } // summary notice String notice = RequestInterpreter.getNotice(request); if (notice != null) { result.add( HtmlFactory.get("li") .add(HtmlFactory.get("strong").add("Notice")) .add(": ") .add(notice)); // INTLANG; } if (availability != null && availability.intValue() != FacilityAvailability.COMPLETE_AVAILABLE) { FacilityAvailability da = RequestInterpreter.getCompleteFacilityAvailabilityForInsertion( request, SessionAuth.user(request)); if (da != null) { TimeFrame baseTimeFrame = da.getBasePeriodOfTime(); if (baseTimeFrame != null) { String timeText = interval == FacilityAvailability.ONE_TIME ? "Coming into effect" : "First time coming into effect"; // INTLANG result.add( HtmlFactory.get("li") .add(HtmlFactory.get("strong").add(timeText)) .add(": ") .add(baseTimeFrame)); // summarize bookings being canceled List<Facility> facilities = new ArrayList<Facility>(); facilities.add(da.getFacility()); List<Booking> bookings = FamDaoProxy.bookingDao().getAll(facilities); int negativeAnswers = 0; for (Booking booking : bookings) { if (!booking.isCanceled() && !booking.sessionAlreadyBegun() && booking.getIdBookedInBookingStrategy() != BookingStrategy.QUEUE_BASED && da.applicableTo(booking.getSessionTimeFrame())) { negativeAnswers++; } } result.add( HtmlFactory.get("li") .add( HtmlFactory.get("strong") .add("Number of letters of refusal sent with this input")) .add(": ") .add( negativeAnswers == 0 ? "no letter" : warningSpan .setContent(negativeAnswers + " letter(s)") .toString())); // INTLANG; // warning on nothing set or left long durationOfBaseTime = baseTimeFrame.getDuration(); long durationOfAnHour = 1000l * 60 * 60; boolean willBlockResource = false; boolean nothingSet = durationOfBaseTime <= 0; if (!nothingSet && interval != FacilityAvailability.ONE_TIME && availability != FacilityAvailability.COMPLETE_AVAILABLE) { if ((interval == FacilityAvailability.EACH_YEAR && durationOfBaseTime >= durationOfAnHour * 24 * 365) || (interval == FacilityAvailability.EACH_MONTH && durationOfBaseTime >= durationOfAnHour * 24 * 365 / 12) || (interval == FacilityAvailability.EACH_WEEK && durationOfBaseTime >= durationOfAnHour * 24 * 7) || (interval == FacilityAvailability.EACH_DAY && durationOfBaseTime >= durationOfAnHour * 24) || (interval == FacilityAvailability.EACH_HOUR && durationOfBaseTime >= durationOfAnHour)) { willBlockResource = true; } } if (willBlockResource) { result.add( HtmlFactory.get("li") .add( warningSpan.setContent( "If setting this, the facility will never ever be available!"))); // INTLANG; } if (nothingSet) { result.add( HtmlFactory.get("li") .add(warningSpan.setContent("The duration of your setting is 0!"))); // INTLANG; } } } } return result; }