Merge remote-tracking branch 'theirs/develop' into gradleWithInternalDependency
[pub/Android/ownCloud.git] / src / com / owncloud / android / operations / GetSharesForFileOperation.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012-2013 ownCloud Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18
19 package com.owncloud.android.operations;
20
21 import java.util.ArrayList;
22
23 import com.owncloud.android.lib.common.OwnCloudClient;
24 import com.owncloud.android.lib.resources.shares.OCShare;
25 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
26 import com.owncloud.android.lib.common.utils.Log_OC;
27 import com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation;
28 import com.owncloud.android.operations.common.SyncOperation;
29
30 /**
31 * Provide a list shares for a specific file.
32 *
33 * @author masensio
34 *
35 */
36 public class GetSharesForFileOperation extends SyncOperation {
37
38 private static final String TAG = GetSharesForFileOperation.class.getSimpleName();
39
40 private String mPath;
41 private boolean mReshares;
42 private boolean mSubfiles;
43
44 /**
45 * Constructor
46 *
47 * @param path Path to file or folder
48 * @param reshares If set to false (default), only shares from the current user are returned
49 * If set to true, all shares from the given file are returned
50 * @param subfiles If set to false (default), lists only the folder being shared
51 * If set to true, all shared files within the folder are returned.
52 */
53 public GetSharesForFileOperation(String path, boolean reshares, boolean subfiles) {
54 mPath = path;
55 mReshares = reshares;
56 mSubfiles = subfiles;
57 }
58
59 @Override
60 protected RemoteOperationResult run(OwnCloudClient client) {
61 GetRemoteSharesForFileOperation operation = new GetRemoteSharesForFileOperation(mPath, mReshares, mSubfiles);
62 RemoteOperationResult result = operation.execute(client);
63
64 if (result.isSuccess()) {
65
66 // Update DB with the response
67 Log_OC.d(TAG, "File = " + mPath + " Share list size " + result.getData().size());
68 ArrayList<OCShare> shares = new ArrayList<OCShare>();
69 for(Object obj: result.getData()) {
70 shares.add((OCShare) obj);
71 }
72
73 getStorageManager().saveSharesDB(shares);
74 }
75
76 return result;
77 }
78
79 }