Skip to content

Commit 2afb96b

Browse files
Merge pull request #733 from nextcloud/profile
Profile page
2 parents f8616af + 9192be1 commit 2afb96b

File tree

4 files changed

+210
-0
lines changed

4 files changed

+210
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* Nextcloud Android Library is available under MIT license
2+
*
3+
* @author Tobias Kaminsky
4+
* Copyright (C) 2021 Tobias Kaminsky
5+
* Copyright (C) 2021 Nextcloud GmbH
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*
26+
*/
27+
package com.nextcloud.android.lib.resources.profile
28+
29+
import com.owncloud.android.AbstractIT
30+
import com.owncloud.android.lib.resources.status.GetStatusRemoteOperation
31+
import com.owncloud.android.lib.resources.status.NextcloudVersion.Companion.nextcloud_23
32+
import com.owncloud.android.lib.resources.status.OwnCloudVersion
33+
import org.junit.Assert
34+
import org.junit.Assume
35+
import org.junit.Before
36+
import org.junit.Test
37+
import java.util.ArrayList
38+
39+
class GetHoverCardRemoteOperationIT : AbstractIT() {
40+
@Before
41+
fun before() {
42+
val result = GetStatusRemoteOperation(context).execute(client)
43+
Assert.assertTrue(result.isSuccess)
44+
val data = result.data as ArrayList<Any>
45+
val ownCloudVersion = data[0] as OwnCloudVersion
46+
Assume.assumeTrue(ownCloudVersion.isNewerOrEqual(nextcloud_23))
47+
}
48+
49+
@Test
50+
fun testHoverCard() {
51+
val result = GetHoverCardRemoteOperation(nextcloudClient.userId)
52+
.execute(nextcloudClient)
53+
Assert.assertTrue(result.isSuccess)
54+
val hoverCard = result.resultData
55+
Assert.assertEquals(nextcloudClient.userId, hoverCard?.userId)
56+
}
57+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* Nextcloud Android Library is available under MIT license
2+
*
3+
* @author Tobias Kaminsky
4+
* Copyright (C) 2021 Tobias Kaminsky
5+
* Copyright (C) 2021 Nextcloud GmbH
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*
26+
*/
27+
package com.nextcloud.android.lib.resources.profile
28+
29+
/**
30+
* Action of HoverCard data model
31+
*/
32+
data class Action(
33+
var appId: String,
34+
var title: String,
35+
var icon: String,
36+
var hyperlink: String
37+
)
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/* Nextcloud Android Library is available under MIT license
2+
*
3+
* @author Tobias Kaminsky
4+
* Copyright (C) 2021 Tobias Kaminsky
5+
* Copyright (C) 2021 Nextcloud GmbH
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*
26+
*/
27+
package com.nextcloud.android.lib.resources.profile
28+
29+
import com.google.gson.reflect.TypeToken
30+
import com.nextcloud.common.NextcloudClient
31+
import com.nextcloud.operations.GetMethod
32+
import com.owncloud.android.lib.common.operations.RemoteOperationResult
33+
import com.owncloud.android.lib.common.utils.Log_OC
34+
import com.owncloud.android.lib.ocs.ServerResponse
35+
import com.owncloud.android.lib.resources.OCSRemoteOperation
36+
import org.apache.commons.httpclient.HttpStatus
37+
38+
/**
39+
* Get hoverCard of an user
40+
*/
41+
class GetHoverCardRemoteOperation(private val userId: String) : OCSRemoteOperation<HoverCard?>() {
42+
@Suppress("TooGenericExceptionCaught")
43+
override fun run(client: NextcloudClient): RemoteOperationResult<HoverCard?> {
44+
var result: RemoteOperationResult<HoverCard?>
45+
var getMethod: GetMethod? = null
46+
try {
47+
getMethod =
48+
GetMethod(client.baseUri.toString() + DIRECT_ENDPOINT + userId + JSON_FORMAT, true)
49+
val status = client.execute(getMethod)
50+
if (status == HttpStatus.SC_OK) {
51+
val hoverCard: HoverCard = getServerResponse<ServerResponse<HoverCard>>(
52+
getMethod,
53+
object : TypeToken<ServerResponse<HoverCard>?>() {}
54+
)
55+
.ocs.data
56+
result = RemoteOperationResult(true, getMethod)
57+
result.setResultData(hoverCard)
58+
} else {
59+
result = RemoteOperationResult(false, getMethod)
60+
}
61+
} catch (e: Exception) {
62+
result = RemoteOperationResult(e)
63+
Log_OC.e(
64+
TAG, "Get hoverCard for user " + userId + " failed: " + result.logMessage,
65+
result.exception
66+
)
67+
} finally {
68+
getMethod?.releaseConnection()
69+
}
70+
return result
71+
}
72+
73+
companion object {
74+
private val TAG = GetHoverCardRemoteOperation::class.java.simpleName
75+
private const val DIRECT_ENDPOINT = "/ocs/v2.php/hovercard/v1/"
76+
private const val JSON_FORMAT = "?format=json"
77+
}
78+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* Nextcloud Android Library is available under MIT license
2+
*
3+
* @author Tobias Kaminsky
4+
* Copyright (C) 2021 Tobias Kaminsky
5+
* Copyright (C) 2021 Nextcloud GmbH
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*
26+
*/
27+
package com.nextcloud.android.lib.resources.profile
28+
29+
import java.util.ArrayList
30+
31+
/**
32+
* HoverCard data model
33+
*/
34+
data class HoverCard(
35+
val userId: String,
36+
val displayName: String,
37+
val actions: List<Action> = ArrayList()
38+
)

0 commit comments

Comments
 (0)