use of org.opendatakit.briefcase.operations.Common.SERVER_URL in project briefcase by opendatakit.
the class PullFormFromCentral method pullFromCentral.
private static void pullFromCentral(Args args) {
CliEventsCompanion.attach(log);
Path briefcaseDir = Common.getOrCreateBriefcaseDir(args.get(STORAGE_DIR));
FormCache formCache = FormCache.from(briefcaseDir);
formCache.update();
BriefcasePreferences appPreferences = BriefcasePreferences.appScoped();
FormMetadataPort formMetadataPort = FileSystemFormMetadataAdapter.at(briefcaseDir);
int maxHttpConnections = Optionals.race(args.getOptional(MAX_HTTP_CONNECTIONS), appPreferences.getMaxHttpConnections()).orElse(DEFAULT_HTTP_CONNECTIONS);
Http http = appPreferences.getHttpProxy().map(host -> CommonsHttp.of(maxHttpConnections, host)).orElseGet(() -> CommonsHttp.of(maxHttpConnections));
CentralServer server = CentralServer.of(args.get(SERVER_URL), args.get(PROJECT_ID), new Credentials(args.get(CREDENTIALS_EMAIL), args.get(CREDENTIALS_PASSWORD)));
String token = http.execute(server.getSessionTokenRequest()).orElseThrow(() -> new BriefcaseException("Can't authenticate with ODK Central"));
Response<List<RemoteFormDefinition>> response = http.execute(server.getFormsListRequest(token));
if (!response.isSuccess()) {
System.err.println(response.isRedirection() ? "Error connecting to Central: Redirection detected" : response.isUnauthorized() ? "Error connecting to Central: Wrong credentials" : response.isNotFound() ? "Error connecting to Central: Central not found" : "Error connecting to Central");
return;
}
Optional<String> formId = args.getOptional(FORM_ID);
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();
PullFromCentral pullOp = new PullFromCentral(http, server, briefcaseDir, token, PullFormFromCentral::onEvent, formMetadataPort);
JobsRunner.launchAsync(forms.map(pullOp::pull), PullFormFromCentral::onError).waitForCompletion();
System.out.println();
System.out.println("All operations completed");
System.out.println();
}
use of org.opendatakit.briefcase.operations.Common.SERVER_URL in project briefcase by opendatakit.
the class Launcher method main.
public static void main(String[] args) {
BriefcasePreferences appPreferences = BriefcasePreferences.appScoped();
if (!appPreferences.hasKey(BRIEFCASE_TRACKING_CONSENT_PROPERTY))
appPreferences.put(BRIEFCASE_TRACKING_CONSENT_PROPERTY, TRUE.toString());
Optional<SentryClient> sentry = SENTRY_ENABLED ? Optional.of(initSentryClient(appPreferences)) : Optional.empty();
new Cli().deprecate(DEPRECATED_PULL_AGGREGATE, PULL_AGGREGATE).deprecate(DEPRECATED_PULL_IN_PARALLEL, MAX_HTTP_CONNECTIONS).deprecate(DEPRECATED_AGGREGATE_SERVER, SERVER_URL).register(PULL_FORM_FROM_AGGREGATE).register(PullFormFromCentral.OPERATION).register(PUSH_FORM_TO_AGGREGATE).register(PushFormToCentral.OPERATION).register(IMPORT_FROM_ODK).register(EXPORT_FORM).register(CLEAR_PREFS).otherwise((cli, commandLine) -> {
if (args.length == 0)
launchGUI();
else
runLegacyCli(commandLine, cli::printHelp);
}).onError(throwable -> {
System.err.println(throwable instanceof BriefcaseException ? "Error: " + throwable.getMessage() : "Unexpected error in Briefcase. Please review briefcase.log for more information. For help, post to https://forum.getodk.org/c/support");
log.error("Error", throwable);
sentry.ifPresent(client -> client.sendException(throwable));
System.exit(1);
}).run(args);
}
use of org.opendatakit.briefcase.operations.Common.SERVER_URL in project briefcase by opendatakit.
the class PushFormToCentral method pushToCentral.
private static void pushToCentral(Args args) {
CliEventsCompanion.attach(log);
Path briefcaseDir = Common.getOrCreateBriefcaseDir(args.get(STORAGE_DIR));
FormCache formCache = FormCache.from(briefcaseDir);
formCache.update();
BriefcasePreferences appPreferences = BriefcasePreferences.appScoped();
int maxHttpConnections = Optionals.race(args.getOptional(MAX_HTTP_CONNECTIONS), appPreferences.getMaxHttpConnections()).orElse(DEFAULT_HTTP_CONNECTIONS);
Http http = appPreferences.getHttpProxy().map(host -> CommonsHttp.of(maxHttpConnections, host)).orElseGet(() -> CommonsHttp.of(maxHttpConnections));
CentralServer server = CentralServer.of(args.get(SERVER_URL), args.get(PROJECT_ID), new Credentials(args.get(CREDENTIALS_EMAIL), args.get(CREDENTIALS_PASSWORD)));
String token = http.execute(server.getSessionTokenRequest()).orElseThrow(() -> new BriefcaseException("Can't authenticate with ODK Central"));
List<FormStatus> statuses;
if (args.getOptional(FORM_ID).isPresent()) {
String requestedFormId = args.getOptional(FORM_ID).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();
PushToCentral pushOp = new PushToCentral(http, server, briefcaseDir, token, PushFormToCentral::onEvent);
JobsRunner.launchAsync(forms.map(pushOp::push), PushFormToCentral::onError).waitForCompletion();
System.out.println();
System.out.println("All operations completed");
System.out.println();
}
Aggregations