use of com.owncloud.android.operations.RemoveFileOperation in project android by nextcloud.
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);
Account account = new Account("name", MainApp.getAccountType());
// ... when method under test is called ...
String errorMessage = ErrorMessageAdapter.getErrorCauseMessage(new RemoteOperationResult(RemoteOperationResult.ResultCode.FORBIDDEN), new RemoveFileOperation(PATH_TO_DELETE, false, account, MainApp.getAppContext()), mMockResources);
// ... then the result should be the expected one.
assertThat(errorMessage, is(EXPECTED_ERROR_MESSAGE));
}
use of com.owncloud.android.operations.RemoveFileOperation in project android by owncloud.
the class OperationsService method newOperation.
/**
* Creates a new operation, as described by operationIntent.
*
* TODO - move to ServiceHandler (probably)
*
* @param operationIntent Intent describing a new operation to queue and execute.
* @return Pair with the new operation object and the information about its
* target server.
*/
private Pair<Target, RemoteOperation> newOperation(Intent operationIntent) {
RemoteOperation operation = null;
Target target = null;
try {
if (!operationIntent.hasExtra(EXTRA_ACCOUNT) && !operationIntent.hasExtra(EXTRA_SERVER_URL)) {
Timber.e("Not enough information provided in intent");
} else {
Account account = operationIntent.getParcelableExtra(EXTRA_ACCOUNT);
String serverUrl = operationIntent.getStringExtra(EXTRA_SERVER_URL);
String cookie = operationIntent.getStringExtra(EXTRA_COOKIE);
target = new Target(account, (serverUrl == null) ? null : Uri.parse(serverUrl), cookie);
String action = operationIntent.getAction();
if (action != null) {
switch(action) {
case ACTION_RENAME:
{
// Rename file or folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
String newName = operationIntent.getStringExtra(EXTRA_NEWNAME);
operation = new RenameFileOperation(remotePath, newName);
break;
}
case ACTION_REMOVE:
{
// Remove file or folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
boolean onlyLocalCopy = operationIntent.getBooleanExtra(EXTRA_REMOVE_ONLY_LOCAL, false);
operation = new RemoveFileOperation(remotePath, onlyLocalCopy, operationIntent.getBooleanExtra(EXTRA_IS_LAST_FILE_TO_REMOVE, false));
break;
}
case ACTION_CREATE_FOLDER:
{
// Create Folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
boolean createFullPath = operationIntent.getBooleanExtra(EXTRA_CREATE_FULL_PATH, true);
operation = new CreateFolderOperation(remotePath, createFullPath);
break;
}
case ACTION_SYNC_FILE:
{
// Sync file
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
operation = new SynchronizeFileOperation(remotePath, account, getApplicationContext());
break;
}
case ACTION_SYNC_FOLDER:
{
// Sync folder (all its descendant files are synced)
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
boolean pushOnly = operationIntent.getBooleanExtra(EXTRA_PUSH_ONLY, false);
boolean syncContentOfRegularFiles = operationIntent.getBooleanExtra(EXTRA_SYNC_REGULAR_FILES, false);
operation = new SynchronizeFolderOperation(// TODO remove this dependency from construction time
this, remotePath, account, // TODO remove this dependency from construction time
System.currentTimeMillis(), pushOnly, false, syncContentOfRegularFiles);
break;
}
case ACTION_MOVE_FILE:
{
// Move file/folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
String newParentPath = operationIntent.getStringExtra(EXTRA_NEW_PARENT_PATH);
operation = new MoveFileOperation(remotePath, newParentPath);
break;
}
case ACTION_COPY_FILE:
{
// Copy file/folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
String newParentPath = operationIntent.getStringExtra(EXTRA_NEW_PARENT_PATH);
operation = new CopyFileOperation(remotePath, newParentPath);
break;
}
case ACTION_CHECK_CURRENT_CREDENTIALS:
// Check validity of currently stored credentials for a given account
operation = new CheckCurrentCredentialsOperation(account);
break;
}
}
}
} catch (IllegalArgumentException e) {
Timber.e(e, "Bad information provided in intent: %s", e.getMessage());
operation = null;
}
if (operation != null) {
return new Pair<>(target, operation);
} else {
return null;
}
}
use of com.owncloud.android.operations.RemoveFileOperation 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.operations.RemoveFileOperation in project android by nextcloud.
the class OperationsService method newOperation.
/**
* Creates a new operation, as described by operationIntent.
*
* TODO - move to ServiceHandler (probably)
*
* @param operationIntent Intent describing a new operation to queue and execute.
* @return Pair with the new operation object and the information about its
* target server.
*/
private Pair<Target, RemoteOperation> newOperation(Intent operationIntent) {
RemoteOperation operation = null;
Target target = null;
try {
if (!operationIntent.hasExtra(EXTRA_ACCOUNT) && !operationIntent.hasExtra(EXTRA_SERVER_URL)) {
Log_OC.e(TAG, "Not enough information provided in intent");
} else {
Account account = operationIntent.getParcelableExtra(EXTRA_ACCOUNT);
String serverUrl = operationIntent.getStringExtra(EXTRA_SERVER_URL);
String cookie = operationIntent.getStringExtra(EXTRA_COOKIE);
target = new Target(account, (serverUrl == null) ? null : Uri.parse(serverUrl), cookie);
String action = operationIntent.getAction();
if (action.equals(ACTION_CREATE_SHARE_VIA_LINK)) {
// Create public share via link
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
String password = operationIntent.getStringExtra(EXTRA_SHARE_PASSWORD);
if (remotePath.length() > 0) {
operation = new CreateShareViaLinkOperation(remotePath, password);
}
} else if (ACTION_UPDATE_SHARE.equals(action)) {
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
long shareId = operationIntent.getLongExtra(EXTRA_SHARE_ID, -1);
if (remotePath != null && remotePath.length() > 0) {
operation = new UpdateShareViaLinkOperation(remotePath);
String password = operationIntent.getStringExtra(EXTRA_SHARE_PASSWORD);
((UpdateShareViaLinkOperation) operation).setPassword(password);
long expirationDate = operationIntent.getLongExtra(EXTRA_SHARE_EXPIRATION_DATE_IN_MILLIS, 0);
((UpdateShareViaLinkOperation) operation).setExpirationDate(expirationDate);
if (operationIntent.hasExtra(EXTRA_SHARE_PUBLIC_UPLOAD)) {
((UpdateShareViaLinkOperation) operation).setPublicUpload(operationIntent.getBooleanExtra(EXTRA_SHARE_PUBLIC_UPLOAD, false));
}
} else if (shareId > 0) {
operation = new UpdateSharePermissionsOperation(shareId);
int permissions = operationIntent.getIntExtra(EXTRA_SHARE_PERMISSIONS, 1);
((UpdateSharePermissionsOperation) operation).setPermissions(permissions);
}
} else if (action.equals(ACTION_CREATE_SHARE_WITH_SHAREE)) {
// Create private share with user or group
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
String shareeName = operationIntent.getStringExtra(EXTRA_SHARE_WITH);
ShareType shareType = (ShareType) operationIntent.getSerializableExtra(EXTRA_SHARE_TYPE);
int permissions = operationIntent.getIntExtra(EXTRA_SHARE_PERMISSIONS, -1);
if (remotePath.length() > 0) {
operation = new CreateShareWithShareeOperation(remotePath, shareeName, shareType, permissions);
}
} else if (action.equals(ACTION_UNSHARE)) {
// Unshare file
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
ShareType shareType = (ShareType) operationIntent.getSerializableExtra(EXTRA_SHARE_TYPE);
String shareWith = operationIntent.getStringExtra(EXTRA_SHARE_WITH);
if (remotePath.length() > 0) {
operation = new UnshareOperation(remotePath, shareType, shareWith, OperationsService.this);
}
} else if (action.equals(ACTION_GET_SERVER_INFO)) {
// check OC server and get basic information from it
operation = new GetServerInfoOperation(serverUrl, OperationsService.this);
} else if (action.equals(ACTION_OAUTH2_GET_ACCESS_TOKEN)) {
// / GET ACCESS TOKEN to the OAuth server
String oauth2QueryParameters = operationIntent.getStringExtra(EXTRA_OAUTH2_QUERY_PARAMETERS);
operation = new OAuth2GetAccessToken(getString(R.string.oauth2_client_id), getString(R.string.oauth2_redirect_uri), getString(R.string.oauth2_grant_type), oauth2QueryParameters);
} else if (action.equals(ACTION_GET_USER_NAME)) {
// Get User Name
operation = new GetRemoteUserInfoOperation();
} else if (action.equals(ACTION_RENAME)) {
// Rename file or folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
String newName = operationIntent.getStringExtra(EXTRA_NEWNAME);
operation = new RenameFileOperation(remotePath, newName);
} else if (action.equals(ACTION_REMOVE)) {
// Remove file or folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
boolean onlyLocalCopy = operationIntent.getBooleanExtra(EXTRA_REMOVE_ONLY_LOCAL, false);
operation = new RemoveFileOperation(remotePath, onlyLocalCopy, account, getApplicationContext());
} else if (action.equals(ACTION_CREATE_FOLDER)) {
// Create Folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
boolean createFullPath = operationIntent.getBooleanExtra(EXTRA_CREATE_FULL_PATH, true);
operation = new CreateFolderOperation(remotePath, createFullPath);
} else if (action.equals(ACTION_SYNC_FILE)) {
// Sync file
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
boolean syncFileContents = operationIntent.getBooleanExtra(EXTRA_SYNC_FILE_CONTENTS, true);
operation = new SynchronizeFileOperation(remotePath, account, syncFileContents, getApplicationContext());
} else if (action.equals(ACTION_SYNC_FOLDER)) {
// Sync folder (all its descendant files are sync'ed)
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
operation = new SynchronizeFolderOperation(// TODO remove this dependency from construction time
this, remotePath, account, // TODO remove this dependency from construction time
System.currentTimeMillis());
} else if (action.equals(ACTION_MOVE_FILE)) {
// Move file/folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
String newParentPath = operationIntent.getStringExtra(EXTRA_NEW_PARENT_PATH);
operation = new MoveFileOperation(remotePath, newParentPath);
} else if (action.equals(ACTION_COPY_FILE)) {
// Copy file/folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
String newParentPath = operationIntent.getStringExtra(EXTRA_NEW_PARENT_PATH);
operation = new CopyFileOperation(remotePath, newParentPath);
} else if (action.equals(ACTION_CHECK_CURRENT_CREDENTIALS)) {
// Check validity of currently stored credentials for a given account
operation = new CheckCurrentCredentialsOperation(account);
}
}
} catch (IllegalArgumentException e) {
Log_OC.e(TAG, "Bad information provided in intent: " + e.getMessage());
operation = null;
}
if (operation != null) {
return new Pair<Target, RemoteOperation>(target, operation);
} else {
return null;
}
}
Aggregations