From efc6e412964ff9bfd8b5c923573f404d2beb4c1b Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 3 Dec 2024 11:22:46 +0100 Subject: [PATCH 01/16] update api Signed-off-by: alperozturk --- .../assistant/GetTaskListRemoteOperation.kt | 4 ++-- .../lib/resources/assistant/model/TaskList.kt | 21 ++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskListRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskListRemoteOperation.kt index 9f7501fbb..ebc930ebf 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskListRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskListRemoteOperation.kt @@ -25,7 +25,7 @@ class GetTaskListRemoteOperation(private val appId: String) : OCSRemoteOperation var getMethod: GetMethod? = null try { getMethod = - GetMethod(client.baseUri.toString() + DIRECT_ENDPOINT + appId + JSON_FORMAT, true) + GetMethod(client.baseUri.toString() + DIRECT_ENDPOINT + JSON_FORMAT, true) val status = client.execute(getMethod) if (status == HttpStatus.SC_OK) { val taskTypes: TaskList? = @@ -53,6 +53,6 @@ class GetTaskListRemoteOperation(private val appId: String) : OCSRemoteOperation companion object { private val TAG = GetTaskTypesRemoteOperation::class.java.simpleName - private const val DIRECT_ENDPOINT = "/ocs/v2.php/textprocessing/tasks/app/" + private const val DIRECT_ENDPOINT = "/ocs/v2.php/apps/assistant/api/v1/tasks" } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskList.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskList.kt index aeefd07d4..bffadbe87 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskList.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskList.kt @@ -15,11 +15,22 @@ data class TaskList( data class Task( val id: Long, val type: String?, - val status: Long?, + val status: String?, val userId: String?, val appId: String?, - val input: String?, - val output: String?, - val identifier: String?, - val completionExpectedAt: String? = null + val input: TaskInput?, + val output: TaskOutput?, + val completionExpectedAt: Int? = null, + var progress: Int? = null, + val lastUpdated: Int? = null, + val scheduledAt: Int? = null, + val endedAt: Int? = null +) + +data class TaskInput ( + var input: String? = null +) + +data class TaskOutput ( + var output : String? = null ) From a6481fadfddb468d558afbc55cd1096370173f6e Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 3 Dec 2024 13:19:48 +0100 Subject: [PATCH 02/16] Use task processing API Signed-off-by: alperozturk --- .../assistant/CreateTaskRemoteOperation.kt | 2 +- .../assistant/DeleteTaskRemoteOperation.kt | 3 +- .../assistant/GetTaskListRemoteOperation.kt | 7 ++-- .../assistant/GetTaskTypesRemoteOperation.kt | 2 +- .../resources/assistant/model/TaskTypes.kt | 36 +++++++++++++++---- 5 files changed, 36 insertions(+), 14 deletions(-) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/CreateTaskRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/CreateTaskRemoteOperation.kt index e82193aa5..220fdbf1a 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/CreateTaskRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/CreateTaskRemoteOperation.kt @@ -43,6 +43,6 @@ class CreateTaskRemoteOperation(private val input: String, private val type: Str } companion object { - const val TAG_URL = "/ocs/v2.php/textprocessing/schedule" + const val TAG_URL = "/ocs/v2.php/taskprocessing/schedule" } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/DeleteTaskRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/DeleteTaskRemoteOperation.kt index cdadde92f..930989276 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/DeleteTaskRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/DeleteTaskRemoteOperation.kt @@ -41,7 +41,6 @@ class DeleteTaskRemoteOperation(private val appId: Long) : RemoteOperation companion object { private val TAG = DeletePrivateKeyRemoteOperation::class.java.simpleName - private const val DIRECT_ENDPOINT = - "/ocs/v2.php/textprocessing/task/" + private const val DIRECT_ENDPOINT = "/ocs/v2.php/taskprocessing/task/" } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskListRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskListRemoteOperation.kt index ebc930ebf..02841eebc 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskListRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskListRemoteOperation.kt @@ -17,15 +17,14 @@ 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() { +class GetTaskListRemoteOperation(private val taskType: String) : OCSRemoteOperation() { @Suppress("TooGenericExceptionCaught") override fun run(client: NextcloudClient): RemoteOperationResult { var result: RemoteOperationResult var getMethod: GetMethod? = null try { getMethod = - GetMethod(client.baseUri.toString() + DIRECT_ENDPOINT + JSON_FORMAT, true) + GetMethod(client.baseUri.toString() + DIRECT_ENDPOINT + taskType + "&format=json", true) val status = client.execute(getMethod) if (status == HttpStatus.SC_OK) { val taskTypes: TaskList? = @@ -53,6 +52,6 @@ class GetTaskListRemoteOperation(private val appId: String) : OCSRemoteOperation companion object { private val TAG = GetTaskTypesRemoteOperation::class.java.simpleName - private const val DIRECT_ENDPOINT = "/ocs/v2.php/apps/assistant/api/v1/tasks" + private const val DIRECT_ENDPOINT = "/ocs/v2.php/taskprocessing/tasks?taskType=" } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskTypesRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskTypesRemoteOperation.kt index aad05a3bc..103299f72 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskTypesRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskTypesRemoteOperation.kt @@ -53,6 +53,6 @@ class GetTaskTypesRemoteOperation : OCSRemoteOperation() { companion object { private val TAG = GetTaskTypesRemoteOperation::class.java.simpleName - private const val DIRECT_ENDPOINT = "/ocs/v2.php/textprocessing/tasktypes" + private const val DIRECT_ENDPOINT = "/ocs/v2.php/taskprocessing/tasktypes" } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt index 5a4174b9f..66f55e483 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt @@ -8,12 +8,36 @@ package com.owncloud.android.lib.resources.assistant.model -data class TaskTypes( - var types: List -) +import com.google.gson.annotations.SerializedName +data class TaskTypes(val types: TaskType) data class TaskType( - val id: String?, - val name: String?, - val description: String? + @SerializedName("core:text2text") + val coreText2text: CoreText2text, + @SerializedName("core:text2text:topics") + val coreText2textTopics: CoreText2textTopics, + @SerializedName("core:text2text:headline") + val coreText2textHeadline: CoreText2textHeadline, + @SerializedName("core:text2text:summary") + val coreText2textSummary: CoreText2textSummary, + @SerializedName("core:text2text:translate") + val coreText2textTranslate: CoreText2textTranslate, + @SerializedName("core:text2image") + val coreText2image: CoreText2image, + @SerializedName("core:audio2text") + val coreAudio2text: CoreAudio2text, + @SerializedName("core:contextwrite") + val coreContextwrite: CoreContextwrite, + @SerializedName("context_chat:context_chat") + val contextChatContextChat: ContextChatContextChat ) + +data class CoreText2text(val name: String, val description: String) +data class CoreText2textTopics(val name: String, val description: String) +data class CoreText2textHeadline(val name: String, val description: String) +data class CoreText2textSummary(val name: String, val description: String) +data class CoreText2textTranslate(val name: String, val description: String) +data class CoreText2image(val name: String, val description: String) +data class CoreAudio2text(val name: String, val description: String) +data class CoreContextwrite(val name: String, val description: String) +data class ContextChatContextChat(val name: String, val description: String) From 7c403e60cda7a3264bbcc66a9a3fadbe15b67dd4 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 3 Dec 2024 13:20:41 +0100 Subject: [PATCH 03/16] Use task processing API Signed-off-by: alperozturk --- .../owncloud/android/lib/resources/assistant/model/TaskTypes.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt index 66f55e483..8434dbbec 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt @@ -9,6 +9,7 @@ package com.owncloud.android.lib.resources.assistant.model import com.google.gson.annotations.SerializedName + data class TaskTypes(val types: TaskType) data class TaskType( From 729a1df99ff74c348f76a3064a66d3e5fbe04222 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 3 Dec 2024 13:36:17 +0100 Subject: [PATCH 04/16] only use text context Signed-off-by: alperozturk --- .../android/lib/resources/assistant/model/TaskTypes.kt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt index 8434dbbec..4e785cc96 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt @@ -23,10 +23,6 @@ data class TaskType( val coreText2textSummary: CoreText2textSummary, @SerializedName("core:text2text:translate") val coreText2textTranslate: CoreText2textTranslate, - @SerializedName("core:text2image") - val coreText2image: CoreText2image, - @SerializedName("core:audio2text") - val coreAudio2text: CoreAudio2text, @SerializedName("core:contextwrite") val coreContextwrite: CoreContextwrite, @SerializedName("context_chat:context_chat") @@ -38,7 +34,5 @@ data class CoreText2textTopics(val name: String, val description: String) data class CoreText2textHeadline(val name: String, val description: String) data class CoreText2textSummary(val name: String, val description: String) data class CoreText2textTranslate(val name: String, val description: String) -data class CoreText2image(val name: String, val description: String) -data class CoreAudio2text(val name: String, val description: String) data class CoreContextwrite(val name: String, val description: String) data class ContextChatContextChat(val name: String, val description: String) From 13af03d2238e93e99523d2763c8887f903d02eea Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 3 Dec 2024 14:50:48 +0100 Subject: [PATCH 05/16] fix add operation Signed-off-by: alperozturk --- .../assistant/CreateTaskRemoteOperation.kt | 7 ++-- .../resources/assistant/model/TaskTypes.kt | 32 +++++++++---------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/CreateTaskRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/CreateTaskRemoteOperation.kt index 220fdbf1a..9e8dd5309 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/CreateTaskRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/CreateTaskRemoteOperation.kt @@ -18,13 +18,16 @@ import org.apache.commons.httpclient.HttpStatus class CreateTaskRemoteOperation(private val input: String, private val type: String) : RemoteOperation() { + override fun run(client: NextcloudClient): RemoteOperationResult { + val inputField = hashMapOf("input" to input) + val requestBody = hashMapOf( - "input" to input, + "input" to inputField, "type" to type, "appId" to "assistant", - "identifier" to "" + "customId" to "" ) val json = gson.toJson(requestBody) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt index 4e785cc96..4db909304 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt @@ -10,29 +10,27 @@ package com.owncloud.android.lib.resources.assistant.model import com.google.gson.annotations.SerializedName +enum class TaskIds(val id: String) { + GenerateText("core:text2text"), + ExtractTopics("core:text2text:topics"), + GenerateHeadline("core:text2text:headline"), + Summarize("core:text2text:summary"), +} + data class TaskTypes(val types: TaskType) data class TaskType( @SerializedName("core:text2text") - val coreText2text: CoreText2text, + val generateText: GenerateText, @SerializedName("core:text2text:topics") - val coreText2textTopics: CoreText2textTopics, + val extractTopics: ExtractTopics, @SerializedName("core:text2text:headline") - val coreText2textHeadline: CoreText2textHeadline, + val generateHeadline: GenerateHeadline, @SerializedName("core:text2text:summary") - val coreText2textSummary: CoreText2textSummary, - @SerializedName("core:text2text:translate") - val coreText2textTranslate: CoreText2textTranslate, - @SerializedName("core:contextwrite") - val coreContextwrite: CoreContextwrite, - @SerializedName("context_chat:context_chat") - val contextChatContextChat: ContextChatContextChat + val summarize: Summarize ) -data class CoreText2text(val name: String, val description: String) -data class CoreText2textTopics(val name: String, val description: String) -data class CoreText2textHeadline(val name: String, val description: String) -data class CoreText2textSummary(val name: String, val description: String) -data class CoreText2textTranslate(val name: String, val description: String) -data class CoreContextwrite(val name: String, val description: String) -data class ContextChatContextChat(val name: String, val description: String) +data class GenerateText(val name: String, val description: String) +data class ExtractTopics(val name: String, val description: String) +data class GenerateHeadline(val name: String, val description: String) +data class Summarize(val name: String, val description: String) From 272b47f348fc5d2c2a6dcc18c5a4afeac1e495f5 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 3 Dec 2024 16:04:37 +0100 Subject: [PATCH 06/16] Fix kotlin spotless check Signed-off-by: alperozturk --- .../lib/resources/assistant/CreateTaskRemoteOperation.kt | 1 - .../lib/resources/assistant/GetTaskListRemoteOperation.kt | 1 + .../android/lib/resources/assistant/model/TaskList.kt | 6 +++--- .../android/lib/resources/assistant/model/TaskTypes.kt | 5 ++++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/CreateTaskRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/CreateTaskRemoteOperation.kt index 9e8dd5309..72f566dd5 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/CreateTaskRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/CreateTaskRemoteOperation.kt @@ -18,7 +18,6 @@ import org.apache.commons.httpclient.HttpStatus class CreateTaskRemoteOperation(private val input: String, private val type: String) : RemoteOperation() { - override fun run(client: NextcloudClient): RemoteOperationResult { val inputField = hashMapOf("input" to input) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskListRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskListRemoteOperation.kt index 02841eebc..d0ed14d2d 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskListRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskListRemoteOperation.kt @@ -17,6 +17,7 @@ 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 taskType: String) : OCSRemoteOperation() { @Suppress("TooGenericExceptionCaught") override fun run(client: NextcloudClient): RemoteOperationResult { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskList.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskList.kt index bffadbe87..75594d032 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskList.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskList.kt @@ -27,10 +27,10 @@ data class Task( val endedAt: Int? = null ) -data class TaskInput ( +data class TaskInput( var input: String? = null ) -data class TaskOutput ( - var output : String? = null +data class TaskOutput( + var output: String? = null ) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt index 4db909304..de88b6fa6 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt @@ -14,7 +14,7 @@ enum class TaskIds(val id: String) { GenerateText("core:text2text"), ExtractTopics("core:text2text:topics"), GenerateHeadline("core:text2text:headline"), - Summarize("core:text2text:summary"), + Summarize("core:text2text:summary") } data class TaskTypes(val types: TaskType) @@ -31,6 +31,9 @@ data class TaskType( ) data class GenerateText(val name: String, val description: String) + data class ExtractTopics(val name: String, val description: String) + data class GenerateHeadline(val name: String, val description: String) + data class Summarize(val name: String, val description: String) From c0d0affe3b84b29745acf2967c1ed3e0b787a9ff Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 4 Dec 2024 10:21:14 +0100 Subject: [PATCH 07/16] Use task types for create operation Signed-off-by: alperozturk --- .../assistant/CreateTaskRemoteOperation.kt | 5 ++- .../resources/assistant/model/TaskTypes.kt | 41 ++++++++++--------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/CreateTaskRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/CreateTaskRemoteOperation.kt index 72f566dd5..efb877227 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/CreateTaskRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/CreateTaskRemoteOperation.kt @@ -12,11 +12,12 @@ 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.resources.assistant.model.TaskTypeData 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) : +class CreateTaskRemoteOperation(private val input: String, private val taskType: TaskTypeData) : RemoteOperation() { override fun run(client: NextcloudClient): RemoteOperationResult { val inputField = hashMapOf("input" to input) @@ -24,7 +25,7 @@ class CreateTaskRemoteOperation(private val input: String, private val type: Str val requestBody = hashMapOf( "input" to inputField, - "type" to type, + "type" to taskType.id, "appId" to "assistant", "customId" to "" ) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt index de88b6fa6..719efb065 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt @@ -10,30 +10,31 @@ package com.owncloud.android.lib.resources.assistant.model import com.google.gson.annotations.SerializedName -enum class TaskIds(val id: String) { - GenerateText("core:text2text"), - ExtractTopics("core:text2text:topics"), - GenerateHeadline("core:text2text:headline"), - Summarize("core:text2text:summary") -} +private const val generateTextId = "core:text2text" +private const val extractTopicsId = "core:text2text:topics" +private const val generateHeadlineId = "core:text2text:headline" +private const val summarizeId = "core:text2text:summary" data class TaskTypes(val types: TaskType) data class TaskType( - @SerializedName("core:text2text") - val generateText: GenerateText, - @SerializedName("core:text2text:topics") - val extractTopics: ExtractTopics, - @SerializedName("core:text2text:headline") - val generateHeadline: GenerateHeadline, - @SerializedName("core:text2text:summary") - val summarize: Summarize + @SerializedName(generateTextId) + val generateText: TaskTypeData, + @SerializedName(extractTopicsId) + val extractTopics: TaskTypeData, + @SerializedName(generateHeadlineId) + val generateHeadline: TaskTypeData, + @SerializedName(summarizeId) + val summarize: TaskTypeData ) -data class GenerateText(val name: String, val description: String) - -data class ExtractTopics(val name: String, val description: String) +data class TaskTypeData(val id: String?, val name: String?, val description: String?) -data class GenerateHeadline(val name: String, val description: String) - -data class Summarize(val name: String, val description: String) +fun TaskTypes.toTaskTypeDataList(): List { + return listOf( + types.generateText to generateTextId, + types.extractTopics to extractTopicsId, + types.generateHeadline to generateHeadlineId, + types.summarize to summarizeId + ).map { (taskData, id) -> taskData.copy(id = taskData.id ?: id) } +} From e4e341c56a1b3e2a2de5a6dec0cd406dea36b0c2 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 4 Dec 2024 10:50:21 +0100 Subject: [PATCH 08/16] use response key for id Signed-off-by: alperozturk --- .../assistant/GetTaskTypesRemoteOperation.kt | 30 ++++++++++--- .../resources/assistant/model/TaskTypes.kt | 43 ++++++++----------- 2 files changed, 41 insertions(+), 32 deletions(-) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskTypesRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskTypesRemoteOperation.kt index 103299f72..1da85c5f2 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskTypesRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskTypesRemoteOperation.kt @@ -15,26 +15,44 @@ 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.TaskTypeData import com.owncloud.android.lib.resources.assistant.model.TaskTypes import org.apache.commons.httpclient.HttpStatus -class GetTaskTypesRemoteOperation : OCSRemoteOperation() { +class GetTaskTypesRemoteOperation : OCSRemoteOperation>() { + + private val supportedTaskType = "Text" + @Suppress("TooGenericExceptionCaught") - override fun run(client: NextcloudClient): RemoteOperationResult { - var result: RemoteOperationResult + override fun run(client: NextcloudClient): RemoteOperationResult> { + var result: RemoteOperationResult> 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? = + val response = getServerResponse( getMethod, object : TypeToken>() {} - )?.ocs?.data + )?.ocs?.data?.types + + val taskTypeList = response?.map { (key, value) -> + value.copy(id = value.id ?: key) + } + + val supportedTaskTypeList = taskTypeList?.filter { taskType -> + taskType.inputShape?.any { inputShape -> + inputShape.type == supportedTaskType + } == true && taskType.outputShape?.any { outputShape -> + outputShape.type == supportedTaskType + } == true + } + result = RemoteOperationResult(true, getMethod) - result.setResultData(taskTypes) + result.setResultData(supportedTaskTypeList) } else { result = RemoteOperationResult(false, getMethod) } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt index 719efb065..86fd56a8a 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt @@ -8,33 +8,24 @@ package com.owncloud.android.lib.resources.assistant.model -import com.google.gson.annotations.SerializedName +data class TaskTypes(val types: Map) -private const val generateTextId = "core:text2text" -private const val extractTopicsId = "core:text2text:topics" -private const val generateHeadlineId = "core:text2text:headline" -private const val summarizeId = "core:text2text:summary" - -data class TaskTypes(val types: TaskType) - -data class TaskType( - @SerializedName(generateTextId) - val generateText: TaskTypeData, - @SerializedName(extractTopicsId) - val extractTopics: TaskTypeData, - @SerializedName(generateHeadlineId) - val generateHeadline: TaskTypeData, - @SerializedName(summarizeId) - val summarize: TaskTypeData +data class TaskTypeData( + val id: String?, + val name: String?, + val description: String?, + val inputShape: List?, + val outputShape: List? ) -data class TaskTypeData(val id: String?, val name: String?, val description: String?) +data class TaskInputShape( + val name: String?, + val description: String?, + val type: String?, +) -fun TaskTypes.toTaskTypeDataList(): List { - return listOf( - types.generateText to generateTextId, - types.extractTopics to extractTopicsId, - types.generateHeadline to generateHeadlineId, - types.summarize to summarizeId - ).map { (taskData, id) -> taskData.copy(id = taskData.id ?: id) } -} +data class TaskOutputShape( + val name: String?, + val description: String?, + val type: String?, +) From 34f2c801e44cea2c5655066106f211abafe22b66 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 12 Dec 2024 10:17:24 +0100 Subject: [PATCH 09/16] fix test Signed-off-by: alperozturk --- .../lib/resources/assistant/AssistantIT.kt | 35 ++++++++++++++++--- .../assistant/GetTaskTypesRemoteOperation.kt | 23 ++++++------ .../resources/assistant/model/TaskTypes.kt | 6 ++-- 3 files changed, 45 insertions(+), 19 deletions(-) diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/AssistantIT.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/AssistantIT.kt index 33213bac0..eddb7bc81 100644 --- a/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/AssistantIT.kt +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/AssistantIT.kt @@ -9,6 +9,9 @@ package com.owncloud.android.lib.resources.assistant import com.owncloud.android.AbstractIT +import com.owncloud.android.lib.resources.assistant.model.TaskInputShape +import com.owncloud.android.lib.resources.assistant.model.TaskOutputShape +import com.owncloud.android.lib.resources.assistant.model.TaskTypeData import com.owncloud.android.lib.resources.status.NextcloudVersion import junit.framework.TestCase.assertEquals import junit.framework.TestCase.assertTrue @@ -21,12 +24,34 @@ class AssistantIT : AbstractIT() { testOnlyOnServer(NextcloudVersion.nextcloud_28) } + private fun getTaskType(): TaskTypeData { + return TaskTypeData( + "core:text2text", + "Free text to text prompt", + "Runs an arbitrary prompt through a language model that returns a reply", + listOf( + TaskInputShape( + "Prompt", + "Describe a task that you want the assistant to do or ask a question", + "Text" + ) + ), + listOf( + TaskOutputShape( + "Generated reply", + "The generated text from the assistant", + "Text" + ) + ) + ) + } + @Test fun testGetTaskTypes() { val result = GetTaskTypesRemoteOperation().execute(nextcloudClient) assertTrue(result.isSuccess) - val taskTypes = result.resultData.types + val taskTypes = result.resultData assertTrue(taskTypes.isNotEmpty()) } @@ -38,8 +63,8 @@ class AssistantIT : AbstractIT() { // create one task val input = "Give me some random output for test purpose" - val type = "OCP\\TextProcessing\\FreePromptTaskType" - assertTrue(CreateTaskRemoteOperation(input, type).execute(nextcloudClient).isSuccess) + val taskType = getTaskType() + assertTrue(CreateTaskRemoteOperation(input, taskType).execute(nextcloudClient).isSuccess) result = GetTaskListRemoteOperation("assistant").execute(nextcloudClient) assertTrue(result.isSuccess) @@ -52,8 +77,8 @@ class AssistantIT : AbstractIT() { fun testDeleteTask() { // create one task val input = "Give me some random output for test purpose" - val type = "OCP\\TextProcessing\\FreePromptTaskType" - assertTrue(CreateTaskRemoteOperation(input, type).execute(nextcloudClient).isSuccess) + val taskType = getTaskType() + assertTrue(CreateTaskRemoteOperation(input, taskType).execute(nextcloudClient).isSuccess) var result = GetTaskListRemoteOperation("assistant").execute(nextcloudClient) assertTrue(result.isSuccess) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskTypesRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskTypesRemoteOperation.kt index 1da85c5f2..916fc4b4a 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskTypesRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskTypesRemoteOperation.kt @@ -20,7 +20,6 @@ import com.owncloud.android.lib.resources.assistant.model.TaskTypes import org.apache.commons.httpclient.HttpStatus class GetTaskTypesRemoteOperation : OCSRemoteOperation>() { - private val supportedTaskType = "Text" @Suppress("TooGenericExceptionCaught") @@ -39,17 +38,19 @@ class GetTaskTypesRemoteOperation : OCSRemoteOperation>() { object : TypeToken>() {} )?.ocs?.data?.types - val taskTypeList = response?.map { (key, value) -> - value.copy(id = value.id ?: key) - } + val taskTypeList = + response?.map { (key, value) -> + value.copy(id = value.id ?: key) + } - val supportedTaskTypeList = taskTypeList?.filter { taskType -> - taskType.inputShape?.any { inputShape -> - inputShape.type == supportedTaskType - } == true && taskType.outputShape?.any { outputShape -> - outputShape.type == supportedTaskType - } == true - } + val supportedTaskTypeList = + taskTypeList?.filter { taskType -> + taskType.inputShape?.any { inputShape -> + inputShape.type == supportedTaskType + } == true && taskType.outputShape?.any { outputShape -> + outputShape.type == supportedTaskType + } == true + } result = RemoteOperationResult(true, getMethod) result.setResultData(supportedTaskTypeList) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt index 86fd56a8a..f3356e0d4 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt @@ -8,7 +8,7 @@ package com.owncloud.android.lib.resources.assistant.model -data class TaskTypes(val types: Map) +data class TaskTypes(val types: Map) data class TaskTypeData( val id: String?, @@ -21,11 +21,11 @@ data class TaskTypeData( data class TaskInputShape( val name: String?, val description: String?, - val type: String?, + val type: String? ) data class TaskOutputShape( val name: String?, val description: String?, - val type: String?, + val type: String? ) From 1053e258e69effa40660750bdbaa33093ef8e1e7 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 12 Dec 2024 11:10:52 +0100 Subject: [PATCH 10/16] use correct nx version Signed-off-by: alperozturk --- .../com/owncloud/android/lib/resources/assistant/AssistantIT.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/AssistantIT.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/AssistantIT.kt index eddb7bc81..2cb5086d7 100644 --- a/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/AssistantIT.kt +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/AssistantIT.kt @@ -21,7 +21,7 @@ import org.junit.Test class AssistantIT : AbstractIT() { @Before fun before() { - testOnlyOnServer(NextcloudVersion.nextcloud_28) + testOnlyOnServer(NextcloudVersion.nextcloud_30) } private fun getTaskType(): TaskTypeData { From 808861fb4d1e68b155f9b98339f3ff60d9f208e0 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 12 Dec 2024 11:12:48 +0100 Subject: [PATCH 11/16] use correct task type Signed-off-by: alperozturk --- .../android/lib/resources/assistant/AssistantIT.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/AssistantIT.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/AssistantIT.kt index 2cb5086d7..e18f5756d 100644 --- a/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/AssistantIT.kt +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/AssistantIT.kt @@ -57,7 +57,8 @@ class AssistantIT : AbstractIT() { @Test fun testGetTaskList() { - var result = GetTaskListRemoteOperation("assistant").execute(nextcloudClient) + val selectedTaskType = "core:text2text" + var result = GetTaskListRemoteOperation(selectedTaskType).execute(nextcloudClient) assertTrue(result.isSuccess) assertTrue(result.resultData.tasks.isEmpty()) @@ -66,7 +67,7 @@ class AssistantIT : AbstractIT() { val taskType = getTaskType() assertTrue(CreateTaskRemoteOperation(input, taskType).execute(nextcloudClient).isSuccess) - result = GetTaskListRemoteOperation("assistant").execute(nextcloudClient) + result = GetTaskListRemoteOperation(selectedTaskType).execute(nextcloudClient) assertTrue(result.isSuccess) val taskList = result.resultData.tasks @@ -78,9 +79,10 @@ class AssistantIT : AbstractIT() { // create one task val input = "Give me some random output for test purpose" val taskType = getTaskType() + val selectedTaskType = "core:text2text" assertTrue(CreateTaskRemoteOperation(input, taskType).execute(nextcloudClient).isSuccess) - var result = GetTaskListRemoteOperation("assistant").execute(nextcloudClient) + var result = GetTaskListRemoteOperation(selectedTaskType).execute(nextcloudClient) assertTrue(result.isSuccess) val tasks = result.resultData.tasks @@ -89,7 +91,7 @@ class AssistantIT : AbstractIT() { // delete assertTrue(DeleteTaskRemoteOperation(tasks.first().id).execute(nextcloudClient).isSuccess) - result = GetTaskListRemoteOperation("assistant").execute(nextcloudClient) + result = GetTaskListRemoteOperation(selectedTaskType).execute(nextcloudClient) assertTrue(result.isSuccess) assertEquals(countBefore - 1, result.resultData.tasks.size) From 594878ed23b82ea012d6cbd302ecc088cb0e6378 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 12 Dec 2024 11:14:06 +0100 Subject: [PATCH 12/16] use correct task type Signed-off-by: alperozturk --- .../android/lib/resources/assistant/AssistantIT.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/AssistantIT.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/AssistantIT.kt index e18f5756d..0962a30fe 100644 --- a/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/AssistantIT.kt +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/AssistantIT.kt @@ -46,6 +46,8 @@ class AssistantIT : AbstractIT() { ) } + private fun getSelectedTaskType(): String = "core:text2text" + @Test fun testGetTaskTypes() { val result = GetTaskTypesRemoteOperation().execute(nextcloudClient) @@ -57,14 +59,15 @@ class AssistantIT : AbstractIT() { @Test fun testGetTaskList() { - val selectedTaskType = "core:text2text" + val taskType = getTaskType() + val selectedTaskType = getSelectedTaskType() + var result = GetTaskListRemoteOperation(selectedTaskType).execute(nextcloudClient) assertTrue(result.isSuccess) assertTrue(result.resultData.tasks.isEmpty()) // create one task val input = "Give me some random output for test purpose" - val taskType = getTaskType() assertTrue(CreateTaskRemoteOperation(input, taskType).execute(nextcloudClient).isSuccess) result = GetTaskListRemoteOperation(selectedTaskType).execute(nextcloudClient) @@ -79,7 +82,8 @@ class AssistantIT : AbstractIT() { // create one task val input = "Give me some random output for test purpose" val taskType = getTaskType() - val selectedTaskType = "core:text2text" + val selectedTaskType = getSelectedTaskType() + assertTrue(CreateTaskRemoteOperation(input, taskType).execute(nextcloudClient).isSuccess) var result = GetTaskListRemoteOperation(selectedTaskType).execute(nextcloudClient) From 7035a1689f4fb4450e3eb67cfd18fa9daa6dd065 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 12 Dec 2024 13:17:12 +0100 Subject: [PATCH 13/16] fix tests Signed-off-by: alperozturk --- .../owncloud/android/lib/resources/assistant/AssistantIT.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/AssistantIT.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/AssistantIT.kt index 0962a30fe..3b07ff750 100644 --- a/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/AssistantIT.kt +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/AssistantIT.kt @@ -52,9 +52,6 @@ class AssistantIT : AbstractIT() { fun testGetTaskTypes() { val result = GetTaskTypesRemoteOperation().execute(nextcloudClient) assertTrue(result.isSuccess) - - val taskTypes = result.resultData - assertTrue(taskTypes.isNotEmpty()) } @Test From dce1121e7f8abb5ee626b0c3e3766b58abb38d15 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 12 Dec 2024 16:28:04 +0100 Subject: [PATCH 14/16] add v1 api Signed-off-by: alperozturk --- .../resources/assistant/v1/AssistantITV1.kt | 72 +++++++++++++++++++ .../{AssistantIT.kt => v2/AssistantITV2.kt} | 28 ++++---- .../v1/CreateTaskRemoteOperationV1.kt | 48 +++++++++++++ .../DeleteTaskRemoteOperationV1.kt} | 7 +- .../v1/GetTaskListRemoteOperationV1.kt | 58 +++++++++++++++ .../v1/GetTaskTypesRemoteOperationV1.kt | 58 +++++++++++++++ .../resources/assistant/v1/model/TaskList.kt | 25 +++++++ .../resources/assistant/v1/model/TaskTypes.kt | 19 +++++ .../CreateTaskRemoteOperationV2.kt} | 6 +- .../v2/DeleteTaskRemoteOperationV2.kt | 45 ++++++++++++ .../GetTaskListRemoteOperationV2.kt} | 8 +-- .../GetTaskTypesRemoteOperationV2.kt} | 10 +-- .../assistant/{ => v2}/model/TaskList.kt | 2 +- .../assistant/{ => v2}/model/TaskTypes.kt | 2 +- 14 files changed, 357 insertions(+), 31 deletions(-) create mode 100644 library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/v1/AssistantITV1.kt rename library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/{AssistantIT.kt => v2/AssistantITV2.kt} (66%) create mode 100644 library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/CreateTaskRemoteOperationV1.kt rename library/src/main/java/com/owncloud/android/lib/resources/assistant/{DeleteTaskRemoteOperation.kt => v1/DeleteTaskRemoteOperationV1.kt} (86%) create mode 100644 library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/GetTaskListRemoteOperationV1.kt create mode 100644 library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/GetTaskTypesRemoteOperationV1.kt create mode 100644 library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/model/TaskList.kt create mode 100644 library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/model/TaskTypes.kt rename library/src/main/java/com/owncloud/android/lib/resources/assistant/{CreateTaskRemoteOperation.kt => v2/CreateTaskRemoteOperationV2.kt} (87%) create mode 100644 library/src/main/java/com/owncloud/android/lib/resources/assistant/v2/DeleteTaskRemoteOperationV2.kt rename library/src/main/java/com/owncloud/android/lib/resources/assistant/{GetTaskListRemoteOperation.kt => v2/GetTaskListRemoteOperationV2.kt} (86%) rename library/src/main/java/com/owncloud/android/lib/resources/assistant/{GetTaskTypesRemoteOperation.kt => v2/GetTaskTypesRemoteOperationV2.kt} (88%) rename library/src/main/java/com/owncloud/android/lib/resources/assistant/{ => v2}/model/TaskList.kt (92%) rename library/src/main/java/com/owncloud/android/lib/resources/assistant/{ => v2}/model/TaskTypes.kt (91%) diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/v1/AssistantITV1.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/v1/AssistantITV1.kt new file mode 100644 index 000000000..632cad2ce --- /dev/null +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/v1/AssistantITV1.kt @@ -0,0 +1,72 @@ +/* + * Nextcloud Android Library + * + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2024 Alper Ozturk + * SPDX-License-Identifier: MIT + */ + +package com.owncloud.android.lib.resources.assistant.v1 + +import com.owncloud.android.AbstractIT +import com.owncloud.android.lib.resources.status.NextcloudVersion +import junit.framework.TestCase.assertEquals +import junit.framework.TestCase.assertTrue +import org.junit.Before +import org.junit.Test + +class AssistantITV1 : AbstractIT() { + @Before + fun before() { + testOnlyOnServer(NextcloudVersion.nextcloud_28) + } + + @Test + fun testGetTaskTypes() { + val result = GetTaskTypesRemoteOperationV1().execute(nextcloudClient) + assertTrue(result.isSuccess) + + val taskTypes = result.resultData.types + assertTrue(taskTypes.isNotEmpty()) + } + + @Test + fun testGetTaskList() { + var result = GetTaskListRemoteOperationV1("assistant").execute(nextcloudClient) + assertTrue(result.isSuccess) + assertTrue(result.resultData.tasks.isEmpty()) + + // create one task + val input = "Give me some random output for test purpose" + val type = "OCP\\TextProcessing\\FreePromptTaskType" + assertTrue(CreateTaskRemoteOperationV1(input, type).execute(nextcloudClient).isSuccess) + + result = GetTaskListRemoteOperationV1("assistant").execute(nextcloudClient) + assertTrue(result.isSuccess) + + val taskList = result.resultData.tasks + assertTrue(taskList.isNotEmpty()) + } + + @Test + fun testDeleteTask() { + // create one task + val input = "Give me some random output for test purpose" + val type = "OCP\\TextProcessing\\FreePromptTaskType" + assertTrue(CreateTaskRemoteOperationV1(input, type).execute(nextcloudClient).isSuccess) + + var result = GetTaskListRemoteOperationV1("assistant").execute(nextcloudClient) + assertTrue(result.isSuccess) + + val tasks = result.resultData.tasks + val countBefore = tasks.size + + // delete + assertTrue(DeleteTaskRemoteOperationV1(tasks.first().id).execute(nextcloudClient).isSuccess) + + result = GetTaskListRemoteOperationV1("assistant").execute(nextcloudClient) + assertTrue(result.isSuccess) + + assertEquals(countBefore - 1, result.resultData.tasks.size) + } +} diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/AssistantIT.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/v2/AssistantITV2.kt similarity index 66% rename from library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/AssistantIT.kt rename to library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/v2/AssistantITV2.kt index 3b07ff750..a732ae616 100644 --- a/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/AssistantIT.kt +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/v2/AssistantITV2.kt @@ -2,23 +2,23 @@ * Nextcloud Android Library * * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors - * SPDX-FileCopyrightText: 2024 Tobias Kaminsky + * SPDX-FileCopyrightText: 2024 Alper Ozturk * SPDX-License-Identifier: MIT */ -package com.owncloud.android.lib.resources.assistant +package com.owncloud.android.lib.resources.assistant.v2 import com.owncloud.android.AbstractIT -import com.owncloud.android.lib.resources.assistant.model.TaskInputShape -import com.owncloud.android.lib.resources.assistant.model.TaskOutputShape -import com.owncloud.android.lib.resources.assistant.model.TaskTypeData +import com.owncloud.android.lib.resources.assistant.v2.model.TaskInputShape +import com.owncloud.android.lib.resources.assistant.v2.model.TaskOutputShape +import com.owncloud.android.lib.resources.assistant.v2.model.TaskTypeData import com.owncloud.android.lib.resources.status.NextcloudVersion import junit.framework.TestCase.assertEquals import junit.framework.TestCase.assertTrue import org.junit.Before import org.junit.Test -class AssistantIT : AbstractIT() { +class AssistantITV2 : AbstractIT() { @Before fun before() { testOnlyOnServer(NextcloudVersion.nextcloud_30) @@ -50,7 +50,7 @@ class AssistantIT : AbstractIT() { @Test fun testGetTaskTypes() { - val result = GetTaskTypesRemoteOperation().execute(nextcloudClient) + val result = GetTaskTypesRemoteOperationV2().execute(nextcloudClient) assertTrue(result.isSuccess) } @@ -59,15 +59,15 @@ class AssistantIT : AbstractIT() { val taskType = getTaskType() val selectedTaskType = getSelectedTaskType() - var result = GetTaskListRemoteOperation(selectedTaskType).execute(nextcloudClient) + var result = GetTaskListRemoteOperationV2(selectedTaskType).execute(nextcloudClient) assertTrue(result.isSuccess) assertTrue(result.resultData.tasks.isEmpty()) // create one task val input = "Give me some random output for test purpose" - assertTrue(CreateTaskRemoteOperation(input, taskType).execute(nextcloudClient).isSuccess) + assertTrue(CreateTaskRemoteOperationV2(input, taskType).execute(nextcloudClient).isSuccess) - result = GetTaskListRemoteOperation(selectedTaskType).execute(nextcloudClient) + result = GetTaskListRemoteOperationV2(selectedTaskType).execute(nextcloudClient) assertTrue(result.isSuccess) val taskList = result.resultData.tasks @@ -81,18 +81,18 @@ class AssistantIT : AbstractIT() { val taskType = getTaskType() val selectedTaskType = getSelectedTaskType() - assertTrue(CreateTaskRemoteOperation(input, taskType).execute(nextcloudClient).isSuccess) + assertTrue(CreateTaskRemoteOperationV2(input, taskType).execute(nextcloudClient).isSuccess) - var result = GetTaskListRemoteOperation(selectedTaskType).execute(nextcloudClient) + var result = GetTaskListRemoteOperationV2(selectedTaskType).execute(nextcloudClient) assertTrue(result.isSuccess) val tasks = result.resultData.tasks val countBefore = tasks.size // delete - assertTrue(DeleteTaskRemoteOperation(tasks.first().id).execute(nextcloudClient).isSuccess) + assertTrue(DeleteTaskRemoteOperationV2(tasks.first().id).execute(nextcloudClient).isSuccess) - result = GetTaskListRemoteOperation(selectedTaskType).execute(nextcloudClient) + result = GetTaskListRemoteOperationV2(selectedTaskType).execute(nextcloudClient) assertTrue(result.isSuccess) assertEquals(countBefore - 1, result.resultData.tasks.size) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/CreateTaskRemoteOperationV1.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/CreateTaskRemoteOperationV1.kt new file mode 100644 index 000000000..cc4487c32 --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/CreateTaskRemoteOperationV1.kt @@ -0,0 +1,48 @@ +/* + * Nextcloud Android Library + * + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2024 Alper Ozturk + * SPDX-License-Identifier: MIT + */ + +package com.owncloud.android.lib.resources.assistant.v1 + +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 CreateTaskRemoteOperationV1(private val input: String, private val type: String) : + RemoteOperation() { + override fun run(client: NextcloudClient): RemoteOperationResult { + 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(true, postMethod) + } else { + RemoteOperationResult(false, postMethod) + } + } + + companion object { + const val TAG_URL = "/ocs/v2.php/textprocessing/schedule" + } +} diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/DeleteTaskRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/DeleteTaskRemoteOperationV1.kt similarity index 86% rename from library/src/main/java/com/owncloud/android/lib/resources/assistant/DeleteTaskRemoteOperation.kt rename to library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/DeleteTaskRemoteOperationV1.kt index 930989276..2f5ad083a 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/DeleteTaskRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/DeleteTaskRemoteOperationV1.kt @@ -6,7 +6,7 @@ * SPDX-License-Identifier: MIT */ -package com.owncloud.android.lib.resources.assistant +package com.owncloud.android.lib.resources.assistant.v1 import com.nextcloud.common.NextcloudClient import com.nextcloud.operations.DeleteMethod @@ -17,7 +17,7 @@ import com.owncloud.android.lib.resources.users.DeletePrivateKeyRemoteOperation import java.io.IOException import java.net.HttpURLConnection -class DeleteTaskRemoteOperation(private val appId: Long) : RemoteOperation() { +class DeleteTaskRemoteOperationV1(private val appId: Long) : RemoteOperation() { override fun run(client: NextcloudClient): RemoteOperationResult { var postMethod: DeleteMethod? = null var result: RemoteOperationResult @@ -41,6 +41,7 @@ class DeleteTaskRemoteOperation(private val appId: Long) : RemoteOperation companion object { private val TAG = DeletePrivateKeyRemoteOperation::class.java.simpleName - private const val DIRECT_ENDPOINT = "/ocs/v2.php/taskprocessing/task/" + private const val DIRECT_ENDPOINT = + "/ocs/v2.php/textprocessing/task/" } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/GetTaskListRemoteOperationV1.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/GetTaskListRemoteOperationV1.kt new file mode 100644 index 000000000..384c95e9b --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/GetTaskListRemoteOperationV1.kt @@ -0,0 +1,58 @@ +/* + * Nextcloud Android Library + * + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2024 Alper Ozturk + * SPDX-License-Identifier: MIT + */ + +package com.owncloud.android.lib.resources.assistant.v1 + +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.v1.model.TaskList +import org.apache.commons.httpclient.HttpStatus + +class GetTaskListRemoteOperationV1(private val appId: String) : OCSRemoteOperation() { + @Suppress("TooGenericExceptionCaught") + override fun run(client: NextcloudClient): RemoteOperationResult { + var result: RemoteOperationResult + 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>() {} + )?.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 = GetTaskListRemoteOperationV1::class.java.simpleName + private const val DIRECT_ENDPOINT = "/ocs/v2.php/textprocessing/tasks/app/" + } +} diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/GetTaskTypesRemoteOperationV1.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/GetTaskTypesRemoteOperationV1.kt new file mode 100644 index 000000000..7047022e2 --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/GetTaskTypesRemoteOperationV1.kt @@ -0,0 +1,58 @@ +/* + * Nextcloud Android Library + * + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2024 Alper Ozturk + * SPDX-License-Identifier: MIT + */ + +package com.owncloud.android.lib.resources.assistant.v1 + +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.v1.model.TaskTypes +import org.apache.commons.httpclient.HttpStatus + +class GetTaskTypesRemoteOperationV1 : OCSRemoteOperation() { + @Suppress("TooGenericExceptionCaught") + override fun run(client: NextcloudClient): RemoteOperationResult { + var result: RemoteOperationResult + 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>() {} + )?.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 = GetTaskTypesRemoteOperationV1::class.java.simpleName + private const val DIRECT_ENDPOINT = "/ocs/v2.php/textprocessing/tasktypes" + } +} diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/model/TaskList.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/model/TaskList.kt new file mode 100644 index 000000000..d72d93a09 --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/model/TaskList.kt @@ -0,0 +1,25 @@ +/* + * Nextcloud Android Library + * + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2024 Alper Ozturk + * SPDX-License-Identifier: MIT + */ + +package com.owncloud.android.lib.resources.assistant.v1.model + +data class TaskList( + var tasks: List +) + +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 +) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/model/TaskTypes.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/model/TaskTypes.kt new file mode 100644 index 000000000..a3ab9d342 --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/model/TaskTypes.kt @@ -0,0 +1,19 @@ +/* + * Nextcloud Android Library + * + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2024 Alper Ozturk + * SPDX-License-Identifier: MIT + */ + +package com.owncloud.android.lib.resources.assistant.v1.model + +data class TaskTypes( + var types: List +) + +data class TaskType( + val id: String?, + val name: String?, + val description: String? +) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/CreateTaskRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v2/CreateTaskRemoteOperationV2.kt similarity index 87% rename from library/src/main/java/com/owncloud/android/lib/resources/assistant/CreateTaskRemoteOperation.kt rename to library/src/main/java/com/owncloud/android/lib/resources/assistant/v2/CreateTaskRemoteOperationV2.kt index efb877227..49670f4a1 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/CreateTaskRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v2/CreateTaskRemoteOperationV2.kt @@ -6,18 +6,18 @@ * SPDX-License-Identifier: MIT */ -package com.owncloud.android.lib.resources.assistant +package com.owncloud.android.lib.resources.assistant.v2 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.resources.assistant.model.TaskTypeData +import com.owncloud.android.lib.resources.assistant.v2.model.TaskTypeData import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.RequestBody.Companion.toRequestBody import org.apache.commons.httpclient.HttpStatus -class CreateTaskRemoteOperation(private val input: String, private val taskType: TaskTypeData) : +class CreateTaskRemoteOperationV2(private val input: String, private val taskType: TaskTypeData) : RemoteOperation() { override fun run(client: NextcloudClient): RemoteOperationResult { val inputField = hashMapOf("input" to input) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/v2/DeleteTaskRemoteOperationV2.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v2/DeleteTaskRemoteOperationV2.kt new file mode 100644 index 000000000..302f9349a --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v2/DeleteTaskRemoteOperationV2.kt @@ -0,0 +1,45 @@ +/* + * Nextcloud Android Library + * + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2024 Alper Ozturk + * SPDX-License-Identifier: MIT + */ + +package com.owncloud.android.lib.resources.assistant.v2 + +import com.nextcloud.common.NextcloudClient +import com.nextcloud.operations.DeleteMethod +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 java.io.IOException +import java.net.HttpURLConnection + +class DeleteTaskRemoteOperationV2(private val appId: Long) : RemoteOperation() { + override fun run(client: NextcloudClient): RemoteOperationResult { + var postMethod: DeleteMethod? = null + var result: RemoteOperationResult + try { + postMethod = + DeleteMethod( + client.baseUri.toString() + DIRECT_ENDPOINT + appId, + true + ) + val status = client.execute(postMethod) + result = RemoteOperationResult(status == HttpURLConnection.HTTP_OK, postMethod) + } catch (e: IOException) { + result = RemoteOperationResult(e) + Log_OC.e(TAG, "Deletion of task failed: " + result.logMessage, result.exception) + } finally { + postMethod?.releaseConnection() + } + + return result + } + + companion object { + private val TAG = DeleteTaskRemoteOperationV2::class.java.simpleName + private const val DIRECT_ENDPOINT = "/ocs/v2.php/taskprocessing/task/" + } +} diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskListRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v2/GetTaskListRemoteOperationV2.kt similarity index 86% rename from library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskListRemoteOperation.kt rename to library/src/main/java/com/owncloud/android/lib/resources/assistant/v2/GetTaskListRemoteOperationV2.kt index d0ed14d2d..19dc6c83c 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskListRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v2/GetTaskListRemoteOperationV2.kt @@ -6,7 +6,7 @@ * SPDX-License-Identifier: MIT */ -package com.owncloud.android.lib.resources.assistant +package com.owncloud.android.lib.resources.assistant.v2 import com.google.gson.reflect.TypeToken import com.nextcloud.common.NextcloudClient @@ -15,10 +15,10 @@ 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 com.owncloud.android.lib.resources.assistant.v2.model.TaskList import org.apache.commons.httpclient.HttpStatus -class GetTaskListRemoteOperation(private val taskType: String) : OCSRemoteOperation() { +class GetTaskListRemoteOperationV2(private val taskType: String) : OCSRemoteOperation() { @Suppress("TooGenericExceptionCaught") override fun run(client: NextcloudClient): RemoteOperationResult { var result: RemoteOperationResult @@ -52,7 +52,7 @@ class GetTaskListRemoteOperation(private val taskType: String) : OCSRemoteOperat } companion object { - private val TAG = GetTaskTypesRemoteOperation::class.java.simpleName + private val TAG = GetTaskTypesRemoteOperationV2::class.java.simpleName private const val DIRECT_ENDPOINT = "/ocs/v2.php/taskprocessing/tasks?taskType=" } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskTypesRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v2/GetTaskTypesRemoteOperationV2.kt similarity index 88% rename from library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskTypesRemoteOperation.kt rename to library/src/main/java/com/owncloud/android/lib/resources/assistant/v2/GetTaskTypesRemoteOperationV2.kt index 916fc4b4a..b2f3822d0 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskTypesRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v2/GetTaskTypesRemoteOperationV2.kt @@ -6,7 +6,7 @@ * SPDX-License-Identifier: MIT */ -package com.owncloud.android.lib.resources.assistant +package com.owncloud.android.lib.resources.assistant.v2 import com.google.gson.reflect.TypeToken import com.nextcloud.common.NextcloudClient @@ -15,11 +15,11 @@ 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.TaskTypeData -import com.owncloud.android.lib.resources.assistant.model.TaskTypes +import com.owncloud.android.lib.resources.assistant.v2.model.TaskTypeData +import com.owncloud.android.lib.resources.assistant.v2.model.TaskTypes import org.apache.commons.httpclient.HttpStatus -class GetTaskTypesRemoteOperation : OCSRemoteOperation>() { +class GetTaskTypesRemoteOperationV2 : OCSRemoteOperation>() { private val supportedTaskType = "Text" @Suppress("TooGenericExceptionCaught") @@ -71,7 +71,7 @@ class GetTaskTypesRemoteOperation : OCSRemoteOperation>() { } companion object { - private val TAG = GetTaskTypesRemoteOperation::class.java.simpleName + private val TAG = GetTaskTypesRemoteOperationV2::class.java.simpleName private const val DIRECT_ENDPOINT = "/ocs/v2.php/taskprocessing/tasktypes" } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskList.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v2/model/TaskList.kt similarity index 92% rename from library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskList.kt rename to library/src/main/java/com/owncloud/android/lib/resources/assistant/v2/model/TaskList.kt index 75594d032..a33dae69c 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskList.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v2/model/TaskList.kt @@ -6,7 +6,7 @@ * SPDX-License-Identifier: MIT */ -package com.owncloud.android.lib.resources.assistant.model +package com.owncloud.android.lib.resources.assistant.v2.model data class TaskList( var tasks: List diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v2/model/TaskTypes.kt similarity index 91% rename from library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt rename to library/src/main/java/com/owncloud/android/lib/resources/assistant/v2/model/TaskTypes.kt index f3356e0d4..616c6e919 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v2/model/TaskTypes.kt @@ -6,7 +6,7 @@ * SPDX-License-Identifier: MIT */ -package com.owncloud.android.lib.resources.assistant.model +package com.owncloud.android.lib.resources.assistant.v2.model data class TaskTypes(val types: Map) From 40c69c4f2c3d916949b644c4a3c024dbac066fe2 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 12 Dec 2024 16:28:48 +0100 Subject: [PATCH 15/16] add v1 api Signed-off-by: alperozturk --- .../assistant/v1/{AssistantITV1.kt => AssistantV1Tests.kt} | 2 +- .../assistant/v2/{AssistantITV2.kt => AssistantV2Tests.kt} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/v1/{AssistantITV1.kt => AssistantV1Tests.kt} (98%) rename library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/v2/{AssistantITV2.kt => AssistantV2Tests.kt} (98%) diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/v1/AssistantITV1.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/v1/AssistantV1Tests.kt similarity index 98% rename from library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/v1/AssistantITV1.kt rename to library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/v1/AssistantV1Tests.kt index 632cad2ce..842995add 100644 --- a/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/v1/AssistantITV1.kt +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/v1/AssistantV1Tests.kt @@ -15,7 +15,7 @@ import junit.framework.TestCase.assertTrue import org.junit.Before import org.junit.Test -class AssistantITV1 : AbstractIT() { +class AssistantV1Tests : AbstractIT() { @Before fun before() { testOnlyOnServer(NextcloudVersion.nextcloud_28) diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/v2/AssistantITV2.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/v2/AssistantV2Tests.kt similarity index 98% rename from library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/v2/AssistantITV2.kt rename to library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/v2/AssistantV2Tests.kt index a732ae616..c15c37866 100644 --- a/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/v2/AssistantITV2.kt +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/v2/AssistantV2Tests.kt @@ -18,7 +18,7 @@ import junit.framework.TestCase.assertTrue import org.junit.Before import org.junit.Test -class AssistantITV2 : AbstractIT() { +class AssistantV2Tests : AbstractIT() { @Before fun before() { testOnlyOnServer(NextcloudVersion.nextcloud_30) From 74d072cdf3f4bbaf71761f660049203e0d30b36a Mon Sep 17 00:00:00 2001 From: alperozturk Date: Fri, 13 Dec 2024 10:05:36 +0100 Subject: [PATCH 16/16] add backward compatibility Signed-off-by: alperozturk --- .../resources/assistant/v1/model/TaskList.kt | 28 +++++++++++++++++++ .../resources/assistant/v1/model/TaskTypes.kt | 14 ++++++++++ 2 files changed, 42 insertions(+) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/model/TaskList.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/model/TaskList.kt index d72d93a09..4a4ee48a5 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/model/TaskList.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/model/TaskList.kt @@ -23,3 +23,31 @@ data class Task( val identifier: String?, val completionExpectedAt: String? = null ) + +fun TaskList.toV2(): com.owncloud.android.lib.resources.assistant.v2.model.TaskList { + return com.owncloud.android.lib.resources.assistant.v2.model.TaskList( + tasks = + tasks.map { task -> + com.owncloud.android.lib.resources.assistant.v2.model.Task( + id = task.id, + type = task.type, + status = task.status?.toString(), + userId = task.userId, + appId = task.appId, + input = + task.input?.let { + com.owncloud.android.lib.resources.assistant.v2.model.TaskInput(input = it) + }, + output = + task.output?.let { + com.owncloud.android.lib.resources.assistant.v2.model.TaskOutput(output = it) + }, + completionExpectedAt = task.completionExpectedAt?.toIntOrNull(), + progress = null, + lastUpdated = null, + scheduledAt = null, + endedAt = null + ) + } + ) +} diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/model/TaskTypes.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/model/TaskTypes.kt index a3ab9d342..0f65ca7c1 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/model/TaskTypes.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/model/TaskTypes.kt @@ -8,6 +8,8 @@ package com.owncloud.android.lib.resources.assistant.v1.model +import com.owncloud.android.lib.resources.assistant.v2.model.TaskTypeData + data class TaskTypes( var types: List ) @@ -17,3 +19,15 @@ data class TaskType( val name: String?, val description: String? ) + +fun TaskTypes.toV2(): List { + return types.map { taskType -> + TaskTypeData( + id = taskType.id, + name = taskType.name, + description = taskType.description, + inputShape = null, + outputShape = null + ) + } +}