import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.OwnCloudClient;
-import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.files.FileUtils;
import com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation;
public class CreateShareWithShareeOperation extends SyncOperation {
- private static final int READ_ONLY = 1;
-
protected FileDataStorageManager mStorageManager;
private String mPath;
- private String mTargetName;
- private boolean mWithGroup;
+ private String mShareeName;
+ private ShareType mShareType;
/**
- * Constructor
- * @param path Full path of the file/folder being shared. Mandatory argument
+ * Constructor.
+ *
+ * @param path Full path of the file/folder being shared.
+ * @param shareeName User or group name of the target sharee.
+ * @param shareType Type of share determines type of sharee; {@link ShareType#USER} and {@link ShareType#GROUP}
+ * are the only valid values for the moment.
*/
- public CreateShareWithShareeOperation(
- String path,
- String targetName,
- boolean withGroup
- ) {
-
+ public CreateShareWithShareeOperation(String path, String shareeName, ShareType shareType) {
+ if (!ShareType.USER.equals(shareType) && !ShareType.GROUP.equals(shareType)) {
+ throw new IllegalArgumentException("Illegal share type " + shareType);
+ }
mPath = path;
- mTargetName = targetName;
- mWithGroup = withGroup;
+ mShareeName = shareeName;
+ mShareType = shareType;
}
@Override
if (!result.isSuccess() || result.getData().size() <= 0) {
*/
- RemoteOperation operation = new CreateRemoteShareOperation(
+ CreateRemoteShareOperation operation = new CreateRemoteShareOperation(
mPath,
- (mWithGroup ? ShareType.GROUP : ShareType.USER),
- mTargetName,
+ mShareType,
+ mShareeName,
false,
"",
- READ_ONLY
+ OCShare.DEFAULT_PERMISSION
);
+ operation.setGetShareDetails(true);
RemoteOperationResult result = operation.execute(client);
private void updateData(OCShare share) {
// Update DB with the response
share.setPath(mPath);
- if (mPath.endsWith(FileUtils.PATH_SEPARATOR)) {
- share.setIsFolder(true);
- } else {
- share.setIsFolder(false);
- }
- share.setPermissions(READ_ONLY);
-
+ share.setIsFolder(mPath.endsWith(FileUtils.PATH_SEPARATOR));
+
getStorageManager().saveShare(share);
// Update OCFile with data from share: ShareByLink and publicLink