2 * ownCloud Android client application
5 * @author David A. Velasco
6 * Copyright (C) 2015 ownCloud Inc.
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 package com
.owncloud
.android
.operations
;
25 * Creates a new private share for a given file
29 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
30 import com
.owncloud
.android
.datamodel
.OCFile
;
31 import com
.owncloud
.android
.lib
.common
.OwnCloudClient
;
32 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
33 import com
.owncloud
.android
.lib
.resources
.files
.FileUtils
;
34 import com
.owncloud
.android
.lib
.resources
.shares
.CreateRemoteShareOperation
;
35 import com
.owncloud
.android
.lib
.resources
.shares
.OCShare
;
36 import com
.owncloud
.android
.lib
.resources
.shares
.ShareType
;
37 import com
.owncloud
.android
.operations
.common
.SyncOperation
;
39 public class CreateShareWithShareeOperation
extends SyncOperation
{
41 private static final int READ_ONLY
= 1;
43 protected FileDataStorageManager mStorageManager
;
46 private String mShareeName
;
47 private ShareType mShareType
;
52 * @param path Full path of the file/folder being shared.
53 * @param shareeName User or group name of the target sharee.
54 * @param shareType Type of share determines type of sharee; {@link ShareType#USER} and {@link ShareType#GROUP}
55 * are the only valid values for the moment.
57 public CreateShareWithShareeOperation(String path
, String shareeName
, ShareType shareType
) {
58 if (!ShareType
.USER
.equals(shareType
) && !ShareType
.GROUP
.equals(shareType
)) {
59 throw new IllegalArgumentException("Illegal share type " + shareType
);
62 mShareeName
= shareeName
;
63 mShareType
= shareType
;
67 protected RemoteOperationResult
run(OwnCloudClient client
) {
68 // Check if the share link already exists
71 RemoteOperation operation = new GetRemoteSharesForFileOperation(mPath, false, false);
72 RemoteOperationResult result = operation.execute(client);
73 if (!result.isSuccess() || result.getData().size() <= 0) {
76 CreateRemoteShareOperation operation
= new CreateRemoteShareOperation(
84 operation
.setGetShareDetails(true
);
85 RemoteOperationResult result
= operation
.execute(client
);
88 if (result
.isSuccess()) {
89 if (result
.getData().size() > 0) {
90 OCShare share
= (OCShare
) result
.getData().get(0);
98 public String
getPath() {
102 private void updateData(OCShare share
) {
103 // Update DB with the response
104 share
.setPath(mPath
);
105 share
.setIsFolder(mPath
.endsWith(FileUtils
.PATH_SEPARATOR
));
106 share
.setPermissions(READ_ONLY
);
108 getStorageManager().saveShare(share
);
110 // Update OCFile with data from share: ShareByLink and publicLink
111 OCFile file
= getStorageManager().getFileByPath(mPath
);
113 file
.setShareWithSharee(true
); // TODO - this should be done by the FileContentProvider, as part of getStorageManager().saveShare(share)
114 getStorageManager().saveFile(file
);