7ca716b8b870182257241cf2a833b19508e12df0
[pub/Android/ownCloud.git] / src / com / owncloud / android / operations / GetSharesOperation.java
1 /* ownCloud Android client application
2 *
3 * @author masensio
4 * @author David A. Velasco
5 * Copyright (C) 2012-2014 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 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.common.operations.RemoteOperationResult;
27 import com.owncloud.android.lib.common.utils.Log_OC;
28 import com.owncloud.android.lib.resources.shares.OCShare;
29 import com.owncloud.android.lib.resources.shares.GetRemoteSharesOperation;
30 import com.owncloud.android.operations.common.SyncOperation;
31
32 /**
33 * Access to remote operation to get the share files/folders
34 * Save the data in Database
35 */
36
37 public class GetSharesOperation extends SyncOperation {
38
39 private static final String TAG = GetSharesOperation.class.getSimpleName();
40
41 @Override
42 protected RemoteOperationResult run(OwnCloudClient client) {
43 GetRemoteSharesOperation operation = new GetRemoteSharesOperation();
44 RemoteOperationResult result = operation.execute(client);
45
46 if (result.isSuccess()) {
47
48 // Update DB with the response
49 Log_OC.d(TAG, "Share list size = " + result.getData().size());
50 ArrayList<OCShare> shares = new ArrayList<OCShare>();
51 for(Object obj: result.getData()) {
52 shares.add((OCShare) obj);
53 }
54
55 getStorageManager().saveSharesDB(shares);
56 }
57
58 return result;
59 }
60
61 }