private void deleteNotExisting(SynchronizationBusinessDataRequest request) { final Long departmentId = request.getDepartmentId(); final List<Long> newDepartmentIds = request.getDepartment().stream().map(Department::getId).collect(Collectors.toList()); final List<Long> newTransporterIds = request.getTransporter().stream().map(Transporter::getId).collect(Collectors.toList()); final List<Long> newEployeeIds = request.getEmployee().stream().map(Employee::getId).collect(Collectors.toList()); final List<Long> transitIds = request.getTransit().stream().map(Transit::getId).collect(Collectors.toList()); final List<Long> oldDepartmentIds = departmentRepository.selectIds(); final List<Long> oldTransporterIds = transporterRepository.selectIds(); final List<Long> oldEmployeeIds = employeeRepository.selectIds(); final List<Long> oldTransitIds = transitRepository.selectIds(); // oldDepartmentIds.stream().filter(oldId -> // !newDepartmentIds.contains(oldId)).forEach(departmentRepository::delete); // oldTransporterIds.stream().filter(oldId -> // !newTransporterIds.contains(oldId)).forEach(transporterRepository::delete); // oldEmployeeIds.stream().filter(oldId -> // !newEployeeIds.contains(oldId)).forEach(employeeRepository::delete); // oldTransitIds.stream().filter(oldId -> // !transitIds.contains(oldId)).forEach(transitRepository::delete); }
private void updateOrSaveNew(SynchronizationBusinessDataRequest request) { final Long departmentId = request.getDepartmentId(); for (Department d : request.getDepartment()) { d.setSourceDepartmentId(departmentId); d.setDataSourceId(d.getId()); } for (Transporter t : request.getTransporter()) { t.setSourceDepartmentId(departmentId); t.setDataSourceId(t.getId()); } for (Employee e : request.getEmployee()) { e.setSourceDepartmentId(departmentId); e.setDataSourceId(e.getId()); } for (Transit t : request.getTransit()) { t.setSourceDepartmentId(departmentId); t.setDataSourceId(t.getId()); } departmentRepository.save(request.getDepartment()); transporterRepository.save(request.getTransporter()); employeeRepository.save(request.getEmployee()); transitRepository.save(request.getTransit()); }