diff --git a/src/androidTest/java/com/nextcloud/android/lib/resources/profile/GetHoverCardRemoteOperationIT.kt b/src/androidTest/java/com/nextcloud/android/lib/resources/profile/GetHoverCardRemoteOperationIT.kt new file mode 100644 index 000000000..5dd95fc2b --- /dev/null +++ b/src/androidTest/java/com/nextcloud/android/lib/resources/profile/GetHoverCardRemoteOperationIT.kt @@ -0,0 +1,57 @@ +/* Nextcloud Android Library is available under MIT license + * + * @author Tobias Kaminsky + * Copyright (C) 2021 Tobias Kaminsky + * Copyright (C) 2021 Nextcloud GmbH + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ +package com.nextcloud.android.lib.resources.profile + +import com.owncloud.android.AbstractIT +import com.owncloud.android.lib.resources.status.GetStatusRemoteOperation +import com.owncloud.android.lib.resources.status.NextcloudVersion.Companion.nextcloud_23 +import com.owncloud.android.lib.resources.status.OwnCloudVersion +import org.junit.Assert +import org.junit.Assume +import org.junit.Before +import org.junit.Test +import java.util.ArrayList + +class GetHoverCardRemoteOperationIT : AbstractIT() { + @Before + fun before() { + val result = GetStatusRemoteOperation(context).execute(client) + Assert.assertTrue(result.isSuccess) + val data = result.data as ArrayList + val ownCloudVersion = data[0] as OwnCloudVersion + Assume.assumeTrue(ownCloudVersion.isNewerOrEqual(nextcloud_23)) + } + + @Test + fun testHoverCard() { + val result = GetHoverCardRemoteOperation(nextcloudClient.userId) + .execute(nextcloudClient) + Assert.assertTrue(result.isSuccess) + val hoverCard = result.resultData + Assert.assertEquals(nextcloudClient.userId, hoverCard?.userId) + } +} diff --git a/src/main/java/com/nextcloud/android/lib/resources/profile/Action.kt b/src/main/java/com/nextcloud/android/lib/resources/profile/Action.kt new file mode 100644 index 000000000..eb8d48ad1 --- /dev/null +++ b/src/main/java/com/nextcloud/android/lib/resources/profile/Action.kt @@ -0,0 +1,37 @@ +/* Nextcloud Android Library is available under MIT license + * + * @author Tobias Kaminsky + * Copyright (C) 2021 Tobias Kaminsky + * Copyright (C) 2021 Nextcloud GmbH + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ +package com.nextcloud.android.lib.resources.profile + +/** + * Action of HoverCard data model + */ +data class Action( + var appId: String, + var title: String, + var icon: String, + var hyperlink: String +) diff --git a/src/main/java/com/nextcloud/android/lib/resources/profile/GetHoverCardRemoteOperation.kt b/src/main/java/com/nextcloud/android/lib/resources/profile/GetHoverCardRemoteOperation.kt new file mode 100644 index 000000000..0501d54c0 --- /dev/null +++ b/src/main/java/com/nextcloud/android/lib/resources/profile/GetHoverCardRemoteOperation.kt @@ -0,0 +1,78 @@ +/* Nextcloud Android Library is available under MIT license + * + * @author Tobias Kaminsky + * Copyright (C) 2021 Tobias Kaminsky + * Copyright (C) 2021 Nextcloud GmbH + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ +package com.nextcloud.android.lib.resources.profile + +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 hoverCard of an user + */ +class GetHoverCardRemoteOperation(private val userId: 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 + userId + JSON_FORMAT, true) + val status = client.execute(getMethod) + if (status == HttpStatus.SC_OK) { + val hoverCard: HoverCard = getServerResponse>( + getMethod, + object : TypeToken?>() {} + ) + .ocs.data + result = RemoteOperationResult(true, getMethod) + result.setResultData(hoverCard) + } else { + result = RemoteOperationResult(false, getMethod) + } + } catch (e: Exception) { + result = RemoteOperationResult(e) + Log_OC.e( + TAG, "Get hoverCard for user " + userId + " failed: " + result.logMessage, + result.exception + ) + } finally { + getMethod?.releaseConnection() + } + return result + } + + companion object { + private val TAG = GetHoverCardRemoteOperation::class.java.simpleName + private const val DIRECT_ENDPOINT = "/ocs/v2.php/hovercard/v1/" + private const val JSON_FORMAT = "?format=json" + } +} diff --git a/src/main/java/com/nextcloud/android/lib/resources/profile/HoverCard.kt b/src/main/java/com/nextcloud/android/lib/resources/profile/HoverCard.kt new file mode 100644 index 000000000..8f7c0fee6 --- /dev/null +++ b/src/main/java/com/nextcloud/android/lib/resources/profile/HoverCard.kt @@ -0,0 +1,38 @@ +/* Nextcloud Android Library is available under MIT license + * + * @author Tobias Kaminsky + * Copyright (C) 2021 Tobias Kaminsky + * Copyright (C) 2021 Nextcloud GmbH + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ +package com.nextcloud.android.lib.resources.profile + +import java.util.ArrayList + +/** + * HoverCard data model + */ +data class HoverCard( + val userId: String, + val displayName: String, + val actions: List = ArrayList() +)