Fix, creation of subdirectories
authormasensio <masensio@solidgear.es>
Thu, 14 Nov 2013 16:18:33 +0000 (17:18 +0100)
committermasensio <masensio@solidgear.es>
Thu, 14 Nov 2013 16:18:33 +0000 (17:18 +0100)
oc_framework-test-project/oc_framework-test-test/src/com/owncloud/android/oc_framework_test_project/test/CreateFolderTest.java
oc_framework-test-project/src/com/owncloud/android/oc_framework_test_project/TestActivity.java
oc_framework/src/com/owncloud/android/oc_framework/operations/remote/CreateRemoteFolderOperation.java
src/com/owncloud/android/files/services/FileUploader.java
src/com/owncloud/android/operations/CreateFolderOperation.java
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

index 667f7eb..5f84747 100644 (file)
@@ -38,53 +38,72 @@ public class CreateFolderTest extends ActivityInstrumentationTestCase2<TestActiv
         */
        public void testCreateFolder() {
 
         */
        public void testCreateFolder() {
 
+               String folderName = "testCreateFolder" + mCurrentDate;
                String remotePath = "/testCreateFolder" + mCurrentDate;
                boolean createFullPath = true;
                
                String remotePath = "/testCreateFolder" + mCurrentDate;
                boolean createFullPath = true;
                
-               RemoteOperationResult result =  mActivity.createFolder(remotePath, createFullPath);
+               RemoteOperationResult result =  mActivity.createFolder(folderName, remotePath, createFullPath);
+               assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT);
+               
+               // Create Subfolder
+               folderName = "testCreateFolder" + mCurrentDate;
+               remotePath = "/testCreateFolder" + mCurrentDate + "/" + "testCreateFolder" + mCurrentDate;
+               createFullPath = true;
+               
+               result =  mActivity.createFolder(folderName, remotePath, createFullPath);
                assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT);
        }
        
                assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT);
        }
        
+       
        /**
         * Test to Create Folder with special characters
         */
        public void testCreateFolderSpecialCharacters() {               
                boolean createFullPath = true;
                
        /**
         * Test to Create Folder with special characters
         */
        public void testCreateFolderSpecialCharacters() {               
                boolean createFullPath = true;
                
+               String folderName = "testSpecialCharacters_//" + mCurrentDate;
                String remotePath = "/testSpecialCharacters_//" + mCurrentDate;
                String remotePath = "/testSpecialCharacters_//" + mCurrentDate;
-               RemoteOperationResult result =  mActivity.createFolder(remotePath, createFullPath);
+               RemoteOperationResult result =  mActivity.createFolder(folderName, remotePath, createFullPath);
                assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
                
                assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
                
+               folderName = "testSpecialCharacters_\\" + mCurrentDate;
                remotePath = "/testSpecialCharacters_\\" + mCurrentDate;                
                remotePath = "/testSpecialCharacters_\\" + mCurrentDate;                
-               result =  mActivity.createFolder(remotePath, createFullPath);
+               result =  mActivity.createFolder(folderName, remotePath, createFullPath);
                assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
                
                assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
                
+               folderName = "testSpecialCharacters_<" + mCurrentDate;
                remotePath = "/testSpecialCharacters_<" + mCurrentDate;         
                remotePath = "/testSpecialCharacters_<" + mCurrentDate;         
-               result =  mActivity.createFolder(remotePath, createFullPath);
+               result =  mActivity.createFolder(folderName, remotePath, createFullPath);
                assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
                
                assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
                
+               folderName = "testSpecialCharacters_>" + mCurrentDate;
                remotePath = "/testSpecialCharacters_>" + mCurrentDate;         
                remotePath = "/testSpecialCharacters_>" + mCurrentDate;         
-               result =  mActivity.createFolder(remotePath, createFullPath);
+               result =  mActivity.createFolder(folderName, remotePath, createFullPath);
                assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
                
                assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
                
+               folderName = "testSpecialCharacters_:" + mCurrentDate;
                remotePath = "/testSpecialCharacters_:" + mCurrentDate;         
                remotePath = "/testSpecialCharacters_:" + mCurrentDate;         
-               result =  mActivity.createFolder(remotePath, createFullPath);
+               result =  mActivity.createFolder(folderName, remotePath, createFullPath);
                assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
                
                assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
                
+               folderName = "testSpecialCharacters_\"" + mCurrentDate;
                remotePath = "/testSpecialCharacters_\"" + mCurrentDate;                
                remotePath = "/testSpecialCharacters_\"" + mCurrentDate;                
-               result =  mActivity.createFolder(remotePath, createFullPath);
+               result =  mActivity.createFolder(folderName, remotePath, createFullPath);
                assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
                
                assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
                
+               folderName = "testSpecialCharacters_|" + mCurrentDate;
                remotePath = "/testSpecialCharacters_|" + mCurrentDate;         
                remotePath = "/testSpecialCharacters_|" + mCurrentDate;         
-               result =  mActivity.createFolder(remotePath, createFullPath);
+               result =  mActivity.createFolder(folderName, remotePath, createFullPath);
                assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
                
                assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
                
+               folderName = "testSpecialCharacters_?" + mCurrentDate;
                remotePath = "/testSpecialCharacters_?" + mCurrentDate;         
                remotePath = "/testSpecialCharacters_?" + mCurrentDate;         
-               result =  mActivity.createFolder(remotePath, createFullPath);
+               result =  mActivity.createFolder(folderName, remotePath, createFullPath);
                assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
                
                assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
                
+               folderName = "testSpecialCharacters_*" + mCurrentDate;
                remotePath = "/testSpecialCharacters_*" + mCurrentDate;         
                remotePath = "/testSpecialCharacters_*" + mCurrentDate;         
-               result =  mActivity.createFolder(remotePath, createFullPath);
+               result =  mActivity.createFolder(folderName, remotePath, createFullPath);
                assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
        }
 
                assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
        }
 
index 78efe3e..ec3f5d5 100644 (file)
@@ -88,13 +88,14 @@ public class TestActivity extends Activity {
 
        /**
         * Access to the library method to Create a Folder
 
        /**
         * Access to the library method to Create a Folder
+        * @param folderName
         * @param remotePath
         * @param createFullPath
         * @return
         */
         * @param remotePath
         * @param createFullPath
         * @return
         */
-       public RemoteOperationResult createFolder(String remotePath, boolean createFullPath) {
+       public RemoteOperationResult createFolder(String folderName, String remotePath, boolean createFullPath) {
                
                
-               CreateRemoteFolderOperation createOperation = new CreateRemoteFolderOperation(remotePath, createFullPath);
+               CreateRemoteFolderOperation createOperation = new CreateRemoteFolderOperation(folderName, remotePath, createFullPath);
                RemoteOperationResult result =  createOperation.execute(mClient);
                
                return result;
                RemoteOperationResult result =  createOperation.execute(mClient);
                
                return result;
index a326ed1..f25c22e 100644 (file)
@@ -29,17 +29,19 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
     private static final int CONNECTION_TIMEOUT = 5000;
     
 
     private static final int CONNECTION_TIMEOUT = 5000;
     
 
-    
+    protected String mFolderName;
     protected String mRemotePath;
     protected boolean mCreateFullPath;
     
     /**
      * Constructor
      * 
     protected String mRemotePath;
     protected boolean mCreateFullPath;
     
     /**
      * Constructor
      * 
+     * @param folderName                       Name of new directory
      * @param remotePath            Full path to the new directory to create in the remote server.
      * @param createFullPath        'True' means that all the ancestor folders should be created if don't exist yet.
      */
      * @param remotePath            Full path to the new directory to create in the remote server.
      * @param createFullPath        'True' means that all the ancestor folders should be created if don't exist yet.
      */
-    public CreateRemoteFolderOperation(String remotePath, boolean createFullPath) {
+    public CreateRemoteFolderOperation(String folderName, String remotePath, boolean createFullPath) {
+       mFolderName = folderName;
         mRemotePath = remotePath;
         mCreateFullPath = createFullPath;
     }
         mRemotePath = remotePath;
         mCreateFullPath = createFullPath;
     }
@@ -54,7 +56,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
         RemoteOperationResult result = null;
         MkColMethod mkcol = null;
         
         RemoteOperationResult result = null;
         MkColMethod mkcol = null;
         
-        boolean noInvalidChars = FileUtils.validateName(mRemotePath);
+        boolean noInvalidChars = FileUtils.validateName(mFolderName);
         if (noInvalidChars) {
                try {
                        mkcol = new MkColMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath));
         if (noInvalidChars) {
                try {
                        mkcol = new MkColMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath));
@@ -85,7 +87,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
 
     
     private RemoteOperationResult createParentFolder(String parentPath, WebdavClient client) {
 
     
     private RemoteOperationResult createParentFolder(String parentPath, WebdavClient client) {
-        RemoteOperation operation = new CreateRemoteFolderOperation(  parentPath,
+        RemoteOperation operation = new CreateRemoteFolderOperation("", parentPath,
                                                                 mCreateFullPath);
         return operation.execute(client);
     }
                                                                 mCreateFullPath);
         return operation.execute(client);
     }
index 74b5556..6e80fd5 100644 (file)
@@ -564,9 +564,10 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
         RemoteOperation operation = new ExistenceCheckOperation(pathToGrant, this, false);
         RemoteOperationResult result = operation.execute(mUploadClient);
         if (!result.isSuccess() && result.getCode() == ResultCode.FILE_NOT_FOUND && mCurrentUpload.isRemoteFolderToBeCreated()) {
         RemoteOperation operation = new ExistenceCheckOperation(pathToGrant, this, false);
         RemoteOperationResult result = operation.execute(mUploadClient);
         if (!result.isSuccess() && result.getCode() == ResultCode.FILE_NOT_FOUND && mCurrentUpload.isRemoteFolderToBeCreated()) {
-            operation = new CreateFolderOperation(  pathToGrant,
-                                                    true,
-                                                    mStorageManager    );
+            operation = new CreateFolderOperation(  mCurrentUpload.getFileName(),
+                    pathToGrant,
+                    true,
+                    mStorageManager    );
             result = operation.execute(mUploadClient);
         }
         if (result.isSuccess()) {
             result = operation.execute(mUploadClient);
         }
         if (result.isSuccess()) {
index f5e190d..5784333 100644 (file)
@@ -39,6 +39,7 @@ public class CreateFolderOperation extends RemoteOperation implements OnRemoteOp
     
     private static final String TAG = CreateFolderOperation.class.getSimpleName();
     
     
     private static final String TAG = CreateFolderOperation.class.getSimpleName();
     
+    protected String mFolderName;
     protected String mRemotePath;
     protected boolean mCreateFullPath;
     protected FileDataStorageManager mStorageManager;
     protected String mRemotePath;
     protected boolean mCreateFullPath;
     protected FileDataStorageManager mStorageManager;
@@ -50,7 +51,8 @@ public class CreateFolderOperation extends RemoteOperation implements OnRemoteOp
      * @param createFullPath        'True' means that all the ancestor folders should be created if don't exist yet.
      * @param storageManager        Reference to the local database corresponding to the account where the file is contained. 
      */
      * @param createFullPath        'True' means that all the ancestor folders should be created if don't exist yet.
      * @param storageManager        Reference to the local database corresponding to the account where the file is contained. 
      */
-    public CreateFolderOperation(String remotePath, boolean createFullPath, FileDataStorageManager storageManager) {
+    public CreateFolderOperation(String folderName, String remotePath, boolean createFullPath, FileDataStorageManager storageManager) {
+        mFolderName = folderName;
         mRemotePath = remotePath;
         mCreateFullPath = createFullPath;
         mStorageManager = storageManager;
         mRemotePath = remotePath;
         mCreateFullPath = createFullPath;
         mStorageManager = storageManager;
@@ -60,7 +62,7 @@ public class CreateFolderOperation extends RemoteOperation implements OnRemoteOp
 
     @Override
     protected RemoteOperationResult run(WebdavClient client) {
 
     @Override
     protected RemoteOperationResult run(WebdavClient client) {
-        CreateRemoteFolderOperation operation = new CreateRemoteFolderOperation(mRemotePath, mCreateFullPath);
+        CreateRemoteFolderOperation operation = new CreateRemoteFolderOperation(mFolderName, mRemotePath, mCreateFullPath);
         RemoteOperationResult result =  operation.execute(client);
         
         if (result.isSuccess()) {
         RemoteOperationResult result =  operation.execute(client);
         
         if (result.isSuccess()) {
index 37455d2..199f8c2 100644 (file)
@@ -1439,7 +1439,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
 
                 // Create directory
                 path += newDirectoryName + OCFile.PATH_SEPARATOR;
 
                 // Create directory
                 path += newDirectoryName + OCFile.PATH_SEPARATOR;
-                RemoteOperation operation = new CreateFolderOperation(path, false, mStorageManager);
+                RemoteOperation operation = new CreateFolderOperation(newDirectoryName, path, false, mStorageManager);
                 operation.execute(  getAccount(), 
                         FileDisplayActivity.this, 
                         FileDisplayActivity.this, 
                 operation.execute(  getAccount(), 
                         FileDisplayActivity.this, 
                         FileDisplayActivity.this,