コード例 #1
0
 @Override
 public Employee createEmployee(EmployeeDTO employeeDTO) {
   Employee employee = new Employee();
   employee.setEmail(employeeDTO.getEmail());
   employee.setPasswordHash(hashPassword(employeeDTO.getPassword()));
   employee.setRole(employeeDTO.getRole());
   return employeeRepository.save(employee);
 }
コード例 #2
0
 public void updateEmployee(EmployeeDTO employeeDTO) {
   Employee employee = employeeRepository.findOneByEmail(employeeDTO.getEmail()).get();
   if (checkIfValidEntity(employee)) {
     employee.setFunctionalLevel(employeeDTO.getFunctionalLevel());
     employee.setActive(employeeDTO.getActive());
     if (employeeDTO.getActive() == false && employee.getCurrentCar() != null) {
       moveCurrentCarToCarHistory(employee);
     }
     employeeRepository.save(employee);
   }
 }
コード例 #3
0
  private void moveCurrentCarToCarHistory(Employee employee) {
    Car currentCar = carRepository.findOne(employee.getCurrentCar().getId());
    Set<Car> carHistory = employee.getCarHistory();
    carHistory.add(employee.getCurrentCar());

    if (currentCar.getEndLeasing().isAfter(LocalDate.now())
        && !(currentCar.getEndLeasing().isEqual(LocalDate.now()))) {
      currentCar.setInThePool(true);
    }
    carRepository.save(currentCar);
  }
コード例 #4
0
  @Override
  public CarDTO assignCarToEmployee(
      Order order, int leasingDurationInYears, String numberPlate, String vinNumber) {
    Employee employee = order.getEmployee();
    if (employee.getCurrentCar() != null) {
      moveCurrentCarToCarHistory(employee);
    }

    Car car = createNewCarFromOrder(order, leasingDurationInYears, numberPlate, vinNumber);

    employee.setCurrentCar(car);

    employeeRepository.save(employee);
    return CarMapper.mapCarObjectToCarDTO(car);
  }
コード例 #5
0
 public boolean checkIfValidEntity(Employee employee) {
   int functionalLevel = employee.getFunctionalLevel();
   if (functionalLevel < 1 || functionalLevel > 7)
     throw new IllegalArgumentException(
         "The functional level can not be lower than 1 or higher than 7!");
   return true;
 }
コード例 #6
0
  @Override
  public CarDTO assignPoolCarToEmployee(EmployeeDTO employeeDTO, CarDTO carDTO) {
    Employee employee = employeeRepository.findOneByEmail(employeeDTO.getEmail()).get();

    updatePoolCar(carRepository.findOne(carDTO.getId()));
    Car currentCar = employee.getCurrentCar();

    if (currentCar != null) {
      Set<Car> carHistory = employee.getCarHistory();
      currentCar.setEndLeasing(LocalDate.now());
      carHistory.add(currentCar);
    }
    employee.setCurrentCar(carRepository.findOne(carDTO.getId()));
    employee.setReceivedMailForNewCar(false);
    employeeRepository.save(employee);
    return carDTO;
  }