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

retrieve recommendations #1605

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
@@ -0,0 +1,24 @@
/*
* Nextcloud Android Library
*
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2024 Tobias Kaminsky <[email protected]>
* SPDX-License-Identifier: MIT
*/
package com.nextcloud.android.lib.resources.recommendations

import com.owncloud.android.AbstractIT
import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation
import org.junit.Assert.assertTrue
import org.junit.Test

class GetRecommendationsRemoteOperationIT : AbstractIT() {
@Test
fun getRecommendations() {
assertTrue(CreateFolderRemoteOperation("/test/", true).execute(client).isSuccess)

val result = GetRecommendationsRemoteOperation().execute(nextcloudClient).resultData

assertTrue(result.isNotEmpty())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Nextcloud Android Library
*
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2024 Tobias Kaminsky <[email protected]>
* SPDX-License-Identifier: MIT
*/
package com.nextcloud.android.lib.resources.recommendations

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 org.apache.commons.httpclient.HttpStatus

/**
* Get recommendation of an user
*/
class GetRecommendationsRemoteOperation :
OCSRemoteOperation<List<Recommendation>>() {
@Suppress("TooGenericExceptionCaught")
override fun run(client: NextcloudClient): RemoteOperationResult<List<Recommendation>> {
var result: RemoteOperationResult<List<Recommendation>>
var getMethod: GetMethod? = null
try {
getMethod =
GetMethod(
client.baseUri.toString() + ENDPOINT + JSON_FORMAT,
true
)
val status = client.execute(getMethod)
if (status == HttpStatus.SC_OK) {
val map =
getServerResponse(
getMethod,
object : TypeToken<ServerResponse<List<Recommendation>>>() {}
)?.ocs?.data

if (map != null) {
result = RemoteOperationResult(true, getMethod)
result.setResultData(map)
} else {
result = RemoteOperationResult(false, getMethod)
}
} else {
result = RemoteOperationResult(false, getMethod)
}
} catch (e: Exception) {
result = RemoteOperationResult(e)
Log_OC.e(
TAG,
"Get recommendations failed: " + result.logMessage,
result.exception
)
} finally {
getMethod?.releaseConnection()
}
return result
}

companion object {
private val TAG = GetRecommendationsRemoteOperation::class.java.simpleName
private const val ENDPOINT = "/ocs/v2.php/apps/recommendations/api/v1/recommendations"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Nextcloud Android Library
*
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2024 Tobias Kaminsky <[email protected]>
* SPDX-License-Identifier: MIT
*/

package com.nextcloud.android.lib.resources.recommendations

data class Recommendation(
val id: Long,
val timestamp: Long,
val name: String,
val directory: String,
val extension: String,
val mimeType: String,
val hasPreview: Boolean,
val reason: String
)
Loading