Search in sources :

Example 1 with ExportSucceededEvent

use of org.opendatakit.briefcase.model.ExportSucceededEvent in project briefcase by opendatakit.

the class FormsTableUnitTest method appends_to_a_forms_status_history_when_export_events_are_sent.

@Test
@Ignore
public void appends_to_a_forms_status_history_when_export_events_are_sent() {
    FormStatus theForm = buildFormStatus(1);
    ExportForms forms = new ExportForms(Collections.singletonList(theForm), ExportConfiguration.empty(), new HashMap<>(), new HashMap<>(), new HashMap<>());
    TestFormsTableViewModel viewModel = new TestFormsTableViewModel(forms);
    new FormsTable(forms, new TestFormsTableView(viewModel), viewModel);
    // TODO Event publishing happens asynchronously. We have to work this test a little more to stop ignoring it
    EventBus.publish(new ExportProgressEvent("some progress", (BriefcaseFormDefinition) theForm.getFormDefinition()));
    EventBus.publish(new ExportFailedEvent((BriefcaseFormDefinition) theForm.getFormDefinition()));
    EventBus.publish(new ExportSucceededEvent((BriefcaseFormDefinition) theForm.getFormDefinition()));
    EventBus.publish(new ExportSucceededWithErrorsEvent((BriefcaseFormDefinition) theForm.getFormDefinition()));
    assertThat(theForm.getStatusHistory(), Matchers.containsString("some progress"));
    assertThat(theForm.getStatusHistory(), Matchers.containsString("Failed."));
    assertThat(theForm.getStatusHistory(), Matchers.containsString("Succeeded."));
    assertThat(theForm.getStatusHistory(), Matchers.containsString("Succeeded, but with errors."));
}
Also used : ExportForms(org.opendatakit.briefcase.export.ExportForms) FormStatus(org.opendatakit.briefcase.model.FormStatus) FormStatusBuilder.buildFormStatus(org.opendatakit.briefcase.model.FormStatusBuilder.buildFormStatus) BriefcaseFormDefinition(org.opendatakit.briefcase.model.BriefcaseFormDefinition) ExportSucceededWithErrorsEvent(org.opendatakit.briefcase.model.ExportSucceededWithErrorsEvent) ExportProgressEvent(org.opendatakit.briefcase.model.ExportProgressEvent) ExportFailedEvent(org.opendatakit.briefcase.model.ExportFailedEvent) ExportSucceededEvent(org.opendatakit.briefcase.model.ExportSucceededEvent) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with ExportSucceededEvent

use of org.opendatakit.briefcase.model.ExportSucceededEvent in project briefcase by opendatakit.

the class ExportToCsv method export.

public static void export(Path exportDir, BriefcaseFormDefinition formDefinition, String baseFilename, boolean exportMedia, boolean overwriteFiles, Optional<LocalDate> startDate, Optional<LocalDate> endDate) {
    log.info("exporting to : " + exportDir);
    ExportToCsv action = new ExportToCsv(new TerminationFuture(), exportDir.toFile(), formDefinition, baseFilename, exportMedia, overwriteFiles, startDate.map(ld -> Date.from(ld.atStartOfDay(systemDefault()).toInstant())).orElse(null), endDate.map(ld -> Date.from(ld.atStartOfDay(systemDefault()).toInstant())).orElse(null));
    try {
        boolean allSuccessful = action.doAction();
        if (allSuccessful && action.someSkipped())
            EventBus.publish(new ExportSucceededWithErrorsEvent(action.getFormDefinition()));
        if (allSuccessful && action.noneSkipped())
            EventBus.publish(new ExportSucceededEvent(action.getFormDefinition()));
        if (allSuccessful && action.allSkipped())
            throw new ExportException(formDefinition, "None of the instances where exported");
        if (!allSuccessful)
            throw new ExportException(formDefinition);
    } catch (Throwable t) {
        throw new ExportException(formDefinition);
    }
}
Also used : ExportSucceededWithErrorsEvent(org.opendatakit.briefcase.model.ExportSucceededWithErrorsEvent) TerminationFuture(org.opendatakit.briefcase.model.TerminationFuture) ExportSucceededEvent(org.opendatakit.briefcase.model.ExportSucceededEvent) ExportException(org.opendatakit.briefcase.operations.ExportException)

Aggregations

ExportSucceededEvent (org.opendatakit.briefcase.model.ExportSucceededEvent)2 ExportSucceededWithErrorsEvent (org.opendatakit.briefcase.model.ExportSucceededWithErrorsEvent)2 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 ExportForms (org.opendatakit.briefcase.export.ExportForms)1 BriefcaseFormDefinition (org.opendatakit.briefcase.model.BriefcaseFormDefinition)1 ExportFailedEvent (org.opendatakit.briefcase.model.ExportFailedEvent)1 ExportProgressEvent (org.opendatakit.briefcase.model.ExportProgressEvent)1 FormStatus (org.opendatakit.briefcase.model.FormStatus)1 FormStatusBuilder.buildFormStatus (org.opendatakit.briefcase.model.FormStatusBuilder.buildFormStatus)1 TerminationFuture (org.opendatakit.briefcase.model.TerminationFuture)1 ExportException (org.opendatakit.briefcase.operations.ExportException)1