Search in sources :

Example 1 with ISO_DATE_TIME

use of java.time.format.DateTimeFormatter.ISO_DATE_TIME in project briefcase by opendatakit.

the class Export method export.

public static void export(String storageDir, String formid, Path exportPath, String baseFilename, boolean includeMediaFiles, boolean overwriteFiles, Optional<LocalDate> startDate, Optional<LocalDate> endDate, Optional<Path> maybePemFile) {
    CliEventsCompanion.attach(log);
    bootCache(storageDir);
    Optional<BriefcaseFormDefinition> maybeFormDefinition = FileSystemUtils.getBriefcaseFormList().stream().filter(form -> form.getFormId().equals(formid)).findFirst();
    BriefcaseFormDefinition formDefinition = maybeFormDefinition.orElseThrow(() -> new FormNotFoundException(formid));
    if (formDefinition.isFileEncryptedForm() || formDefinition.isFieldEncryptedForm()) {
        Path pemFile = maybePemFile.filter(Files::exists).orElseThrow(() -> new BriefcaseException("Missing pem file configuration"));
        try (PEMReader rdr = new PEMReader(new BufferedReader(new InputStreamReader(Files.newInputStream(pemFile), "UTF-8")))) {
            Object o = Optional.ofNullable(rdr.readObject()).orElseThrow(() -> new BriefcaseException("Can't parse Pem file"));
            Optional<PrivateKey> privKey;
            if (o instanceof KeyPair)
                privKey = Optional.of(((KeyPair) o).getPrivate());
            else if (o instanceof PrivateKey)
                privKey = Optional.of((PrivateKey) o);
            else
                privKey = Optional.empty();
            formDefinition.setPrivateKey(privKey.orElseThrow(() -> new BriefcaseException("No private key found on Pem file")));
            EventBus.publish(new ExportProgressEvent("Successfully parsed Pem file", formDefinition));
        } catch (IOException e) {
            throw new BriefcaseException("Can't parse Pem file");
        }
    }
    System.out.println("Exporting form " + formDefinition.getFormName() + " (" + formDefinition.getFormId() + ") to: " + exportPath);
    ExportToCsv.export(exportPath, formDefinition, baseFilename, includeMediaFiles, overwriteFiles, startDate, endDate);
    BriefcasePreferences.forClass(ExportPanel.class).put(buildExportDateTimePrefix(formDefinition.getFormId()), LocalDateTime.now().format(ISO_DATE_TIME));
}
Also used : Common.bootCache(org.opendatakit.briefcase.operations.Common.bootCache) KeyPair(java.security.KeyPair) Arrays(java.util.Arrays) ExportProgressEvent(org.opendatakit.briefcase.model.ExportProgressEvent) LocalDateTime(java.time.LocalDateTime) BriefcasePreferences(org.opendatakit.briefcase.model.BriefcasePreferences) LoggerFactory(org.slf4j.LoggerFactory) BriefcaseFormDefinition(org.opendatakit.briefcase.model.BriefcaseFormDefinition) FORM_ID(org.opendatakit.briefcase.operations.Common.FORM_ID) Operation(org.opendatakit.common.cli.Operation) ExportPanel(org.opendatakit.briefcase.ui.export.ExportPanel) EventBus(org.bushe.swing.event.EventBus) ISO_DATE_TIME(java.time.format.DateTimeFormatter.ISO_DATE_TIME) BriefcaseException(org.opendatakit.briefcase.reused.BriefcaseException) Path(java.nio.file.Path) FileSystemUtils(org.opendatakit.briefcase.util.FileSystemUtils) Logger(org.slf4j.Logger) Files(java.nio.file.Files) Param(org.opendatakit.common.cli.Param) STORAGE_DIR(org.opendatakit.briefcase.operations.Common.STORAGE_DIR) PEMReader(org.bouncycastle.openssl.PEMReader) IOException(java.io.IOException) ExportToCsv(org.opendatakit.briefcase.util.ExportToCsv) InputStreamReader(java.io.InputStreamReader) ExportForms.buildExportDateTimePrefix(org.opendatakit.briefcase.export.ExportForms.buildExportDateTimePrefix) Paths(java.nio.file.Paths) PrivateKey(java.security.PrivateKey) LocalDate(java.time.LocalDate) Optional(java.util.Optional) BufferedReader(java.io.BufferedReader) Path(java.nio.file.Path) ExportPanel(org.opendatakit.briefcase.ui.export.ExportPanel) KeyPair(java.security.KeyPair) PrivateKey(java.security.PrivateKey) InputStreamReader(java.io.InputStreamReader) PEMReader(org.bouncycastle.openssl.PEMReader) IOException(java.io.IOException) ExportProgressEvent(org.opendatakit.briefcase.model.ExportProgressEvent) BriefcaseException(org.opendatakit.briefcase.reused.BriefcaseException) BufferedReader(java.io.BufferedReader) BriefcaseFormDefinition(org.opendatakit.briefcase.model.BriefcaseFormDefinition)

Aggregations

BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 KeyPair (java.security.KeyPair)1 PrivateKey (java.security.PrivateKey)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 ISO_DATE_TIME (java.time.format.DateTimeFormatter.ISO_DATE_TIME)1 Arrays (java.util.Arrays)1 Optional (java.util.Optional)1 PEMReader (org.bouncycastle.openssl.PEMReader)1 EventBus (org.bushe.swing.event.EventBus)1 ExportForms.buildExportDateTimePrefix (org.opendatakit.briefcase.export.ExportForms.buildExportDateTimePrefix)1 BriefcaseFormDefinition (org.opendatakit.briefcase.model.BriefcaseFormDefinition)1 BriefcasePreferences (org.opendatakit.briefcase.model.BriefcasePreferences)1 ExportProgressEvent (org.opendatakit.briefcase.model.ExportProgressEvent)1 FORM_ID (org.opendatakit.briefcase.operations.Common.FORM_ID)1