public String createEmployee()

in service/src/main/java/org/apache/fineract/cn/office/internal/command/handler/EmployeeAggregate.java [71:98]


  public String createEmployee(final CreateEmployeeCommand createEmployeeCommand)
      throws ServiceException {
    final Employee employee = createEmployeeCommand.employee();

    if (this.employeeRepository.existsByIdentifier(employee.getIdentifier())) {
      throw ServiceException.conflict("Employee {0} already exists.", employee.getIdentifier());
    }

    final EmployeeEntity employeeEntity = EmployeeMapper.map(employee);

    if (employee.getAssignedOffice() != null) {
      final Optional<OfficeEntity> officeEntity = this.officeRepository.findByIdentifier(employee.getAssignedOffice());
      if (officeEntity.isPresent()) {
        employeeEntity.setAssignedOffice(officeEntity.get());
      } else {
        throw ServiceException.notFound("Assigned office {0} not found.", employee.getAssignedOffice());
      }
    }
    employeeEntity.setCreatedBy(UserContextHolder.checkedGetUser());
    employeeEntity.setCreatedOn(Utils.utcNow());
    final EmployeeEntity savedEmployeeEntity = this.employeeRepository.save(employeeEntity);

    if (employee.getContactDetails() != null) {
      this.saveContactDetail(savedEmployeeEntity, employee.getContactDetails());
    }

    return employee.getIdentifier();
  }