Ejemplo n.º 1
0
  public ActionForward checkRooms(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    DynaActionForm examForm = (DynaActionForm) form;
    ContextUtils.setCurricularYearsContext(request);

    String infoExamId = (String) request.getAttribute(PresentationConstants.EXAM_OID);
    if (infoExamId == null) {
      infoExamId = request.getParameter(PresentationConstants.EXAM_OID);
    }
    request.setAttribute(PresentationConstants.EXAM_OID, infoExamId);

    String[] executionCourseArray = (String[]) examForm.get("executionCourses");

    List executionCourseList = new ArrayList();
    for (String element : executionCourseArray) {

      InfoExecutionCourse executionCourse;
      try {
        executionCourse =
            ReadExecutionCourseWithAssociatedCurricularCourses.run(new Integer(element));
      } catch (Exception ex) {
        throw new Exception(ex);
      }

      executionCourseList.add(executionCourse);
    }
    request.setAttribute(PresentationConstants.EXECUTION_COURSES_LIST, executionCourseList);

    String nextPage = request.getParameter("nextPage");
    request.setAttribute(PresentationConstants.NEXT_PAGE, nextPage);

    List examSeasons = Util.getExamSeasons();
    request.setAttribute(PresentationConstants.LABLELIST_SEASONS, examSeasons);

    List executionCourseNames =
        (List) request.getAttribute(PresentationConstants.LIST_EXECUTION_COURSE_NAMES);
    request.setAttribute(PresentationConstants.LIST_EXECUTION_COURSE_NAMES, executionCourseNames);

    String[] executionCourse = (String[]) examForm.get("executionCourses");
    examForm.set("executionCourses", executionCourse);

    String[] scopeIDArray = (String[]) examForm.get("scopes");
    examForm.set("scopes", scopeIDArray);

    // exam start time
    Calendar examStartTime = Calendar.getInstance();
    Integer startHour = new Integer((String) examForm.get("beginningHour"));
    Integer startMinute = new Integer((String) examForm.get("beginningMinute"));
    examStartTime.set(Calendar.HOUR_OF_DAY, startHour.intValue());
    examStartTime.set(Calendar.MINUTE, startMinute.intValue());
    examStartTime.set(Calendar.SECOND, 0);

    // exam end time
    Calendar examEndTime = Calendar.getInstance();
    Integer endHour = new Integer((String) examForm.get("endHour"));
    Integer endMinute = new Integer((String) examForm.get("endMinute"));
    examEndTime.set(Calendar.HOUR_OF_DAY, endHour.intValue());
    examEndTime.set(Calendar.MINUTE, endMinute.intValue());
    examEndTime.set(Calendar.SECOND, 0);

    if (examStartTime.after(examEndTime)) {
      addErrorMessage(request, "error.timeSwitched", "error.timeSwitched");
      return prepare(mapping, form, request, response);
    }

    // exam date
    Calendar examDate = Calendar.getInstance();
    Integer day = new Integer((String) examForm.get("day"));
    Integer month = new Integer((String) examForm.get("month"));
    Integer year = new Integer((String) examForm.get("year"));
    examDate.set(Calendar.YEAR, year.intValue());
    examDate.set(Calendar.MONTH, month.intValue() - 1);
    examDate.set(Calendar.DAY_OF_MONTH, day.intValue());

    int dayOfWeekInt = examDate.get(Calendar.DAY_OF_WEEK);
    DiaSemana dayOfWeek = new DiaSemana(dayOfWeekInt);
    if (dayOfWeekInt == Calendar.SUNDAY) {
      addErrorMessage(request, "error.sunday", "error.sunday");
      return prepare(mapping, form, request, response);
    }

    List<InfoRoom> availableInfoRoom =
        ReadAvailableRoomsForExam.run(
            YearMonthDay.fromCalendarFields(examDate),
            YearMonthDay.fromCalendarFields(examDate),
            HourMinuteSecond.fromCalendarFields(examStartTime),
            HourMinuteSecond.fromCalendarFields(examEndTime),
            dayOfWeek,
            null,
            null,
            Boolean.FALSE);

    String[] rooms = (String[]) examForm.get("rooms");
    List<InfoRoom> selectedRooms = new ArrayList<InfoRoom>();
    List<InfoRoom> occupiedSelectedRooms = new ArrayList<InfoRoom>();

    if (rooms != null && rooms.length > 0) {

      for (String room : rooms) {

        InfoRoom infoRoom = ReadRoomByOID.run(Integer.valueOf(room));

        selectedRooms.add(infoRoom);
      }

      for (int iterSR = 0; iterSR < selectedRooms.size(); iterSR++) {
        InfoRoom selectedInfoRoom = selectedRooms.get(iterSR);

        boolean infoContida = false;

        for (int iterAIF = 0; iterAIF < availableInfoRoom.size(); iterAIF++) {
          InfoRoom availInfoRoom = availableInfoRoom.get(iterAIF);

          if (selectedInfoRoom.equals(availInfoRoom)) {
            infoContida = true;
            break;
          }
        }

        if (!infoContida) {
          // room occupied
          occupiedSelectedRooms.add(selectedInfoRoom);
        }
      }

      for (int iterOSR = 0; iterOSR < occupiedSelectedRooms.size(); iterOSR++) {
        InfoRoom occupiedInfoRoom = occupiedSelectedRooms.get(iterOSR);
        selectedRooms.remove(occupiedInfoRoom);
      }

      request.setAttribute("rooms", selectedRooms);
    }

    return mapping.findForward("showCreateForm");
  }
Ejemplo n.º 2
0
  public ActionForward search(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    IUserView userView = UserView.getUser();
    DynaValidatorForm roomSearchForm = (DynaValidatorForm) form;

    // date
    Calendar searchDate = Calendar.getInstance();
    Integer day = new Integer((String) roomSearchForm.get("day"));
    Integer month = new Integer((String) roomSearchForm.get("month"));
    Integer year = new Integer((String) roomSearchForm.get("year"));
    request.setAttribute("day", day.toString());
    request.setAttribute("month", month.toString());
    request.setAttribute("year", year.toString());
    searchDate.set(Calendar.YEAR, year.intValue());
    searchDate.set(Calendar.MONTH, month.intValue() - 1);
    searchDate.set(Calendar.DAY_OF_MONTH, day.intValue());
    if (searchDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
      ActionError actionError = new ActionError("error.sunday");
      ActionErrors actionErrors = new ActionErrors();
      actionErrors.add("error.sunday", actionError);
      saveErrors(request, actionErrors);
      return prepare(mapping, form, request, response);
    }

    // exam start time
    Calendar searchStartTime = Calendar.getInstance();
    Integer startHour = new Integer((String) roomSearchForm.get("beginningHour"));
    Integer startMinute = new Integer((String) roomSearchForm.get("beginningMinute"));
    request.setAttribute("beginningHour", startHour.toString());
    request.setAttribute("beginningMinute", startMinute.toString());
    searchStartTime.set(Calendar.HOUR_OF_DAY, startHour.intValue());
    searchStartTime.set(Calendar.MINUTE, startMinute.intValue());
    searchStartTime.set(Calendar.SECOND, 0);

    // exam end time
    Calendar searchEndTime = Calendar.getInstance();
    Integer endHour = new Integer((String) roomSearchForm.get("endHour"));
    Integer endMinute = new Integer((String) roomSearchForm.get("endMinute"));
    request.setAttribute("endHour", endHour.toString());
    request.setAttribute("endMinute", endMinute.toString());
    searchEndTime.set(Calendar.HOUR_OF_DAY, endHour.intValue());
    searchEndTime.set(Calendar.MINUTE, endMinute.intValue());
    searchEndTime.set(Calendar.SECOND, 0);

    if (searchStartTime.after(searchEndTime)) {
      ActionError actionError = new ActionError("error.timeSwitched");
      ActionErrors actionErrors = new ActionErrors();
      actionErrors.add("error.timeSwitched", actionError);
      saveErrors(request, actionErrors);
      return prepare(mapping, form, request, response);
    }

    int dayOfWeekInt = searchDate.get(Calendar.DAY_OF_WEEK);
    DiaSemana dayOfWeek = new DiaSemana(dayOfWeekInt);

    List<InfoRoom> availableInfoRoom = null;
    availableInfoRoom =
        ReadAvailableRoomsForExam.run(
            YearMonthDay.fromCalendarFields(searchDate),
            YearMonthDay.fromCalendarFields(searchDate),
            HourMinuteSecond.fromCalendarFields(searchStartTime),
            HourMinuteSecond.fromCalendarFields(searchEndTime),
            dayOfWeek,
            null,
            null,
            Boolean.FALSE);
    String sdate =
        roomSearchForm.get("day")
            + "/"
            + roomSearchForm.get("month")
            + "/"
            + roomSearchForm.get("year");
    String startTime =
        roomSearchForm.get("beginningHour") + ":" + roomSearchForm.get("beginningMinute");
    String endTime = roomSearchForm.get("endHour") + ":" + roomSearchForm.get("endMinute");
    request.setAttribute(PresentationConstants.DATE, sdate);
    request.setAttribute(PresentationConstants.START_TIME, startTime);
    request.setAttribute(PresentationConstants.END_TIME, endTime);

    Integer exam = null;
    Integer normal = null;
    List<InfoRoom> newAvailableInfoRoom = new ArrayList<InfoRoom>();
    if (availableInfoRoom != null && !availableInfoRoom.isEmpty()) {
      try {
        exam = new Integer((String) roomSearchForm.get("exam"));
      } catch (NumberFormatException ex) {
        // the user didn't speciefy a exam minimum capacity
      }
      try {
        normal = new Integer((String) roomSearchForm.get("normal"));
      } catch (NumberFormatException ex) {
        // the user didn't speciefy a normal minimum capacity
      }
      if (normal != null || exam != null) {
        Iterator<InfoRoom> iter = availableInfoRoom.iterator();
        while (iter.hasNext()) {
          InfoRoom elem = iter.next();
          if (!((normal != null && elem.getCapacidadeNormal().intValue() < normal.intValue())
              || (exam != null && elem.getCapacidadeExame().intValue() < exam.intValue()))) {
            newAvailableInfoRoom.add(elem);
          }
        }
      } else {
        newAvailableInfoRoom = availableInfoRoom;
      }
    }
    if (newAvailableInfoRoom != null && !newAvailableInfoRoom.isEmpty()) {
      Collections.sort(newAvailableInfoRoom, new BeanComparator("nome"));
      String[] availableRoomId = new String[newAvailableInfoRoom.size()];
      Iterator<InfoRoom> iter = newAvailableInfoRoom.iterator();
      int i = 0;
      while (iter.hasNext()) {
        InfoRoom elem = iter.next();
        availableRoomId[i] = elem.getIdInternal().toString();
      }
      request.setAttribute(PresentationConstants.AVAILABLE_ROOMS_ID, availableRoomId);
    }

    request.setAttribute(PresentationConstants.AVAILABLE_ROOMS, newAvailableInfoRoom);
    return mapping.findForward("showRooms");
  }