Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
  • Loading branch information
tobiasKaminsky committed Aug 30, 2023
1 parent f8e5d04 commit d3924f1
Show file tree
Hide file tree
Showing 93 changed files with 1,158 additions and 582 deletions.
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 @@ -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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,28 @@

package com.owncloud.android.lib.common.accounts;

import com.nextcloud.common.NextcloudClient;
import com.nextcloud.operations.GetMethod;
import com.owncloud.android.lib.common.ExternalLink;
import com.owncloud.android.lib.common.ExternalLinkType;
import com.owncloud.android.lib.common.OwnCloudClient;
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 com.owncloud.android.lib.resources.status.GetCapabilitiesRemoteOperation;
import com.owncloud.android.lib.resources.status.OCCapability;

import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;

/**
* gets external links provided by 'external' app
*/

public class ExternalLinksOperation extends RemoteOperation {
public class ExternalLinksOperation extends NextcloudRemoteOperation<ArrayList<ExternalLink>> {

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

Expand All @@ -68,24 +68,26 @@ public class ExternalLinksOperation extends RemoteOperation {


@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null;
public RemoteOperationResult<ArrayList<ExternalLink>> run(NextcloudClient client) {
RemoteOperationResult<ArrayList<ExternalLink>> result = null;
int status = -1;
GetMethod get = null;
String ocsUrl = client.getBaseUri() + OCS_ROUTE_EXTERNAL_LINKS;

try {
// check capabilities
RemoteOperation getCapabilities = new GetCapabilitiesRemoteOperation();
RemoteOperationResult capabilitiesResult = getCapabilities.execute(client);
NextcloudRemoteOperation getCapabilities = new GetCapabilitiesRemoteOperation();
RemoteOperationResult capabilitiesResult = client.execute(getCapabilities);
OCCapability capability = (OCCapability) capabilitiesResult.getData().get(0);

if (capability.getExternalLinks().isTrue()) {

get = new GetMethod(ocsUrl);
get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
get.setQueryString(new NameValuePair[]{new NameValuePair("format", "json")});
status = client.executeMethod(get);
get = new GetMethod(ocsUrl, true);
HashMap<String, String> parameters = new HashMap<>();
parameters.put("format", "json");
get.setQueryString(parameters);

status = client.execute(get);

if (isSuccess(status)) {
String response = get.getResponseBodyAsString();
Expand All @@ -94,13 +96,13 @@ protected RemoteOperationResult run(OwnCloudClient client) {
// parse
JSONArray links = new JSONObject(response).getJSONObject(NODE_OCS).getJSONArray(NODE_DATA);

ArrayList<Object> resultLinks = new ArrayList<>();
ArrayList<ExternalLink> resultLinks = new ArrayList<>();

for (int i = 0; i < links.length(); i++) {
JSONObject link = links.getJSONObject(i);

if (link != null) {
Integer id = link.getInt(NODE_ID);
int id = link.getInt(NODE_ID);
String iconUrl = link.getString(NODE_ICON);
String language = "";
if (link.has(NODE_LANGUAGE)) {
Expand Down Expand Up @@ -137,26 +139,22 @@ protected RemoteOperationResult run(OwnCloudClient client) {
}
}

result = new RemoteOperationResult(true, status, get.getResponseHeaders());
result.setData(resultLinks);
result = new RemoteOperationResult<>(true, get);
result.setResultData(resultLinks);

} else {
result = new RemoteOperationResult(false, status, get.getResponseHeaders());
result = new RemoteOperationResult<>(false, get);
String response = get.getResponseBodyAsString();
Log_OC.e(TAG, "Failed response while getting external links ");
if (response != null) {
Log_OC.e(TAG, "*** status code: " + status + " ; response message: " + response);
} else {
Log_OC.e(TAG, "*** status code: " + status);
}
Log_OC.e(TAG, "*** status code: " + status + " ; response message: " + response);
}
} else {
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.NOT_AVAILABLE);
result = new RemoteOperationResult<>(RemoteOperationResult.ResultCode.NOT_AVAILABLE);
Log_OC.d(TAG, "External links disabled");
}

} catch (Exception e) {
result = new RemoteOperationResult(e);
result = new RemoteOperationResult<>(e);
Log_OC.e(TAG, "Exception while getting external links ", e);
} finally {
if (get != null) {
Expand Down
Loading

0 comments on commit d3924f1

Please sign in to comment.