From d04786b1be70f22857fc860ec423d98ad1ad04e8 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Fri, 10 Mar 2023 14:08:44 +0100 Subject: [PATCH] Update file version Signed-off-by: tobiasKaminsky --- .../ReadFileVersionsRemoteOperationIT.kt | 14 +++++--- .../ReadFileVersionsRemoteOperation.java | 33 ++++++++++--------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/files/ReadFileVersionsRemoteOperationIT.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/files/ReadFileVersionsRemoteOperationIT.kt index 38a7e24da..0a2c227fd 100644 --- a/library/src/androidTest/java/com/owncloud/android/lib/resources/files/ReadFileVersionsRemoteOperationIT.kt +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/files/ReadFileVersionsRemoteOperationIT.kt @@ -36,12 +36,13 @@ class ReadFileVersionsRemoteOperationIT : AbstractIT() { fun listVersions() { val txtFile = getFile(ASSETS__TEXT_FILE_NAME) val filePath = "/test.md" + val mimetype = "txt/plain" var uploadResult = UploadFileRemoteOperation( txtFile.absolutePath, filePath, - "txt/plain", + mimetype, System.currentTimeMillis() / MILLI_TO_SECOND ) .execute(client) @@ -62,7 +63,7 @@ class ReadFileVersionsRemoteOperationIT : AbstractIT() { // with NC26+ we always have a starting version versionCount++ } - assertEquals(versionCount, sutResult.data.size) + assertEquals(versionCount, sutResult.resultData.size) // modify file to have a version FileWriter(txtFile).apply { @@ -75,7 +76,7 @@ class ReadFileVersionsRemoteOperationIT : AbstractIT() { UploadFileRemoteOperation( txtFile.absolutePath, filePath, - "txt/plain", + mimetype, System.currentTimeMillis() / MILLI_TO_SECOND ) .execute(client) @@ -89,6 +90,11 @@ class ReadFileVersionsRemoteOperationIT : AbstractIT() { assertTrue(sutResult.isSuccess) versionCount++ - assertEquals(versionCount, sutResult.data.size) + val versions = sutResult.resultData + assertEquals(versionCount, versions.size) + versions[0].apply { + assertTrue(fileLength > 0) + assertEquals(mimetype, mimeType) + } } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/ReadFileVersionsRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/ReadFileVersionsRemoteOperation.java index a93790809..0c91dde5e 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/ReadFileVersionsRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/ReadFileVersionsRemoteOperation.java @@ -47,12 +47,12 @@ * Remote operation performing the read of remote versions on Nextcloud server. */ -public class ReadFileVersionsRemoteOperation extends RemoteOperation { +public class ReadFileVersionsRemoteOperation extends RemoteOperation> { private static final String TAG = ReadFileVersionsRemoteOperation.class.getSimpleName(); private final long localId; - private ArrayList versions; + private ArrayList versions; /** * Constructor @@ -69,8 +69,8 @@ public ReadFileVersionsRemoteOperation(long fileId) { * @param client Client object to communicate with the remote ownCloud server. */ @Override - protected RemoteOperationResult run(OwnCloudClient client) { - RemoteOperationResult result = null; + protected RemoteOperationResult> run(OwnCloudClient client) { + RemoteOperationResult> result = null; PropFindMethod query = null; try { @@ -89,34 +89,34 @@ protected RemoteOperationResult run(OwnCloudClient client) { readData(dataInServer, client); // Result of the operation - result = new RemoteOperationResult(true, query); + result = new RemoteOperationResult<>(true, query); // Add data to the result if (result.isSuccess()) { - result.setData(versions); + result.setResultData(versions); } } else { // synchronization failed client.exhaustResponse(query.getResponseBodyAsStream()); - result = new RemoteOperationResult(false, query); + result = new RemoteOperationResult<>(false, query); } } catch (Exception e) { - result = new RemoteOperationResult(e); + result = new RemoteOperationResult<>(e); } finally { if (query != null) query.releaseConnection(); // let the connection available for other methods if (result == null) { - result = new RemoteOperationResult(new Exception("unknown error")); - Log_OC.e(TAG, "Synchronized file with id " + localId + ": failed"); + result = new RemoteOperationResult<>(new Exception("unknown error")); + Log_OC.e(TAG, "Read file version for " + localId + ": failed"); } else { if (result.isSuccess()) { - Log_OC.i(TAG, "Synchronized file with id " + localId + ": " + result.getLogMessage()); + Log_OC.i(TAG, "Read file version for " + localId + ": " + result.getLogMessage()); } else { if (result.isException()) { - Log_OC.e(TAG, "Synchronized with id " + localId + ": " + result.getLogMessage(), - result.getException()); + Log_OC.e(TAG, "Read file version for " + localId + ": " + result.getLogMessage(), + result.getException()); } else { - Log_OC.w(TAG, "Synchronized with id " + localId + ": " + result.getLogMessage()); + Log_OC.w(TAG, "Read file version for " + localId + ": " + result.getLogMessage()); } } } @@ -139,7 +139,10 @@ private void readData(MultiStatus remoteData, OwnCloudClient client) { // loop to update every child for (int i = 1; i < remoteData.getResponses().length; ++i) { - versions.add(new FileVersion(localId, new WebdavEntry(remoteData.getResponses()[i], splitElement))); + versions.add(new FileVersion( + localId, + new WebdavEntry(remoteData.getResponses()[i], splitElement)) + ); } } }