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