Skip to content

Commit

Permalink
Deprecate OwncloudClient - DirectEditing
Browse files Browse the repository at this point in the history
Signed-off-by: ZetaTom <70907959+ZetaTom@users.noreply.github.com>
  • Loading branch information
ZetaTom committed Dec 20, 2023
1 parent d799954 commit 5b5eab3
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -42,8 +43,6 @@

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;
Expand All @@ -65,45 +64,44 @@ public DirectEditingCreateFileRemoteOperation(String path, String editor, String
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,22 @@
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;
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
*/

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;
Expand All @@ -56,37 +54,34 @@ public DirectEditingObtainListOfTemplatesRemoteOperation(String editor, String t
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,32 @@
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
*/

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,
Expand All @@ -66,11 +61,10 @@ protected RemoteOperationResult<DirectEditing> run(OwnCloudClient client) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -54,19 +53,20 @@ public DirectEditingOpenFileRemoteOperation(String filePath, String editor) {
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();
Expand All @@ -75,15 +75,14 @@ protected RemoteOperationResult run(OwnCloudClient client) {
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) {
Expand Down

0 comments on commit 5b5eab3

Please sign in to comment.