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
.network
.OwnCloudClient
;
24 import com
.owncloud
.android
.lib
.operations
.common
.OCShare
;
25 import com
.owncloud
.android
.lib
.operations
.common
.RemoteOperationResult
;
26 import com
.owncloud
.android
.lib
.operations
.common
.ShareType
;
27 import com
.owncloud
.android
.lib
.operations
.common
.RemoteOperationResult
.ResultCode
;
28 import com
.owncloud
.android
.lib
.operations
.remote
.ExistenceCheckRemoteOperation
;
29 import com
.owncloud
.android
.lib
.operations
.remote
.RemoveRemoteShareOperation
;
30 import com
.owncloud
.android
.operations
.common
.SyncOperation
;
31 import com
.owncloud
.android
.utils
.Log_OC
;
35 * Save the data in Database
39 public class UnshareLinkOperation
extends SyncOperation
{
41 private static final String TAG
= UnshareLinkOperation
.class.getSimpleName();
43 private String mRemotePath
;
44 private Context mContext
;
47 public UnshareLinkOperation(String remotePath
, Context context
) {
48 mRemotePath
= remotePath
;
53 protected RemoteOperationResult
run(OwnCloudClient client
) {
54 RemoteOperationResult result
= null
;
56 // Get Share for a file
57 OCShare share
= getStorageManager().getFirstShareByPathAndType(mRemotePath
, ShareType
.PUBLIC_LINK
);
60 RemoveRemoteShareOperation operation
= new RemoveRemoteShareOperation((int) share
.getIdRemoteShared());
61 result
= operation
.execute(client
);
63 if (result
.isSuccess() || result
.getCode() == ResultCode
.SHARE_NOT_FOUND
) {
64 Log_OC
.d(TAG
, "Share id = " + share
.getIdRemoteShared() + " deleted");
66 OCFile file
= getStorageManager().getFileByPath(mRemotePath
);
67 file
.setShareByLink(false
);
68 file
.setPublicLink("");
69 getStorageManager().saveFile(file
);
70 getStorageManager().removeShare(share
);
72 if (result
.getCode() == ResultCode
.SHARE_NOT_FOUND
) {
73 if (existsFile(client
, file
.getRemotePath())) {
74 result
= new RemoteOperationResult(ResultCode
.OK
);
76 getStorageManager().removeFile(file
, true
, true
);
82 result
= new RemoteOperationResult(ResultCode
.SHARE_NOT_FOUND
);
88 private boolean existsFile(OwnCloudClient client
, String remotePath
){
89 ExistenceCheckRemoteOperation existsOperation
= new ExistenceCheckRemoteOperation(remotePath
, mContext
, false
);
90 RemoteOperationResult result
= existsOperation
.execute(client
);
91 return result
.isSuccess();