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);
}
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);
}
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));
}
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);
}
}
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;
}
Aggregations