Source:
private void uploadInternal(D2ProgressManager progressManager, ObservableEmitter<D2Progress> emitter, List<DataSetCompleteRegistration> toPostDataSetCompleteRegistrations, List<DataSetCompleteRegistration> toDeleteDataSetCompleteRegistrations) throws D2Error { DataValueImportSummary dataValueImportSummary = DataValueImportSummary.EMPTY; DataSetCompleteRegistrationPayload dataSetCompleteRegistrationPayload = new DataSetCompleteRegistrationPayload(toPostDataSetCompleteRegistrations); if (!toPostDataSetCompleteRegistrations.isEmpty()) { markPartitionsAsUploading(toPostDataSetCompleteRegistrations); dataValueImportSummary = apiCallExecutor.executeObjectCall( dataSetCompleteRegistrationService.postDataSetCompleteRegistrations( dataSetCompleteRegistrationPayload)); } List<DataSetCompleteRegistration> deletedDataSetCompleteRegistrations = new ArrayList<>(); List<DataSetCompleteRegistration> withErrorDataSetCompleteRegistrations = new ArrayList<>(); if (!toDeleteDataSetCompleteRegistrations.isEmpty()) { for (DataSetCompleteRegistration dataSetCompleteRegistration : toDeleteDataSetCompleteRegistrations) { try { CategoryOptionCombo coc = categoryOptionComboCollectionRepository .withCategoryOptions() .uid(dataSetCompleteRegistration.attributeOptionCombo()) .blockingGet(); markPartitionsAsUploading(toDeleteDataSetCompleteRegistrations); apiCallExecutor.executeObjectCallWithEmptyResponse( dataSetCompleteRegistrationService.deleteDataSetCompleteRegistration( dataSetCompleteRegistration.dataSet(), dataSetCompleteRegistration.period(), dataSetCompleteRegistration.organisationUnit(), coc.categoryCombo().uid(), semicolonSeparatedCollectionValues(UidsHelper.getUids(coc.categoryOptions())), false)); deletedDataSetCompleteRegistrations.add(dataSetCompleteRegistration); } catch (D2Error d2Error) { withErrorDataSetCompleteRegistrations.add(dataSetCompleteRegistration); } } } dataSetCompleteRegistrationImportHandler.handleImportSummary( dataSetCompleteRegistrationPayload, dataValueImportSummary, deletedDataSetCompleteRegistrations, withErrorDataSetCompleteRegistrations); emitter.onNext(progressManager.increaseProgress(DataSetCompleteRegistration.class, true)); emitter.onComplete(); }

Target:
private void uploadInternal(D2ProgressManager progressManager, ObservableEmitter<D2Progress> emitter, List<DataSetCompleteRegistration> toPostDataSetCompleteRegistrations, List<DataSetCompleteRegistration> toDeleteDataSetCompleteRegistrations) throws D2Error { DataValueImportSummary dataValueImportSummary = DataValueImportSummary.EMPTY; DataSetCompleteRegistrationPayload dataSetCompleteRegistrationPayload = new DataSetCompleteRegistrationPayload(toPostDataSetCompleteRegistrations); if (!toPostDataSetCompleteRegistrations.isEmpty()) { markPartitionsAs(toPostDataSetCompleteRegistrations, State.UPLOADING); try { dataValueImportSummary = apiCallExecutor.executeObjectCall( dataSetCompleteRegistrationService.postDataSetCompleteRegistrations( dataSetCompleteRegistrationPayload)); } catch (Exception e) { markPartitionsAs(toPostDataSetCompleteRegistrations, State.ERROR); throw e; } } List<DataSetCompleteRegistration> deletedDataSetCompleteRegistrations = new ArrayList<>(); List<DataSetCompleteRegistration> withErrorDataSetCompleteRegistrations = new ArrayList<>(); if (!toDeleteDataSetCompleteRegistrations.isEmpty()) { for (DataSetCompleteRegistration dataSetCompleteRegistration : toDeleteDataSetCompleteRegistrations) { try { CategoryOptionCombo coc = categoryOptionComboCollectionRepository .withCategoryOptions() .uid(dataSetCompleteRegistration.attributeOptionCombo()) .blockingGet(); markPartitionsAs(toDeleteDataSetCompleteRegistrations, State.UPLOADING); apiCallExecutor.executeObjectCallWithEmptyResponse( dataSetCompleteRegistrationService.deleteDataSetCompleteRegistration( dataSetCompleteRegistration.dataSet(), dataSetCompleteRegistration.period(), dataSetCompleteRegistration.organisationUnit(), coc.categoryCombo().uid(), semicolonSeparatedCollectionValues(UidsHelper.getUids(coc.categoryOptions())), false)); deletedDataSetCompleteRegistrations.add(dataSetCompleteRegistration); } catch (D2Error d2Error) { withErrorDataSetCompleteRegistrations.add(dataSetCompleteRegistration); } } } dataSetCompleteRegistrationImportHandler.handleImportSummary( dataSetCompleteRegistrationPayload, dataValueImportSummary, deletedDataSetCompleteRegistrations, withErrorDataSetCompleteRegistrations); emitter.onNext(progressManager.increaseProgress(DataSetCompleteRegistration.class, true)); emitter.onComplete(); }