Пример #1
0
  /**
   * Return the list of registered drivers for the JSF page.
   *
   * @return A list of JSF SelectItem objects to fill a page component with the list of drivers.
   */
  public List<SelectItem> getDriverList() {
    List<SelectItem> driverList = new ArrayList<SelectItem>();
    driverList.add(
        new SelectItem(null, getI18nMessage("msgs", "manageAmbulances.text.currentDriver.none")));

    List<Employee> drivers = employeeDAO.retrieveDrivers();
    for (Employee driver : drivers)
      driverList.add(new SelectItem(driver.getId(), driver.getName()));

    return driverList;
  }
Пример #2
0
  /**
   * Called from the assignment page's form, sends the data on the end of the current assignment
   * and/or the beginning of a new one and changes the driver assigned to the ambulance.
   *
   * <p>This method executes a scenario in the service class.
   */
  public void changeAssignment() {
    // Only change an assignment if the driver actually changed.
    if ((driverId != null)
        && (currentAssignment.getDriver() != null)
        && (driverId.equals(currentAssignment.getDriver().getId()))) {
      logger.log(
          Level.WARNING,
          "Assigning ambulance # {0} (id {1}) with the same driver. Current assignment's driver's ID: {3}, supplied ID: {4}.",
          new Object[] {
            selectedEntity.getNumber(),
            selectedEntity.getId(),
            currentAssignment.getDriver().getId(),
            driverId
          });
      addGlobalI18nMessage(
          "msgs",
          FacesMessage.SEVERITY_WARN,
          "manageAmbulances.warn.sameDriverAssignment",
          currentAssignment.getDriver().getName());
    } else {
      Employee driver = (driverId == null) ? null : employeeDAO.retrieveById(driverId);

      try {
        // If the driver was specified, create a new assignment, possibly ending a current
        // assignment.
        if (driver != null) {
          logger.log(
              Level.INFO,
              "Assigning ambulance # {0} (id {1}). Driver: {2}.",
              new Object[] {selectedEntity.getNumber(), selectedEntity.getId(), driver.getName()});
          currentAssignment = getCrudService().assignAmbulance(selectedEntity, driver);
          free = false;
          addGlobalI18nMessage(
              "msgs", FacesMessage.SEVERITY_INFO, "manageAmbulances.info.assignmentStarted");
        }
        // If not, end the current assignment.
        else {
          logger.log(
              Level.INFO,
              "Ending current assignment for ambulance # {0} (id {1}).",
              new Object[] {selectedEntity.getNumber(), selectedEntity.getId()});
          getCrudService().endCurrentAssignment(selectedEntity);
          currentAssignment = null;
          free = true;
          addGlobalI18nMessage(
              "msgs", FacesMessage.SEVERITY_INFO, "manageAmbulances.info.assignmentEnded");
        }
      } catch (AmbulanceHasMultipleCurrentDriverAssignmentsException e) {
        logger.log(
            Level.SEVERE,
            "There has been an error while assigning a driver to ambulance # "
                + selectedEntity.getNumber()
                + " (id "
                + selectedEntity.getId()
                + ")",
            e);
        addGlobalI18nMessage(
            "msgs",
            FacesMessage.SEVERITY_ERROR,
            "manageAmbulances.error.assignmentError",
            selectedEntity.getNumber());
        driverId = null;
      } catch (AmbulanceHasNoCurrentDriverAssignmentsException e) {
        logger.log(
            Level.SEVERE,
            "There has been an error while assigning a driver to ambulance # "
                + selectedEntity.getNumber()
                + " (id "
                + selectedEntity.getId()
                + ")",
            e);
        addGlobalI18nMessage(
            "msgs",
            FacesMessage.SEVERITY_ERROR,
            "manageAmbulances.error.assignmentError",
            selectedEntity.getNumber());
        driverId = null;
      } catch (EmployeeIsNotDriverException e) {
        logger.log(
            Level.SEVERE,
            "There has been an error while assigning a driver to ambulance # "
                + selectedEntity.getNumber()
                + " (id "
                + selectedEntity.getId()
                + "): the specified employee ("
                + driver.getLogin()
                + ") is not a driver!",
            e);
        addGlobalI18nMessage(
            "msgs",
            FacesMessage.SEVERITY_ERROR,
            "manageAmbulances.error.assignmentErrorNotDriver",
            driver.getName(),
            selectedEntity.getNumber());
        driverId = null;
      }
    }
  }