+++ /dev/null
-package com.owncloud.android.oc_framework_test_project.test;
-
-
-import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
-import com.owncloud.android.oc_framework_test_project.TestActivity;
-
-import android.test.ActivityInstrumentationTestCase2;
-
-public class ReadFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
-
-
- /* Folder data to read. This folder must exist on the account */
- private final String mRemoteFolderPath = "/folderToRead";
-
- /* File data to rename. This file must exist on the account */
- private final String mRemoteFilePath = "/fileToRead.txt";
-
- private TestActivity mActivity;
-
- public ReadFileTest() {
- super(TestActivity.class);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- setActivityInitialTouchMode(false);
- mActivity = getActivity();
- }
-
- /**
- * Test Read Folder
- */
- public void testReadFolder() {
-
- RemoteOperationResult result = mActivity.readFile(mRemoteFolderPath);
- assertTrue(result.isSuccess());
- }
-
- /**
- * Test Read File
- */
- public void testReadFile() {
-
- RemoteOperationResult result = mActivity.readFile(mRemoteFilePath);
- assertTrue(result.isSuccess());
- }
-}
--- /dev/null
+package com.owncloud.android.oc_framework_test_project.test;
+
+
+import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
+import com.owncloud.android.oc_framework_test_project.TestActivity;
+
+import android.test.ActivityInstrumentationTestCase2;
+
+/**
+ * Class to test Read Folder Operation
+ * @author masensio
+ *
+ */
+
+public class ReadFolderTest extends ActivityInstrumentationTestCase2<TestActivity> {
+
+
+ /* Folder data to read. This folder must exist on the account */
+ private final String mRemoteFolderPath = "/folderToRead";
+
+
+ private TestActivity mActivity;
+
+ public ReadFolderTest() {
+ super(TestActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ setActivityInitialTouchMode(false);
+ mActivity = getActivity();
+ }
+
+ /**
+ * Test Read Folder
+ */
+ public void testReadFolder() {
+
+ RemoteOperationResult result = mActivity.readFile(mRemoteFolderPath);
+ assertTrue(result.getFile() != null);
+ assertTrue(result.getData().size() > 0);
+ assertTrue(result.getData().size() == 3);
+ assertTrue(result.isSuccess());
+ }
+
+}
import android.test.ActivityInstrumentationTestCase2;
+/**
+ * Class to test Rename File Operation
+ * @author masensio
+ *
+ */
+
public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
/* Folder data to rename. This folder must exist on the account */
import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
import com.owncloud.android.oc_framework.operations.remote.CreateRemoteFolderOperation;
-import com.owncloud.android.oc_framework.operations.remote.ReadRemoteFileOperation;
+import com.owncloud.android.oc_framework.operations.remote.ReadRemoteFolderOperation;
import com.owncloud.android.oc_framework.operations.remote.RemoveRemoteFileOperation;
import com.owncloud.android.oc_framework.operations.remote.RenameRemoteFileOperation;
}
/**
- * Access to the library method to Read a File or Folder (PROPFIND DEPTH 1)
+ * Access to the library method to Read a Folder (PROPFIND DEPTH 1)
* @param remotePath
*
* @return
*/
public RemoteOperationResult readFile(String remotePath) {
- ReadRemoteFileOperation readOperation= new ReadRemoteFileOperation(remotePath);
+ ReadRemoteFolderOperation readOperation= new ReadRemoteFolderOperation(remotePath);
RemoteOperationResult result = readOperation.execute(mClient);
return result;
import com.owncloud.android.oc_framework.utils.FileUtils;
+/**
+ * Contains the data of a Remote File from a WebDavEntry
+ *
+ * @author masensio
+ */
public class RemoteFile implements Parcelable, Serializable{
+++ /dev/null
-package com.owncloud.android.oc_framework.operations.remote;
-
-import java.util.ArrayList;
-
-import org.apache.http.HttpStatus;
-import org.apache.jackrabbit.webdav.DavConstants;
-import org.apache.jackrabbit.webdav.MultiStatus;
-import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
-
-import android.util.Log;
-
-import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
-import com.owncloud.android.oc_framework.network.webdav.WebdavEntry;
-import com.owncloud.android.oc_framework.network.webdav.WebdavUtils;
-import com.owncloud.android.oc_framework.operations.RemoteFile;
-import com.owncloud.android.oc_framework.operations.RemoteOperation;
-import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
-
-/**
- * Remote operation performing the read of remote file or folder in the ownCloud server.
- *
- * @author David A. Velasco
- * @author masensio
- */
-
-public class ReadRemoteFileOperation extends RemoteOperation {
-
- private static final String TAG = ReadRemoteFileOperation.class.getSimpleName();
-
- private String mRemotePath;
- private RemoteFile mFolder;
- private ArrayList<RemoteFile> mFiles;
-
- /**
- * Constructor
- *
- * @param remotePath Remote path of the file.
- */
- public ReadRemoteFileOperation(String remotePath) {
- mRemotePath = remotePath;
- }
-
- /**
- * Performs the read operation.
- *
- * @param client Client object to communicate with the remote ownCloud server.
- */
- @Override
- protected RemoteOperationResult run(WebdavClient client) {
- RemoteOperationResult result = null;
- PropFindMethod query = null;
-
- try {
- // remote request
- query = new PropFindMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath),
- DavConstants.PROPFIND_ALL_PROP,
- DavConstants.DEPTH_1);
- int status = client.executeMethod(query);
-
- // check and process response
- if (isMultiStatus(status)) {
- // get data from remote folder
- MultiStatus dataInServer = query.getResponseBodyAsMultiStatus();
- readData(dataInServer, client);
-
- // Result of the operation
- result = new RemoteOperationResult(true, status, query.getResponseHeaders());
- // Add data to the result
- if (result.isSuccess()) {
- result.setFile(mFolder);
- result.setData(mFiles);
- }
- } else {
- // synchronization failed
- client.exhaustResponse(query.getResponseBodyAsStream());
- result = new RemoteOperationResult(false, status, query.getResponseHeaders());
- }
-
- } catch (Exception e) {
- result = new RemoteOperationResult(e);
-
-
- } finally {
- if (query != null)
- query.releaseConnection(); // let the connection available for other methods
- if (result.isSuccess()) {
- Log.i(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage());
- } else {
- if (result.isException()) {
- Log.e(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage(), result.getException());
- } else {
- Log.e(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage());
- }
- }
-
- }
- return result;
- }
-
- public boolean isMultiStatus(int status) {
- return (status == HttpStatus.SC_MULTI_STATUS);
- }
-
- /**
- * Read the data retrieved from the server about the contents of the target folder
- *
- *
- * @param dataInServer Full response got from the server with the data of the target
- * folder and its direct children.
- * @param client Client instance to the remote server where the data were
- * retrieved.
- * @return
- */
- private void readData(MultiStatus dataInServer, WebdavClient client) {
- // parse data from remote folder
- WebdavEntry we = new WebdavEntry(dataInServer.getResponses()[0], client.getBaseUri().getPath());
- mFolder = fillOCFile(we);
-
- Log.d(TAG, "Remote folder " + mRemotePath + " changed - starting update of local data ");
-
-
- // loop to update every child
- RemoteFile remoteFile = null;
- mFiles = new ArrayList<RemoteFile>();
- for (int i = 1; i < dataInServer.getResponses().length; ++i) {
- /// new OCFile instance with the data from the server
- we = new WebdavEntry(dataInServer.getResponses()[i], client.getBaseUri().getPath());
- remoteFile = fillOCFile(we);
-
- mFiles.add(remoteFile);
- }
-
- }
-
- /**
- * Creates and populates a new {@link RemoteFile} object with the data read from the server.
- *
- * @param we WebDAV entry read from the server for a WebDAV resource (remote file or folder).
- * @return New OCFile instance representing the remote resource described by we.
- */
- private RemoteFile fillOCFile(WebdavEntry we) {
- RemoteFile file = new RemoteFile(we.decodedPath());
- file.setCreationTimestamp(we.createTimestamp());
- file.setLength(we.contentLength());
- file.setMimeType(we.contentType());
- file.setModifiedTimestamp(we.modifiedTimestamp());
- file.setEtag(we.etag());
- return file;
- }
-}
--- /dev/null
+package com.owncloud.android.oc_framework.operations.remote;
+
+import java.util.ArrayList;
+
+import org.apache.http.HttpStatus;
+import org.apache.jackrabbit.webdav.DavConstants;
+import org.apache.jackrabbit.webdav.MultiStatus;
+import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
+
+import android.util.Log;
+
+import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
+import com.owncloud.android.oc_framework.network.webdav.WebdavEntry;
+import com.owncloud.android.oc_framework.network.webdav.WebdavUtils;
+import com.owncloud.android.oc_framework.operations.RemoteFile;
+import com.owncloud.android.oc_framework.operations.RemoteOperation;
+import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
+
+/**
+ * Remote operation performing the read of remote file or folder in the ownCloud server.
+ *
+ * @author David A. Velasco
+ * @author masensio
+ */
+
+public class ReadRemoteFolderOperation extends RemoteOperation {
+
+ private static final String TAG = ReadRemoteFolderOperation.class.getSimpleName();
+
+ private String mRemotePath;
+ private RemoteFile mFolder;
+ private ArrayList<RemoteFile> mFiles;
+
+ /**
+ * Constructor
+ *
+ * @param remotePath Remote path of the file.
+ */
+ public ReadRemoteFolderOperation(String remotePath) {
+ mRemotePath = remotePath;
+ }
+
+ /**
+ * Performs the read operation.
+ *
+ * @param client Client object to communicate with the remote ownCloud server.
+ */
+ @Override
+ protected RemoteOperationResult run(WebdavClient client) {
+ RemoteOperationResult result = null;
+ PropFindMethod query = null;
+
+ try {
+ // remote request
+ query = new PropFindMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath),
+ DavConstants.PROPFIND_ALL_PROP,
+ DavConstants.DEPTH_1);
+ int status = client.executeMethod(query);
+
+ // check and process response
+ if (isMultiStatus(status)) {
+ // get data from remote folder
+ MultiStatus dataInServer = query.getResponseBodyAsMultiStatus();
+ readData(dataInServer, client);
+
+ // Result of the operation
+ result = new RemoteOperationResult(true, status, query.getResponseHeaders());
+ // Add data to the result
+ if (result.isSuccess()) {
+ result.setFile(mFolder);
+ result.setData(mFiles);
+ }
+ } else {
+ // synchronization failed
+ client.exhaustResponse(query.getResponseBodyAsStream());
+ result = new RemoteOperationResult(false, status, query.getResponseHeaders());
+ }
+
+ } catch (Exception e) {
+ result = new RemoteOperationResult(e);
+
+
+ } finally {
+ if (query != null)
+ query.releaseConnection(); // let the connection available for other methods
+ if (result.isSuccess()) {
+ Log.i(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage());
+ } else {
+ if (result.isException()) {
+ Log.e(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage(), result.getException());
+ } else {
+ Log.e(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage());
+ }
+ }
+
+ }
+ return result;
+ }
+
+ public boolean isMultiStatus(int status) {
+ return (status == HttpStatus.SC_MULTI_STATUS);
+ }
+
+ /**
+ * Read the data retrieved from the server about the contents of the target folder
+ *
+ *
+ * @param dataInServer Full response got from the server with the data of the target
+ * folder and its direct children.
+ * @param client Client instance to the remote server where the data were
+ * retrieved.
+ * @return
+ */
+ private void readData(MultiStatus dataInServer, WebdavClient client) {
+ // parse data from remote folder
+ WebdavEntry we = new WebdavEntry(dataInServer.getResponses()[0], client.getBaseUri().getPath());
+ mFolder = fillOCFile(we);
+
+
+ // loop to update every child
+ RemoteFile remoteFile = null;
+ mFiles = new ArrayList<RemoteFile>();
+ for (int i = 1; i < dataInServer.getResponses().length; ++i) {
+ /// new OCFile instance with the data from the server
+ we = new WebdavEntry(dataInServer.getResponses()[i], client.getBaseUri().getPath());
+ remoteFile = fillOCFile(we);
+
+ mFiles.add(remoteFile);
+ }
+
+ }
+
+ /**
+ * Creates and populates a new {@link RemoteFile} object with the data read from the server.
+ *
+ * @param we WebDAV entry read from the server for a WebDAV resource (remote file or folder).
+ * @return New OCFile instance representing the remote resource described by we.
+ */
+ private RemoteFile fillOCFile(WebdavEntry we) {
+ RemoteFile file = new RemoteFile(we.decodedPath());
+ file.setCreationTimestamp(we.createTimestamp());
+ file.setLength(we.contentLength());
+ file.setMimeType(we.contentType());
+ file.setModifiedTimestamp(we.modifiedTimestamp());
+ file.setEtag(we.etag());
+ return file;
+ }
+}
import com.owncloud.android.oc_framework.operations.RemoteOperation;
import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
import com.owncloud.android.oc_framework.operations.RemoteOperationResult.ResultCode;
-import com.owncloud.android.oc_framework.operations.remote.ReadRemoteFileOperation;
+import com.owncloud.android.oc_framework.operations.remote.ReadRemoteFolderOperation;
import com.owncloud.android.oc_framework.operations.RemoteFile;
import com.owncloud.android.syncadapter.FileSyncService;
import com.owncloud.android.utils.FileStorageUtils;
private RemoteOperationResult fetchAndSyncRemoteFolder(WebdavClient client) {
String remotePath = mLocalFolder.getRemotePath();
- ReadRemoteFileOperation operation = new ReadRemoteFileOperation(remotePath);
+ ReadRemoteFolderOperation operation = new ReadRemoteFolderOperation(remotePath);
RemoteOperationResult result = operation.execute(client);
Log_OC.d(TAG, "Synchronizing " + mAccount.name + remotePath);