Search in sources :

Example 1 with ServerConnectionInfo

use of org.opendatakit.briefcase.model.ServerConnectionInfo in project briefcase by opendatakit.

the class PullFormFromAggregate method pullFormFromAggregate.

public static void pullFormFromAggregate(String storageDir, String formid, String username, String password, String server) {
    CliEventsCompanion.attach(log);
    bootCache(storageDir);
    ServerConnectionInfo transferSettings = new ServerConnectionInfo(server, username, password.toCharArray());
    ServerConnectionTest.testPull(transferSettings);
    Optional<FormStatus> maybeForm = RetrieveAvailableFormsFromServer.get(transferSettings).stream().filter(f -> f.getFormDefinition().getFormId().equals(formid)).findFirst();
    if (!maybeForm.isPresent())
        throw new FormNotFoundException(formid);
    FormStatus form = maybeForm.get();
    EventBus.publish(new StartPullEvent(form));
    TransferFromServer.pull(transferSettings, form);
}
Also used : Common.bootCache(org.opendatakit.briefcase.operations.Common.bootCache) Arrays(java.util.Arrays) ServerConnectionTest(org.opendatakit.briefcase.util.ServerConnectionTest) FormStatus(org.opendatakit.briefcase.model.FormStatus) Logger(org.slf4j.Logger) ODK_USERNAME(org.opendatakit.briefcase.operations.Common.ODK_USERNAME) Param(org.opendatakit.common.cli.Param) STORAGE_DIR(org.opendatakit.briefcase.operations.Common.STORAGE_DIR) LoggerFactory(org.slf4j.LoggerFactory) ServerConnectionInfo(org.opendatakit.briefcase.model.ServerConnectionInfo) RetrieveAvailableFormsFromServer(org.opendatakit.briefcase.util.RetrieveAvailableFormsFromServer) AGGREGATE_SERVER(org.opendatakit.briefcase.operations.Common.AGGREGATE_SERVER) FORM_ID(org.opendatakit.briefcase.operations.Common.FORM_ID) Operation(org.opendatakit.common.cli.Operation) TransferFromServer(org.opendatakit.briefcase.util.TransferFromServer) EventBus(org.bushe.swing.event.EventBus) Optional(java.util.Optional) ODK_PASSWORD(org.opendatakit.briefcase.operations.Common.ODK_PASSWORD) ServerConnectionInfo(org.opendatakit.briefcase.model.ServerConnectionInfo) FormStatus(org.opendatakit.briefcase.model.FormStatus)

Example 2 with ServerConnectionInfo

use of org.opendatakit.briefcase.model.ServerConnectionInfo in project briefcase by opendatakit.

the class PushFormToAggregate method pushFormToAggregate.

private static void pushFormToAggregate(String storageDir, String formid, String username, String password, String server) {
    CliEventsCompanion.attach(log);
    bootCache(storageDir);
    Optional<FormStatus> maybeFormStatus = FileSystemUtils.getBriefcaseFormList().stream().filter(form -> form.getFormId().equals(formid)).map(formDef -> new FormStatus(FormStatus.TransferType.UPLOAD, formDef)).findFirst();
    FormStatus form = maybeFormStatus.orElseThrow(() -> new FormNotFoundException(formid));
    ServerConnectionInfo transferSettings = new ServerConnectionInfo(server, username, password.toCharArray());
    ServerConnectionTest.testPush(transferSettings);
    TransferToServer.push(transferSettings, form);
}
Also used : Common.bootCache(org.opendatakit.briefcase.operations.Common.bootCache) Arrays(java.util.Arrays) ServerConnectionTest(org.opendatakit.briefcase.util.ServerConnectionTest) FormStatus(org.opendatakit.briefcase.model.FormStatus) Logger(org.slf4j.Logger) ODK_USERNAME(org.opendatakit.briefcase.operations.Common.ODK_USERNAME) Param(org.opendatakit.common.cli.Param) STORAGE_DIR(org.opendatakit.briefcase.operations.Common.STORAGE_DIR) LoggerFactory(org.slf4j.LoggerFactory) ServerConnectionInfo(org.opendatakit.briefcase.model.ServerConnectionInfo) TransferToServer(org.opendatakit.briefcase.util.TransferToServer) AGGREGATE_SERVER(org.opendatakit.briefcase.operations.Common.AGGREGATE_SERVER) FORM_ID(org.opendatakit.briefcase.operations.Common.FORM_ID) Operation(org.opendatakit.common.cli.Operation) Optional(java.util.Optional) ODK_PASSWORD(org.opendatakit.briefcase.operations.Common.ODK_PASSWORD) FileSystemUtils(org.opendatakit.briefcase.util.FileSystemUtils) ServerConnectionInfo(org.opendatakit.briefcase.model.ServerConnectionInfo) FormStatus(org.opendatakit.briefcase.model.FormStatus)

Example 3 with ServerConnectionInfo

use of org.opendatakit.briefcase.model.ServerConnectionInfo in project briefcase by opendatakit.

the class ExportFormsTest method the_factory_tries_to_load_any_transfer_settings_found_in_preferences.

@Test
public void the_factory_tries_to_load_any_transfer_settings_found_in_preferences() {
    ServerConnectionInfo expectedTransferSettings = new ServerConnectionInfo("http://some/url", "some username", "some password".toCharArray());
    FormStatus formWithTransferSettings = buildFormStatus(1);
    FormStatus formWithoutTransferSettings = buildFormStatus(2);
    List<FormStatus> formsList = Arrays.asList(formWithTransferSettings, formWithoutTransferSettings);
    BriefcasePreferences exportPreferences = new BriefcasePreferences(InMemoryPreferences.empty());
    BriefcasePreferences appPreferences = new BriefcasePreferences(InMemoryPreferences.empty());
    appPreferences.put(String.format("%s_pull_settings_url", formWithTransferSettings.getFormDefinition().getFormId()), expectedTransferSettings.getUrl());
    appPreferences.put(String.format("%s_pull_settings_username", formWithTransferSettings.getFormDefinition().getFormId()), expectedTransferSettings.getUsername());
    appPreferences.put(String.format("%s_pull_settings_password", formWithTransferSettings.getFormDefinition().getFormId()), String.valueOf(expectedTransferSettings.getPassword()));
    ExportForms forms = ExportForms.load(ExportConfiguration.empty(), formsList, exportPreferences, appPreferences);
    assertThat(forms.getTransferSettings(formWithoutTransferSettings.getFormDefinition().getFormId()), isEmpty());
    assertThat(forms.getTransferSettings(formWithTransferSettings.getFormDefinition().getFormId()), isPresentAndIs(expectedTransferSettings));
}
Also used : ServerConnectionInfo(org.opendatakit.briefcase.model.ServerConnectionInfo) BriefcasePreferences(org.opendatakit.briefcase.model.BriefcasePreferences) FormStatus(org.opendatakit.briefcase.model.FormStatus) FormStatusBuilder.buildFormStatus(org.opendatakit.briefcase.model.FormStatusBuilder.buildFormStatus) Test(org.junit.Test)

Example 4 with ServerConnectionInfo

use of org.opendatakit.briefcase.model.ServerConnectionInfo in project briefcase by opendatakit.

the class ServerConnectionDialog method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (CONNECT.equals(e.getActionCommand())) {
        // do action...
        final ServerConnectionInfo info = new ServerConnectionInfo((textUrlField.getText()).trim(), textUsernameField.getText(), textPasswordField.getPassword());
        okButton.setEnabled(false);
        cancelButton.setEnabled(false);
        String errorString;
        Cursor saved = getCursor();
        try {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            paint(getGraphics());
            terminationFuture.reset();
            ServerConnectionTest backgroundAction = new ServerConnectionTest(info, terminationFuture, asTarget);
            backgroundAction.run();
            isSuccessful = backgroundAction.isSuccessful();
            errorString = backgroundAction.getErrorReason();
        } finally {
            setCursor(saved);
        }
        if (isSuccessful) {
            serverInfo = info;
            this.setVisible(false);
        } else {
            String errorMessage = errorString.trim();
            // with punctuation and some not
            if (!(errorMessage.endsWith("!") || errorMessage.endsWith("."))) {
                errorMessage += ". ";
            }
            ODKOptionPane.showErrorDialog(this, errorMessage + MessageStrings.PROXY_SET_ADVICE, "Invalid Server URL");
            okButton.setEnabled(true);
            cancelButton.setEnabled(true);
        }
    } else {
        // cancel...
        terminationFuture.markAsCancelled(new TransferAbortEvent("User cancels connection."));
        this.setVisible(false);
    }
}
Also used : ServerConnectionTest(org.opendatakit.briefcase.util.ServerConnectionTest) ServerConnectionInfo(org.opendatakit.briefcase.model.ServerConnectionInfo) Cursor(java.awt.Cursor) TransferAbortEvent(org.opendatakit.briefcase.model.TransferAbortEvent)

Example 5 with ServerConnectionInfo

use of org.opendatakit.briefcase.model.ServerConnectionInfo in project briefcase by opendatakit.

the class PullTransferPanel method initServerInfoWithPreferences.

private ServerConnectionInfo initServerInfoWithPreferences(EndPointType type) {
    ServerConnectionInfo connectionInfo = null;
    if (type == EndPointType.AGGREGATE_1_0_CHOICE) {
        String url = tabPreferences.get(BriefcasePreferences.AGGREGATE_1_0_URL, "");
        String username = tabPreferences.get(BriefcasePreferences.USERNAME, "");
        char[] password = BriefcasePreferences.getStorePasswordsConsentProperty() ? tabPreferences.get(BriefcasePreferences.PASSWORD, "").toCharArray() : new char[0];
        connectionInfo = new ServerConnectionInfo(url, username, password);
    }
    return connectionInfo;
}
Also used : ServerConnectionInfo(org.opendatakit.briefcase.model.ServerConnectionInfo)

Aggregations

ServerConnectionInfo (org.opendatakit.briefcase.model.ServerConnectionInfo)5 FormStatus (org.opendatakit.briefcase.model.FormStatus)3 ServerConnectionTest (org.opendatakit.briefcase.util.ServerConnectionTest)3 Arrays (java.util.Arrays)2 Optional (java.util.Optional)2 AGGREGATE_SERVER (org.opendatakit.briefcase.operations.Common.AGGREGATE_SERVER)2 FORM_ID (org.opendatakit.briefcase.operations.Common.FORM_ID)2 ODK_PASSWORD (org.opendatakit.briefcase.operations.Common.ODK_PASSWORD)2 ODK_USERNAME (org.opendatakit.briefcase.operations.Common.ODK_USERNAME)2 STORAGE_DIR (org.opendatakit.briefcase.operations.Common.STORAGE_DIR)2 Common.bootCache (org.opendatakit.briefcase.operations.Common.bootCache)2 Operation (org.opendatakit.common.cli.Operation)2 Param (org.opendatakit.common.cli.Param)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Cursor (java.awt.Cursor)1 EventBus (org.bushe.swing.event.EventBus)1 Test (org.junit.Test)1 BriefcasePreferences (org.opendatakit.briefcase.model.BriefcasePreferences)1 FormStatusBuilder.buildFormStatus (org.opendatakit.briefcase.model.FormStatusBuilder.buildFormStatus)1