use of org.opendatakit.briefcase.reused.http.response.Response in project briefcase by opendatakit.
the class PushFormToAggregate method pushFormToAggregate.
private static void pushFormToAggregate(Path storageDir, Optional<String> formid, String username, String password, URL server, boolean forceSendBlank, Optional<Integer> maybeMaxConnections) {
CliEventsCompanion.attach(log);
Path briefcaseDir = Common.getOrCreateBriefcaseDir(storageDir);
FormCache formCache = FormCache.from(briefcaseDir);
formCache.update();
BriefcasePreferences appPreferences = BriefcasePreferences.appScoped();
int maxHttpConnections = Optionals.race(maybeMaxConnections, appPreferences.getMaxHttpConnections()).orElse(DEFAULT_HTTP_CONNECTIONS);
Http http = appPreferences.getHttpProxy().map(host -> CommonsHttp.of(maxHttpConnections, host)).orElseGet(() -> CommonsHttp.of(maxHttpConnections));
AggregateServer aggregateServer = AggregateServer.authenticated(server, new Credentials(username, password));
Response response = http.execute(aggregateServer.getPushFormPreflightRequest());
if (!response.isSuccess()) {
System.err.println(response.isRedirection() ? "Error connecting to Aggregate: Redirection detected" : response.isUnauthorized() ? "Error connecting to Aggregate: Wrong credentials" : response.isNotFound() ? "Error connecting to Aggregate: Aggregate not found" : "Error connecting to Aggregate");
return;
}
List<FormStatus> statuses;
if (formid.isPresent()) {
String requestedFormId = formid.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();
PushToAggregate pushOp = new PushToAggregate(http, aggregateServer, briefcaseDir, forceSendBlank, PushFormToAggregate::onEvent);
JobsRunner.launchAsync(forms.map(pushOp::push), PushFormToAggregate::onError).waitForCompletion();
System.out.println();
System.out.println("All operations completed");
System.out.println();
}
Aggregations