Skip to content

Commit 7599117

Browse files
tobiasKaminskyalperozturk96
authored andcommitted
retrieve recommendations
Signed-off-by: tobiasKaminsky <[email protected]>
1 parent 2504465 commit 7599117

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Nextcloud Android Library
3+
*
4+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-FileCopyrightText: 2024 Tobias Kaminsky <[email protected]>
6+
* SPDX-License-Identifier: MIT
7+
*/
8+
package com.nextcloud.android.lib.resources.recommendations
9+
10+
import com.owncloud.android.AbstractIT
11+
import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation
12+
import org.junit.Assert.assertTrue
13+
import org.junit.Test
14+
15+
class GetRecommendationsRemoteOperationIT : AbstractIT() {
16+
@Test
17+
fun getRecommendations() {
18+
assertTrue(CreateFolderRemoteOperation("/test/", true).execute(client).isSuccess)
19+
20+
val result = GetRecommendationsRemoteOperation().execute(nextcloudClient).resultData
21+
22+
assertTrue(result.isNotEmpty())
23+
}
24+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Nextcloud Android Library
3+
*
4+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-FileCopyrightText: 2024 Tobias Kaminsky <[email protected]>
6+
* SPDX-License-Identifier: MIT
7+
*/
8+
package com.nextcloud.android.lib.resources.recommendations
9+
10+
import com.google.gson.reflect.TypeToken
11+
import com.nextcloud.common.NextcloudClient
12+
import com.nextcloud.operations.GetMethod
13+
import com.owncloud.android.lib.common.operations.RemoteOperationResult
14+
import com.owncloud.android.lib.common.utils.Log_OC
15+
import com.owncloud.android.lib.ocs.ServerResponse
16+
import com.owncloud.android.lib.resources.OCSRemoteOperation
17+
import org.apache.commons.httpclient.HttpStatus
18+
19+
/**
20+
* Get recommendation of an user
21+
*/
22+
class GetRecommendationsRemoteOperation :
23+
OCSRemoteOperation<List<Recommendation>>() {
24+
@Suppress("TooGenericExceptionCaught")
25+
override fun run(client: NextcloudClient): RemoteOperationResult<List<Recommendation>> {
26+
var result: RemoteOperationResult<List<Recommendation>>
27+
var getMethod: GetMethod? = null
28+
try {
29+
getMethod =
30+
GetMethod(
31+
client.baseUri.toString() + ENDPOINT + JSON_FORMAT,
32+
true
33+
)
34+
val status = client.execute(getMethod)
35+
if (status == HttpStatus.SC_OK) {
36+
val map =
37+
getServerResponse(
38+
getMethod,
39+
object : TypeToken<ServerResponse<List<Recommendation>>>() {}
40+
)?.ocs?.data
41+
42+
if (map != null) {
43+
result = RemoteOperationResult(true, getMethod)
44+
result.setResultData(map)
45+
} else {
46+
result = RemoteOperationResult(false, getMethod)
47+
}
48+
} else {
49+
result = RemoteOperationResult(false, getMethod)
50+
}
51+
} catch (e: Exception) {
52+
result = RemoteOperationResult(e)
53+
Log_OC.e(
54+
TAG,
55+
"Get recommendations failed: " + result.logMessage,
56+
result.exception
57+
)
58+
} finally {
59+
getMethod?.releaseConnection()
60+
}
61+
return result
62+
}
63+
64+
companion object {
65+
private val TAG = GetRecommendationsRemoteOperation::class.java.simpleName
66+
private const val ENDPOINT = "/ocs/v2.php/apps/recommendations/api/v1/recommendations"
67+
}
68+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Nextcloud Android Library
3+
*
4+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-FileCopyrightText: 2024 Tobias Kaminsky <[email protected]>
6+
* SPDX-License-Identifier: MIT
7+
*/
8+
9+
package com.nextcloud.android.lib.resources.recommendations
10+
11+
data class Recommendation(
12+
val id: Long,
13+
val timestamp: Long,
14+
val name: String,
15+
val directory: String,
16+
val extension: String,
17+
val mimeType: String,
18+
val hasPreview: Boolean,
19+
val reason: String
20+
)

0 commit comments

Comments
 (0)