import android.content.Context;
import android.content.Intent;
-import com.owncloud.android.Log_OC;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.operations.RemoteOperationResult.ResultCode;
+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;
+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;
-import eu.alefzero.webdav.WebdavClient;
-import eu.alefzero.webdav.WebdavEntry;
-import eu.alefzero.webdav.WebdavUtils;
/**
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);
*/
private void synchronizeData(MultiStatus dataInServer, WebdavClient client) {
// get 'fresh data' from the database
- mLocalFolder = mStorageManager.getFileById(mLocalFolder.getFileId());
+ mLocalFolder = mStorageManager.getFileByPath(mLocalFolder.getRemotePath());
// parse data from remote folder
WebdavEntry we = new WebdavEntry(dataInServer.getResponses()[0], client.getBaseUri().getPath());
}
}
-
/**
* Scans the default location for saving local copies of files searching for
* a 'lost' file with the same full name as the {@link OCFile} received as
* @param dirRemotePath Remote path of a folder that was just synchronized (with or without success)
*/
private void sendStickyBroadcast(boolean inProgress, String dirRemotePath, RemoteOperationResult result) {
- Intent i = new Intent(FileSyncService.SYNC_MESSAGE);
+ Intent i = new Intent(FileSyncService.getSyncMessage());
i.putExtra(FileSyncService.IN_PROGRESS, inProgress);
i.putExtra(FileSyncService.ACCOUNT_NAME, mAccount.name);
if (dirRemotePath != null) {