use of org.opendatakit.briefcase.reused.BriefcaseException in project briefcase by opendatakit.
the class Cli method run.
/**
* Runs the command line program
*
* @param args command line arguments
* @see <a href="https://blog.idrsolutions.com/2015/03/java-8-consumer-supplier-explained-in-5-minutes/">Java 8 consumer supplier explained in 5 minutes</a>
*/
public void run(String[] args) {
Set<Param> allParams = getAllParams();
CommandLine cli = getCli(args, allParams);
try {
requiredOperations.forEach(operation -> {
checkForMissingParams(cli, operation.requiredParams);
operation.argsConsumer.accept(Args.from(cli, operation.requiredParams));
});
operations.forEach(operation -> {
if (cli.hasOption(operation.param.shortCode)) {
checkForMissingParams(cli, operation.requiredParams);
operation.argsConsumer.accept(Args.from(cli, operation.getAllParams()));
executedOperations.add(operation);
}
});
if (executedOperations.isEmpty())
otherwiseRunnables.forEach(Runnable::run);
} catch (BriefcaseException e) {
System.err.println("Error: " + e.getMessage());
log.error("Error", e);
System.exit(1);
} catch (Throwable t) {
System.err.println("Briefcase unexpected error. Please review the logs and contact maintainers on the following URLs:");
System.err.println("\thttps://opendatakit.slack.com/messages/C374LNDK9/");
System.err.println("\thttps://forum.opendatakit.org/c/support");
log.error("Error", t);
System.exit(1);
}
}
use of org.opendatakit.briefcase.reused.BriefcaseException 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));
}
Aggregations