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

Assistant Endpoints #1363

Merged
merged 50 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
c5c8901
Add GetAssistantTaskTypes
alperozturk96 Feb 26, 2024
fc9061b
Add GetAssistantTaskTypes
alperozturk96 Feb 26, 2024
a0a3d02
Add NetworkManager
alperozturk96 Feb 26, 2024
b646e3c
Add createTask
alperozturk96 Feb 26, 2024
16d4b78
Add rest operations
alperozturk96 Feb 27, 2024
5bc8920
Add NetworkManagerInterceptor
alperozturk96 Feb 28, 2024
0731045
Fix create task
alperozturk96 Feb 28, 2024
7a69750
Move repository
alperozturk96 Feb 28, 2024
01635ee
Use OCSRemoteOperation for GetTaskTypes
alperozturk96 Feb 28, 2024
cf4cec6
Add CreateTaskRemoteOperation
alperozturk96 Feb 28, 2024
08ce459
Add GetTaskListRemoteOperation
alperozturk96 Feb 28, 2024
a77d32e
add NC assistant
tobiasKaminsky Feb 28, 2024
4892fd1
On NC27 stable: use 1.0.2 of NC Assistant
tobiasKaminsky Feb 29, 2024
638da62
fix build of NC Assistant
tobiasKaminsky Feb 29, 2024
bd60f10
chown faster
tobiasKaminsky Feb 29, 2024
cce68b1
assistant on stable 27
tobiasKaminsky Feb 29, 2024
ab8debc
typo
tobiasKaminsky Feb 29, 2024
3862a8c
sign
tobiasKaminsky Feb 29, 2024
79690cc
npm
tobiasKaminsky Feb 29, 2024
09e1a02
sign
tobiasKaminsky Feb 29, 2024
ee7f0ec
Add GetAssistantTaskTypes
alperozturk96 Feb 26, 2024
fb57390
Add GetAssistantTaskTypes
alperozturk96 Feb 26, 2024
129f7c5
Add NetworkManager
alperozturk96 Feb 26, 2024
905e2c2
Add createTask
alperozturk96 Feb 26, 2024
644d0e1
Add rest operations
alperozturk96 Feb 27, 2024
a852354
Add NetworkManagerInterceptor
alperozturk96 Feb 28, 2024
4d272ad
Fix create task
alperozturk96 Feb 28, 2024
b58eeb3
Move repository
alperozturk96 Feb 28, 2024
5a23cb6
Use OCSRemoteOperation for GetTaskTypes
alperozturk96 Feb 28, 2024
7a52d15
Add CreateTaskRemoteOperation
alperozturk96 Feb 28, 2024
bceb216
Add GetTaskListRemoteOperation
alperozturk96 Feb 28, 2024
b329502
Add DeleteTaskRemoteOperation
alperozturk96 Feb 29, 2024
68af3d1
Add DeleteTaskRemoteOperation
alperozturk96 Feb 29, 2024
cf7b3df
Add Nullable fields
alperozturk96 Feb 29, 2024
2dbff88
Merge remote-tracking branch 'origin/feature/assistant-endpoints' int…
alperozturk96 Feb 29, 2024
d0cf269
Add Nullable fields
alperozturk96 Feb 29, 2024
dc0b76d
Add Nullable fields
alperozturk96 Feb 29, 2024
b756551
Add filter task type
alperozturk96 Feb 29, 2024
5abbc3c
Fix kotlin spotlesscheck
alperozturk96 Feb 29, 2024
113c9ff
Update copyrights
alperozturk96 Feb 29, 2024
e50667e
Solve git conflicts
alperozturk96 Mar 1, 2024
780c18f
Solve git conflicts
alperozturk96 Mar 1, 2024
060f9e5
Add Jetpack Compose ColorScheme
alperozturk96 Mar 1, 2024
ac43a6a
Revert dependency versions
alperozturk96 Mar 1, 2024
d29846d
add IT for NC Assistant
tobiasKaminsky Mar 1, 2024
14c6bcf
update drone
tobiasKaminsky Mar 4, 2024
1d546d0
fix upload report
tobiasKaminsky Mar 4, 2024
02e6205
run only on NC28+
tobiasKaminsky Mar 4, 2024
c757437
update license
tobiasKaminsky Mar 4, 2024
570caa3
fix spotless
tobiasKaminsky Mar 4, 2024
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 @@ -33,6 +33,7 @@

import androidx.annotation.NonNull;

import com.google.gson.Gson;
import com.nextcloud.common.NextcloudClient;
import com.nextcloud.common.User;
import com.owncloud.android.lib.common.OwnCloudAccount;
Expand All @@ -55,6 +56,7 @@
*/
public abstract class RemoteOperation<T> implements Runnable {

public final Gson gson = new Gson();
private static final String TAG = RemoteOperation.class.getSimpleName();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

package com.owncloud.android.lib.resources;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
Expand All @@ -48,21 +47,13 @@ public abstract class OCSRemoteOperation<T> extends RemoteOperation<T> {
@Deprecated
public <T> T getServerResponse(HttpMethodBase method, TypeToken<T> type) throws IOException {
String response = method.getResponseBodyAsString();
JsonParser parser = new JsonParser();
JsonElement element = parser.parse(response);

Gson gson = new Gson();

JsonElement element = JsonParser.parseString(response);
return gson.fromJson(element, type.getType());
}

public <T> T getServerResponse(OkHttpMethodBase method, TypeToken<T> type) {
String response = method.getResponseBodyAsString();
JsonParser parser = new JsonParser();
JsonElement element = parser.parse(response);

Gson gson = new Gson();

JsonElement element = JsonParser.parseString(response);
return gson.fromJson(element, type.getType());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
alperozturk96 marked this conversation as resolved.
Show resolved Hide resolved
* Nextcloud Android client application
*
* @author Alper Ozturk
* Copyright (C) 2024 Alper Ozturk
* Copyright (C) 2024 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.owncloud.android.lib.resources.assistant

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 okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody.Companion.toRequestBody
import org.apache.commons.httpclient.HttpStatus

class CreateTaskRemoteOperation(private val input: String, private val type: String) :
RemoteOperation<Void>() {
override fun run(client: NextcloudClient): RemoteOperationResult<Void> {
val requestBody = hashMapOf(
"input" to input,
"type" to type,
"appId" to "assistant",
"identifier" to ""
)

val json = gson.toJson(requestBody)

val request = json.toRequestBody("application/json".toMediaTypeOrNull())

val postMethod = PostMethod(client.baseUri.toString() + TAG_URL, true, request)

val status = postMethod.execute(client)

return if (status == HttpStatus.SC_OK) {
RemoteOperationResult<Void>(true, postMethod)
} else {
RemoteOperationResult<Void>(false, postMethod)
}
}

companion object {
const val TAG_URL = "/ocs/v2.php/textprocessing/schedule"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Nextcloud Android client application
*
* @author Alper Ozturk
* Copyright (C) 2024 Alper Ozturk
* Copyright (C) 2024 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.owncloud.android.lib.resources.assistant

import com.google.gson.reflect.TypeToken
import com.nextcloud.common.NextcloudClient
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.assistant.model.TaskList
import org.apache.commons.httpclient.HttpStatus

class GetTaskListRemoteOperation(private val appId: String) : OCSRemoteOperation<TaskList>() {
@Suppress("TooGenericExceptionCaught")
override fun run(client: NextcloudClient): RemoteOperationResult<TaskList> {
var result: RemoteOperationResult<TaskList>
var getMethod: GetMethod? = null
try {
getMethod =
GetMethod(client.baseUri.toString() + DIRECT_ENDPOINT + appId + JSON_FORMAT, true)
val status = client.execute(getMethod)
if (status == HttpStatus.SC_OK) {
val taskTypes: TaskList =
getServerResponse(
getMethod,
object : TypeToken<ServerResponse<TaskList>>() {}
)
.ocs.data
result = RemoteOperationResult(true, getMethod)
result.setResultData(taskTypes)
} else {
result = RemoteOperationResult(false, getMethod)
}
} catch (e: Exception) {
result = RemoteOperationResult(e)
Log_OC.e(
TAG,
"Get task list for user " + " failed: " + result.logMessage,
result.exception
)
} finally {
getMethod?.releaseConnection()
}
return result
}

companion object {
private val TAG = GetTaskTypesRemoteOperation::class.java.simpleName
private const val DIRECT_ENDPOINT = "/ocs/v2.php/textprocessing/tasks/app/"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Nextcloud Android client application
*
* @author Alper Ozturk
* Copyright (C) 2024 Alper Ozturk
* Copyright (C) 2024 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.owncloud.android.lib.resources.assistant

import com.google.gson.reflect.TypeToken
import com.nextcloud.common.NextcloudClient
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.assistant.model.TaskTypes
import org.apache.commons.httpclient.HttpStatus

class GetTaskTypesRemoteOperation : OCSRemoteOperation<TaskTypes>() {
@Suppress("TooGenericExceptionCaught")
override fun run(client: NextcloudClient): RemoteOperationResult<TaskTypes> {
var result: RemoteOperationResult<TaskTypes>
var getMethod: GetMethod? = null
try {
getMethod =
GetMethod(client.baseUri.toString() + DIRECT_ENDPOINT + JSON_FORMAT, true)
val status = client.execute(getMethod)
if (status == HttpStatus.SC_OK) {
val taskTypes: TaskTypes =
getServerResponse(
getMethod,
object : TypeToken<ServerResponse<TaskTypes>>() {}
)
.ocs.data
result = RemoteOperationResult(true, getMethod)
result.setResultData(taskTypes)
} else {
result = RemoteOperationResult(false, getMethod)
}
} catch (e: Exception) {
result = RemoteOperationResult(e)
Log_OC.e(
TAG,
"Get task types for user " + " failed: " + result.logMessage,
result.exception
)
} finally {
getMethod?.releaseConnection()
}
return result
}

companion object {
private val TAG = GetTaskTypesRemoteOperation::class.java.simpleName
private const val DIRECT_ENDPOINT = "/ocs/v2.php/textprocessing/tasktypes"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Nextcloud Android client application
*
* @author Alper Ozturk
* Copyright (C) 2024 Alper Ozturk
* Copyright (C) 2024 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.owncloud.android.lib.resources.assistant.model

data class TaskList (
val tasks: List<Task>
)

data class Task (
val id: Long,
val type: String,
val status: Long,
val userId: String,
val appId: String,
val input: String,
val output: String,
val identifier: String,
val completionExpectedAt: String? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Nextcloud Android client application
*
* @author Alper Ozturk
* Copyright (C) 2024 Alper Ozturk
* Copyright (C) 2024 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.owncloud.android.lib.resources.assistant.model

data class TaskTypes (
val types: List<TaskType>
)

data class TaskType(
val id: String,
val name: String,
val description: String
)
Loading