2 * ownCloud Android client application
4 * @author David A. Velasco
5 * Copyright (C) 2015 ownCloud Inc.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2,
9 * as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 package com
.owncloud
.android
.operations
;
23 import com
.owncloud
.android
.datamodel
.OCFile
;
24 import com
.owncloud
.android
.lib
.common
.OwnCloudClient
;
25 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperation
;
26 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
27 import com
.owncloud
.android
.lib
.resources
.files
.FileUtils
;
28 import com
.owncloud
.android
.lib
.resources
.shares
.GetRemoteShareOperation
;
29 import com
.owncloud
.android
.lib
.resources
.shares
.OCShare
;
30 import com
.owncloud
.android
.lib
.resources
.shares
.ShareType
;
31 import com
.owncloud
.android
.lib
.resources
.shares
.UpdateRemoteShareOperation
;
32 import com
.owncloud
.android
.operations
.common
.SyncOperation
;
36 * Updates an existing public share for a given file
39 public class UpdateShareViaLinkOperation
extends SyncOperation
{
42 private String mPassword
;
46 * @param path Full path of the file/folder being shared. Mandatory argument
47 * @param password Password to protect a public link share.
49 public UpdateShareViaLinkOperation(
59 protected RemoteOperationResult
run(OwnCloudClient client
) {
61 OCShare publicShare
= getStorageManager().getFirstShareByPathAndType(
63 ShareType
.PUBLIC_LINK
,
67 if (publicShare
== null
) {
68 // TODO try to get remote?
72 // Update remote share with password
73 RemoteOperation operation
= new UpdateRemoteShareOperation(
74 publicShare
.getRemoteId()
76 ((UpdateRemoteShareOperation
)operation
).setPassword(mPassword
);
77 RemoteOperationResult result
= operation
.execute(client
);
80 if (!result.isSuccess() || result.getData().size() <= 0) {
81 operation = new CreateRemoteShareOperation(
83 ShareType.PUBLIC_LINK,
87 OCShare.DEFAULT_PERMISSION
89 result = operation.execute(client);
93 if (result
.isSuccess()) {
94 // Retrieve updated share / save directly with password? -> no; the password is not be saved
95 operation
= new GetRemoteShareOperation(publicShare
.getRemoteId());
96 result
= operation
.execute(client
);
97 if (result
.isSuccess()) {
98 OCShare share
= (OCShare
) result
.getData().get(0);
106 public String
getPath() {
110 public String
getPassword() {
114 private void updateData(OCShare share
) {
115 // Update DB with the response
116 share
.setPath(mPath
);
117 if (mPath
.endsWith(FileUtils
.PATH_SEPARATOR
)) {
118 share
.setIsFolder(true
);
120 share
.setIsFolder(false
);
123 getStorageManager().saveShare(share
); // TODO info about having a password? ask to Gonzalo
125 // Update OCFile with data from share: ShareByLink and publicLink
126 // TODO check & remove if not needed
127 OCFile file
= getStorageManager().getFileByPath(mPath
);
129 file
.setPublicLink(share
.getShareLink());
130 file
.setShareViaLink(true
);
131 getStorageManager().saveFile(file
);