Search in sources :

Example 66 with RemoteOperationResult

use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by nextcloud.

the class GetCapabilitiesOperation method run.

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    final FileDataStorageManager storageManager = getStorageManager();
    OCCapability currentCapability = null;
    if (!storageManager.getUser().isAnonymous()) {
        currentCapability = storageManager.getCapability(storageManager.getUser().getAccountName());
    }
    RemoteOperationResult result = new GetCapabilitiesRemoteOperation(currentCapability).execute(client);
    if (result.isSuccess() && result.getData() != null && result.getData().size() > 0) {
        // Read data from the result
        OCCapability capability = (OCCapability) result.getData().get(0);
        // Save the capabilities into database
        storageManager.saveCapabilities(capability);
    }
    return result;
}
Also used : OCCapability(com.owncloud.android.lib.resources.status.OCCapability) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) GetCapabilitiesRemoteOperation(com.owncloud.android.lib.resources.status.GetCapabilitiesRemoteOperation)

Example 67 with RemoteOperationResult

use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by nextcloud.

the class MoveFileOperation method run.

/**
 * Performs the operation.
 *
 * @param   client      Client object to communicate with the remote ownCloud server.
 */
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    // / 1. check move validity
    if (targetParentPath.startsWith(srcPath)) {
        return new RemoteOperationResult(ResultCode.INVALID_MOVE_INTO_DESCENDANT);
    }
    OCFile file = getStorageManager().getFileByPath(srcPath);
    if (file == null) {
        return new RemoteOperationResult(ResultCode.FILE_NOT_FOUND);
    }
    // / 2. remote move
    String targetPath = targetParentPath + file.getFileName();
    if (file.isFolder()) {
        targetPath += OCFile.PATH_SEPARATOR;
    }
    RemoteOperationResult result = new MoveFileRemoteOperation(srcPath, targetPath, false).execute(client);
    // / 3. local move
    if (result.isSuccess()) {
        getStorageManager().moveLocalFile(file, targetPath, targetParentPath);
    }
    return result;
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) MoveFileRemoteOperation(com.owncloud.android.lib.resources.files.MoveFileRemoteOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult)

Example 68 with RemoteOperationResult

use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by nextcloud.

the class RichDocumentsCreateAssetOperation method run.

protected RemoteOperationResult run(OwnCloudClient client) {
    RemoteOperationResult result;
    Utf8PostMethod postMethod = null;
    try {
        postMethod = new Utf8PostMethod(client.getBaseUri() + ASSET_URL);
        postMethod.setParameter(PARAMETER_PATH, path);
        postMethod.setParameter(PARAMETER_FORMAT, PARAMETER_FORMAT_VALUE);
        // remote request
        postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
        int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);
        if (status == HttpStatus.SC_OK) {
            String response = postMethod.getResponseBodyAsString();
            // Parse the response
            JSONObject respJSON = new JSONObject(response);
            String url = respJSON.getString(NODE_URL);
            result = new RemoteOperationResult(true, postMethod);
            result.setSingleData(url);
        } else {
            result = new RemoteOperationResult(false, postMethod);
            client.exhaustResponse(postMethod.getResponseBodyAsStream());
        }
    } catch (Exception e) {
        result = new RemoteOperationResult(e);
        Log_OC.e(TAG, "Create asset for richdocuments with path " + path + " failed: " + result.getLogMessage(), result.getException());
    } finally {
        if (postMethod != null) {
            postMethod.releaseConnection();
        }
    }
    return result;
}
Also used : Utf8PostMethod(org.apache.commons.httpclient.methods.Utf8PostMethod) JSONObject(org.json.JSONObject) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult)

Example 69 with RemoteOperationResult

use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by nextcloud.

the class RefreshFolderOperation method updateOCVersion.

private void updateOCVersion(OwnCloudClient client) {
    UpdateOCVersionOperation update = new UpdateOCVersionOperation(user.toPlatformAccount(), mContext);
    RemoteOperationResult result = update.execute(client);
    if (result.isSuccess()) {
        // Update Capabilities for this account
        updateCapabilities();
    }
}
Also used : RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult)

Example 70 with RemoteOperationResult

use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by nextcloud.

the class RefreshFolderOperation method refreshSharesForFolder.

/**
 * Syncs the Share resources for the files contained in the folder refreshed (children, not deeper descendants).
 *
 * @param client    Handler of a session with an OC server.
 * @return The result of the remote operation retrieving the Share resources in the folder refreshed by
 *                  the operation.
 */
private RemoteOperationResult refreshSharesForFolder(OwnCloudClient client) {
    RemoteOperationResult result;
    // remote request
    GetSharesForFileRemoteOperation operation = new GetSharesForFileRemoteOperation(mLocalFolder.getRemotePath(), true, true);
    result = operation.execute(client);
    if (result.isSuccess()) {
        // update local database
        ArrayList<OCShare> shares = new ArrayList<>();
        OCShare share;
        for (Object obj : result.getData()) {
            share = (OCShare) obj;
            if (!ShareType.NO_SHARED.equals(share.getShareType())) {
                shares.add(share);
            }
        }
        mStorageManager.saveSharesInFolder(shares, mLocalFolder);
    }
    return result;
}
Also used : RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) OCShare(com.owncloud.android.lib.resources.shares.OCShare) ArrayList(java.util.ArrayList) GetSharesForFileRemoteOperation(com.owncloud.android.lib.resources.shares.GetSharesForFileRemoteOperation)

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