Search in sources :

Example 1 with PushToCentral

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()));
}
Also used : FileSystemFormMetadataAdapter(org.opendatakit.briefcase.model.form.FileSystemFormMetadataAdapter) BriefcasePreferences(org.opendatakit.briefcase.model.BriefcasePreferences) PushToCentral(org.opendatakit.briefcase.push.central.PushToCentral) HashSet(java.util.HashSet) FormMetadataPort(org.opendatakit.briefcase.model.form.FormMetadataPort) EventBus(org.bushe.swing.event.EventBus) BriefcaseException(org.opendatakit.briefcase.reused.BriefcaseException) TransferForms(org.opendatakit.briefcase.transfer.TransferForms) CentralServerDialog(org.opendatakit.briefcase.ui.reused.transfer.sourcetarget.CentralServerDialog) Container(java.awt.Container) UI.uncheckedBrowse(org.opendatakit.briefcase.ui.reused.UI.uncheckedBrowse) Path(java.nio.file.Path) FormKey(org.opendatakit.briefcase.model.form.FormKey) FormMetadataQueries.submissionVersionsOf(org.opendatakit.briefcase.model.form.FormMetadataQueries.submissionVersionsOf) Test(org.opendatakit.briefcase.reused.transfer.RemoteServer.Test) FormStatus(org.opendatakit.briefcase.model.FormStatus) CentralServer(org.opendatakit.briefcase.reused.transfer.CentralServer) JobsRunner(org.opendatakit.briefcase.reused.job.JobsRunner) Set(java.util.Set) Http(org.opendatakit.briefcase.reused.http.Http) Consumer(java.util.function.Consumer) PushEvent(org.opendatakit.briefcase.push.PushEvent) JLabel(javax.swing.JLabel) UI.makeClickable(org.opendatakit.briefcase.ui.reused.UI.makeClickable) Optional(java.util.Optional) BriefcaseException(org.opendatakit.briefcase.reused.BriefcaseException) PushToCentral(org.opendatakit.briefcase.push.central.PushToCentral) EventBus(org.bushe.swing.event.EventBus)

Example 2 with PushToCentral

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();
}
Also used : Path(java.nio.file.Path) Arrays(java.util.Arrays) Credentials(org.opendatakit.briefcase.reused.http.Credentials) BriefcasePreferences(org.opendatakit.briefcase.model.BriefcasePreferences) PushToCentral(org.opendatakit.briefcase.push.central.PushToCentral) Optionals(org.opendatakit.briefcase.reused.Optionals) LoggerFactory(org.slf4j.LoggerFactory) DEFAULT_HTTP_CONNECTIONS(org.opendatakit.briefcase.reused.http.Http.DEFAULT_HTTP_CONNECTIONS) MAX_HTTP_CONNECTIONS(org.opendatakit.briefcase.operations.Common.MAX_HTTP_CONNECTIONS) FORM_ID(org.opendatakit.briefcase.operations.Common.FORM_ID) Operation(org.opendatakit.common.cli.Operation) BriefcaseException(org.opendatakit.briefcase.reused.BriefcaseException) TransferForms(org.opendatakit.briefcase.transfer.TransferForms) SERVER_URL(org.opendatakit.briefcase.operations.Common.SERVER_URL) CREDENTIALS_PASSWORD(org.opendatakit.briefcase.operations.Common.CREDENTIALS_PASSWORD) FormCache(org.opendatakit.briefcase.util.FormCache) Path(java.nio.file.Path) CommonsHttp(org.opendatakit.briefcase.reused.http.CommonsHttp) FormStatus(org.opendatakit.briefcase.model.FormStatus) FormStatusEvent(org.opendatakit.briefcase.model.FormStatusEvent) CentralServer(org.opendatakit.briefcase.reused.transfer.CentralServer) Logger(org.slf4j.Logger) Param(org.opendatakit.common.cli.Param) STORAGE_DIR(org.opendatakit.briefcase.operations.Common.STORAGE_DIR) JobsRunner(org.opendatakit.briefcase.reused.job.JobsRunner) Collectors(java.util.stream.Collectors) Http(org.opendatakit.briefcase.reused.http.Http) PROJECT_ID(org.opendatakit.briefcase.operations.Common.PROJECT_ID) List(java.util.List) CREDENTIALS_EMAIL(org.opendatakit.briefcase.operations.Common.CREDENTIALS_EMAIL) Args(org.opendatakit.common.cli.Args) FormCache(org.opendatakit.briefcase.util.FormCache) BriefcasePreferences(org.opendatakit.briefcase.model.BriefcasePreferences) CommonsHttp(org.opendatakit.briefcase.reused.http.CommonsHttp) Http(org.opendatakit.briefcase.reused.http.Http) PushToCentral(org.opendatakit.briefcase.push.central.PushToCentral) BriefcaseException(org.opendatakit.briefcase.reused.BriefcaseException) TransferForms(org.opendatakit.briefcase.transfer.TransferForms) FormStatus(org.opendatakit.briefcase.model.FormStatus) CentralServer(org.opendatakit.briefcase.reused.transfer.CentralServer) Credentials(org.opendatakit.briefcase.reused.http.Credentials)

Aggregations

Path (java.nio.file.Path)2 BriefcasePreferences (org.opendatakit.briefcase.model.BriefcasePreferences)2 FormStatus (org.opendatakit.briefcase.model.FormStatus)2 PushToCentral (org.opendatakit.briefcase.push.central.PushToCentral)2 BriefcaseException (org.opendatakit.briefcase.reused.BriefcaseException)2 Http (org.opendatakit.briefcase.reused.http.Http)2 JobsRunner (org.opendatakit.briefcase.reused.job.JobsRunner)2 CentralServer (org.opendatakit.briefcase.reused.transfer.CentralServer)2 TransferForms (org.opendatakit.briefcase.transfer.TransferForms)2 Container (java.awt.Container)1 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 JLabel (javax.swing.JLabel)1 EventBus (org.bushe.swing.event.EventBus)1 FormStatusEvent (org.opendatakit.briefcase.model.FormStatusEvent)1