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
;
34 import java
.util
.Calendar
;
38 * Updates an existing public share for a given file
41 public class UpdateShareViaLinkOperation
extends SyncOperation
{
44 private String mPassword
;
45 private Calendar mExpirationDate
;
50 * @param path Full path of the file/folder being shared. Mandatory argument
52 public UpdateShareViaLinkOperation(String path
) {
56 mExpirationDate
= null
;
61 * Set password to update in public link.
63 * @param password Password to set to the public link.
64 * Empty string clears the current password.
65 * Null results in no update applied to the password.
67 public void setPassword(String password
) {
73 * Set expiration date to update in Share resource.
75 * @param expirationDate Expiration date to set to the public link.
76 * Start-of-epoch clears the current expiration date.
77 * Null results in no update applied to the expiration date.
79 public void setExpirationDate(Calendar expirationDate
) {
80 mExpirationDate
= expirationDate
;
85 protected RemoteOperationResult
run(OwnCloudClient client
) {
87 OCShare publicShare
= getStorageManager().getFirstShareByPathAndType(
89 ShareType
.PUBLIC_LINK
,
93 if (publicShare
== null
) {
94 // TODO try to get remote?
98 // Update remote share with password
99 UpdateRemoteShareOperation udpateOp
= new UpdateRemoteShareOperation(
100 publicShare
.getRemoteId()
102 udpateOp
.setPassword(mPassword
);
103 udpateOp
.setExpirationDate(mExpirationDate
);
104 RemoteOperationResult result
= udpateOp
.execute(client
);
107 if (!result.isSuccess() || result.getData().size() <= 0) {
108 operation = new CreateRemoteShareOperation(
110 ShareType.PUBLIC_LINK,
114 OCShare.DEFAULT_PERMISSION
116 result = operation.execute(client);
120 if (result
.isSuccess()) {
121 // Retrieve updated share / save directly with password? -> no; the password is not be saved
122 RemoteOperation getShareOp
= new GetRemoteShareOperation(publicShare
.getRemoteId());
123 result
= getShareOp
.execute(client
);
124 if (result
.isSuccess()) {
125 OCShare share
= (OCShare
) result
.getData().get(0);
133 public String
getPath() {
137 public String
getPassword() {
141 private void updateData(OCShare share
) {
142 // Update DB with the response
143 share
.setPath(mPath
);
144 if (mPath
.endsWith(FileUtils
.PATH_SEPARATOR
)) {
145 share
.setIsFolder(true
);
147 share
.setIsFolder(false
);
150 getStorageManager().saveShare(share
); // TODO info about having a password? ask to Gonzalo
152 // Update OCFile with data from share: ShareByLink and publicLink
153 // TODO check & remove if not needed
154 OCFile file
= getStorageManager().getFileByPath(mPath
);
156 file
.setPublicLink(share
.getShareLink());
157 file
.setShareViaLink(true
);
158 getStorageManager().saveFile(file
);