Search in sources :

Example 1 with DateRange

use of org.opendatakit.briefcase.export.DateRange in project briefcase by opendatakit.

the class ConfigurationPanelForm method triggerOnChange.

private void triggerOnChange() {
    ExportConfiguration conf = ExportConfiguration.Builder.empty().setExportDir(exportDir, error -> {
        errorMessage("Invalid export dir", error);
        clearExportDir();
    }).setPemFile(pemFile, error -> {
        errorMessage("Invalid PEM file selected", error);
        clearPemFile();
    }).setDateRange(dateRange).setPullBefore(pullBefore).setOverwriteFiles(overwriteFiles).setExportMedia(exportMedia).setSplitSelectMultiples(splitSelectMultiples).setIncludeGeoJsonExport(includeGeoJsonExport).setRemoveGroupNames(removeGroupNames).build();
    onChangeCallbacks.forEach(callback -> callback.accept(conf));
}
Also used : Color(java.awt.Color) Insets(java.awt.Insets) Host.isMac(org.opendatakit.briefcase.util.Host.isMac) JTextField(javax.swing.JTextField) ArrayList(java.util.ArrayList) FileChooser.isUnderBriefcaseFolder(org.opendatakit.briefcase.ui.reused.FileChooser.isUnderBriefcaseFolder) ExportConfiguration(org.opendatakit.briefcase.export.ExportConfiguration) TRUE(org.opendatakit.briefcase.reused.TriStateBoolean.TRUE) JTextPane(javax.swing.JTextPane) FileChooser(org.opendatakit.briefcase.ui.reused.FileChooser) Path(java.nio.file.Path) DatePicker(com.github.lgooddatepicker.components.DatePicker) JComponent(javax.swing.JComponent) FlowLayout(java.awt.FlowLayout) JButton(javax.swing.JButton) UI.confirm(org.opendatakit.briefcase.ui.reused.UI.confirm) Host.isWindows(org.opendatakit.briefcase.util.Host.isWindows) UI.errorMessage(org.opendatakit.briefcase.ui.reused.UI.errorMessage) GridBagConstraints(java.awt.GridBagConstraints) DateRange(org.opendatakit.briefcase.export.DateRange) File(java.io.File) FileSystemUtils.isUnderODKFolder(org.opendatakit.briefcase.util.FileSystemUtils.isUnderODKFolder) Consumer(java.util.function.Consumer) List(java.util.List) Paths(java.nio.file.Paths) JLabel(javax.swing.JLabel) LocalDate(java.time.LocalDate) FileChooser.file(org.opendatakit.briefcase.ui.reused.FileChooser.file) JCheckBox(javax.swing.JCheckBox) Optional(java.util.Optional) OverridableBoolean(org.opendatakit.briefcase.reused.OverridableBoolean) GridBagLayout(java.awt.GridBagLayout) FileChooser.directory(org.opendatakit.briefcase.ui.reused.FileChooser.directory) JPanel(javax.swing.JPanel) TriStateBoolean(org.opendatakit.briefcase.reused.TriStateBoolean) StringUtils(org.opendatakit.briefcase.util.StringUtils) ExportConfiguration(org.opendatakit.briefcase.export.ExportConfiguration)

Example 2 with DateRange

use of org.opendatakit.briefcase.export.DateRange 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

Path (java.nio.file.Path)2 LocalDate (java.time.LocalDate)2 Optional (java.util.Optional)2 DateRange (org.opendatakit.briefcase.export.DateRange)2 ExportConfiguration (org.opendatakit.briefcase.export.ExportConfiguration)2 DatePicker (com.github.lgooddatepicker.components.DatePicker)1 Color (java.awt.Color)1 FlowLayout (java.awt.FlowLayout)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 File (java.io.File)1 Paths (java.nio.file.Paths)1 LocalDateTime (java.time.LocalDateTime)1 ISO_DATE_TIME (java.time.format.DateTimeFormatter.ISO_DATE_TIME)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1 JButton (javax.swing.JButton)1