1 /* ownCloud Android client application
2 * Copyright (C) 2012 ownCloud Inc.
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.
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.
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/>.
18 package com
.owncloud
.android
.operations
;
20 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
21 import com
.owncloud
.android
.datamodel
.OCFile
;
22 import com
.owncloud
.android
.lib
.network
.OwnCloudClient
;
23 import com
.owncloud
.android
.lib
.operations
.remote
.CreateRemoteFolderOperation
;
24 import com
.owncloud
.android
.lib
.operations
.common
.OnRemoteOperationListener
;
25 import com
.owncloud
.android
.lib
.operations
.common
.RemoteOperation
;
26 import com
.owncloud
.android
.lib
.operations
.common
.RemoteOperationResult
;
27 import com
.owncloud
.android
.utils
.FileStorageUtils
;
28 import com
.owncloud
.android
.utils
.Log_OC
;
32 * Access to remote operation performing the creation of a new folder in the ownCloud server.
33 * Save the new folder in Database
35 * @author David A. Velasco
38 public class CreateFolderOperation
extends RemoteOperation
implements OnRemoteOperationListener
{
40 private static final String TAG
= CreateFolderOperation
.class.getSimpleName();
42 protected String mRemotePath
;
43 protected boolean mCreateFullPath
;
44 protected FileDataStorageManager mStorageManager
;
49 * @param createFullPath 'True' means that all the ancestor folders should be created if don't exist yet.
50 * @param storageManager Reference to the local database corresponding to the account where the file is contained.
52 public CreateFolderOperation(String remotePath
, boolean createFullPath
, FileDataStorageManager storageManager
) {
53 mRemotePath
= remotePath
;
54 mCreateFullPath
= createFullPath
;
55 mStorageManager
= storageManager
;
61 protected RemoteOperationResult
run(OwnCloudClient client
) {
62 CreateRemoteFolderOperation operation
= new CreateRemoteFolderOperation(mRemotePath
, mCreateFullPath
);
63 RemoteOperationResult result
= operation
.execute(client
);
65 if (result
.isSuccess()) {
68 Log_OC
.e(TAG
, mRemotePath
+ "hasn't been created");
75 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
76 if (operation
instanceof CreateRemoteFolderOperation
) {
77 onCreateRemoteFolderOperationFinish((CreateRemoteFolderOperation
)operation
, result
);
82 private void onCreateRemoteFolderOperationFinish(CreateRemoteFolderOperation operation
, RemoteOperationResult result
) {
83 if (result
.isSuccess()) {
86 Log_OC
.e(TAG
, mRemotePath
+ "hasn't been created");
92 * Save new directory in local database
94 public void saveFolderInDB() {
95 OCFile newDir
= new OCFile(mRemotePath
);
96 newDir
.setMimetype("DIR");
97 long parentId
= mStorageManager
.getFileByPath(FileStorageUtils
.getParentPath(mRemotePath
)).getFileId();
98 newDir
.setParentId(parentId
);
99 newDir
.setModificationTimestamp(System
.currentTimeMillis());
100 mStorageManager
.saveFile(newDir
);
102 Log_OC
.d(TAG
, "Create directory " + mRemotePath
+ " in Database");