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