@Transactional public void update(final Employee employee) { // Following is added to prevent null values and empty assignment // objects getting persisted employee.setAssignments( employee .getAssignments() .parallelStream() .filter(assignment -> assignment.getPosition() != null) .collect(Collectors.toList())); for (final Assignment assign : employee.getAssignments()) { assign.setEmployee(employee); assign.setDepartment(assign.getDepartment()); for (final HeadOfDepartments hod : assign.getDeptSet()) hod.setAssignment(assign); } employee.setJurisdictions( employee .getJurisdictions() .parallelStream() .filter( Jurisdictions -> Jurisdictions.getBoundaryType() != null && Jurisdictions.getBoundary() != null) .collect(Collectors.toList())); for (final Jurisdiction jurisdiction : employee.getJurisdictions()) { jurisdiction.setEmployee(employee); jurisdiction.setBoundaryType(jurisdiction.getBoundaryType()); jurisdiction.setBoundary(jurisdiction.getBoundary()); } employeeRepository.saveAndFlush(employee); }
@Transactional public void create(final Employee employee) { employee.setPwdExpiryDate( new DateTime().plusDays(applicationProperties.userPasswordExpiryInDays()).toDate()); employee.setPassword(passwordEncoder.encode(EisConstants.DEFAULT_EMPLOYEE_PWD)); // Following is added to prevent null values and empty assignment // objects getting persisted employee.setAssignments( employee .getAssignments() .parallelStream() .filter(assignment -> assignment.getPosition() != null) .collect(Collectors.toList())); for (final Assignment assign : employee.getAssignments()) { assign.setEmployee(employee); assign.setDepartment(assign.getDepartment()); for (final HeadOfDepartments hod : assign.getDeptSet()) hod.setAssignment(assign); } employee.setJurisdictions( employee .getJurisdictions() .parallelStream() .filter( Jurisdictions -> Jurisdictions.getBoundaryType() != null && Jurisdictions.getBoundary() != null) .collect(Collectors.toList())); for (final Jurisdiction jurisdiction : employee.getJurisdictions()) { jurisdiction.setEmployee(employee); jurisdiction.setBoundaryType(jurisdiction.getBoundaryType()); jurisdiction.setBoundary(jurisdiction.getBoundary()); } employee.getRoles().add(roleService.getRoleByName(EisConstants.ROLE_EMPLOYEE)); employeeRepository.save(employee); }