Search in sources :

Example 1 with CheckPathExistenceRemoteOperation

use of com.owncloud.android.lib.resources.files.CheckPathExistenceRemoteOperation in project android by owncloud.

the class CheckCurrentCredentialsOperation method run.

@Override
protected RemoteOperationResult<Account> run(OwnCloudClient client) {
    if (!getStorageManager().getAccount().name.equals(mAccount.name)) {
        return new RemoteOperationResult<>(new IllegalStateException("Account to validate is not the account connected to!"));
    } else {
        RemoteOperation checkPathExistenceOperation = new CheckPathExistenceRemoteOperation(OCFile.ROOT_PATH, false);
        final RemoteOperationResult existenceCheckResult = checkPathExistenceOperation.execute(client);
        final RemoteOperationResult<Account> result = new RemoteOperationResult<>(existenceCheckResult.getCode());
        result.setData(mAccount);
        return result;
    }
}
Also used : CheckPathExistenceRemoteOperation(com.owncloud.android.lib.resources.files.CheckPathExistenceRemoteOperation) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) Account(android.accounts.Account) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) CheckPathExistenceRemoteOperation(com.owncloud.android.lib.resources.files.CheckPathExistenceRemoteOperation)

Example 2 with CheckPathExistenceRemoteOperation

use of com.owncloud.android.lib.resources.files.CheckPathExistenceRemoteOperation in project android by owncloud.

the class UploadFileOperation method grantFolderExistence.

/**
 * Checks the existence of the folder where the current file will be uploaded both
 * in the remote server and in the local database.
 * <p>
 * If the upload is set to enforce the creation of the folder, the method tries to
 * create it both remote and locally.
 *
 * @param pathToGrant Full remote path whose existence will be granted.
 * @return An {@link OCFile} instance corresponding to the folder where the file
 * will be uploaded.
 */
private RemoteOperationResult grantFolderExistence(String pathToGrant, OwnCloudClient client) {
    RemoteOperation checkPathExistenceOperation = new CheckPathExistenceRemoteOperation(pathToGrant, false);
    RemoteOperationResult result = checkPathExistenceOperation.execute(client);
    if (!result.isSuccess() && result.getCode() == ResultCode.FILE_NOT_FOUND && mRemoteFolderToBeCreated) {
        SyncOperation syncOp = new CreateFolderOperation(pathToGrant, true);
        result = syncOp.execute(client, getStorageManager());
    }
    if (result.isSuccess()) {
        OCFile parentDir = getStorageManager().getFileByPath(pathToGrant);
        if (parentDir == null) {
            parentDir = createLocalFolder(pathToGrant);
        }
        if (parentDir != null) {
            result = new RemoteOperationResult(ResultCode.OK);
        } else {
            result = new RemoteOperationResult(ResultCode.UNKNOWN_ERROR);
        }
    }
    return result;
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) CheckPathExistenceRemoteOperation(com.owncloud.android.lib.resources.files.CheckPathExistenceRemoteOperation) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) CheckPathExistenceRemoteOperation(com.owncloud.android.lib.resources.files.CheckPathExistenceRemoteOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) SyncOperation(com.owncloud.android.operations.common.SyncOperation)

Aggregations

RemoteOperation (com.owncloud.android.lib.common.operations.RemoteOperation)2 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)2 CheckPathExistenceRemoteOperation (com.owncloud.android.lib.resources.files.CheckPathExistenceRemoteOperation)2 Account (android.accounts.Account)1 OCFile (com.owncloud.android.datamodel.OCFile)1 SyncOperation (com.owncloud.android.operations.common.SyncOperation)1