Search in sources :

Example 1 with RemoteServer

use of org.opendatakit.briefcase.reused.transfer.RemoteServer in project briefcase by opendatakit.

the class ExportPanel method export.

private void export() {
    Stream<Job<?>> allJobs = forms.getSelectedForms().stream().map(form -> {
        FormKey key = FormKey.from(form);
        FormMetadata formMetadata = formMetadataPort.fetch(key).orElseThrow(BriefcaseException::new);
        form.setStatusString("Starting to export form");
        String formId = form.getFormDefinition().getFormId();
        ExportConfiguration configuration = forms.getConfiguration(formId);
        FormDefinition formDef = FormDefinition.from((BriefcaseFormDefinition) form.getFormDefinition());
        // TODO Abstract away the subtype of RemoteServer. This should say Optional<RemoteServer>
        Optional<AggregateServer> savedPullSource = RemoteServer.readFromPrefs(appPreferences, pullPanelPrefs, form);
        Job<Void> pullJob = configuration.resolvePullBefore() && savedPullSource.isPresent() ? new PullFromAggregate(http, savedPullSource.get(), appPreferences.getBriefcaseDir().orElseThrow(BriefcaseException::new), false, EventBus::publish, formMetadataPort).pull(form, appPreferences.resolveStartFromLast() ? Optional.of(formMetadata.getCursor()) : Optional.empty()) : Job.noOpSupplier();
        Job<Void> exportJob = Job.run(runnerStatus -> ExportToCsv.export(formMetadataPort, formMetadata, form, formDef, appPreferences.getBriefcaseDir().orElseThrow(BriefcaseException::new), configuration, analytics));
        Job<Void> exportGeoJsonJob = configuration.resolveIncludeGeoJsonExport() ? Job.run(runnerStatus -> ExportToGeoJson.export(formMetadata, formDef, configuration, analytics)) : Job.noOp;
        return Job.run(runnerStatus -> form.clearStatusHistory()).thenRun(pullJob).thenRun(exportJob).thenRun(exportGeoJsonJob);
    });
    JobsRunner.launchAsync(allJobs).onComplete(form::unsetExporting).waitForCompletion();
}
Also used : Builder.load(org.opendatakit.briefcase.export.ExportConfiguration.Builder.load) FormDefinition(org.opendatakit.briefcase.export.FormDefinition) LocalDateTime(java.time.LocalDateTime) BriefcasePreferences(org.opendatakit.briefcase.model.BriefcasePreferences) RemoteServer(org.opendatakit.briefcase.reused.transfer.RemoteServer) BriefcaseFormDefinition(org.opendatakit.briefcase.model.BriefcaseFormDefinition) ArrayList(java.util.ArrayList) ExportToGeoJson(org.opendatakit.briefcase.export.ExportToGeoJson) Builder.empty(org.opendatakit.briefcase.export.ExportConfiguration.Builder.empty) AnnotationProcessor(org.bushe.swing.event.annotation.AnnotationProcessor) FormMetadataPort(org.opendatakit.briefcase.model.form.FormMetadataPort) EventBus(org.bushe.swing.event.EventBus) ExportConfiguration(org.opendatakit.briefcase.export.ExportConfiguration) ISO_DATE_TIME(java.time.format.DateTimeFormatter.ISO_DATE_TIME) FormMetadata(org.opendatakit.briefcase.model.form.FormMetadata) BriefcaseException(org.opendatakit.briefcase.reused.BriefcaseException) AggregateServer(org.opendatakit.briefcase.reused.transfer.AggregateServer) ExportForms(org.opendatakit.briefcase.export.ExportForms) FormCache(org.opendatakit.briefcase.util.FormCache) FormKey(org.opendatakit.briefcase.model.form.FormKey) ExportForms.buildCustomConfPrefix(org.opendatakit.briefcase.export.ExportForms.buildCustomConfPrefix) FormStatus(org.opendatakit.briefcase.model.FormStatus) JobsRunner(org.opendatakit.briefcase.reused.job.JobsRunner) UI.errorMessage(org.opendatakit.briefcase.ui.reused.UI.errorMessage) Http(org.opendatakit.briefcase.reused.http.Http) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Stream(java.util.stream.Stream) PullFromAggregate(org.opendatakit.briefcase.pull.aggregate.PullFromAggregate) CacheUpdateEvent(org.opendatakit.briefcase.reused.CacheUpdateEvent) Optional(java.util.Optional) EventSubscriber(org.bushe.swing.event.annotation.EventSubscriber) ExportEvent(org.opendatakit.briefcase.export.ExportEvent) Analytics(org.opendatakit.briefcase.ui.reused.Analytics) Job(org.opendatakit.briefcase.reused.job.Job) ExportToCsv(org.opendatakit.briefcase.export.ExportToCsv) ExportConfiguration(org.opendatakit.briefcase.export.ExportConfiguration) EventBus(org.bushe.swing.event.EventBus) FormKey(org.opendatakit.briefcase.model.form.FormKey) FormMetadata(org.opendatakit.briefcase.model.form.FormMetadata) BriefcaseException(org.opendatakit.briefcase.reused.BriefcaseException) PullFromAggregate(org.opendatakit.briefcase.pull.aggregate.PullFromAggregate) Job(org.opendatakit.briefcase.reused.job.Job) FormDefinition(org.opendatakit.briefcase.export.FormDefinition) BriefcaseFormDefinition(org.opendatakit.briefcase.model.BriefcaseFormDefinition) AggregateServer(org.opendatakit.briefcase.reused.transfer.AggregateServer)

Aggregations

LocalDateTime (java.time.LocalDateTime)1 ISO_DATE_TIME (java.time.format.DateTimeFormatter.ISO_DATE_TIME)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors.toList (java.util.stream.Collectors.toList)1 Stream (java.util.stream.Stream)1 EventBus (org.bushe.swing.event.EventBus)1 AnnotationProcessor (org.bushe.swing.event.annotation.AnnotationProcessor)1 EventSubscriber (org.bushe.swing.event.annotation.EventSubscriber)1 ExportConfiguration (org.opendatakit.briefcase.export.ExportConfiguration)1 Builder.empty (org.opendatakit.briefcase.export.ExportConfiguration.Builder.empty)1 Builder.load (org.opendatakit.briefcase.export.ExportConfiguration.Builder.load)1 ExportEvent (org.opendatakit.briefcase.export.ExportEvent)1 ExportForms (org.opendatakit.briefcase.export.ExportForms)1 ExportForms.buildCustomConfPrefix (org.opendatakit.briefcase.export.ExportForms.buildCustomConfPrefix)1 ExportToCsv (org.opendatakit.briefcase.export.ExportToCsv)1 ExportToGeoJson (org.opendatakit.briefcase.export.ExportToGeoJson)1 FormDefinition (org.opendatakit.briefcase.export.FormDefinition)1 BriefcaseFormDefinition (org.opendatakit.briefcase.model.BriefcaseFormDefinition)1