Search in sources :

Example 1 with AggregateServer

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

the class PullFromAggregateIntegrationTest method setUp.

@Before
public void setUp() throws IOException {
    Files.createDirectories(briefcaseDir);
    prefs = new BriefcasePreferences(InMemoryPreferences.empty());
    prefs.setStorageDir(tmpDir);
    server = httpServer(serverPort);
    tracker = new PullFromAggregateTracker(form, e -> {
    });
    formMetadataPort = new InMemoryFormMetadataAdapter();
    pullOp = new PullFromAggregate(CommonsHttp.of(1), aggregateServer, briefcaseDir, true, e -> {
    }, formMetadataPort);
    runnerStatus = new TestRunnerStatus(false);
}
Also used : UncheckedFiles.deleteRecursive(org.opendatakit.briefcase.reused.UncheckedFiles.deleteRecursive) RequestBuilder.url(org.opendatakit.briefcase.reused.http.RequestBuilder.url) URL(java.net.URL) JobsRunner.launchSync(org.opendatakit.briefcase.reused.job.JobsRunner.launchSync) Assert.assertThat(org.junit.Assert.assertThat) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UncheckedFiles.readAllBytes(org.opendatakit.briefcase.reused.UncheckedFiles.readAllBytes) After(org.junit.After) AggregateServer(org.opendatakit.briefcase.reused.transfer.AggregateServer) Pair(org.opendatakit.briefcase.reused.Pair) Path(java.nio.file.Path) FormKey(org.opendatakit.briefcase.model.form.FormKey) CommonsHttp(org.opendatakit.briefcase.reused.http.CommonsHttp) Moco.httpServer(com.github.dreamhead.moco.Moco.httpServer) TransferTestHelpers.buildMediaFiles(org.opendatakit.briefcase.reused.transfer.TransferTestHelpers.buildMediaFiles) FormStatus(org.opendatakit.briefcase.model.FormStatus) FormMetadataQueries.lastCursorOf(org.opendatakit.briefcase.model.form.FormMetadataQueries.lastCursorOf) Moco.method(com.github.dreamhead.moco.Moco.method) TransferTestHelpers.generatePages(org.opendatakit.briefcase.reused.transfer.TransferTestHelpers.generatePages) UncheckedFiles.createTempDirectory(org.opendatakit.briefcase.reused.UncheckedFiles.createTempDirectory) GET(com.github.dreamhead.moco.HttpMethod.GET) Collectors.joining(java.util.stream.Collectors.joining) TransferTestHelpers(org.opendatakit.briefcase.reused.transfer.TransferTestHelpers) UncheckedFiles.toURI(org.opendatakit.briefcase.reused.UncheckedFiles.toURI) List(java.util.List) Moco.seq(com.github.dreamhead.moco.Moco.seq) OffsetDateTime(java.time.OffsetDateTime) Runner.running(com.github.dreamhead.moco.Runner.running) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) Matchers.containsString(org.hamcrest.Matchers.containsString) HttpServer(com.github.dreamhead.moco.HttpServer) IntStream(java.util.stream.IntStream) InMemoryFormMetadataAdapter(org.opendatakit.briefcase.model.form.InMemoryFormMetadataAdapter) Moco.uri(com.github.dreamhead.moco.Moco.uri) BriefcasePreferences(org.opendatakit.briefcase.model.BriefcasePreferences) TransferTestHelpers.buildFormStatus(org.opendatakit.briefcase.reused.transfer.TransferTestHelpers.buildFormStatus) InMemoryPreferences(org.opendatakit.briefcase.model.InMemoryPreferences) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Before(org.junit.Before) TransferTestHelpers.buildManifestXml(org.opendatakit.briefcase.reused.transfer.TransferTestHelpers.buildManifestXml) Files(java.nio.file.Files) RunnerStatus(org.opendatakit.briefcase.reused.job.RunnerStatus) IOException(java.io.IOException) Test(org.junit.Test) Collectors.toList(java.util.stream.Collectors.toList) Paths(java.nio.file.Paths) DateTimeFormatter(java.time.format.DateTimeFormatter) TestRunnerStatus(org.opendatakit.briefcase.reused.job.TestRunnerStatus) Moco.by(com.github.dreamhead.moco.Moco.by) BriefcasePreferences(org.opendatakit.briefcase.model.BriefcasePreferences) InMemoryFormMetadataAdapter(org.opendatakit.briefcase.model.form.InMemoryFormMetadataAdapter) TestRunnerStatus(org.opendatakit.briefcase.reused.job.TestRunnerStatus) Before(org.junit.Before)

Example 2 with AggregateServer

use of org.opendatakit.briefcase.reused.transfer.AggregateServer 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)

Example 3 with AggregateServer

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

the class PullFormFromAggregate method pullFormFromAggregate.

public static void pullFormFromAggregate(Path storageDir, Optional<String> formId, String username, String password, URL server, boolean resumeLastPull, Optional<LocalDate> startFromDate, boolean includeIncomplete, Optional<Integer> maybeMaxHttpConnections) {
    CliEventsCompanion.attach(log);
    Path briefcaseDir = Common.getOrCreateBriefcaseDir(storageDir);
    FormCache formCache = FormCache.from(briefcaseDir);
    formCache.update();
    BriefcasePreferences appPreferences = BriefcasePreferences.appScoped();
    FormMetadataPort formMetadataPort = FileSystemFormMetadataAdapter.at(briefcaseDir);
    int maxHttpConnections = Optionals.race(maybeMaxHttpConnections, appPreferences.getMaxHttpConnections()).orElse(DEFAULT_HTTP_CONNECTIONS);
    Http http = appPreferences.getHttpProxy().map(host -> CommonsHttp.of(maxHttpConnections, host)).orElseGet(() -> CommonsHttp.of(maxHttpConnections));
    AggregateServer aggregateServer = AggregateServer.authenticated(server, new Credentials(username, password));
    Response<List<RemoteFormDefinition>> response = http.execute(aggregateServer.getFormListRequest());
    if (!response.isSuccess()) {
        System.err.println(response.isRedirection() ? "Error connecting to Aggregate: Redirection detected" : response.isUnauthorized() ? "Error connecting to Aggregate: Wrong credentials" : response.isNotFound() ? "Error connecting to Aggregate: Aggregate not found" : "Error connecting to Aggregate");
        return;
    }
    List<FormStatus> filteredForms = response.orElseThrow(BriefcaseException::new).stream().filter(f -> formId.map(id -> f.getFormId().equals(id)).orElse(true)).map(FormStatus::new).collect(toList());
    if (formId.isPresent() && filteredForms.isEmpty())
        throw new BriefcaseException("Form " + formId.get() + " not found");
    TransferForms forms = TransferForms.empty();
    forms.load(filteredForms);
    forms.selectAll();
    PullFromAggregate pullOp = new PullFromAggregate(http, aggregateServer, briefcaseDir, includeIncomplete, PullFormFromAggregate::onEvent, formMetadataPort);
    JobsRunner.launchAsync(forms.map(form -> pullOp.pull(form, resolveCursor(resumeLastPull, startFromDate, form, formMetadataPort))), PullFormFromAggregate::onError).waitForCompletion();
    System.out.println();
    System.out.println("All operations completed");
    System.out.println();
}
Also used : Path(java.nio.file.Path) Arrays(java.util.Arrays) FileSystemFormMetadataAdapter(org.opendatakit.briefcase.model.form.FileSystemFormMetadataAdapter) Credentials(org.opendatakit.briefcase.reused.http.Credentials) URL(java.net.URL) BriefcasePreferences(org.opendatakit.briefcase.model.BriefcasePreferences) Optionals(org.opendatakit.briefcase.reused.Optionals) Response(org.opendatakit.briefcase.reused.http.response.Response) LoggerFactory(org.slf4j.LoggerFactory) DEFAULT_HTTP_CONNECTIONS(org.opendatakit.briefcase.reused.http.Http.DEFAULT_HTTP_CONNECTIONS) MAX_HTTP_CONNECTIONS(org.opendatakit.briefcase.operations.Common.MAX_HTTP_CONNECTIONS) FORM_ID(org.opendatakit.briefcase.operations.Common.FORM_ID) Operation(org.opendatakit.common.cli.Operation) FormMetadataPort(org.opendatakit.briefcase.model.form.FormMetadataPort) BriefcaseException(org.opendatakit.briefcase.reused.BriefcaseException) AggregateServer(org.opendatakit.briefcase.reused.transfer.AggregateServer) TransferForms(org.opendatakit.briefcase.transfer.TransferForms) SERVER_URL(org.opendatakit.briefcase.operations.Common.SERVER_URL) CREDENTIALS_PASSWORD(org.opendatakit.briefcase.operations.Common.CREDENTIALS_PASSWORD) FormCache(org.opendatakit.briefcase.util.FormCache) Path(java.nio.file.Path) FormKey(org.opendatakit.briefcase.model.form.FormKey) CommonsHttp(org.opendatakit.briefcase.reused.http.CommonsHttp) RemoteFormDefinition(org.opendatakit.briefcase.model.RemoteFormDefinition) FormStatus(org.opendatakit.briefcase.model.FormStatus) FormStatusEvent(org.opendatakit.briefcase.model.FormStatusEvent) Logger(org.slf4j.Logger) FormMetadataQueries.lastCursorOf(org.opendatakit.briefcase.model.form.FormMetadataQueries.lastCursorOf) Param(org.opendatakit.common.cli.Param) Cursor(org.opendatakit.briefcase.pull.aggregate.Cursor) STORAGE_DIR(org.opendatakit.briefcase.operations.Common.STORAGE_DIR) JobsRunner(org.opendatakit.briefcase.reused.job.JobsRunner) Http(org.opendatakit.briefcase.reused.http.Http) CREDENTIALS_USERNAME(org.opendatakit.briefcase.operations.Common.CREDENTIALS_USERNAME) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) PullFromAggregate(org.opendatakit.briefcase.pull.aggregate.PullFromAggregate) LocalDate(java.time.LocalDate) Optional(java.util.Optional) FormCache(org.opendatakit.briefcase.util.FormCache) BriefcasePreferences(org.opendatakit.briefcase.model.BriefcasePreferences) FormMetadataPort(org.opendatakit.briefcase.model.form.FormMetadataPort) CommonsHttp(org.opendatakit.briefcase.reused.http.CommonsHttp) Http(org.opendatakit.briefcase.reused.http.Http) BriefcaseException(org.opendatakit.briefcase.reused.BriefcaseException) PullFromAggregate(org.opendatakit.briefcase.pull.aggregate.PullFromAggregate) TransferForms(org.opendatakit.briefcase.transfer.TransferForms) FormStatus(org.opendatakit.briefcase.model.FormStatus) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) AggregateServer(org.opendatakit.briefcase.reused.transfer.AggregateServer) Credentials(org.opendatakit.briefcase.reused.http.Credentials)

Example 4 with AggregateServer

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

the class PushFormToAggregate method pushFormToAggregate.

private static void pushFormToAggregate(Path storageDir, Optional<String> formid, String username, String password, URL server, boolean forceSendBlank, Optional<Integer> maybeMaxConnections) {
    CliEventsCompanion.attach(log);
    Path briefcaseDir = Common.getOrCreateBriefcaseDir(storageDir);
    FormCache formCache = FormCache.from(briefcaseDir);
    formCache.update();
    BriefcasePreferences appPreferences = BriefcasePreferences.appScoped();
    int maxHttpConnections = Optionals.race(maybeMaxConnections, appPreferences.getMaxHttpConnections()).orElse(DEFAULT_HTTP_CONNECTIONS);
    Http http = appPreferences.getHttpProxy().map(host -> CommonsHttp.of(maxHttpConnections, host)).orElseGet(() -> CommonsHttp.of(maxHttpConnections));
    AggregateServer aggregateServer = AggregateServer.authenticated(server, new Credentials(username, password));
    Response response = http.execute(aggregateServer.getPushFormPreflightRequest());
    if (!response.isSuccess()) {
        System.err.println(response.isRedirection() ? "Error connecting to Aggregate: Redirection detected" : response.isUnauthorized() ? "Error connecting to Aggregate: Wrong credentials" : response.isNotFound() ? "Error connecting to Aggregate: Aggregate not found" : "Error connecting to Aggregate");
        return;
    }
    List<FormStatus> statuses;
    if (formid.isPresent()) {
        String requestedFormId = formid.get();
        FormStatus status = formCache.getForms().stream().filter(form -> form.getFormId().equals(requestedFormId)).map(FormStatus::new).findFirst().orElseThrow(() -> new BriefcaseException("Form " + requestedFormId + " not found"));
        statuses = Arrays.asList(status);
    } else {
        statuses = formCache.getForms().stream().map(FormStatus::new).collect(Collectors.toList());
    }
    TransferForms forms = TransferForms.of(statuses);
    forms.selectAll();
    PushToAggregate pushOp = new PushToAggregate(http, aggregateServer, briefcaseDir, forceSendBlank, PushFormToAggregate::onEvent);
    JobsRunner.launchAsync(forms.map(pushOp::push), PushFormToAggregate::onError).waitForCompletion();
    System.out.println();
    System.out.println("All operations completed");
    System.out.println();
}
Also used : Path(java.nio.file.Path) Arrays(java.util.Arrays) Credentials(org.opendatakit.briefcase.reused.http.Credentials) URL(java.net.URL) BriefcasePreferences(org.opendatakit.briefcase.model.BriefcasePreferences) Optionals(org.opendatakit.briefcase.reused.Optionals) Response(org.opendatakit.briefcase.reused.http.response.Response) LoggerFactory(org.slf4j.LoggerFactory) DEFAULT_HTTP_CONNECTIONS(org.opendatakit.briefcase.reused.http.Http.DEFAULT_HTTP_CONNECTIONS) MAX_HTTP_CONNECTIONS(org.opendatakit.briefcase.operations.Common.MAX_HTTP_CONNECTIONS) FORM_ID(org.opendatakit.briefcase.operations.Common.FORM_ID) Operation(org.opendatakit.common.cli.Operation) BriefcaseException(org.opendatakit.briefcase.reused.BriefcaseException) AggregateServer(org.opendatakit.briefcase.reused.transfer.AggregateServer) TransferForms(org.opendatakit.briefcase.transfer.TransferForms) SERVER_URL(org.opendatakit.briefcase.operations.Common.SERVER_URL) CREDENTIALS_PASSWORD(org.opendatakit.briefcase.operations.Common.CREDENTIALS_PASSWORD) FormCache(org.opendatakit.briefcase.util.FormCache) Path(java.nio.file.Path) CommonsHttp(org.opendatakit.briefcase.reused.http.CommonsHttp) PushToAggregate(org.opendatakit.briefcase.push.aggregate.PushToAggregate) FormStatus(org.opendatakit.briefcase.model.FormStatus) FormStatusEvent(org.opendatakit.briefcase.model.FormStatusEvent) Logger(org.slf4j.Logger) Param(org.opendatakit.common.cli.Param) STORAGE_DIR(org.opendatakit.briefcase.operations.Common.STORAGE_DIR) JobsRunner(org.opendatakit.briefcase.reused.job.JobsRunner) Collectors(java.util.stream.Collectors) Http(org.opendatakit.briefcase.reused.http.Http) CREDENTIALS_USERNAME(org.opendatakit.briefcase.operations.Common.CREDENTIALS_USERNAME) List(java.util.List) Optional(java.util.Optional) FormCache(org.opendatakit.briefcase.util.FormCache) BriefcasePreferences(org.opendatakit.briefcase.model.BriefcasePreferences) CommonsHttp(org.opendatakit.briefcase.reused.http.CommonsHttp) Http(org.opendatakit.briefcase.reused.http.Http) Response(org.opendatakit.briefcase.reused.http.response.Response) PushToAggregate(org.opendatakit.briefcase.push.aggregate.PushToAggregate) BriefcaseException(org.opendatakit.briefcase.reused.BriefcaseException) TransferForms(org.opendatakit.briefcase.transfer.TransferForms) FormStatus(org.opendatakit.briefcase.model.FormStatus) AggregateServer(org.opendatakit.briefcase.reused.transfer.AggregateServer) Credentials(org.opendatakit.briefcase.reused.http.Credentials)

Example 5 with AggregateServer

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

the class Export method export.

public static void export(Path storageDir, String formid, Path exportDir, String baseFilename, boolean exportMedia, boolean overwriteFiles, boolean pullBefore, Optional<LocalDate> startDate, Optional<LocalDate> endDate, Optional<Path> maybePemFile, boolean splitSelectMultiples, boolean includeGeoJsonExport, boolean removeGroupNames, boolean smartAppend) {
    CliEventsCompanion.attach(log);
    Path briefcaseDir = Common.getOrCreateBriefcaseDir(storageDir);
    FormCache formCache = FormCache.from(briefcaseDir);
    formCache.update();
    BriefcasePreferences appPreferences = BriefcasePreferences.appScoped();
    BriefcasePreferences exportPrefs = BriefcasePreferences.forClass(ExportPanel.class);
    BriefcasePreferences pullPrefs = BriefcasePreferences.forClass(ExportPanel.class);
    FormMetadataPort formMetadataPort = FileSystemFormMetadataAdapter.at(briefcaseDir);
    int maxHttpConnections = appPreferences.getMaxHttpConnections().orElse(DEFAULT_HTTP_CONNECTIONS);
    Http http = appPreferences.getHttpProxy().map(host -> CommonsHttp.of(maxHttpConnections, host)).orElseGet(() -> CommonsHttp.of(maxHttpConnections));
    Optional<BriefcaseFormDefinition> maybeFormDefinition = formCache.getForms().stream().filter(form -> form.getFormId().equals(formid)).findFirst();
    createDirectories(exportDir);
    BriefcaseFormDefinition formDefinition = maybeFormDefinition.orElseThrow(() -> new BriefcaseException("Form " + formid + " not found"));
    FormDefinition formDef = FormDefinition.from(formDefinition);
    System.out.println("Exporting form " + formDefinition.getFormName() + " (" + formDefinition.getFormId() + ") to: " + exportDir);
    DateRange dateRange = new DateRange(startDate, endDate);
    ExportConfiguration configuration = ExportConfiguration.Builder.empty().setExportFilename(baseFilename).setExportDir(exportDir).setPemFile(maybePemFile).setDateRange(dateRange).setPullBefore(pullBefore).setOverwriteFiles(overwriteFiles).setExportMedia(exportMedia).setSplitSelectMultiples(splitSelectMultiples).setIncludeGeoJsonExport(includeGeoJsonExport).setRemoveGroupNames(removeGroupNames).setSmartAppend(smartAppend).build();
    FormStatus formStatus = new FormStatus(formDefinition);
    FormKey key = FormKey.from(formStatus);
    FormMetadata formMetadata = formMetadataPort.fetch(key).orElseThrow(BriefcaseException::new);
    Job<Void> pullJob = Job.noOpSupplier();
    if (configuration.resolvePullBefore()) {
        Optional<AggregateServer> server = AggregateServer.readFromPrefs(appPreferences, pullPrefs, formStatus);
        if (server.isPresent()) {
            Optional<Cursor> lastCursor = appPreferences.resolveStartFromLast() ? formMetadataPort.query(lastCursorOf(key)) : Optional.empty();
            pullJob = new PullFromAggregate(http, server.get(), briefcaseDir, false, Export::onEvent, formMetadataPort).pull(formStatus, lastCursor);
        }
    }
    Job<Void> exportJob = Job.run(runnerStatus -> ExportToCsv.export(formMetadataPort, formMetadata, formStatus, formDef, briefcaseDir, configuration));
    Job<Void> exportGeoJsonJob = configuration.resolveIncludeGeoJsonExport() ? Job.run(runnerStatus -> ExportToGeoJson.export(formMetadata, formDef, configuration)) : Job.noOp;
    Job<Void> job = pullJob.thenRun(exportJob).thenRun(exportGeoJsonJob).thenRun(__ -> exportPrefs.put(buildExportDateTimePrefix(formDefinition.getFormId()), LocalDateTime.now().format(ISO_DATE_TIME)));
    JobsRunner.launchAsync(job, Export::onError).waitForCompletion();
    System.out.println();
    System.out.println("All operations completed");
    System.out.println();
}
Also used : Path(java.nio.file.Path) Arrays(java.util.Arrays) FormDefinition(org.opendatakit.briefcase.export.FormDefinition) FileSystemFormMetadataAdapter(org.opendatakit.briefcase.model.form.FileSystemFormMetadataAdapter) LocalDateTime(java.time.LocalDateTime) BriefcasePreferences(org.opendatakit.briefcase.model.BriefcasePreferences) LoggerFactory(org.slf4j.LoggerFactory) DEFAULT_HTTP_CONNECTIONS(org.opendatakit.briefcase.reused.http.Http.DEFAULT_HTTP_CONNECTIONS) BriefcaseFormDefinition(org.opendatakit.briefcase.model.BriefcaseFormDefinition) ExportToGeoJson(org.opendatakit.briefcase.export.ExportToGeoJson) FORM_ID(org.opendatakit.briefcase.operations.Common.FORM_ID) Operation(org.opendatakit.common.cli.Operation) ExportPanel(org.opendatakit.briefcase.ui.export.ExportPanel) FormMetadataPort(org.opendatakit.briefcase.model.form.FormMetadataPort) 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) FormCache(org.opendatakit.briefcase.util.FormCache) Path(java.nio.file.Path) FormKey(org.opendatakit.briefcase.model.form.FormKey) CommonsHttp(org.opendatakit.briefcase.reused.http.CommonsHttp) FormStatus(org.opendatakit.briefcase.model.FormStatus) FormStatusEvent(org.opendatakit.briefcase.model.FormStatusEvent) Logger(org.slf4j.Logger) FormMetadataQueries.lastCursorOf(org.opendatakit.briefcase.model.form.FormMetadataQueries.lastCursorOf) Param(org.opendatakit.common.cli.Param) Cursor(org.opendatakit.briefcase.pull.aggregate.Cursor) STORAGE_DIR(org.opendatakit.briefcase.operations.Common.STORAGE_DIR) JobsRunner(org.opendatakit.briefcase.reused.job.JobsRunner) DateRange(org.opendatakit.briefcase.export.DateRange) Http(org.opendatakit.briefcase.reused.http.Http) UncheckedFiles.createDirectories(org.opendatakit.briefcase.reused.UncheckedFiles.createDirectories) ExportForms.buildExportDateTimePrefix(org.opendatakit.briefcase.export.ExportForms.buildExportDateTimePrefix) PullFromAggregate(org.opendatakit.briefcase.pull.aggregate.PullFromAggregate) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Job(org.opendatakit.briefcase.reused.job.Job) ExportToCsv(org.opendatakit.briefcase.export.ExportToCsv) FormCache(org.opendatakit.briefcase.util.FormCache) BriefcasePreferences(org.opendatakit.briefcase.model.BriefcasePreferences) FormMetadataPort(org.opendatakit.briefcase.model.form.FormMetadataPort) ExportConfiguration(org.opendatakit.briefcase.export.ExportConfiguration) CommonsHttp(org.opendatakit.briefcase.reused.http.CommonsHttp) Http(org.opendatakit.briefcase.reused.http.Http) FormKey(org.opendatakit.briefcase.model.form.FormKey) Cursor(org.opendatakit.briefcase.pull.aggregate.Cursor) FormMetadata(org.opendatakit.briefcase.model.form.FormMetadata) BriefcaseException(org.opendatakit.briefcase.reused.BriefcaseException) DateRange(org.opendatakit.briefcase.export.DateRange) PullFromAggregate(org.opendatakit.briefcase.pull.aggregate.PullFromAggregate) FormStatus(org.opendatakit.briefcase.model.FormStatus) BriefcaseFormDefinition(org.opendatakit.briefcase.model.BriefcaseFormDefinition) FormDefinition(org.opendatakit.briefcase.export.FormDefinition) BriefcaseFormDefinition(org.opendatakit.briefcase.model.BriefcaseFormDefinition) AggregateServer(org.opendatakit.briefcase.reused.transfer.AggregateServer)

Aggregations

AggregateServer (org.opendatakit.briefcase.reused.transfer.AggregateServer)6 List (java.util.List)5 Optional (java.util.Optional)5 BriefcasePreferences (org.opendatakit.briefcase.model.BriefcasePreferences)5 FormStatus (org.opendatakit.briefcase.model.FormStatus)5 BriefcaseException (org.opendatakit.briefcase.reused.BriefcaseException)5 URL (java.net.URL)4 Path (java.nio.file.Path)4 CommonsHttp (org.opendatakit.briefcase.reused.http.CommonsHttp)4 Http (org.opendatakit.briefcase.reused.http.Http)4 JobsRunner (org.opendatakit.briefcase.reused.job.JobsRunner)4 FormCache (org.opendatakit.briefcase.util.FormCache)4 Arrays (java.util.Arrays)3 Collectors.toList (java.util.stream.Collectors.toList)3 FormKey (org.opendatakit.briefcase.model.form.FormKey)3 LocalDate (java.time.LocalDate)2 LocalDateTime (java.time.LocalDateTime)2 ISO_DATE_TIME (java.time.format.DateTimeFormatter.ISO_DATE_TIME)2 ArrayList (java.util.ArrayList)2 FormStatusEvent (org.opendatakit.briefcase.model.FormStatusEvent)2