Merge branch 'share_link_show_shared_files' into share_link__new_share
[pub/Android/ownCloud.git] / src / com / owncloud / android / operations / CreateShareOperation.java
1 /* ownCloud Android client application
2 * Copyright (C) 2014 ownCloud Inc.
3 *
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.
7 *
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.
12 *
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/>.
15 *
16 */
17
18 package com.owncloud.android.operations;
19
20 /**
21 * Creates a new share from a given file
22 *
23 * @author masensio
24 *
25 */
26
27 import com.owncloud.android.datamodel.FileDataStorageManager;
28 import com.owncloud.android.lib.network.OwnCloudClient;
29 import com.owncloud.android.lib.operations.common.RemoteOperation;
30 import com.owncloud.android.lib.operations.common.RemoteOperationResult;
31 import com.owncloud.android.lib.operations.common.ShareType;
32 import com.owncloud.android.lib.operations.remote.CreateShareRemoteOperation;
33
34 public class CreateShareOperation extends RemoteOperation {
35
36 private static final String TAG = CreateShareOperation.class.getSimpleName();
37
38 protected FileDataStorageManager mStorageManager;
39
40 private String mPath;
41 private ShareType mShareType;
42 private String mShareWith;
43 private boolean mPublicUpload;
44 private String mPassword;
45 private int mPermissions;
46
47 /**
48 * Constructor
49 * @param path Full path of the file/folder being shared. Mandatory argument
50 * @param shareType \910\92 = user, \911\92 = group, \913\92 = Public link. Mandatory argument
51 * @param shareWith User/group ID with who the file should be shared. This is mandatory for shareType of 0 or 1
52 * @param publicUpload If \91false\92 (default) public cannot upload to a public shared folder.
53 * If \91true\92 public can upload to a shared folder. Only available for public link shares
54 * @param password Password to protect a public link share. Only available for public link shares
55 * @param permissions 1 - Read only \96 Default for \93public\94 shares
56 * 2 - Update
57 * 4 - Create
58 * 8 - Delete
59 * 16- Re-share
60 * 31- All above \96 Default for \93private\94 shares
61 * For user or group shares.
62 * To obtain combinations, add the desired values together.
63 * For instance, for \93Re-Share\94, \93delete\94, \93read\94, \93update\94, add 16+8+2+1 = 27.
64 */
65 public CreateShareOperation(String path, ShareType shareType, String shareWith, boolean publicUpload,
66 String password, int permissions) {
67
68 mPath = path;
69 mShareType = shareType;
70 mShareWith = shareWith;
71 mPublicUpload = publicUpload;
72 mPassword = password;
73 mPermissions = permissions;
74 }
75
76 @Override
77 protected RemoteOperationResult run(OwnCloudClient client) {
78 CreateShareRemoteOperation operation = new CreateShareRemoteOperation(mPath, mShareType, mShareWith, mPublicUpload, mPassword, mPermissions);
79 RemoteOperationResult result = operation.execute(client);
80
81 if (result.isSuccess()) {
82 // TODO
83 // Update DB with the response
84
85 }
86
87 return result;
88 }
89
90 }