use of org.opendatakit.briefcase.push.central.PushToCentral in project briefcase by opendatakit.
the class Central method push.
@Override
public JobsRunner push(TransferForms forms, Path briefcaseDir) {
forms.filter(FormStatus::isEncrypted).forEach(form -> form.setStatusString("Skipping. Encrypted forms can't be pushed to ODK Central yet"));
String token = http.execute(server.getSessionTokenRequest()).orElseThrow(() -> new BriefcaseException("Can't authenticate with ODK Central"));
PushToCentral pushOp = new PushToCentral(http, server, briefcaseDir, token, EventBus::publish);
return JobsRunner.launchAsync(forms.filter(f -> !f.isEncrypted()).map(pushOp::push)).onComplete(() -> EventBus.publish(new PushEvent.Complete()));
}
use of org.opendatakit.briefcase.push.central.PushToCentral 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