1 /* ownCloud Android client application
2 * Copyright (C) 2014 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 android
.content
.Context
;
22 import com
.owncloud
.android
.datamodel
.OCFile
;
23 import com
.owncloud
.android
.lib
.common
.OwnCloudClient
;
24 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
25 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
.ResultCode
;
26 import com
.owncloud
.android
.lib
.resources
.files
.ExistenceCheckRemoteOperation
;
27 import com
.owncloud
.android
.lib
.resources
.shares
.OCShare
;
28 import com
.owncloud
.android
.lib
.resources
.shares
.RemoveRemoteShareOperation
;
29 import com
.owncloud
.android
.operations
.common
.SyncOperation
;
30 import com
.owncloud
.android
.utils
.Log_OC
;
34 * Save the data in Database
38 public class UnshareLinkOperation
extends SyncOperation
{
40 private static final String TAG
= UnshareLinkOperation
.class.getSimpleName();
42 private String mRemotePath
;
43 private Context mContext
;
46 public UnshareLinkOperation(String remotePath
, Context context
) {
47 mRemotePath
= remotePath
;
52 protected RemoteOperationResult
run(OwnCloudClient client
) {
53 RemoteOperationResult result
= null
;
55 // Get Share for a file
56 OCShare share
= getStorageManager().getShareByPath(mRemotePath
);
59 RemoveRemoteShareOperation operation
= new RemoveRemoteShareOperation((int) share
.getIdRemoteShared());
60 result
= operation
.execute(client
);
62 if (result
.isSuccess() || result
.getCode() == ResultCode
.SHARE_NOT_FOUND
) {
63 Log_OC
.d(TAG
, "Share id = " + share
.getIdRemoteShared() + " deleted");
65 OCFile file
= getStorageManager().getFileByPath(mRemotePath
);
66 file
.setShareByLink(false
);
67 file
.setPublicLink("");
68 getStorageManager().saveFile(file
);
69 getStorageManager().removeShare(share
);
71 if (result
.getCode() == ResultCode
.SHARE_NOT_FOUND
) {
72 if (existsFile(client
, file
.getRemotePath())) {
73 result
= new RemoteOperationResult(ResultCode
.OK
);
75 getStorageManager().removeFile(file
, true
, true
);
81 result
= new RemoteOperationResult(ResultCode
.SHARE_NOT_FOUND
);
87 private boolean existsFile(OwnCloudClient client
, String remotePath
){
88 ExistenceCheckRemoteOperation existsOperation
= new ExistenceCheckRemoteOperation(remotePath
, mContext
, false
);
89 RemoteOperationResult result
= existsOperation
.execute(client
);
90 return result
.isSuccess();