use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by owncloud.
the class DetectAuthenticationMethodOperation method run.
/**
* Performs the operation.
*
* Triggers a check of existence on the root folder of the server, granting
* that the request is not authenticated.
*
* Analyzes the result of check to find out what authentication method, if
* any, is requested by the server.
*/
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null;
AuthenticationMethod authMethod = AuthenticationMethod.UNKNOWN;
RemoteOperation operation = new ExistenceCheckRemoteOperation("", mContext, false);
client.clearCredentials();
client.setFollowRedirects(false);
// try to access the root folder, following redirections but not SAML SSO redirections
result = operation.execute(client);
String redirectedLocation = result.getRedirectedLocation();
while (redirectedLocation != null && redirectedLocation.length() > 0 && !result.isIdPRedirection()) {
client.setBaseUri(Uri.parse(result.getRedirectedLocation()));
result = operation.execute(client);
redirectedLocation = result.getRedirectedLocation();
}
// analyze response
if (result.getHttpCode() == HttpStatus.SC_UNAUTHORIZED) {
String authRequest = ((result.getAuthenticateHeader()).trim()).toLowerCase();
if (authRequest.startsWith("basic")) {
authMethod = AuthenticationMethod.BASIC_HTTP_AUTH;
} else if (authRequest.startsWith("bearer")) {
authMethod = AuthenticationMethod.BEARER_TOKEN;
}
// else - fall back to UNKNOWN
} else if (result.isSuccess()) {
authMethod = AuthenticationMethod.NONE;
} else if (result.isIdPRedirection()) {
authMethod = AuthenticationMethod.SAML_WEB_SSO;
}
// else - fall back to UNKNOWN
Log_OC.d(TAG, "Authentication method found: " + authenticationMethodToString(authMethod));
if (!authMethod.equals(AuthenticationMethod.UNKNOWN)) {
result = new RemoteOperationResult(true, result.getHttpCode(), result.getHttpPhrase(), null);
}
ArrayList<Object> data = new ArrayList<Object>();
data.add(authMethod);
result.setData(data);
// same result instance, so that other errors
return result;
// can be handled by the caller transparently
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by owncloud.
the class GetCapabilitiesOperarion method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
GetRemoteCapabilitiesOperation getCapabilities = new GetRemoteCapabilitiesOperation();
RemoteOperationResult result = getCapabilities.execute(client);
if (result.isSuccess()) {
// Read data from the result
if (result.getData() != null && result.getData().size() > 0) {
OCCapability capability = (OCCapability) result.getData().get(0);
// Save the capabilities into database
getStorageManager().saveCapabilities(capability);
}
}
return result;
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by owncloud.
the class ErrorMessageAdapterUnitTest method getErrorCauseMessageForForbiddenRemoval.
@Test
public void getErrorCauseMessageForForbiddenRemoval() {
// Given a mocked set of resources passed to the object under test...
when(mMockResources.getString(R.string.forbidden_permissions)).thenReturn(MOCK_FORBIDDEN_PERMISSIONS);
when(mMockResources.getString(R.string.forbidden_permissions_delete)).thenReturn(MOCK_TO_DELETE);
// ... when method under test is called ...
String errorMessage = ErrorMessageAdapter.getErrorCauseMessage(new RemoteOperationResult(RemoteOperationResult.ResultCode.FORBIDDEN), new RemoveFileOperation(PATH_TO_DELETE, false), mMockResources);
// ... then the result should be the expected one.
assertThat(errorMessage, is(EXPECTED_ERROR_MESSAGE));
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by nextcloud.
the class ContactsBackupFragment method refreshBackupFolder.
private void refreshBackupFolder(final String backupFolderPath, final ContactsPreferenceActivity contactsPreferenceActivity) {
AsyncTask<String, Integer, Boolean> task = new AsyncTask<String, Integer, Boolean>() {
@Override
protected Boolean doInBackground(String... path) {
FileDataStorageManager storageManager = new FileDataStorageManager(account, contactsPreferenceActivity.getContentResolver());
OCFile folder = storageManager.getFileByPath(path[0]);
if (folder != null) {
RefreshFolderOperation operation = new RefreshFolderOperation(folder, System.currentTimeMillis(), false, false, false, storageManager, account, getContext());
RemoteOperationResult result = operation.execute(account, getContext());
return result.isSuccess();
} else {
return false;
}
}
@Override
protected void onPostExecute(Boolean result) {
if (result) {
OCFile backupFolder = contactsPreferenceActivity.getStorageManager().getFileByPath(backupFolderPath);
List<OCFile> backupFiles = contactsPreferenceActivity.getStorageManager().getFolderContent(backupFolder, false);
if (backupFiles == null || backupFiles.size() == 0) {
contactsDatePickerBtn.setVisibility(View.GONE);
} else {
contactsDatePickerBtn.setVisibility(View.VISIBLE);
}
}
}
};
task.execute(backupFolderPath);
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by nextcloud.
the class FileOperationsHelper method syncFile.
private void syncFile(OCFile file, Account account, FileDataStorageManager storageManager) {
mFileActivity.runOnUiThread(() -> mFileActivity.showLoadingDialog(mFileActivity.getResources().getString(R.string.sync_in_progress)));
SynchronizeFileOperation sfo = new SynchronizeFileOperation(file, null, account, true, mFileActivity);
RemoteOperationResult result = sfo.execute(storageManager, mFileActivity);
if (result.getCode() == RemoteOperationResult.ResultCode.SYNC_CONFLICT) {
// ISSUE 5: if the user is not running the app (this is a service!),
// this can be very intrusive; a notification should be preferred
Intent i = new Intent(mFileActivity, ConflictsResolveActivity.class);
i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra(ConflictsResolveActivity.EXTRA_FILE, file);
i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, account);
mFileActivity.startActivity(i);
} else {
if (file.isDown()) {
FileStorageUtils.checkIfFileFinishedSaving(file);
if (!result.isSuccess()) {
DisplayUtils.showSnackMessage(mFileActivity, R.string.file_not_synced);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
Log.e(TAG, "Failed to sleep for a bit");
}
}
}
}
mFileActivity.dismissLoadingDialog();
}
Aggregations