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

Remote operation part2 #1149

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 0 additions & 2 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Sep 16 08:12:41 CEST 2022
#Thu Jun 15 14:34:27 CEST 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,14 @@ package com.nextcloud.android.lib.resources.groupfolders

import com.owncloud.android.AbstractIT
import com.owncloud.android.lib.resources.status.GetCapabilitiesRemoteOperation
import com.owncloud.android.lib.resources.status.OCCapability
import org.junit.Assert.assertEquals
import org.junit.Assume.assumeTrue
import org.junit.Test

class GetGroupfoldersRemoteOperationIT : AbstractIT() {
@Test
fun getGroupfolders() {
val capability = GetCapabilitiesRemoteOperation().execute(client).singleData as OCCapability

val capability = GetCapabilitiesRemoteOperation().execute(nextcloudClient).resultData
assumeTrue(capability.groupfolders.isTrue)

val map = GetGroupfoldersRemoteOperation().execute(nextcloudClient).resultData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ public static File extractAsset(String fileName, Context context) throws IOExcep

@After
public void after() {
// removeOnClient(client);
// removeOnClient(client2);
removeOnClient(client);
removeOnClient(client2);
}

private void removeOnClient(OwnCloudClient client) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,25 @@ public class GetCapabilitiesIT extends AbstractIT {
@Test
public void testGetRemoteCapabilitiesOperation() {
// get capabilities
RemoteOperationResult result = new GetCapabilitiesRemoteOperation().execute(client);
RemoteOperationResult<OCCapability> result = new GetCapabilitiesRemoteOperation().execute(nextcloudClient);
assertTrue(result.isSuccess());
assertTrue(result.getData() != null && result.getData().size() == 1);

OCCapability capability = (OCCapability) result.getData().get(0);
OCCapability capability = result.getResultData();
checkCapability(capability, client.getUserId());
}

@Test
public void testGetRemoteCapabilitiesOperationEtag() {
// get capabilities
RemoteOperationResult result = new GetCapabilitiesRemoteOperation().execute(client);
RemoteOperationResult<OCCapability> result = new GetCapabilitiesRemoteOperation().execute(nextcloudClient);
assertTrue(result.isSuccess());
assertTrue(result.getData() != null && result.getData().size() == 1);

OCCapability capability = (OCCapability) result.getData().get(0);
OCCapability capability = result.getResultData();

RemoteOperationResult resultEtag = new GetCapabilitiesRemoteOperation(capability).execute(client);
RemoteOperationResult<OCCapability> resultEtag = new GetCapabilitiesRemoteOperation(capability).execute(nextcloudClient);
assertTrue(resultEtag.isSuccess());
assertTrue(resultEtag.getData() != null && resultEtag.getData().size() == 1);

OCCapability sameCapability = (OCCapability) resultEtag.getData().get(0);
OCCapability sameCapability = resultEtag.getResultData();

if (capability.getVersion().isNewerOrEqual(OwnCloudVersion.nextcloud_19)) {
assertEquals(capability, sameCapability);
Expand All @@ -89,28 +86,25 @@ public void testGetRemoteCapabilitiesOperationEtag() {
@Test
public void testGetRemoteCapabilitiesOperationWithNextcloudClient() {
// get capabilities
RemoteOperationResult result = new GetCapabilitiesRemoteOperation().execute(nextcloudClient);
RemoteOperationResult<OCCapability> result = new GetCapabilitiesRemoteOperation().execute(nextcloudClient);
assertTrue(result.isSuccess());
assertTrue(result.getData() != null && result.getData().size() == 1);

OCCapability capability = (OCCapability) result.getData().get(0);
OCCapability capability = result.getResultData();
checkCapability(capability, client.getUserId());
}

@Test
public void testGetRemoteCapabilitiesOperationEtagWithNextcloudClient() {
// get capabilities
RemoteOperationResult result = new GetCapabilitiesRemoteOperation().execute(nextcloudClient);
RemoteOperationResult<OCCapability> result = new GetCapabilitiesRemoteOperation().execute(nextcloudClient);
assertTrue(result.isSuccess());
assertTrue(result.getData() != null && result.getData().size() == 1);

OCCapability capability = (OCCapability) result.getData().get(0);
OCCapability capability = result.getResultData();

RemoteOperationResult resultEtag = new GetCapabilitiesRemoteOperation(capability).execute(nextcloudClient);
RemoteOperationResult<OCCapability> resultEtag = new GetCapabilitiesRemoteOperation(capability).execute(nextcloudClient);
assertTrue(resultEtag.isSuccess());
assertTrue(resultEtag.getData() != null && resultEtag.getData().size() == 1);

OCCapability sameCapability = (OCCapability) resultEtag.getData().get(0);
OCCapability sameCapability = resultEtag.getResultData();

if (capability.getVersion().isNewerOrEqual(OwnCloudVersion.nextcloud_19)) {
assertEquals(capability, sameCapability);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,17 @@
package com.owncloud.android.lib.common.accounts

import com.owncloud.android.AbstractIT
import com.owncloud.android.lib.common.ExternalLink
import junit.framework.Assert.assertEquals
import junit.framework.Assert.assertTrue
import org.junit.Test

class ExternalLinksOperationIT : AbstractIT() {
@Test
fun retrieveExternalLinks() {
val result = ExternalLinksOperation().execute(client)
val result = ExternalLinksOperation().execute(nextcloudClient)
assertTrue(result.isSuccess)

val data = result.data as ArrayList<ExternalLink>
val data = result.resultData
assertEquals(2, data.size)

assertEquals("Nextcloud", data[0].name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import com.owncloud.android.AbstractIT
import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation
import com.owncloud.android.lib.resources.files.UploadFileRemoteOperation
import com.owncloud.android.lib.resources.files.model.RemoteFile
import junit.framework.Assert.assertEquals
import junit.framework.Assert.assertTrue
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod
import org.junit.Test

class CommentFileRemoteOperationIT : AbstractIT() {
Expand All @@ -44,18 +46,27 @@ class CommentFileRemoteOperationIT : AbstractIT() {
)

val readResult = ReadFileRemoteOperation(remotePath).execute(client)
val remoteFile = readResult.data.get(0) as RemoteFile
val remoteFile = readResult.data[0] as RemoteFile
assertTrue(readResult.isSuccess)

checkComments(0, remoteFile.localId)

assertTrue(
CommentFileRemoteOperation("test", remoteFile.localId)
.execute(client)
.isSuccess
)

assertTrue(
MarkCommentsAsReadRemoteOperation(remoteFile.localId)
.execute(client)
.isSuccess
)
checkComments(1, remoteFile.localId)
}

private fun checkComments(expectedComments: Int, fileId: Long) {
val readComment =
PropFindMethod(client.baseUri.toString() + "/remote.php/dav/comments/files/" + fileId)
client.executeMethod(readComment)
assertTrue(readComment.succeeded())

// offset by 1, as "root" entry always exists if file exists
assertEquals(expectedComments + 1, readComment.responseBodyAsMultiStatus.responses.size)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public class SearchRemoteOperationIT extends AbstractIT {

@BeforeClass
public static void beforeClass() {
capability = (OCCapability) new GetCapabilitiesRemoteOperation(null)
.execute(client)
capability = (OCCapability) new GetCapabilitiesRemoteOperation()
.execute(nextcloudClient)
.getSingleData();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ import com.nextcloud.common.NextcloudClient
import com.nextcloud.operations.GetMethod
import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.ocs.ServerResponse
import com.owncloud.android.lib.resources.OCSRemoteOperation
import com.owncloud.android.lib.resources.OCSNextcloudRemoteOperation
import org.apache.commons.httpclient.HttpStatus
import java.io.IOException

class DashboardGetWidgetItemsRemoteOperation(val id: String, private val limitSize: Int) :
OCSRemoteOperation<HashMap<String, List<DashboardWidgetItem>>>() {
OCSNextcloudRemoteOperation<HashMap<String, List<DashboardWidgetItem>>>() {

override fun run(client: NextcloudClient): RemoteOperationResult<HashMap<String, List<DashboardWidgetItem>>> {
lateinit var result: RemoteOperationResult<HashMap<String, List<DashboardWidgetItem>>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import com.nextcloud.common.NextcloudClient
import com.nextcloud.operations.GetMethod
import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.ocs.ServerResponse
import com.owncloud.android.lib.resources.OCSRemoteOperation
import com.owncloud.android.lib.resources.OCSNextcloudRemoteOperation
import org.apache.commons.httpclient.HttpStatus
import java.io.IOException

class DashboardListWidgetsRemoteOperation : OCSRemoteOperation<Map<String, DashboardWidget>>() {
class DashboardListWidgetsRemoteOperation : OCSNextcloudRemoteOperation<Map<String, DashboardWidget>>() {

override fun run(client: NextcloudClient): RemoteOperationResult<Map<String, DashboardWidget>> {
lateinit var result: RemoteOperationResult<Map<String, DashboardWidget>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
package com.nextcloud.android.lib.resources.directediting;

import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.LegacyRemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;

Expand All @@ -40,7 +40,7 @@
* Create file with direct editing api
*/

public class DirectEditingCreateFileRemoteOperation extends RemoteOperation<String> {
public class DirectEditingCreateFileRemoteOperation extends LegacyRemoteOperation<String> {
private static final String TAG = DirectEditingCreateFileRemoteOperation.class.getSimpleName();
private static final int SYNC_READ_TIMEOUT = 40000;
private static final int SYNC_CONNECTION_TIMEOUT = 5000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
package com.nextcloud.android.lib.resources.directediting;

import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.LegacyRemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;

Expand All @@ -40,7 +40,7 @@
* open file for direct editing
*/

public class DirectEditingOpenFileRemoteOperation extends RemoteOperation {
public class DirectEditingOpenFileRemoteOperation extends LegacyRemoteOperation {
private static final String TAG = DirectEditingOpenFileRemoteOperation.class.getSimpleName();
private static final int SYNC_READ_TIMEOUT = 40000;
private static final int SYNC_CONNECTION_TIMEOUT = 5000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.nextcloud.common.NextcloudClient
import com.nextcloud.common.OkHttpMethodBase
import com.nextcloud.operations.LockMethod
import com.nextcloud.operations.UnlockMethod
import com.owncloud.android.lib.common.operations.RemoteOperation
import com.owncloud.android.lib.common.operations.NextcloudRemoteOperation
import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.common.utils.Log_OC
import org.apache.commons.httpclient.HttpStatus
Expand All @@ -35,7 +35,7 @@ import org.apache.commons.httpclient.HttpStatus
* @param toLock `true` if file is to be locked, `false` if it is to be unlocked
*/
class ToggleFileLockRemoteOperation(private val toLock: Boolean, private val filePath: String) :
RemoteOperation<Void>() {
NextcloudRemoteOperation<Void>() {
@Suppress("TooGenericExceptionCaught")
override fun run(client: NextcloudClient): RemoteOperationResult<Void> {
var method: OkHttpMethodBase? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ import com.nextcloud.operations.GetMethod
import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.lib.ocs.ServerResponse
import com.owncloud.android.lib.resources.OCSRemoteOperation
import com.owncloud.android.lib.resources.OCSNextcloudRemoteOperation
import org.apache.commons.httpclient.HttpStatus

/**
* Get groupfolders of an user
*/
class GetGroupfoldersRemoteOperation :
OCSRemoteOperation<Map<String, Groupfolder>>() {
OCSNextcloudRemoteOperation<Map<String, Groupfolder>>() {
@Suppress("TooGenericExceptionCaught")
override fun run(client: NextcloudClient): RemoteOperationResult<Map<String, Groupfolder>> {
var result: RemoteOperationResult<Map<String, Groupfolder>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ import com.nextcloud.operations.GetMethod
import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.lib.ocs.ServerResponse
import com.owncloud.android.lib.resources.OCSRemoteOperation
import com.owncloud.android.lib.resources.OCSNextcloudRemoteOperation
import org.apache.commons.httpclient.HttpStatus

/**
* Get hoverCard of an user
*/
class GetHoverCardRemoteOperation(private val userId: String) : OCSRemoteOperation<HoverCard?>() {
class GetHoverCardRemoteOperation(private val userId: String) : OCSNextcloudRemoteOperation<HoverCard?>() {
@Suppress("TooGenericExceptionCaught")
override fun run(client: NextcloudClient): RemoteOperationResult<HoverCard?> {
var result: RemoteOperationResult<HoverCard?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ import com.owncloud.android.lib.common.SearchProviders
import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.lib.ocs.ServerResponse
import com.owncloud.android.lib.resources.OCSRemoteOperation
import com.owncloud.android.lib.resources.OCSNextcloudRemoteOperation
import org.apache.commons.httpclient.HttpStatus

/**
* Get all search providers for unified search
*/
@Suppress("TooGenericExceptionCaught")
class UnifiedSearchProvidersRemoteOperation : OCSRemoteOperation<SearchProviders>() {
class UnifiedSearchProvidersRemoteOperation : OCSNextcloudRemoteOperation<SearchProviders>() {
companion object {
private val TAG = UnifiedSearchProvidersRemoteOperation::class.java.simpleName
private const val ENDPOINT = "/ocs/v2.php/search/providers"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import com.owncloud.android.lib.common.SearchResult
import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.lib.ocs.ServerResponse
import com.owncloud.android.lib.resources.OCSRemoteOperation
import com.owncloud.android.lib.resources.OCSNextcloudRemoteOperation
import org.apache.commons.httpclient.HttpStatus
import java.net.URLEncoder

Expand All @@ -43,7 +43,7 @@ class UnifiedSearchRemoteOperation(
val cursor: Int? = null,
val limit: Int = 5
) :
OCSRemoteOperation<SearchResult>() {
OCSNextcloudRemoteOperation<SearchResult>() {
companion object {
private val TAG = UnifiedSearchRemoteOperation::class.java.simpleName
private const val ENDPOINT = "/ocs/v2.php/search/providers/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import com.google.gson.GsonBuilder;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.LegacyRemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;

Expand All @@ -45,7 +45,7 @@
* Get direct editing url for rich workspace
*/

public class RichWorkspaceDirectEditingRemoteOperation extends RemoteOperation {
public class RichWorkspaceDirectEditingRemoteOperation extends LegacyRemoteOperation {
private static final String TAG = RichWorkspaceDirectEditingRemoteOperation.class.getSimpleName();
private static final int SYNC_READ_TIMEOUT = 40000;
private static final int SYNC_CONNECTION_TIMEOUT = 5000;
Expand Down
4 changes: 2 additions & 2 deletions library/src/main/java/com/nextcloud/common/NextcloudClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import com.owncloud.android.lib.common.accounts.AccountUtils
import com.owncloud.android.lib.common.network.AdvancedX509TrustManager
import com.owncloud.android.lib.common.network.NetworkUtils
import com.owncloud.android.lib.common.network.RedirectionPath
import com.owncloud.android.lib.common.operations.RemoteOperation
import com.owncloud.android.lib.common.operations.NextcloudRemoteOperation
import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.common.utils.Log_OC
import okhttp3.CookieJar
Expand Down Expand Up @@ -101,7 +101,7 @@ class NextcloudClient private constructor(
) : this(baseUri, userId, credentials, createDefaultClient(context))

@Suppress("TooGenericExceptionCaught")
fun <T> execute(remoteOperation: RemoteOperation<T>): RemoteOperationResult<T> {
fun <T> execute(remoteOperation: NextcloudRemoteOperation<T>): RemoteOperationResult<T> {
return try {
remoteOperation.run(this)
} catch (ex: Exception) {
Expand Down
Loading