@Test public void downloadFormTemplates_shouldReturnSaveErrorIfSaveExceptionOccur() throws FormController.FormSaveException { String[] formUuids = {}; doThrow(new FormController.FormSaveException(null)).when(formController).replaceFormTemplates(anyList()); assertThat(muzimaSyncService.downloadFormTemplates(formUuids,true)[0], is(SyncStatusConstants.SAVE_ERROR)); }
public int[] downloadFormTemplates(String[] formIds, boolean replaceExistingTemplates) { int[] result = new int[4]; try { List<FormTemplate> formTemplates = formController.downloadFormTemplates(formIds); formTemplates.removeAll(Collections.singleton(null)); Log.i(getClass().getSimpleName(), formTemplates.size() + " form template download successful"); if (replaceExistingTemplates) { formController.replaceFormTemplates(formTemplates); } else { formController.saveFormTemplates(formTemplates); } Log.i(getClass().getSimpleName(), "Form templates replaced"); result[0] = SUCCESS; result[1] = formTemplates.size(); } catch (FormController.FormSaveException e) { Log.e(getClass().getSimpleName(), "Exception when trying to save forms", e); result[0] = SyncStatusConstants.SAVE_ERROR; return result; } catch (FormController.FormFetchException e) { Log.e(getClass().getSimpleName(), "Exception when trying to download forms", e); result[0] = SyncStatusConstants.DOWNLOAD_ERROR; return result; } return result; }
MuzimaSyncService { public int[] downloadFormTemplates(String[] formIds, boolean replaceExistingTemplates) { int[] result = new int[4]; try { List<FormTemplate> formTemplates = formController.downloadFormTemplates(formIds); formTemplates.removeAll(Collections.singleton(null)); Log.i(getClass().getSimpleName(), formTemplates.size() + " form template download successful"); if (replaceExistingTemplates) { formController.replaceFormTemplates(formTemplates); } else { formController.saveFormTemplates(formTemplates); } Log.i(getClass().getSimpleName(), "Form templates replaced"); result[0] = SUCCESS; result[1] = formTemplates.size(); } catch (FormController.FormSaveException e) { Log.e(getClass().getSimpleName(), "Exception when trying to save forms", e); result[0] = SyncStatusConstants.SAVE_ERROR; return result; } catch (FormController.FormFetchException e) { Log.e(getClass().getSimpleName(), "Exception when trying to download forms", e); result[0] = SyncStatusConstants.DOWNLOAD_ERROR; return result; } return result; } }
MuzimaSyncService { public int[] downloadFormTemplates(String[] formIds, boolean replaceExistingTemplates) { int[] result = new int[4]; try { List<FormTemplate> formTemplates = formController.downloadFormTemplates(formIds); formTemplates.removeAll(Collections.singleton(null)); Log.i(getClass().getSimpleName(), formTemplates.size() + " form template download successful"); if (replaceExistingTemplates) { formController.replaceFormTemplates(formTemplates); } else { formController.saveFormTemplates(formTemplates); } Log.i(getClass().getSimpleName(), "Form templates replaced"); result[0] = SUCCESS; result[1] = formTemplates.size(); } catch (FormController.FormSaveException e) { Log.e(getClass().getSimpleName(), "Exception when trying to save forms", e); result[0] = SyncStatusConstants.SAVE_ERROR; return result; } catch (FormController.FormFetchException e) { Log.e(getClass().getSimpleName(), "Exception when trying to download forms", e); result[0] = SyncStatusConstants.DOWNLOAD_ERROR; return result; } return result; } MuzimaSyncService(MuzimaApplication muzimaContext); }
MuzimaSyncService { public int[] downloadFormTemplates(String[] formIds, boolean replaceExistingTemplates) { int[] result = new int[4]; try { List<FormTemplate> formTemplates = formController.downloadFormTemplates(formIds); formTemplates.removeAll(Collections.singleton(null)); Log.i(getClass().getSimpleName(), formTemplates.size() + " form template download successful"); if (replaceExistingTemplates) { formController.replaceFormTemplates(formTemplates); } else { formController.saveFormTemplates(formTemplates); } Log.i(getClass().getSimpleName(), "Form templates replaced"); result[0] = SUCCESS; result[1] = formTemplates.size(); } catch (FormController.FormSaveException e) { Log.e(getClass().getSimpleName(), "Exception when trying to save forms", e); result[0] = SyncStatusConstants.SAVE_ERROR; return result; } catch (FormController.FormFetchException e) { Log.e(getClass().getSimpleName(), "Exception when trying to download forms", e); result[0] = SyncStatusConstants.DOWNLOAD_ERROR; return result; } return result; } MuzimaSyncService(MuzimaApplication muzimaContext); int authenticate(String[] credentials); int authenticate(String[] credentials, boolean isUpdatePasswordRequired); int[] downloadForms(); int[] downloadFormTemplatesAndRelatedMetadata(String[] formIds, boolean replaceExistingTemplates); int[] downloadFormTemplates(String[] formIds, boolean replaceExistingTemplates); int[] downloadLocations(String[] locationIds); int[] downloadProviders(String[] providerIds); int[] downloadConcepts(String[] conceptIds); int[] downloadCohorts(); int[] downloadCohorts(String[] cohortUuids); int[] downloadPatientsForCohortsWithUpdatesAvailable(); int[] downloadRemovedCohortMembershipData(String[] cohortUuids); int[] downloadPatientsForCohorts(String[] cohortUuids); int[] downloadPatients(String[] patientUUIDs); int[] downloadObservationsForPatientsByCohortUUIDs(String[] cohortUuids, boolean replaceExistingObservation); int[] downloadObservationsForPatientsByPatientUUIDs(List<String> patientUuids, boolean replaceExistingObservations); int[] downloadEncountersForPatientsByCohortUUIDs(String[] cohortUuids, boolean replaceExistingEncounters); int[] downloadEncountersForPatientsByPatientUUIDs(List<String> patientUuids, boolean replaceExistingEncounters); int[] uploadAllCompletedForms(); void consolidatePatients(); List<FormData> getArchivedFormData(); int[] checkAndDeleteTemporaryDataForProcessedFormData(List<FormData> archivedFormData); List<String> getUuidsForAllPatientsFromLocalStorage(); List<Patient> updatePatientsNotPartOfCohorts(); int[] downloadNotifications(String receiverUuid); int[] downloadPatientReportHeaders(String patientUuid); int[] downloadAllPatientReportHeadersAndReports(); int[] downloadPatientReportsByUuid(String[] reportUuids); void downloadSetupConfigurations(); int[] downloadSetupConfigurationTemplate(String uuid); int[] downloadAndSaveUpdatedSetupConfigurationTemplate(String uuid); int[] updateSetupConfigurationTemplates(); int[] downloadSetting(String property); int[] downloadNewSettings(); void updateSettingsPreferences(List<MuzimaSetting> muzimaSettings); int[] downloadRelationshipsTypes(); int[] downloadRelationshipsForPatientsByPatientUUIDs(List<String> patientUuids); int[] downloadRelationshipsForPatientsByCohortUUIDs(String[] cohortUuids); String getDefaultLocation(); }
MuzimaSyncService { public int[] downloadFormTemplates(String[] formIds, boolean replaceExistingTemplates) { int[] result = new int[4]; try { List<FormTemplate> formTemplates = formController.downloadFormTemplates(formIds); formTemplates.removeAll(Collections.singleton(null)); Log.i(getClass().getSimpleName(), formTemplates.size() + " form template download successful"); if (replaceExistingTemplates) { formController.replaceFormTemplates(formTemplates); } else { formController.saveFormTemplates(formTemplates); } Log.i(getClass().getSimpleName(), "Form templates replaced"); result[0] = SUCCESS; result[1] = formTemplates.size(); } catch (FormController.FormSaveException e) { Log.e(getClass().getSimpleName(), "Exception when trying to save forms", e); result[0] = SyncStatusConstants.SAVE_ERROR; return result; } catch (FormController.FormFetchException e) { Log.e(getClass().getSimpleName(), "Exception when trying to download forms", e); result[0] = SyncStatusConstants.DOWNLOAD_ERROR; return result; } return result; } MuzimaSyncService(MuzimaApplication muzimaContext); int authenticate(String[] credentials); int authenticate(String[] credentials, boolean isUpdatePasswordRequired); int[] downloadForms(); int[] downloadFormTemplatesAndRelatedMetadata(String[] formIds, boolean replaceExistingTemplates); int[] downloadFormTemplates(String[] formIds, boolean replaceExistingTemplates); int[] downloadLocations(String[] locationIds); int[] downloadProviders(String[] providerIds); int[] downloadConcepts(String[] conceptIds); int[] downloadCohorts(); int[] downloadCohorts(String[] cohortUuids); int[] downloadPatientsForCohortsWithUpdatesAvailable(); int[] downloadRemovedCohortMembershipData(String[] cohortUuids); int[] downloadPatientsForCohorts(String[] cohortUuids); int[] downloadPatients(String[] patientUUIDs); int[] downloadObservationsForPatientsByCohortUUIDs(String[] cohortUuids, boolean replaceExistingObservation); int[] downloadObservationsForPatientsByPatientUUIDs(List<String> patientUuids, boolean replaceExistingObservations); int[] downloadEncountersForPatientsByCohortUUIDs(String[] cohortUuids, boolean replaceExistingEncounters); int[] downloadEncountersForPatientsByPatientUUIDs(List<String> patientUuids, boolean replaceExistingEncounters); int[] uploadAllCompletedForms(); void consolidatePatients(); List<FormData> getArchivedFormData(); int[] checkAndDeleteTemporaryDataForProcessedFormData(List<FormData> archivedFormData); List<String> getUuidsForAllPatientsFromLocalStorage(); List<Patient> updatePatientsNotPartOfCohorts(); int[] downloadNotifications(String receiverUuid); int[] downloadPatientReportHeaders(String patientUuid); int[] downloadAllPatientReportHeadersAndReports(); int[] downloadPatientReportsByUuid(String[] reportUuids); void downloadSetupConfigurations(); int[] downloadSetupConfigurationTemplate(String uuid); int[] downloadAndSaveUpdatedSetupConfigurationTemplate(String uuid); int[] updateSetupConfigurationTemplates(); int[] downloadSetting(String property); int[] downloadNewSettings(); void updateSettingsPreferences(List<MuzimaSetting> muzimaSettings); int[] downloadRelationshipsTypes(); int[] downloadRelationshipsForPatientsByPatientUUIDs(List<String> patientUuids); int[] downloadRelationshipsForPatientsByCohortUUIDs(String[] cohortUuids); String getDefaultLocation();  }