From: masensio Date: Mon, 25 Nov 2013 13:50:16 +0000 (+0100) Subject: OC-2202: Change old Read method by new ReadRemoteFileOperation X-Git-Tag: oc-android-1.5.5~116^2~9 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/526a42a11b93c6568efe66814acefa7f9948dcff?ds=sidebyside OC-2202: Change old Read method by new ReadRemoteFileOperation --- diff --git a/oc_framework/src/com/owncloud/android/oc_framework/operations/remote/ReadRemoteFileOperation.java b/oc_framework/src/com/owncloud/android/oc_framework/operations/remote/ReadRemoteFileOperation.java index c6e013fe..a73bad0c 100644 --- a/oc_framework/src/com/owncloud/android/oc_framework/operations/remote/ReadRemoteFileOperation.java +++ b/oc_framework/src/com/owncloud/android/oc_framework/operations/remote/ReadRemoteFileOperation.java @@ -8,26 +8,44 @@ 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.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 WebdavEntry mWe; + private MultiStatus mDataInServer; - public WebdavEntry getWEntry() { - return mWe; + public MultiStatus getDataInServer() { + return mDataInServer; } + + /** + * Constructor + * + * @param remotePath Remote path of the file. + */ public ReadRemoteFileOperation(String remotePath) { mRemotePath = remotePath; + mDataInServer = null; } + /** + * Performs the read operation. + * + * @param client Client object to communicate with the remote ownCloud server. + */ @Override protected RemoteOperationResult run(WebdavClient client) { RemoteOperationResult result = null; @@ -42,9 +60,8 @@ public class ReadRemoteFileOperation extends RemoteOperation { // check and process response if (isMultiStatus(status)) { - MultiStatus dataInServer = query.getResponseBodyAsMultiStatus(); - // parse data from remote folder - mWe = new WebdavEntry(dataInServer.getResponses()[0], client.getBaseUri().getPath()); + // get data from remote folder + mDataInServer = query.getResponseBodyAsMultiStatus(); result = new RemoteOperationResult(true, status, query.getResponseHeaders()); } else { // synchronization failed diff --git a/src/com/owncloud/android/operations/RenameFileOperation.java b/src/com/owncloud/android/operations/RenameFileOperation.java index 9aa573ab..be6cdcce 100644 --- a/src/com/owncloud/android/operations/RenameFileOperation.java +++ b/src/com/owncloud/android/operations/RenameFileOperation.java @@ -20,7 +20,6 @@ package com.owncloud.android.operations; import java.io.File; import java.io.IOException; -import org.apache.commons.httpclient.HttpException; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.oc_framework.network.webdav.WebdavClient; diff --git a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java index 780fd42c..450cc3ed 100644 --- a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java @@ -45,6 +45,7 @@ import com.owncloud.android.oc_framework.network.webdav.WebdavUtils; 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.syncadapter.FileSyncService; import com.owncloud.android.utils.FileStorageUtils; import com.owncloud.android.utils.Log_OC; @@ -241,59 +242,89 @@ public class SynchronizeFolderOperation extends RemoteOperation { private RemoteOperationResult fetchAndSyncRemoteFolder(WebdavClient client) { - RemoteOperationResult result = null; - String remotePath = null; - PropFindMethod query = null; - try { - remotePath = mLocalFolder.getRemotePath(); - Log_OC.d(TAG, "Synchronizing " + mAccount.name + remotePath); - - // remote request - query = new PropFindMethod(client.getBaseUri() + WebdavUtils.encodePath(remotePath), - DavConstants.PROPFIND_ALL_PROP, - DavConstants.DEPTH_1); - int status = client.executeMethod(query); - - // check and process response - if (isMultiStatus(status)) { - synchronizeData(query.getResponseBodyAsMultiStatus(), client); - if (mConflictsFound > 0 || mFailsInFavouritesFound > 0) { - result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT); // should be different result, but will do the job - } else { - result = new RemoteOperationResult(true, status, query.getResponseHeaders()); - } - - } else { - // synchronization failed - client.exhaustResponse(query.getResponseBodyAsStream()); - if (status == HttpStatus.SC_NOT_FOUND) { - removeLocalFolder(); - } - 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_OC.i(TAG, "Synchronized " + mAccount.name + remotePath + ": " + result.getLogMessage()); - } else { - if (result.isException()) { - Log_OC.e(TAG, "Synchronized " + mAccount.name + remotePath + ": " + result.getLogMessage(), result.getException()); - } else { - Log_OC.e(TAG, "Synchronized " + mAccount.name + remotePath + ": " + result.getLogMessage()); - } + String remotePath = mLocalFolder.getRemotePath(); + ReadRemoteFileOperation operation = new ReadRemoteFileOperation(remotePath); + RemoteOperationResult result = operation.execute(client); + Log_OC.d(TAG, "Synchronizing " + mAccount.name + remotePath); + + if (result.isSuccess()) { + MultiStatus dataInServer = ((ReadRemoteFileOperation) operation).getDataInServer(); + synchronizeData(dataInServer, client); + if (mConflictsFound > 0 || mFailsInFavouritesFound > 0) { + result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT); // should be different result, but will do the job } - + } else { + if (result.getCode() == ResultCode.FILE_NOT_FOUND) + removeLocalFolder(); } + +// RemoteOperationResult result = null; +// String remotePath = null; +// PropFindMethod query = null; +// try { +// remotePath = mLocalFolder.getRemotePath(); +// Log_OC.d(TAG, "Synchronizing " + mAccount.name + remotePath); +// +// // remote request +// query = new PropFindMethod(client.getBaseUri() + WebdavUtils.encodePath(remotePath), +// DavConstants.PROPFIND_ALL_PROP, +// DavConstants.DEPTH_1); +// int status = client.executeMethod(query); +// +// // check and process response +// if (isMultiStatus(status)) { +// synchronizeData(query.getResponseBodyAsMultiStatus(), client); +// if (mConflictsFound > 0 || mFailsInFavouritesFound > 0) { +// result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT); // should be different result, but will do the job +// } else { +// result = new RemoteOperationResult(true, status, query.getResponseHeaders()); +// } +// +// } else { +// // synchronization failed +// client.exhaustResponse(query.getResponseBodyAsStream()); +// if (status == HttpStatus.SC_NOT_FOUND) { +// removeLocalFolder(); +// } +// 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_OC.i(TAG, "Synchronized " + mAccount.name + remotePath + ": " + result.getLogMessage()); +// } else { +// if (result.isException()) { +// Log_OC.e(TAG, "Synchronized " + mAccount.name + remotePath + ": " + result.getLogMessage(), result.getException()); +// } else { +// Log_OC.e(TAG, "Synchronized " + mAccount.name + remotePath + ": " + result.getLogMessage()); +// } +// } +// +// } return result; } +// @Override +// public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) { +// if (operation instanceof ReadRemoteFileOperation) { +// if (result.isSuccess()) { +// MultiStatus dataInServer = ((ReadRemoteFileOperation) operation).getDataInServer(); +// synchronizeData(dataInServer, client) +// } else { +// +// } +// +// } +// +// } + private void removeLocalFolder() { if (mStorageManager.fileExists(mLocalFolder.getFileId())) { String currentSavePath = FileStorageUtils.getSavePath(mAccount.name);