Merge getFile and getData methods of RemoteOperationResult in a single one

This commit is contained in:
David A. Velasco 2013-11-29 10:30:53 +01:00
parent d74d2c7800
commit f0dd05ddc4
5 changed files with 16 additions and 32 deletions

View file

@ -38,9 +38,8 @@ public class ReadFolderTest extends ActivityInstrumentationTestCase2<TestActivit
public void testReadFolder() { public void testReadFolder() {
RemoteOperationResult result = mActivity.readFile(mRemoteFolderPath); RemoteOperationResult result = mActivity.readFile(mRemoteFolderPath);
assertTrue(result.getFile() != null); assertTrue(result.getData().size() > 1);
assertTrue(result.getData().size() > 0); assertTrue(result.getData().size() == 4);
assertTrue(result.getData().size() == 3);
assertTrue(result.isSuccess()); assertTrue(result.isSuccess());
} }

View file

@ -13,7 +13,7 @@ import com.owncloud.android.oc_framework.utils.FileUtils;
* @author masensio * @author masensio
*/ */
public class RemoteFile implements Parcelable, Serializable{ public class RemoteFile implements Parcelable, Serializable {
/** Generated - should be refreshed every time the class changes!! */ /** Generated - should be refreshed every time the class changes!! */
private static final long serialVersionUID = 7256606476031992757L; private static final long serialVersionUID = 7256606476031992757L;

View file

@ -98,13 +98,11 @@ public class RemoteOperationResult implements Serializable {
private ResultCode mCode = ResultCode.UNKNOWN_ERROR; private ResultCode mCode = ResultCode.UNKNOWN_ERROR;
private String mRedirectedLocation; private String mRedirectedLocation;
private RemoteFile mFile;
private ArrayList<RemoteFile> mFiles; private ArrayList<RemoteFile> mFiles;
public RemoteOperationResult(ResultCode code) { public RemoteOperationResult(ResultCode code) {
mCode = code; mCode = code;
mSuccess = (code == ResultCode.OK || code == ResultCode.OK_SSL || code == ResultCode.OK_NO_SSL); mSuccess = (code == ResultCode.OK || code == ResultCode.OK_SSL || code == ResultCode.OK_NO_SSL);
mFile= null;
mFiles = null; mFiles = null;
} }
@ -201,12 +199,6 @@ public class RemoteOperationResult implements Serializable {
} }
public void setFile(RemoteFile file){
mFile = file;
}
public RemoteFile getFile(){
return mFile;
}
public void setData(ArrayList<RemoteFile> files){ public void setData(ArrayList<RemoteFile> files){
mFiles = files; mFiles = files;
} }

View file

@ -28,8 +28,7 @@ public class ReadRemoteFolderOperation extends RemoteOperation {
private static final String TAG = ReadRemoteFolderOperation.class.getSimpleName(); private static final String TAG = ReadRemoteFolderOperation.class.getSimpleName();
private String mRemotePath; private String mRemotePath;
private RemoteFile mFolder; private ArrayList<RemoteFile> mFolderAndFiles;
private ArrayList<RemoteFile> mFiles;
/** /**
* Constructor * Constructor
@ -67,8 +66,7 @@ public class ReadRemoteFolderOperation extends RemoteOperation {
result = new RemoteOperationResult(true, status, query.getResponseHeaders()); result = new RemoteOperationResult(true, status, query.getResponseHeaders());
// Add data to the result // Add data to the result
if (result.isSuccess()) { if (result.isSuccess()) {
result.setFile(mFolder); result.setData(mFolderAndFiles);
result.setData(mFiles);
} }
} else { } else {
// synchronization failed // synchronization failed
@ -112,20 +110,19 @@ public class ReadRemoteFolderOperation extends RemoteOperation {
* @return * @return
*/ */
private void readData(MultiStatus dataInServer, WebdavClient client) { private void readData(MultiStatus dataInServer, WebdavClient client) {
mFolderAndFiles = new ArrayList<RemoteFile>();
// parse data from remote folder // parse data from remote folder
WebdavEntry we = new WebdavEntry(dataInServer.getResponses()[0], client.getBaseUri().getPath()); WebdavEntry we = new WebdavEntry(dataInServer.getResponses()[0], client.getBaseUri().getPath());
mFolder = fillOCFile(we); mFolderAndFiles.add(fillOCFile(we));
// loop to update every child // loop to update every child
RemoteFile remoteFile = null; RemoteFile remoteFile = null;
mFiles = new ArrayList<RemoteFile>();
for (int i = 1; i < dataInServer.getResponses().length; ++i) { for (int i = 1; i < dataInServer.getResponses().length; ++i) {
/// new OCFile instance with the data from the server /// new OCFile instance with the data from the server
we = new WebdavEntry(dataInServer.getResponses()[i], client.getBaseUri().getPath()); we = new WebdavEntry(dataInServer.getResponses()[i], client.getBaseUri().getPath());
remoteFile = fillOCFile(we); remoteFile = fillOCFile(we);
mFolderAndFiles.add(remoteFile);
mFiles.add(remoteFile);
} }
} }

View file

@ -249,9 +249,7 @@ public class SynchronizeFolderOperation extends RemoteOperation {
Log_OC.d(TAG, "Synchronizing " + mAccount.name + remotePath); Log_OC.d(TAG, "Synchronizing " + mAccount.name + remotePath);
if (result.isSuccess()) { if (result.isSuccess()) {
RemoteFile folder = result.getFile(); synchronizeData(result.getData(), client);
ArrayList<RemoteFile> files = result.getData();
synchronizeData(folder, files, client);
if (mConflictsFound > 0 || mFailsInFavouritesFound > 0) { if (mConflictsFound > 0 || mFailsInFavouritesFound > 0) {
result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT); // should be different result, but will do the job result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT); // should be different result, but will do the job
} }
@ -278,26 +276,24 @@ public class SynchronizeFolderOperation extends RemoteOperation {
* *
* Grants that mChildren is updated with fresh data after execution. * Grants that mChildren is updated with fresh data after execution.
* *
* @param folder Remote Folder to synchronize * @param folderAndFiles Remote folder and children files in Folder
*
* @param files Remote Files in Folder
* *
* @param client Client instance to the remote server where the data were * @param client Client instance to the remote server where the data were
* retrieved. * retrieved.
* @return 'True' when any change was made in the local data, 'false' otherwise. * @return 'True' when any change was made in the local data, 'false' otherwise.
*/ */
private void synchronizeData(RemoteFile folder, ArrayList<RemoteFile> files, WebdavClient client) { private void synchronizeData(ArrayList<RemoteFile> folderAndFiles, WebdavClient client) {
// get 'fresh data' from the database // get 'fresh data' from the database
mLocalFolder = mStorageManager.getFileByPath(mLocalFolder.getRemotePath()); mLocalFolder = mStorageManager.getFileByPath(mLocalFolder.getRemotePath());
// parse data from remote folder // parse data from remote folder
OCFile remoteFolder = fillOCFile(folder); OCFile remoteFolder = fillOCFile(folderAndFiles.get(0));
remoteFolder.setParentId(mLocalFolder.getParentId()); remoteFolder.setParentId(mLocalFolder.getParentId());
remoteFolder.setFileId(mLocalFolder.getFileId()); remoteFolder.setFileId(mLocalFolder.getFileId());
Log_OC.d(TAG, "Remote folder " + mLocalFolder.getRemotePath() + " changed - starting update of local data "); Log_OC.d(TAG, "Remote folder " + mLocalFolder.getRemotePath() + " changed - starting update of local data ");
List<OCFile> updatedFiles = new Vector<OCFile>(files.size()); List<OCFile> updatedFiles = new Vector<OCFile>(folderAndFiles.size() - 1);
List<SynchronizeFileOperation> filesToSyncContents = new Vector<SynchronizeFileOperation>(); List<SynchronizeFileOperation> filesToSyncContents = new Vector<SynchronizeFileOperation>();
// get current data about local contents of the folder to synchronize // get current data about local contents of the folder to synchronize
@ -309,9 +305,9 @@ public class SynchronizeFolderOperation extends RemoteOperation {
// loop to update every child // loop to update every child
OCFile remoteFile = null, localFile = null; OCFile remoteFile = null, localFile = null;
for (RemoteFile file: files) { for (int i=1; i<folderAndFiles.size(); i++) {
/// new OCFile instance with the data from the server /// new OCFile instance with the data from the server
remoteFile = fillOCFile(file); remoteFile = fillOCFile(folderAndFiles.get(i));
remoteFile.setParentId(mLocalFolder.getFileId()); remoteFile.setParentId(mLocalFolder.getFileId());
/// retrieve local data for the read file /// retrieve local data for the read file