Source:
<code>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); <START> dataValueImportSummary = apiCallExecutor.executeObjectCall( <END> 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(); }</code><technical_language>Wrap in try-catch restore state TO_UPDATE throwing d2error</technical_language>

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(); }