/**
  * return the calendar view requested.
  *
  * @param rq request got
  * @return the calendar view requested
  */
 private String getCalendarView(HttpServletRequest rq) {
   String calView = rq.getParameter(QueryKeys.QUERY_KEY_CALENDAR_VIEW);
   if (calView == null || QueryStringBuilder.isValidCalendarView(calView) == false) {
     Facility d = RequestInterpreter.getFacility(rq);
     if (d == null) {
       calView =
           CalendarViewResolver.getInstance()
               .getDefaultCalendarView(FacilityConfigDao.getUnknownBookableFacility());
     } else {
       calView = CalendarViewResolver.getInstance().getDefaultCalendarView(d);
     }
   }
   return calView;
 }
 private QueryString getQueryString(
     String key, String pageno, HttpServletRequest rq, String logbookKey) {
   return QueryStringBuilder.getLogbookQueryString(
       key, pageno, this.getCountOfEntriesPerPage(rq, logbookKey) + "");
 }
  public Properties getProperties(TemplateResource templateResource) {
    Properties result = new Properties();
    String facilityKey = templateResource.getRequest().getParameter(QueryKeys.QUERY_KEY_FACILITY);
    boolean is_overview =
        this.getCalendarView(templateResource.getRequest()).equals(QueryKeys.OVERVIEW);
    Facility facility = RequestInterpreter.getFacility(templateResource.getRequest());
    if (facility == null) {
      // ↖ wrong url!
      RedirectResolver.redirectClient(
          RedirectTarget.SYSTEM_FACILITY_AVAILABILITY_OVERVIEW, templateResource);
    } else {
      result.put(
          "queue_based",
          facility.isBookable()
              && FacilityConfigDao.bookingRule(facilityKey).getBookingStrategy()
                  == BookingStrategy.QUEUE_BASED);
      result.put("facility_name", FacilityConfigDao.getInstance().getLabel(facilityKey));
      result.put("content", this.getCalendarHtml(templateResource, facilityKey));
      QueryString link_overview =
          QueryStringFactory.get(QueryKeys.QUERY_KEY_CALENDAR_VIEW, QueryKeys.OVERVIEW);
      link_overview.put(QueryKeys.QUERY_KEY_FACILITY, facilityKey);
      result.put("link_hidden_inputs", link_overview.getAsHtmlInputsTypeHidden());
      result.put("text_facilitykey", facilityKey);
      result.put("name_facilitykey", QueryKeys.QUERY_KEY_FACILITY);
      if (is_overview) {
        result.put("link_overview", link_overview.getAsHtmlLinkHref() + "#newrule");
        result.put("link_overview_text", "Add a new rule"); // INTLANG
        result.put("add_or_edit", "add");
      } else {
        result.put("link_overview", link_overview.getAsHtmlLinkHref());
        result.put("link_overview_text", "Edit availability rules"); // INTLANG
        result.put("add_or_edit", "edit");
      }
      link_overview.put(QueryKeys.QUERY_KEY_CALENDAR_VIEW, QueryKeys.WEEK);
      result.put("link_weekview", link_overview.getAsHtmlLinkHref());
      link_overview.put(QueryKeys.QUERY_KEY_CALENDAR_VIEW, QueryKeys.MONTH);
      result.put("link_monthview", link_overview.getAsHtmlLinkHref());
      // has many units
      boolean hasChildren = facility.hasChildren();
      int units = facility.isBookable() ? ((FacilityBookable) facility).getCapacityUnits() : 1;
      result.put("flag_hasmanyunits", units > 1);
      result.put("flag_haschildren", hasChildren);
      if (hasChildren) {
        result.put("number_children", facility.getChildren().size());
      } else {
        result.put("number_children", "");
      }
      if (units > 1) {
        result.put("string_nameofunits", FamText.capacityUnits((FacilityBookable) facility));
      } else {
        result.put("string_nameofunits", "");
      }

      // set edit form
      boolean suddenFailureIsActive = this.suddenFailureIsActive(facilityKey);
      if (is_overview && !suddenFailureIsActive) { // show "add a rule"
        result.put("show_edit", true);
        result.put("show_suddenFailureIsActive", false);
        result.put(
            "querystring",
            QueryStringBuilder.getBigCalendarQueryString(
                facilityKey,
                RequestInterpreter.getCalendar(templateResource.getRequest()),
                QueryKeys.OVERVIEW));

        // get current step
        int currentStep = 1;
        try {
          currentStep = Integer.parseInt(RequestInterpreter.getOf(templateResource.getRequest()));
        } catch (NumberFormatException e) {
        } // ← stay step 1

        QueryString hiddenInputs = null;
        // ↘ it is the final sending of add new rule
        if (currentStep >= 4) {
          hiddenInputs = new QueryString();
          hiddenInputs.put(QueryKeys.QUERY_KEY_FACILITY, facilityKey);
          hiddenInputs.put(QueryKeys.QUERY_KEY_CALENDAR_VIEW, QueryKeys.OVERVIEW);
          currentStep = 1;
        } else {
          hiddenInputs = QueryStringFactory.getInstance().get(templateResource.getRequest());
        }
        hiddenInputs.put(QueryKeys.QUERY_KEY_OF, currentStep + 1);
        // ↘ set flag: nothing shall be deleted when submit form
        hiddenInputs.put(QueryKeys.QUERY_KEY_DELETE, "-1");

        switch (currentStep) {
          case 1:
            // choose of availability
            result.put("name_available", QueryKeys.QUERY_KEY_AVAILABLILITY);
            result.put(
                "value_available_nomaintenance", FacilityAvailability.MAINTENANCE_NOT_AVAILABLE);
            result.put(
                "text_available_nomaintenance",
                FamText.facilityAvailability(FacilityAvailability.MAINTENANCE_NOT_AVAILABLE));
            result.put("value_available_noingeneral", FacilityAvailability.GENERAL_NOT_AVAILABLE);
            result.put(
                "text_available_noingeneral",
                FamText.facilityAvailability(FacilityAvailability.GENERAL_NOT_AVAILABLE));
            result.put(
                "value_available_mustnotstarthere",
                FacilityAvailability.BOOKING_MUST_NOT_START_HERE);
            result.put(
                "text_available_mustnotstarthere",
                FamText.facilityAvailability(FacilityAvailability.BOOKING_MUST_NOT_START_HERE));
            result.put("value_available_available", FacilityAvailability.COMPLETE_AVAILABLE);
            result.put(
                "text_available_available",
                FamText.facilityAvailability(FacilityAvailability.COMPLETE_AVAILABLE));

            // choose interval
            result.put("name_interval", QueryKeys.QUERY_KEY_ITERATION);
            result.put("value_interval_onetime", FacilityAvailability.ONE_TIME);
            result.put("value_interval_yearly", FacilityAvailability.EACH_YEAR);
            result.put("value_interval_monthly", FacilityAvailability.EACH_MONTH);
            result.put("value_interval_weekly", FacilityAvailability.EACH_WEEK);
            result.put("value_interval_daily", FacilityAvailability.EACH_DAY);
            break;
          case 2:
            result.put("text_info", this.getSummary(templateResource.getRequest()));
            result.put("select_time", this.getTimeInput(templateResource.getRequest()));
            result.put("name_notice", QueryKeys.QUERY_KEY_TEXT_NOTICE);
            break;
          case 3:
            result.put("text_info", this.getSummary(templateResource.getRequest()));
            break;
        }

        // set current step
        result.put("current_step", currentStep);

        result.put("hiddenInputs", hiddenInputs.getAsHtmlInputsTypeHidden());
      } else if (suddenFailureIsActive) {
        result.put("show_edit", false);
        result.put("show_suddenFailureIsActive", true);
        result.put("text_facilitykey", facilityKey);
        result.put("name_facilitykey", QueryKeys.QUERY_KEY_FACILITY);
        result.put("value_yes", QueryKeys.YES);
        result.put("name_yes", QueryKeys.QUERY_KEY_YES_NO);
        result.put(
            "querystring",
            QueryStringBuilder.getBigCalendarQueryString(
                facilityKey,
                RequestInterpreter.getCalendar(templateResource.getRequest()),
                QueryKeys.OVERVIEW));
      } else { // it is not the overview / editing view
        result.put("show_edit", false);
        result.put("show_suddenFailureIsActive", false);
      }
    }
    return result;
  }