Refactor parameter user_agent out of RemoteOperation and children
[pub/Android/ownCloud.git] / src / com / owncloud / android / operations / GetSharesOperation.java
1 /**
2 * ownCloud Android client application
3 *
4 * @author masensio
5 * @author David A. Velasco
6 * Copyright (C) 2015 ownCloud Inc.
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2,
10 * as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
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.common.operations.RemoteOperationResult;
29 import com.owncloud.android.lib.common.utils.Log_OC;
30 import com.owncloud.android.lib.resources.shares.OCShare;
31 import com.owncloud.android.lib.resources.shares.GetRemoteSharesOperation;
32 import com.owncloud.android.operations.common.SyncOperation;
33
34 /**
35 * Access to remote operation to get the share files/folders
36 * Save the data in Database
37 */
38
39 public class GetSharesOperation extends SyncOperation {
40
41 private static final String TAG = GetSharesOperation.class.getSimpleName();
42
43 @Override
44 protected RemoteOperationResult run(OwnCloudClient client) {
45 GetRemoteSharesOperation operation = new GetRemoteSharesOperation();
46 RemoteOperationResult result = operation.execute(client);
47
48 if (result.isSuccess()) {
49
50 // Update DB with the response
51 Log_OC.d(TAG, "Share list size = " + result.getData().size());
52 ArrayList<OCShare> shares = new ArrayList<OCShare>();
53 for(Object obj: result.getData()) {
54 shares.add((OCShare) obj);
55 }
56
57 getStorageManager().saveSharesDB(shares);
58 }
59
60 return result;
61 }
62
63 }