1 /* ownCloud Android client application
2 * Copyright (C) 2012-2013 ownCloud Inc.
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.
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.
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/>.
18 package com
.owncloud
.android
.operations
;
20 import java
.util
.ArrayList
;
22 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
23 import com
.owncloud
.android
.datamodel
.OCFile
;
24 import com
.owncloud
.android
.datamodel
.OCShare
;
25 import com
.owncloud
.android
.oc_framework
.network
.webdav
.WebdavClient
;
26 import com
.owncloud
.android
.oc_framework
.operations
.RemoteOperation
;
27 import com
.owncloud
.android
.oc_framework
.operations
.RemoteOperationResult
;
28 import com
.owncloud
.android
.oc_framework
.operations
.ShareRemoteFile
;
29 import com
.owncloud
.android
.oc_framework
.operations
.ShareType
;
30 import com
.owncloud
.android
.oc_framework
.operations
.remote
.GetRemoteSharedFilesOperation
;
31 import com
.owncloud
.android
.oc_framework
.utils
.FileUtils
;
32 import com
.owncloud
.android
.utils
.Log_OC
;
35 * Access to remote operation to get the share files/folders
36 * Save the data in Database
41 public class GetSharedFilesOperation
extends RemoteOperation
{
43 private static final String TAG
= GetSharedFilesOperation
.class.getSimpleName();
45 private String mUrlServer
;
46 protected FileDataStorageManager mStorageManager
;
49 public GetSharedFilesOperation(String urlServer
, FileDataStorageManager storageManager
) {
50 mUrlServer
= urlServer
;
51 mStorageManager
= storageManager
;
55 protected RemoteOperationResult
run(WebdavClient client
) {
56 GetRemoteSharedFilesOperation operation
= new GetRemoteSharedFilesOperation(mUrlServer
);
57 RemoteOperationResult result
= operation
.execute(client
);
59 if (result
.isSuccess()) {
61 // Update DB with the response
62 ArrayList
<ShareRemoteFile
> shareRemoteFiles
= operation
.getSharedFiles();
63 Log_OC
.d(TAG
, "Share list size = " + shareRemoteFiles
.size());
64 for (ShareRemoteFile remoteFile
: shareRemoteFiles
) {
65 OCShare shareFile
= new OCShare(remoteFile
);
66 saveShareFileInDB(shareFile
);
73 private void saveShareFileInDB(OCShare shareFile
) {
75 mStorageManager
.saveShareFile(shareFile
);
78 String path
= shareFile
.getPath();
79 if (shareFile
.isDirectory()) {
80 path
= path
+ FileUtils
.PATH_SEPARATOR
;
83 // Update OCFile with data from share: ShareByLink ¿and publicLink?
84 OCFile file
= mStorageManager
.getFileByPath(path
);
86 if (shareFile
.getShareType().equals(ShareType
.PUBLIC_LINK
)) {
87 file
.setShareByLink(true
);
88 mStorageManager
.saveFile(file
);