Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update file version #1357

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -75,7 +76,7 @@ class ReadFileVersionsRemoteOperationIT : AbstractIT() {
UploadFileRemoteOperation(
txtFile.absolutePath,
filePath,
"txt/plain",
mimetype,
System.currentTimeMillis() / MILLI_TO_SECOND
)
.execute(client)
Expand All @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArrayList<FileVersion>> {

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

private final long localId;
private ArrayList<Object> versions;
private ArrayList<FileVersion> versions;

/**
* Constructor
Expand All @@ -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<ArrayList<FileVersion>> run(OwnCloudClient client) {
RemoteOperationResult<ArrayList<FileVersion>> result = null;
PropFindMethod query = null;

try {
Expand All @@ -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());
}
}
}
Expand All @@ -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))
);
}
}
}
Loading