-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: alperozturk <[email protected]>
- Loading branch information
1 parent
7035a16
commit dce1121
Showing
14 changed files
with
357 additions
and
31 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
...ary/src/androidTest/java/com/owncloud/android/lib/resources/assistant/v1/AssistantITV1.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Nextcloud Android Library | ||
* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-FileCopyrightText: 2024 Alper Ozturk <[email protected]> | ||
* 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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,23 +2,23 @@ | |
* Nextcloud Android Library | ||
* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-FileCopyrightText: 2024 Tobias Kaminsky <[email protected]> | ||
* SPDX-FileCopyrightText: 2024 Alper Ozturk <[email protected]> | ||
* 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) | ||
|
48 changes: 48 additions & 0 deletions
48
.../main/java/com/owncloud/android/lib/resources/assistant/v1/CreateTaskRemoteOperationV1.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Nextcloud Android Library | ||
* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-FileCopyrightText: 2024 Alper Ozturk <[email protected]> | ||
* 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<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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...main/java/com/owncloud/android/lib/resources/assistant/v1/GetTaskListRemoteOperationV1.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Nextcloud Android Library | ||
* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-FileCopyrightText: 2024 Alper Ozturk <[email protected]> | ||
* 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<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 = GetTaskListRemoteOperationV1::class.java.simpleName | ||
private const val DIRECT_ENDPOINT = "/ocs/v2.php/textprocessing/tasks/app/" | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...ain/java/com/owncloud/android/lib/resources/assistant/v1/GetTaskTypesRemoteOperationV1.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Nextcloud Android Library | ||
* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-FileCopyrightText: 2024 Alper Ozturk <[email protected]> | ||
* 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<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 = GetTaskTypesRemoteOperationV1::class.java.simpleName | ||
private const val DIRECT_ENDPOINT = "/ocs/v2.php/textprocessing/tasktypes" | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/model/TaskList.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Nextcloud Android Library | ||
* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-FileCopyrightText: 2024 Alper Ozturk <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
package com.owncloud.android.lib.resources.assistant.v1.model | ||
|
||
data class TaskList( | ||
var 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 | ||
) |
19 changes: 19 additions & 0 deletions
19
library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/model/TaskTypes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Nextcloud Android Library | ||
* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-FileCopyrightText: 2024 Alper Ozturk <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
package com.owncloud.android.lib.resources.assistant.v1.model | ||
|
||
data class TaskTypes( | ||
var types: List<TaskType> | ||
) | ||
|
||
data class TaskType( | ||
val id: String?, | ||
val name: String?, | ||
val description: String? | ||
) |
Oops, something went wrong.