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
.OnRemoteOperationListener
;
27 import com
.owncloud
.android
.oc_framework
.operations
.RemoteOperation
;
28 import com
.owncloud
.android
.oc_framework
.operations
.RemoteOperationResult
;
29 import com
.owncloud
.android
.oc_framework
.operations
.ShareRemoteFile
;
30 import com
.owncloud
.android
.oc_framework
.operations
.ShareType
;
31 import com
.owncloud
.android
.oc_framework
.operations
.remote
.GetRemoteSharedFilesOperation
;
32 import com
.owncloud
.android
.oc_framework
.utils
.FileUtils
;
33 import com
.owncloud
.android
.utils
.Log_OC
;
36 * Access to remote operation to get the share files/folders
37 * Save the data in Database
42 public class GetSharedFilesOperation
extends RemoteOperation
{
44 private static final String TAG
= GetSharedFilesOperation
.class.getSimpleName();
46 private String mUrlServer
;
47 protected FileDataStorageManager mStorageManager
;
50 public GetSharedFilesOperation(String urlServer
, FileDataStorageManager storageManager
) {
51 mUrlServer
= urlServer
;
52 mStorageManager
= storageManager
;
56 protected RemoteOperationResult
run(WebdavClient client
) {
57 GetRemoteSharedFilesOperation operation
= new GetRemoteSharedFilesOperation(mUrlServer
);
58 RemoteOperationResult result
= operation
.execute(client
);
60 if (result
.isSuccess()) {
62 // Update DB with the response
63 ArrayList
<ShareRemoteFile
> shareRemoteFiles
= operation
.getSharedFiles();
64 Log_OC
.d(TAG
, "Share list size = " + shareRemoteFiles
.size());
65 for (ShareRemoteFile remoteFile
: shareRemoteFiles
) {
66 OCShare shareFile
= new OCShare(remoteFile
);
67 saveShareFileInDB(shareFile
);
74 private void saveShareFileInDB(OCShare shareFile
) {
76 mStorageManager
.saveShareFile(shareFile
);
79 String path
= shareFile
.getPath();
80 if (shareFile
.isDirectory()) {
81 path
= path
+ FileUtils
.PATH_SEPARATOR
;
84 // Update OCFile with data from share: ShareByLink ¿and publicLink?
85 OCFile file
= mStorageManager
.getFileByPath(path
);
87 if (shareFile
.getShareType().equals(ShareType
.PUBLIC_LINK
)) {
88 file
.setShareByLink(true
);
89 mStorageManager
.saveFile(file
);