Skip to content

Commit 6f0436b

Browse files
Update file version
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
1 parent 856c251 commit 6f0436b

2 files changed

Lines changed: 28 additions & 19 deletions

File tree

library/src/androidTest/java/com/owncloud/android/lib/resources/files/ReadFileVersionsRemoteOperationIT.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ class ReadFileVersionsRemoteOperationIT : AbstractIT() {
2222
fun listVersions() {
2323
val txtFile = getFile(ASSETS__TEXT_FILE_NAME)
2424
val filePath = "/test.md"
25+
val mimetype = "txt/plain"
2526

2627
var uploadResult =
2728
UploadFileRemoteOperation(
2829
txtFile.absolutePath,
2930
filePath,
30-
"txt/plain",
31+
mimetype,
3132
System.currentTimeMillis() / MILLI_TO_SECOND
3233
)
3334
.execute(client)
@@ -48,7 +49,7 @@ class ReadFileVersionsRemoteOperationIT : AbstractIT() {
4849
// with NC26+ we always have a starting version
4950
versionCount++
5051
}
51-
assertEquals(versionCount, sutResult.data.size)
52+
assertEquals(versionCount, sutResult.resultData.size)
5253

5354
// modify file to have a version
5455
FileWriter(txtFile).apply {
@@ -61,7 +62,7 @@ class ReadFileVersionsRemoteOperationIT : AbstractIT() {
6162
UploadFileRemoteOperation(
6263
txtFile.absolutePath,
6364
filePath,
64-
"txt/plain",
65+
mimetype,
6566
System.currentTimeMillis() / MILLI_TO_SECOND
6667
)
6768
.execute(client)
@@ -75,6 +76,11 @@ class ReadFileVersionsRemoteOperationIT : AbstractIT() {
7576
assertTrue(sutResult.isSuccess)
7677

7778
versionCount++
78-
assertEquals(versionCount, sutResult.data.size)
79+
val versions = sutResult.resultData
80+
assertEquals(versionCount, versions.size)
81+
versions[0].apply {
82+
assertTrue(fileLength > 0)
83+
assertEquals(mimetype, mimeType)
84+
}
7985
}
8086
}

library/src/main/java/com/owncloud/android/lib/resources/files/ReadFileVersionsRemoteOperation.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
* Remote operation performing the read of remote versions on Nextcloud server.
2828
*/
2929

30-
public class ReadFileVersionsRemoteOperation extends RemoteOperation {
30+
public class ReadFileVersionsRemoteOperation extends RemoteOperation<ArrayList<FileVersion>> {
3131

3232
private static final String TAG = ReadFileVersionsRemoteOperation.class.getSimpleName();
3333

3434
private final long localId;
35-
private ArrayList<Object> versions;
35+
private ArrayList<FileVersion> versions;
3636

3737
/**
3838
* Constructor
@@ -49,8 +49,8 @@ public ReadFileVersionsRemoteOperation(long fileId) {
4949
* @param client Client object to communicate with the remote ownCloud server.
5050
*/
5151
@Override
52-
protected RemoteOperationResult run(OwnCloudClient client) {
53-
RemoteOperationResult result = null;
52+
protected RemoteOperationResult<ArrayList<FileVersion>> run(OwnCloudClient client) {
53+
RemoteOperationResult<ArrayList<FileVersion>> result = null;
5454
PropFindMethod query = null;
5555

5656
try {
@@ -69,34 +69,34 @@ protected RemoteOperationResult run(OwnCloudClient client) {
6969
readData(dataInServer, client);
7070

7171
// Result of the operation
72-
result = new RemoteOperationResult(true, query);
72+
result = new RemoteOperationResult<>(true, query);
7373
// Add data to the result
7474
if (result.isSuccess()) {
75-
result.setData(versions);
75+
result.setResultData(versions);
7676
}
7777
} else {
7878
// synchronization failed
7979
client.exhaustResponse(query.getResponseBodyAsStream());
80-
result = new RemoteOperationResult(false, query);
80+
result = new RemoteOperationResult<>(false, query);
8181
}
8282
} catch (Exception e) {
83-
result = new RemoteOperationResult(e);
83+
result = new RemoteOperationResult<>(e);
8484
} finally {
8585
if (query != null)
8686
query.releaseConnection(); // let the connection available for other methods
8787

8888
if (result == null) {
89-
result = new RemoteOperationResult(new Exception("unknown error"));
90-
Log_OC.e(TAG, "Synchronized file with id " + localId + ": failed");
89+
result = new RemoteOperationResult<>(new Exception("unknown error"));
90+
Log_OC.e(TAG, "Read file version for " + localId + ": failed");
9191
} else {
9292
if (result.isSuccess()) {
93-
Log_OC.i(TAG, "Synchronized file with id " + localId + ": " + result.getLogMessage());
93+
Log_OC.i(TAG, "Read file version for " + localId + ": " + result.getLogMessage());
9494
} else {
9595
if (result.isException()) {
96-
Log_OC.e(TAG, "Synchronized with id " + localId + ": " + result.getLogMessage(),
97-
result.getException());
96+
Log_OC.e(TAG, "Read file version for " + localId + ": " + result.getLogMessage(),
97+
result.getException());
9898
} else {
99-
Log_OC.w(TAG, "Synchronized with id " + localId + ": " + result.getLogMessage());
99+
Log_OC.w(TAG, "Read file version for " + localId + ": " + result.getLogMessage());
100100
}
101101
}
102102
}
@@ -119,7 +119,10 @@ private void readData(MultiStatus remoteData, OwnCloudClient client) {
119119

120120
// loop to update every child
121121
for (int i = 1; i < remoteData.getResponses().length; ++i) {
122-
versions.add(new FileVersion(localId, new WebdavEntry(remoteData.getResponses()[i], splitElement)));
122+
versions.add(new FileVersion(
123+
localId,
124+
new WebdavEntry(remoteData.getResponses()[i], splitElement))
125+
);
123126
}
124127
}
125128
}

0 commit comments

Comments
 (0)