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
.RemoteOperationResult
;
26 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
.ResultCode
;
27 import com
.owncloud
.android
.lib
.resources
.files
.MoveRemoteFileOperation
;
28 import com
.owncloud
.android
.operations
.common
.SyncOperation
;
30 import android
.accounts
.Account
;
34 * Operation mmoving an {@link OCFile} to a different folder.
36 public class MoveFileOperation
extends SyncOperation
{
38 //private static final String TAG = MoveFileOperation.class.getSimpleName();
40 private String mSrcPath
;
41 private String mTargetParentPath
;
50 * @param path Remote path of the {@link OCFile} to move.
51 * @param newParentPath Path to the folder where the file will be moved into.
52 * @param account OwnCloud account containing both the file and the target folder
54 public MoveFileOperation(String srcPath
, String targetParentPath
, Account account
) {
56 mTargetParentPath
= targetParentPath
;
57 if (!mTargetParentPath
.endsWith(OCFile
.PATH_SEPARATOR
)) {
58 mTargetParentPath
+= OCFile
.PATH_SEPARATOR
;
65 * Performs the operation.
67 * @param client Client object to communicate with the remote ownCloud server.
70 protected RemoteOperationResult
run(OwnCloudClient client
) {
71 RemoteOperationResult result
= null
;
73 /// 1. check move validity
74 if (mTargetParentPath
.startsWith(mSrcPath
)) {
75 return new RemoteOperationResult(ResultCode
.INVALID_MOVE_INTO_DESCENDANT
);
77 mFile
= getStorageManager().getFileByPath(mSrcPath
);
79 return new RemoteOperationResult(ResultCode
.FILE_NOT_FOUND
);
83 String targetPath
= mTargetParentPath
+ mFile
.getFileName();
84 if (mFile
.isFolder()) {
85 targetPath
+= OCFile
.PATH_SEPARATOR
;
87 MoveRemoteFileOperation operation
= new MoveRemoteFileOperation(
92 result
= operation
.execute(client
);
95 if (result
.isSuccess()) {
96 getStorageManager().moveLocalFile(mFile
, targetPath
, mTargetParentPath
);
98 // TODO handle ResultCode.PARTIAL_MOVE_DONE in client Activity, for the moment