Search in sources :

Example 1 with GetRemoteSharesForFileOperation

use of com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation in project android by owncloud.

the class CreateShareViaLinkOperation method run.

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    // Check if the share link already exists
    RemoteOperation operation = new GetRemoteSharesForFileOperation(mPath, false, false);
    RemoteOperationResult result = operation.execute(client);
    // Create public link if doesn't exist yet
    boolean publicShareExists = false;
    if (result.isSuccess()) {
        OCShare share = null;
        for (int i = 0; i < result.getData().size(); i++) {
            share = (OCShare) result.getData().get(i);
            if (ShareType.PUBLIC_LINK.equals(share.getShareType())) {
                publicShareExists = true;
                break;
            }
        }
    }
    if (!publicShareExists) {
        CreateRemoteShareOperation createOp = new CreateRemoteShareOperation(mPath, ShareType.PUBLIC_LINK, "", false, mPassword, OCShare.DEFAULT_PERMISSION);
        createOp.setGetShareDetails(true);
        result = createOp.execute(client);
    }
    if (result.isSuccess()) {
        if (result.getData().size() > 0) {
            Object item = result.getData().get(0);
            if (item instanceof OCShare) {
                updateData((OCShare) item);
            } else {
                ArrayList<Object> data = result.getData();
                result = new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
                result.setData(data);
            }
        } else {
            result = new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
        }
    }
    return result;
}
Also used : CreateRemoteShareOperation(com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) OCShare(com.owncloud.android.lib.resources.shares.OCShare) GetRemoteSharesForFileOperation(com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation)

Example 2 with GetRemoteSharesForFileOperation

use of com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation in project android by owncloud.

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 
    GetRemoteSharesForFileOperation operation = new GetRemoteSharesForFileOperation(mLocalFolder.getRemotePath(), true, true);
    result = operation.execute(client);
    if (result.isSuccess()) {
        // update local database
        ArrayList<OCShare> shares = new ArrayList<>();
        for (Object obj : result.getData()) {
            shares.add((OCShare) obj);
        }
        getStorageManager().saveSharesInFolder(shares, mLocalFolder);
    }
    return result;
}
Also used : RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) ArrayList(java.util.ArrayList) OCShare(com.owncloud.android.lib.resources.shares.OCShare) GetRemoteSharesForFileOperation(com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation)

Example 3 with GetRemoteSharesForFileOperation

use of com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation in project android by owncloud.

the class GetSharesForFileOperation method run.

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    GetRemoteSharesForFileOperation operation = new GetRemoteSharesForFileOperation(mPath, mReshares, mSubfiles);
    RemoteOperationResult result = operation.execute(client);
    if (result.isSuccess()) {
        // Update DB with the response
        Log_OC.d(TAG, "File = " + mPath + " Share list size  " + result.getData().size());
        ArrayList<OCShare> shares = new ArrayList<OCShare>();
        for (Object obj : result.getData()) {
            shares.add((OCShare) obj);
        }
        getStorageManager().saveSharesDB(shares);
    } else if (result.getCode() == RemoteOperationResult.ResultCode.SHARE_NOT_FOUND) {
        // no share on the file - remove local shares
        getStorageManager().removeSharesForFile(mPath);
    }
    return result;
}
Also used : RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) ArrayList(java.util.ArrayList) OCShare(com.owncloud.android.lib.resources.shares.OCShare) GetRemoteSharesForFileOperation(com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation)

Aggregations

RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)3 GetRemoteSharesForFileOperation (com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation)3 OCShare (com.owncloud.android.lib.resources.shares.OCShare)3 ArrayList (java.util.ArrayList)2 RemoteOperation (com.owncloud.android.lib.common.operations.RemoteOperation)1 CreateRemoteShareOperation (com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation)1