Search in sources :

Example 1 with ExportException

use of org.opendatakit.briefcase.operations.ExportException 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)1 ExportSucceededWithErrorsEvent (org.opendatakit.briefcase.model.ExportSucceededWithErrorsEvent)1 TerminationFuture (org.opendatakit.briefcase.model.TerminationFuture)1 ExportException (org.opendatakit.briefcase.operations.ExportException)1