Search in sources :

Example 1 with CreateShareWithShareeOperation

use of com.owncloud.android.operations.CreateShareWithShareeOperation 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)) {
            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);
            } 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);
                operation = new SynchronizeFileOperation(remotePath, account, getApplicationContext());
            } else if (action.equals(ACTION_SYNC_FOLDER)) {
                // Sync folder (all its descendant files are sync'ed)
                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);
            } 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, account);
            } 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, account);
            } 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;
    }
}
Also used : Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) UnshareOperation(com.owncloud.android.operations.UnshareOperation) RemoveFileOperation(com.owncloud.android.operations.RemoveFileOperation) RenameFileOperation(com.owncloud.android.operations.RenameFileOperation) CopyFileOperation(com.owncloud.android.operations.CopyFileOperation) SynchronizeFolderOperation(com.owncloud.android.operations.SynchronizeFolderOperation) UpdateShareViaLinkOperation(com.owncloud.android.operations.UpdateShareViaLinkOperation) Pair(android.util.Pair) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) GetRemoteUserInfoOperation(com.owncloud.android.lib.resources.users.GetRemoteUserInfoOperation) CreateShareWithShareeOperation(com.owncloud.android.operations.CreateShareWithShareeOperation) CheckCurrentCredentialsOperation(com.owncloud.android.operations.CheckCurrentCredentialsOperation) CreateShareViaLinkOperation(com.owncloud.android.operations.CreateShareViaLinkOperation) CreateFolderOperation(com.owncloud.android.operations.CreateFolderOperation) OAuth2GetAccessToken(com.owncloud.android.operations.OAuth2GetAccessToken) MoveFileOperation(com.owncloud.android.operations.MoveFileOperation) GetServerInfoOperation(com.owncloud.android.operations.GetServerInfoOperation) UpdateSharePermissionsOperation(com.owncloud.android.operations.UpdateSharePermissionsOperation) ShareType(com.owncloud.android.lib.resources.shares.ShareType) SynchronizeFileOperation(com.owncloud.android.operations.SynchronizeFileOperation)

Aggregations

Account (android.accounts.Account)1 Pair (android.util.Pair)1 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)1 RemoteOperation (com.owncloud.android.lib.common.operations.RemoteOperation)1 ShareType (com.owncloud.android.lib.resources.shares.ShareType)1 GetRemoteUserInfoOperation (com.owncloud.android.lib.resources.users.GetRemoteUserInfoOperation)1 CheckCurrentCredentialsOperation (com.owncloud.android.operations.CheckCurrentCredentialsOperation)1 CopyFileOperation (com.owncloud.android.operations.CopyFileOperation)1 CreateFolderOperation (com.owncloud.android.operations.CreateFolderOperation)1 CreateShareViaLinkOperation (com.owncloud.android.operations.CreateShareViaLinkOperation)1 CreateShareWithShareeOperation (com.owncloud.android.operations.CreateShareWithShareeOperation)1 GetServerInfoOperation (com.owncloud.android.operations.GetServerInfoOperation)1 MoveFileOperation (com.owncloud.android.operations.MoveFileOperation)1 OAuth2GetAccessToken (com.owncloud.android.operations.OAuth2GetAccessToken)1 RemoveFileOperation (com.owncloud.android.operations.RemoveFileOperation)1 RenameFileOperation (com.owncloud.android.operations.RenameFileOperation)1 SynchronizeFileOperation (com.owncloud.android.operations.SynchronizeFileOperation)1 SynchronizeFolderOperation (com.owncloud.android.operations.SynchronizeFolderOperation)1 UnshareOperation (com.owncloud.android.operations.UnshareOperation)1 UpdateSharePermissionsOperation (com.owncloud.android.operations.UpdateSharePermissionsOperation)1