Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 63985b61 authored by ZetaTom's avatar ZetaTom
Browse files

Deprecate OwncloudClient - DirectEditing

parent 16c9396b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ import org.junit.Test
class DirectEditingObtainRemoteOperationIT : AbstractIT() {
    @Test
    fun testGetAll() {
        val result = DirectEditingObtainRemoteOperation().execute(client)
        val result = DirectEditingObtainRemoteOperation().run(nextcloudClient)
        assertTrue(result.isSuccess)

        val (editors, creators) = result.resultData
+18 −20
Original line number Diff line number Diff line
@@ -27,13 +27,14 @@

package com.nextcloud.android.lib.resources.directediting;

import com.owncloud.android.lib.common.OwnCloudClient;
import com.nextcloud.common.JSONRequestBody;
import com.nextcloud.common.NextcloudClient;
import com.nextcloud.operations.PostMethod;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;

import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.Utf8PostMethod;
import org.json.JSONObject;

/**
@@ -42,8 +43,6 @@ import org.json.JSONObject;

public class DirectEditingCreateFileRemoteOperation extends RemoteOperation<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;
    private static final String DIRECT_ENDPOINT = "/ocs/v2.php/apps/files/api/v1/directEditing/create";

    private final String path;
@@ -65,45 +64,44 @@ public class DirectEditingCreateFileRemoteOperation extends RemoteOperation<Stri
        this(path, editor, creator, "");
    }

    protected RemoteOperationResult<String> run(OwnCloudClient client) {
    public RemoteOperationResult<String> run(NextcloudClient client) {
        RemoteOperationResult<String> result;
        Utf8PostMethod postMethod = null;
        PostMethod post = null;

        try {
            postMethod = new Utf8PostMethod(client.getBaseUri() + DIRECT_ENDPOINT + JSON_FORMAT);
            postMethod.addParameter("path", path);
            postMethod.addParameter("editorId", editor);
            postMethod.addParameter("creatorId", creator);
            // request body
            JSONRequestBody jsonRequestBody = new JSONRequestBody("path", path);
            jsonRequestBody.put("editorId", editor);
            jsonRequestBody.put("creatorId", creator);

            if (!template.isEmpty()) {
                postMethod.addParameter("templateId", template);
                jsonRequestBody.put("templateId", template);
            }

            // remote request
            postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
            // post request
            post = new PostMethod(client.getBaseUri() + DIRECT_ENDPOINT + JSON_FORMAT, true, jsonRequestBody.get());

            int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);
            int status = client.execute(post);

            if (status == HttpStatus.SC_OK) {
                String response = postMethod.getResponseBodyAsString();
                String response = post.getResponseBodyAsString();

                // Parse the response
                JSONObject respJSON = new JSONObject(response);
                String url = (String) respJSON.getJSONObject("ocs").getJSONObject("data").get("url");

                result = new RemoteOperationResult<>(true, postMethod);
                result = new RemoteOperationResult<>(true, post);
                result.setResultData(url);
            } else {
                result = new RemoteOperationResult<>(false, postMethod);
                client.exhaustResponse(postMethod.getResponseBodyAsStream());
                result = new RemoteOperationResult<>(false, post);
            }
        } catch (Exception e) {
            result = new RemoteOperationResult<>(e);
            Log_OC.e(TAG, "Get all direct editing information failed: " + result.getLogMessage(),
                    result.getException());
        } finally {
            if (postMethod != null) {
                postMethod.releaseConnection();
            if (post != null) {
                post.releaseConnection();
            }
        }
        return result;
+12 −17
Original line number Diff line number Diff line
@@ -28,7 +28,8 @@
package com.nextcloud.android.lib.resources.directediting;

import com.google.gson.reflect.TypeToken;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.nextcloud.common.NextcloudClient;
import com.nextcloud.operations.GetMethod;
import com.owncloud.android.lib.common.TemplateList;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
@@ -36,7 +37,6 @@ import com.owncloud.android.lib.ocs.ServerResponse;
import com.owncloud.android.lib.resources.OCSRemoteOperation;

import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;

/**
 * Get templates for an editor
@@ -44,8 +44,6 @@ import org.apache.commons.httpclient.methods.GetMethod;

public class DirectEditingObtainListOfTemplatesRemoteOperation extends OCSRemoteOperation<TemplateList> {
    private static final String TAG = DirectEditingObtainListOfTemplatesRemoteOperation.class.getSimpleName();
    private static final int SYNC_READ_TIMEOUT = 40000;
    private static final int SYNC_CONNECTION_TIMEOUT = 5000;
    private static final String DIRECT_ENDPOINT = "/ocs/v2.php/apps/files/api/v1/directEditing/templates/";

    private final String editor;
@@ -56,37 +54,34 @@ public class DirectEditingObtainListOfTemplatesRemoteOperation extends OCSRemote
        this.template = template;
    }

    protected RemoteOperationResult<TemplateList> run(OwnCloudClient client) {
    public RemoteOperationResult<TemplateList> run(NextcloudClient client) {
        RemoteOperationResult<TemplateList> result;
        GetMethod getMethod = null;
        com.nextcloud.operations.GetMethod get = null;

        try {
            getMethod = new GetMethod(client.getBaseUri() + DIRECT_ENDPOINT + editor + "/" + template + JSON_FORMAT);
            // get request
            get = new GetMethod(client.getBaseUri() + DIRECT_ENDPOINT + editor + "/" + template + JSON_FORMAT, true);

            // remote request
            getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);

            int status = client.executeMethod(getMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);
            int status = client.execute(get);

            if (status == HttpStatus.SC_OK) {
                TemplateList templateList = getServerResponse(getMethod,
                TemplateList templateList = getServerResponse(get,
                                                              new TypeToken<ServerResponse<TemplateList>>() {
                                                              })
                        .getOcs().getData();

                result = new RemoteOperationResult<>(true, getMethod);
                result = new RemoteOperationResult<>(true, get);
                result.setResultData(templateList);
            } else {
                result = new RemoteOperationResult<>(false, getMethod);
                client.exhaustResponse(getMethod.getResponseBodyAsStream());
                result = new RemoteOperationResult<>(false, get);
            }
        } catch (Exception e) {
            result = new RemoteOperationResult<>(e);
            Log_OC.e(TAG, "Get all direct editing information failed: " + result.getLogMessage(),
                     result.getException());
        } finally {
            if (getMethod != null) {
                getMethod.releaseConnection();
            if (get != null) {
                get.releaseConnection();
            }
        }
        return result;
+7 −13
Original line number Diff line number Diff line
@@ -24,15 +24,15 @@
package com.nextcloud.android.lib.resources.directediting;

import com.google.gson.reflect.TypeToken;
import com.nextcloud.common.NextcloudClient;
import com.nextcloud.operations.GetMethod;
import com.owncloud.android.lib.common.DirectEditing;
import com.owncloud.android.lib.common.OwnCloudClient;
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 org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;

/**
 * Get all editor details from direct editing
@@ -40,21 +40,16 @@ import org.apache.commons.httpclient.methods.GetMethod;

public class DirectEditingObtainRemoteOperation extends OCSRemoteOperation<DirectEditing> {
    private static final String TAG = DirectEditingObtainRemoteOperation.class.getSimpleName();
    private static final int SYNC_READ_TIMEOUT = 40000;
    private static final int SYNC_CONNECTION_TIMEOUT = 5000;
    private static final String DIRECT_ENDPOINT = "/ocs/v2.php/apps/files/api/v1/directEditing";

    protected RemoteOperationResult<DirectEditing> run(OwnCloudClient client) {
    public RemoteOperationResult<DirectEditing> run(NextcloudClient client) {
        RemoteOperationResult<DirectEditing> result;
        GetMethod getMethod = null;
        com.nextcloud.operations.GetMethod getMethod = null;

        try {
            getMethod = new GetMethod(client.getBaseUri() + DIRECT_ENDPOINT + JSON_FORMAT);
            getMethod = new GetMethod(client.getBaseUri() + DIRECT_ENDPOINT + JSON_FORMAT, true);

            // remote request
            getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);

            int status = client.executeMethod(getMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);
            int status = client.execute(getMethod);

            if (status == HttpStatus.SC_OK) {
                DirectEditing directEditing = getServerResponse(getMethod,
@@ -66,11 +61,10 @@ public class DirectEditingObtainRemoteOperation extends OCSRemoteOperation<Direc
                result.setResultData(directEditing);
            } else {
                result = new RemoteOperationResult<>(false, getMethod);
                client.exhaustResponse(getMethod.getResponseBodyAsStream());
            }
        } catch (Exception e) {
            result = new RemoteOperationResult<>(e);
            Log_OC.e(TAG, "Get all direct editing informations failed: " + result.getLogMessage(),
            Log_OC.e(TAG, "Get all direct editing information failed: " + result.getLogMessage(),
                     result.getException());
        } finally {
            if (getMethod != null) {
+19 −20
Original line number Diff line number Diff line
@@ -27,23 +27,22 @@

package com.nextcloud.android.lib.resources.directediting;

import com.owncloud.android.lib.common.OwnCloudClient;
import com.nextcloud.common.JSONRequestBody;
import com.nextcloud.common.NextcloudClient;
import com.nextcloud.operations.PostMethod;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;

import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.Utf8PostMethod;
import org.json.JSONObject;

/**
 * open file for direct editing
 */

public class DirectEditingOpenFileRemoteOperation extends RemoteOperation {
public class DirectEditingOpenFileRemoteOperation extends RemoteOperation<String> {
    private static final String TAG = DirectEditingOpenFileRemoteOperation.class.getSimpleName();
    private static final int SYNC_READ_TIMEOUT = 40000;
    private static final int SYNC_CONNECTION_TIMEOUT = 5000;
    private static final String DIRECT_ENDPOINT = "/ocs/v2.php/apps/files/api/v1/directEditing/open";

    private final String filePath;
@@ -54,19 +53,20 @@ public class DirectEditingOpenFileRemoteOperation extends RemoteOperation {
        this.editor = editor;
    }

    protected RemoteOperationResult run(OwnCloudClient client) {
        RemoteOperationResult result;
        Utf8PostMethod postMethod = null;
    public RemoteOperationResult<String> run(NextcloudClient client) {
        RemoteOperationResult<String> result;
        PostMethod postMethod = null;

        try {
            postMethod = new Utf8PostMethod(client.getBaseUri() + DIRECT_ENDPOINT + JSON_FORMAT);
            postMethod.addParameter("path", filePath);
            postMethod.addParameter("editorId", editor);
            // request body
            JSONRequestBody jsonRequestBody = new JSONRequestBody("path", filePath);
            jsonRequestBody.put("editorId", editor);

            // remote request
            postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
            // post request
            postMethod = new PostMethod(client.getBaseUri() + DIRECT_ENDPOINT + JSON_FORMAT, true,
                                        jsonRequestBody.get());

            int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);
            int status = client.execute(postMethod);

            if (status == HttpStatus.SC_OK) {
                String response = postMethod.getResponseBodyAsString();
@@ -75,15 +75,14 @@ public class DirectEditingOpenFileRemoteOperation extends RemoteOperation {
                JSONObject respJSON = new JSONObject(response);
                String url = (String) respJSON.getJSONObject("ocs").getJSONObject("data").get("url");

                result = new RemoteOperationResult(true, postMethod);
                result.setSingleData(url);
                result = new RemoteOperationResult<>(true, postMethod);
                result.setResultData(url);
            } else {
                result = new RemoteOperationResult(false, postMethod);
                client.exhaustResponse(postMethod.getResponseBodyAsStream());
                result = new RemoteOperationResult<>(false, postMethod);
            }
        } catch (Exception e) {
            result = new RemoteOperationResult(e);
            Log_OC.e(TAG, "Get all direct editing informations failed: " + result.getLogMessage(),
            result = new RemoteOperationResult<>(e);
            Log_OC.e(TAG, "Get all direct editing information failed: " + result.getLogMessage(),
                     result.getException());
        } finally {
            if (postMethod != null) {