Search in sources :

Example 91 with RemoteOperationResult

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
}
Also used : ExistenceCheckRemoteOperation(com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) ExistenceCheckRemoteOperation(com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) ArrayList(java.util.ArrayList)

Example 92 with RemoteOperationResult

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;
}
Also used : OCCapability(com.owncloud.android.lib.resources.status.OCCapability) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) GetRemoteCapabilitiesOperation(com.owncloud.android.lib.resources.status.GetRemoteCapabilitiesOperation)

Example 93 with RemoteOperationResult

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));
}
Also used : RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) RemoveFileOperation(com.owncloud.android.operations.RemoveFileOperation) Test(org.junit.Test)

Example 94 with RemoteOperationResult

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);
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) RefreshFolderOperation(com.owncloud.android.operations.RefreshFolderOperation) AsyncTask(android.os.AsyncTask) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager)

Example 95 with RemoteOperationResult

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();
}
Also used : RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) Intent(android.content.Intent) SynchronizeFileOperation(com.owncloud.android.operations.SynchronizeFileOperation)

Aggregations

RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)172 OCFile (com.owncloud.android.datamodel.OCFile)48 RemoteOperation (com.owncloud.android.lib.common.operations.RemoteOperation)24 ArrayList (java.util.ArrayList)24 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)22 IOException (java.io.IOException)22 Account (android.accounts.Account)19 User (com.nextcloud.client.account.User)18 OCShare (com.owncloud.android.lib.resources.shares.OCShare)18 File (java.io.File)18 OperationCancelledException (com.owncloud.android.lib.common.operations.OperationCancelledException)17 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)16 Context (android.content.Context)15 OwnCloudClient (com.owncloud.android.lib.common.OwnCloudClient)12 RemoteFile (com.owncloud.android.lib.resources.files.model.RemoteFile)12 FileNotFoundException (java.io.FileNotFoundException)12 Intent (android.content.Intent)11 JSONObject (org.json.JSONObject)11 Test (org.junit.Test)11 Uri (android.net.Uri)10