From 10f8d851451731ca54addf91d3ab6102796456a1 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Tue, 16 Jun 2020 12:35:36 +0200 Subject: [PATCH 01/12] notification to v2 Signed-off-by: tobiasKaminsky --- .../GetNotificationsRemoteOperationIT.kt | 38 ++++++++++++++++++ .../com/nextcloud/operations/PostMethod.kt | 5 ++- .../nextcloud/operations/Utf8PostMethod.kt | 39 +++++++++++++++++++ ...DeleteAllNotificationsRemoteOperation.java | 3 +- .../DeleteNotificationRemoteOperation.java | 5 +-- .../GetNotificationRemoteOperation.java | 9 ++--- 6 files changed, 87 insertions(+), 12 deletions(-) create mode 100644 library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperationIT.kt create mode 100644 library/src/main/java/com/nextcloud/operations/Utf8PostMethod.kt diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperationIT.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperationIT.kt new file mode 100644 index 0000000000..265a7eabfe --- /dev/null +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperationIT.kt @@ -0,0 +1,38 @@ +/* + * Nextcloud Android client application + * + * @author Tobias Kaminsky + * Copyright (C) 2022 Tobias Kaminsky + * Copyright (C) 2022 Nextcloud GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ +package com.owncloud.android.lib.resources.notifications + +import com.owncloud.android.AbstractIT +import junit.framework.Assert.assertTrue +import org.junit.Test + +class GetNotificationsRemoteOperationIT : AbstractIT() { + @Test + fun testNotifications() { + val result = nextcloudClient.execute(GetNotificationsRemoteOperation()) + assertTrue(result.isSuccess) + + val notifications = result.resultData + + assertTrue(notifications.isNotEmpty()) + } +} diff --git a/library/src/main/java/com/nextcloud/operations/PostMethod.kt b/library/src/main/java/com/nextcloud/operations/PostMethod.kt index 28110f7268..09fdc806e4 100644 --- a/library/src/main/java/com/nextcloud/operations/PostMethod.kt +++ b/library/src/main/java/com/nextcloud/operations/PostMethod.kt @@ -5,6 +5,7 @@ * SPDX-FileCopyrightText: 2023 Tobias Kaminsky * SPDX-License-Identifier: MIT */ + package com.nextcloud.operations import com.nextcloud.common.OkHttpMethodBase @@ -18,9 +19,9 @@ import okhttp3.RequestBody class PostMethod( uri: String, useOcsApiRequestHeader: Boolean, - val body: RequestBody + val body: RequestBody? ) : OkHttpMethodBase(uri, useOcsApiRequestHeader) { override fun applyType(temp: Request.Builder) { - temp.post(body) + body?.let { temp.post(it) } } } diff --git a/library/src/main/java/com/nextcloud/operations/Utf8PostMethod.kt b/library/src/main/java/com/nextcloud/operations/Utf8PostMethod.kt new file mode 100644 index 0000000000..5cad35c10d --- /dev/null +++ b/library/src/main/java/com/nextcloud/operations/Utf8PostMethod.kt @@ -0,0 +1,39 @@ +/* + * Nextcloud Android client application + * + * @author Tobias Kaminsky + * Copyright (C) 2022 Tobias Kaminsky + * Copyright (C) 2022 Nextcloud GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +package com.nextcloud.operations + +import okhttp3.Request +import okhttp3.RequestBody + +/** + * HTTP POST method that uses OkHttp with new NextcloudClient + */ +class Utf8PostMethod( + uri: String, + useOcsApiRequestHeader: Boolean, + body: RequestBody? +) : PostMethod(uri, useOcsApiRequestHeader, body) { + override fun applyType(temp: Request.Builder) { + temp.addHeader("Content-Type", "charset=utf-8") + } +} diff --git a/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperation.java index 641de60eea..9537ff37b3 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperation.java @@ -14,8 +14,7 @@ import com.owncloud.android.lib.common.utils.Log_OC; /** - * Delete all notification, specified at - * {@link "https://github.com/nextcloud/notifications/blob/master/docs/ocs-endpoint-v2.md"}. + * Delete all notification, specified at {@link "https://github.com/nextcloud/notifications/blob/master/docs/ocs-endpoint-v2.md"}. */ public class DeleteAllNotificationsRemoteOperation extends RemoteOperation { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperation.java index 36d7e463cc..71cd70059d 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperation.java @@ -14,8 +14,7 @@ import com.owncloud.android.lib.common.utils.Log_OC; /** - * Delete a notification, specified at - * {@link "https://github.com/nextcloud/notifications/blob/master/docs/ocs-endpoint-v2.md"}. + * Delete a notification, specified at {@link "https://github.com/nextcloud/notifications/blob/master/docs/ocs-endpoint-v2.md"}. */ public class DeleteNotificationRemoteOperation extends RemoteOperation { @@ -47,7 +46,7 @@ public RemoteOperationResult run(NextcloudClient client) { Log_OC.d(this, "Successful response: " + response); } else { result = new RemoteOperationResult<>(false, delete); - Log_OC.e(this, "Failed response while getting user notifications"); + Log_OC.e(this, "Failed response while deleting user notification: " + id); Log_OC.e(this, "*** status code: " + status + " ;response message: " + response); } } catch (Exception e) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperation.java index 4730e45753..ca0ed34635 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperation.java @@ -23,9 +23,9 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; /** - * Provides the remote notifications from the server handling the following data structure - * accessible via the notifications endpoint at {@value OCS_ROUTE_LIST_V12_AND_UP}, specified at - * {@link "https://github.com/nextcloud/notifications/blob/master/docs/ocs-endpoint-v2.md"}. + * Provides the remote notifications from the server handling the following data structure accessible via the + * notifications endpoint at {@value OCS_ROUTE_LIST_V12_AND_UP}, specified at {@link + * "https://github.com/nextcloud/notifications/blob/master/docs/ocs-endpoint-v2.md"}. */ public class GetNotificationRemoteOperation extends RemoteOperation { @@ -63,8 +63,7 @@ public RemoteOperationResult run(NextcloudClient client) { Log_OC.d(this, "Successful response: " + response); // Parse the response - Notification notification = parseResult(response); - result.setResultData(notification); + result.setResultData(parseResult(response)); } else { result = new RemoteOperationResult<>(false, get); Log_OC.e(this, "Failed response while getting user notifications "); From 9f8e32b1a17216ae455b549d48416c6e52cbff0f Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Mon, 12 Dec 2022 15:30:54 +0100 Subject: [PATCH 02/12] all to Kotlin more tests Signed-off-by: tobiasKaminsky --- .../java/com/owncloud/android/AbstractIT.java | 7 ++ ...DeleteAllNotificationsRemoteOperationIT.kt | 57 ++++++++++ .../DeleteNotificationRemoteOperationIT.kt | 59 ++++++++++ .../GetNotificationRemoteOperationIT.kt | 60 ++++++++++ .../GetNotificationsRemoteOperationIT.kt | 16 ++- .../CreateNotificationRemoteOperation.kt | 86 ++++++++++++++ ... DeleteAllNotificationsRemoteOperation.kt} | 50 ++++----- .../DeleteNotificationRemoteOperation.java | 63 ----------- .../DeleteNotificationRemoteOperation.kt | 57 ++++++++++ .../GetNotificationRemoteOperation.java | 94 ---------------- .../GetNotificationRemoteOperation.kt | 105 ++++++++++++++++++ .../GetNotificationsRemoteOperation.java | 93 ---------------- .../GetNotificationsRemoteOperation.kt | 105 ++++++++++++++++++ 13 files changed, 571 insertions(+), 281 deletions(-) create mode 100644 library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperationIT.kt create mode 100644 library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperationIT.kt create mode 100644 library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperationIT.kt create mode 100644 library/src/main/java/com/owncloud/android/lib/resources/notifications/CreateNotificationRemoteOperation.kt rename library/src/main/java/com/owncloud/android/lib/resources/notifications/{DeleteAllNotificationsRemoteOperation.java => DeleteAllNotificationsRemoteOperation.kt} (55%) delete mode 100644 library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperation.java create mode 100644 library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperation.kt delete mode 100644 library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperation.java create mode 100644 library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperation.kt delete mode 100644 library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperation.java create mode 100644 library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperation.kt diff --git a/library/src/androidTest/java/com/owncloud/android/AbstractIT.java b/library/src/androidTest/java/com/owncloud/android/AbstractIT.java index 629747cce3..7e2d1aba9d 100644 --- a/library/src/androidTest/java/com/owncloud/android/AbstractIT.java +++ b/library/src/androidTest/java/com/owncloud/android/AbstractIT.java @@ -70,6 +70,7 @@ public abstract class AbstractIT { public static OwnCloudClient client; public static OwnCloudClient client2; protected static NextcloudClient nextcloudClient; + protected static NextcloudClient nextcloudClientAdmin; protected static Context context; protected static Uri url; @@ -109,6 +110,12 @@ public static void beforeAll() throws InterruptedException, String credentials = Credentials.basic(loginName, password); nextcloudClient = new NextcloudClient(url, userId, credentials, context); + nextcloudClientAdmin = new NextcloudClient( + url, + "admin", + Credentials.basic("admin", "admin"), + context); + waitForServer(client, url); testConnection(); } diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperationIT.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperationIT.kt new file mode 100644 index 0000000000..2374bba681 --- /dev/null +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperationIT.kt @@ -0,0 +1,57 @@ +/* Nextcloud Android Library is available under MIT license + * + * @author Tobias Kaminsky + * Copyright (C) 2022 Tobias Kaminsky + * Copyright (C) 2022 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.owncloud.android.lib.resources.notifications + +import com.owncloud.android.AbstractIT +import org.junit.Assert.assertTrue +import org.junit.Test + +class DeleteAllNotificationsRemoteOperationIT : AbstractIT() { + @Test + fun testDeleteAllNotification() { + // create one notification + assertTrue( + nextcloudClientAdmin.execute( + CreateNotificationRemoteOperation( + nextcloudClient.userId, + "test" + ) + ).isSuccess + ) + + var result = nextcloudClient.execute(GetNotificationsRemoteOperation()) + assertTrue(result.isSuccess) + assertTrue(result.resultData.isNotEmpty()) + + assertTrue(nextcloudClient.execute(DeleteAllNotificationsRemoteOperation()).isSuccess) + + result = nextcloudClient.execute(GetNotificationsRemoteOperation()) + assertTrue(result.isSuccess) + assertTrue(result.resultData.isEmpty()) + } +} diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperationIT.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperationIT.kt new file mode 100644 index 0000000000..b80973bac8 --- /dev/null +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperationIT.kt @@ -0,0 +1,59 @@ +/* Nextcloud Android Library is available under MIT license + * + * @author Tobias Kaminsky + * Copyright (C) 2022 Tobias Kaminsky + * Copyright (C) 2022 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.owncloud.android.lib.resources.notifications + +import com.owncloud.android.AbstractIT +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +class DeleteNotificationRemoteOperationIT : AbstractIT() { + @Test + fun deleteOneNotification() { + // create one notification + assertTrue( + nextcloudClientAdmin.execute( + CreateNotificationRemoteOperation( + nextcloudClient.userId, + "test" + ) + ).isSuccess + ) + + val result = nextcloudClient.execute(GetNotificationsRemoteOperation()) + assertTrue(result.isSuccess) + assertTrue(result.resultData.isNotEmpty()) + + val firstNotificationId = result.resultData.first().notificationId + + assertTrue(DeleteNotificationRemoteOperation(firstNotificationId).execute(nextcloudClient).isSuccess) + + val getResult = GetNotificationRemoteOperation(firstNotificationId).execute(nextcloudClient) + assertFalse(getResult.isSuccess) + } +} diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperationIT.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperationIT.kt new file mode 100644 index 0000000000..aab7bc0fd9 --- /dev/null +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperationIT.kt @@ -0,0 +1,60 @@ +/* Nextcloud Android Library is available under MIT license + * + * @author Tobias Kaminsky + * Copyright (C) 2022 Tobias Kaminsky + * Copyright (C) 2022 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.owncloud.android.lib.resources.notifications + +import com.owncloud.android.AbstractIT +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertNotNull +import org.junit.Assert.assertTrue +import org.junit.Test + +class GetNotificationRemoteOperationIT : AbstractIT() { + @Test + fun testSingleNotification() { + // get all notifications + val resultAll = nextcloudClient.execute(GetNotificationsRemoteOperation()) + assertTrue(resultAll.isSuccess) + + val allNotifications = resultAll.resultData + val firstNotificationId = allNotifications.first().notificationId + + // check one specific + val result = nextcloudClient.execute(GetNotificationRemoteOperation(firstNotificationId)) + assertTrue(result.isSuccess) + + val notification = result.resultData + assertNotNull(notification) + assertEquals(firstNotificationId, notification.notificationId) + } + + @Test + fun testNonExisting() { + assertFalse(GetNotificationRemoteOperation(-1).execute(nextcloudClient).isSuccess) + } +} diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperationIT.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperationIT.kt index 265a7eabfe..5f0425937e 100644 --- a/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperationIT.kt +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperationIT.kt @@ -23,16 +23,24 @@ package com.owncloud.android.lib.resources.notifications import com.owncloud.android.AbstractIT import junit.framework.Assert.assertTrue +import org.junit.Assert import org.junit.Test class GetNotificationsRemoteOperationIT : AbstractIT() { @Test fun testNotifications() { + // create one notification + Assert.assertTrue( + nextcloudClientAdmin.execute( + CreateNotificationRemoteOperation( + nextcloudClient.userId, + "test" + ) + ).isSuccess + ) + val result = nextcloudClient.execute(GetNotificationsRemoteOperation()) assertTrue(result.isSuccess) - - val notifications = result.resultData - - assertTrue(notifications.isNotEmpty()) + assertTrue(result.resultData.isNotEmpty()) } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/notifications/CreateNotificationRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/notifications/CreateNotificationRemoteOperation.kt new file mode 100644 index 0000000000..614cec5019 --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/notifications/CreateNotificationRemoteOperation.kt @@ -0,0 +1,86 @@ +/* Nextcloud Android Library is available under MIT license + * + * @author Tobias Kaminsky + * Copyright (C) 2022 Tobias Kaminsky + * Copyright (C) 2022 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.owncloud.android.lib.resources.notifications + +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 com.owncloud.android.lib.common.utils.Log_OC +import com.owncloud.android.lib.resources.notifications.models.Notification +import okhttp3.FormBody +import org.apache.commons.httpclient.HttpStatus + +/** + * Provides the remote notifications from the server handling the following data structure accessible via the + * notifications endpoint at {@value OCS_ROUTE_LIST_V12_AND_UP}, specified at {@link + * "https://github.com/nextcloud/notifications/blob/master/docs/ocs-endpoint-v2.md"}. + */ +class CreateNotificationRemoteOperation(private val userId: String, private val message: String) : + RemoteOperation() { + override fun run(client: NextcloudClient): RemoteOperationResult { + var result: RemoteOperationResult + val status: Int + var post: PostMethod? = null + val url = + client.baseUri.toString() + "/ocs/v2.php/apps/notifications/api/v2/admin_notifications/" + + try { + val bodyRequest = FormBody + .Builder() + .add("shortMessage", message) + .build() + + post = PostMethod(url + userId, true, bodyRequest) + status = client.execute(post) + val response = post.getResponseBodyAsString() + if (isSuccess(status)) { + result = RemoteOperationResult(true, post) + Log_OC.d(TAG, "Successful response: $response") + } else { + result = RemoteOperationResult(false, post) + Log_OC.e(TAG, "Failed response while getting user notifications ") + Log_OC.e(TAG, "*** status code: $status ; response message: $response") + } + } catch (e: Exception) { + result = RemoteOperationResult(e) + Log_OC.e(TAG, "Exception while getting remote notifications", e) + } finally { + post?.releaseConnection() + } + return result + } + + private fun isSuccess(status: Int): Boolean { + return status == HttpStatus.SC_OK + } + + companion object { + private val TAG = CreateNotificationRemoteOperation::class.java.simpleName + } +} diff --git a/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperation.kt similarity index 55% rename from library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperation.java rename to library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperation.kt index 9537ff37b3..6e816d1858 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperation.kt @@ -16,42 +16,38 @@ /** * Delete all notification, specified at {@link "https://github.com/nextcloud/notifications/blob/master/docs/ocs-endpoint-v2.md"}. */ -public class DeleteAllNotificationsRemoteOperation extends RemoteOperation { - - // OCS Route - private static final String OCS_ROUTE_LIST_V12_AND_UP = - "/ocs/v2.php/apps/notifications/api/v2/notifications"; - - @Override - public RemoteOperationResult run(NextcloudClient client) { - RemoteOperationResult result; - int status; - DeleteMethod delete = null; - String url = client.getBaseUri() + OCS_ROUTE_LIST_V12_AND_UP; - +class DeleteAllNotificationsRemoteOperation : RemoteOperation() { + override fun run(client: NextcloudClient): RemoteOperationResult { + var result: RemoteOperationResult + val status: Int + var delete: DeleteMethod? = null + val url = client.baseUri.toString() + OCS_ROUTE_LIST_V12_AND_UP try { - delete = new DeleteMethod(url, true); + delete = new DeleteMethod(url, true) status = client.execute(delete); - String response = delete.getResponseBodyAsString(); + String response = delete.getResponseBodyAsString() if (delete.isSuccess()) { - result = new RemoteOperationResult<>(true, delete); - Log_OC.d(this, "Successful response: " + response); + result = new RemoteOperationResult<>(true, delete) + Log_OC.d(this, "Successful response: " + response) } else { - result = new RemoteOperationResult<>(false, delete); - Log_OC.e(this, "Failed response while getting user notifications "); - Log_OC.e(this, "*** status code: " + status + " ;response message: " + response); + result = new RemoteOperationResult<>(false, delete) + Log_OC.e(this, "Failed response while deleting user notifications ") + Log_OC.e(this, "*** status code: $status ;response message: $response") } - } catch (Exception e) { - result = new RemoteOperationResult<>(e); - Log_OC.e(this, "Exception while getting remote notifications", e); + } catch (e: Exception) { + result = RemoteOperationResult(e) + Log_OC.e(this, "Exception while getting remote notifications", e) } finally { - if (delete != null) { - delete.releaseConnection(); - } + delete?.releaseConnection() } + return result + } - return result; + companion object { + // OCS Route + private const val OCS_ROUTE_LIST_V12_AND_UP = + "/ocs/v2.php/apps/notifications/api/v2/notifications" } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperation.java deleted file mode 100644 index 71cd70059d..0000000000 --- a/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperation.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Nextcloud Android Library - * - * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors - * SPDX-FileCopyrightText: 2019 Tobias Kaminsky - * SPDX-License-Identifier: MIT - */ -package com.owncloud.android.lib.resources.notifications; - -import com.nextcloud.common.NextcloudClient; -import com.nextcloud.operations.DeleteMethod; -import com.owncloud.android.lib.common.operations.RemoteOperation; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.utils.Log_OC; - -/** - * Delete a notification, specified at {@link "https://github.com/nextcloud/notifications/blob/master/docs/ocs-endpoint-v2.md"}. - */ -public class DeleteNotificationRemoteOperation extends RemoteOperation { - - // OCS Route - private static final String OCS_ROUTE_LIST_V12_AND_UP = - "/ocs/v2.php/apps/notifications/api/v2/notifications/"; - - private final int id; - - public DeleteNotificationRemoteOperation(int id) { - this.id = id; - } - - @Override - public RemoteOperationResult run(NextcloudClient client) { - RemoteOperationResult result; - int status; - DeleteMethod delete = null; - String url = client.getBaseUri() + OCS_ROUTE_LIST_V12_AND_UP; - - try { - delete = new DeleteMethod(url + id, true); - - status = client.execute(delete); - String response = delete.getResponseBodyAsString(); - - if (delete.isSuccess()) { - result = new RemoteOperationResult<>(true, delete); - Log_OC.d(this, "Successful response: " + response); - } else { - result = new RemoteOperationResult<>(false, delete); - Log_OC.e(this, "Failed response while deleting user notification: " + id); - Log_OC.e(this, "*** status code: " + status + " ;response message: " + response); - } - } catch (Exception e) { - result = new RemoteOperationResult<>(e); - Log_OC.e(this, "Exception while getting remote notifications", e); - } finally { - if (delete != null) { - delete.releaseConnection(); - } - } - - return result; - } -} diff --git a/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperation.kt new file mode 100644 index 0000000000..7edfb79f93 --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperation.kt @@ -0,0 +1,57 @@ +/* + * Nextcloud Android Library + * + * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2019 Tobias Kaminsky + * SPDX-License-Identifier: MIT + */ +package com.owncloud.android.lib.resources.notifications; + +import com.nextcloud.common.NextcloudClient; +import com.nextcloud.operations.DeleteMethod; +import com.owncloud.android.lib.common.operations.RemoteOperation; +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.common.utils.Log_OC; + +/** + * Delete a notification, specified at {@link "https://github.com/nextcloud/notifications/blob/master/docs/ocs-endpoint-v2.md"}. + */ +class DeleteNotificationRemoteOperation(private val id: Int) : RemoteOperation() { + override fun run(client: NextcloudClient): RemoteOperationResult { + var result: RemoteOperationResult + val status: Int + var delete: DeleteMethod? = null + val url = client.baseUri.toString() + OCS_ROUTE_LIST_V12_AND_UP + try { + delete = DeleteMethod(url + id, true) + status = client.execute(delete) + + val response = delete.getResponseBodyAsString() + + if (delete.isSuccess()) { + result = RemoteOperationResult(true, delete) + Log_OC.d(this, "Successful response: $response") + } else { + result = RemoteOperationResult(false, delete) + Log_OC.e(this, "Failed response while deleting user notification: $id ") + Log_OC.e(this, "*** status code: $status ;response message: $response") + } + } catch (e: Exception) { + result = RemoteOperationResult(e) + Log_OC.e(this, "Exception while getting remote notifications", e) + } finally { + delete?.releaseConnection() + } + return result + } + + private fun isSuccess(status: Int): Boolean { + return status == HttpStatus.SC_OK + } + + companion object { + // OCS Route + private const val OCS_ROUTE_LIST_V12_AND_UP = + "/ocs/v2.php/apps/notifications/api/v2/notifications/" + } +} diff --git a/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperation.java deleted file mode 100644 index ca0ed34635..0000000000 --- a/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperation.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Nextcloud Android Library - * - * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors - * SPDX-FileCopyrightText: 2019 Tobias Kaminsky - * SPDX-License-Identifier: MIT - */ -package com.owncloud.android.lib.resources.notifications; - -import com.google.gson.Gson; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.reflect.TypeToken; -import com.nextcloud.common.NextcloudClient; -import com.nextcloud.operations.GetMethod; -import com.owncloud.android.lib.common.operations.RemoteOperation; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.utils.Log_OC; -import com.owncloud.android.lib.resources.notifications.models.Notification; - -import java.lang.reflect.Type; - -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - -/** - * Provides the remote notifications from the server handling the following data structure accessible via the - * notifications endpoint at {@value OCS_ROUTE_LIST_V12_AND_UP}, specified at {@link - * "https://github.com/nextcloud/notifications/blob/master/docs/ocs-endpoint-v2.md"}. - */ -public class GetNotificationRemoteOperation extends RemoteOperation { - - // OCS Route - private static final String OCS_ROUTE_LIST_V12_AND_UP = - "/ocs/v2.php/apps/notifications/api/v2/notifications/"; - - // JSON Node names - private static final String NODE_OCS = "ocs"; - private static final String NODE_DATA = "data"; - - private final int id; - - public GetNotificationRemoteOperation(int id) { - this.id = id; - } - - @SuppressFBWarnings("HTTP_PARAMETER_POLLUTION") - @Override - public RemoteOperationResult run(NextcloudClient client) { - RemoteOperationResult result; - int status; - GetMethod get = null; - String url = client.getBaseUri() + OCS_ROUTE_LIST_V12_AND_UP + id + JSON_FORMAT; - - // get the notification - try { - get = new GetMethod(url, true); - - status = client.execute(get); - String response = get.getResponseBodyAsString(); - - if (get.isSuccess()) { - result = new RemoteOperationResult<>(true, get); - Log_OC.d(this, "Successful response: " + response); - - // Parse the response - result.setResultData(parseResult(response)); - } else { - result = new RemoteOperationResult<>(false, get); - Log_OC.e(this, "Failed response while getting user notifications "); - Log_OC.e(this, "*** status code: " + status + " ; response message: " + response); - } - } catch (Exception e) { - result = new RemoteOperationResult<>(e); - Log_OC.e(this, "Exception while getting remote notifications", e); - } finally { - if (get != null) { - get.releaseConnection(); - } - } - - return result; - } - - private Notification parseResult(String response) { - JsonObject jo = (JsonObject) JsonParser.parseString(response); - JsonObject jsonDataObject = jo.getAsJsonObject(NODE_OCS).getAsJsonObject(NODE_DATA); - - Gson gson = new Gson(); - Type type = new TypeToken() { - }.getType(); - - return gson.fromJson(jsonDataObject, type); - } -} diff --git a/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperation.kt new file mode 100644 index 0000000000..ddfba23492 --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperation.kt @@ -0,0 +1,105 @@ +/* Nextcloud Android Library is available under MIT license + * + * @author Tobias Kaminsky + * Copyright (C) 2019 Tobias Kaminsky + * Copyright (C) 2019 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.owncloud.android.lib.resources.notifications + +import com.google.gson.Gson +import com.google.gson.JsonObject +import com.google.gson.JsonParser +import com.google.gson.reflect.TypeToken +import com.nextcloud.common.NextcloudClient +import com.nextcloud.operations.GetMethod +import com.owncloud.android.lib.common.operations.RemoteOperation +import com.owncloud.android.lib.common.operations.RemoteOperationResult +import com.owncloud.android.lib.common.utils.Log_OC +import com.owncloud.android.lib.resources.notifications.models.Notification +import org.apache.commons.httpclient.HttpStatus +import org.json.JSONException + +/** + * Provides the remote notifications from the server handling the following data structure accessible via the + * notifications endpoint at {@value OCS_ROUTE_LIST_V12_AND_UP}, specified at {@link + * "https://github.com/nextcloud/notifications/blob/master/docs/ocs-endpoint-v2.md"}. + */ +class GetNotificationRemoteOperation(private val id: Int) : RemoteOperation() { + override fun run(client: NextcloudClient): RemoteOperationResult { + var result: RemoteOperationResult + val status: Int + var get: GetMethod? = null + val url = client.baseUri.toString() + OCS_ROUTE_LIST_V12_AND_UP + id + JSON_FORMAT + + // get the notifications + try { + get = GetMethod(url, true) + status = client.execute(get) + val response = get.getResponseBodyAsString() + if (isSuccess(status)) { + result = RemoteOperationResult(true, get) + Log_OC.d(TAG, "Successful response: $response") + + // Parse the response + result.setResultData(parseResult(response)) + } else { + result = RemoteOperationResult(false, get) + Log_OC.e(TAG, "Failed response while getting user notifications ") + Log_OC.e(TAG, "*** status code: $status ; response message: $response") + } + } catch (e: Exception) { + result = RemoteOperationResult(e) + Log_OC.e(TAG, "Exception while getting remote notifications", e) + } finally { + get?.releaseConnection() + } + return result + } + + @Throws(JSONException::class) + private fun parseResult(response: String): Notification { + val jsonParser = JsonParser() + val jo = jsonParser.parse(response) as JsonObject + val jsonDataObject = jo.getAsJsonObject(NODE_OCS).getAsJsonObject(NODE_DATA) + val gson = Gson() + val type = object : TypeToken() {}.type + + return gson.fromJson(jsonDataObject, type) + } + + private fun isSuccess(status: Int): Boolean { + return status == HttpStatus.SC_OK + } + + companion object { + private val TAG = GetNotificationRemoteOperation::class.java.simpleName + + // OCS Route + private const val OCS_ROUTE_LIST_V12_AND_UP = + "/ocs/v2.php/apps/notifications/api/v2/notifications/" + + // JSON Node names + private const val NODE_OCS = "ocs" + private const val NODE_DATA = "data" + } +} diff --git a/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperation.java deleted file mode 100644 index ae2da9e508..0000000000 --- a/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperation.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Nextcloud Android Library - * - * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors - * SPDX-FileCopyrightText: 2017 Andy Scherzinger - * SPDX-FileCopyrightText: 2017 Mario Danic - * SPDX-License-Identifier: MIT - */ -package com.owncloud.android.lib.resources.notifications; - -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.reflect.TypeToken; -import com.nextcloud.common.NextcloudClient; -import com.nextcloud.operations.GetMethod; -import com.owncloud.android.lib.common.operations.RemoteOperation; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.utils.Log_OC; -import com.owncloud.android.lib.resources.notifications.models.Notification; - -import java.lang.reflect.Type; -import java.util.List; - -/** - * Provides the remote notifications from the server handling the following data structure - * accessible via the notifications endpoint at {@value OCS_ROUTE_LIST_V12_AND_UP}, specified at - * {@link "https://github.com/nextcloud/notifications/blob/master/docs/ocs-endpoint-v2.md"}. - */ -public class GetNotificationsRemoteOperation extends RemoteOperation> { - - // OCS Route - private static final String OCS_ROUTE_LIST_V12_AND_UP = - "/ocs/v2.php/apps/notifications/api/v2/notifications" + JSON_FORMAT; - - private static final String TAG = GetNotificationsRemoteOperation.class.getSimpleName(); - - // JSON Node names - private static final String NODE_OCS = "ocs"; - - private static final String NODE_DATA = "data"; - - @Override - public RemoteOperationResult> run(NextcloudClient client) { - RemoteOperationResult> result; - int status; - GetMethod get = null; - List notifications; - String url = client.getBaseUri() + OCS_ROUTE_LIST_V12_AND_UP; - - // get the notifications - try { - get = new GetMethod(url, true); - - status = client.execute(get); - String response = get.getResponseBodyAsString(); - - if (get.isSuccess()) { - result = new RemoteOperationResult<>(true, get); - Log_OC.d(TAG, "Successful response: " + response); - - // Parse the response - notifications = parseResult(response); - result.setResultData(notifications); - } else { - result = new RemoteOperationResult<>(false, get); - Log_OC.e(TAG, "Failed response while getting user notifications "); - Log_OC.e(TAG, "*** status code: " + status + " ; response message: " + response); - } - } catch (Exception e) { - result = new RemoteOperationResult<>(e); - Log_OC.e(TAG, "Exception while getting remote notifications", e); - } finally { - if (get != null) { - get.releaseConnection(); - } - } - - return result; - } - - private List parseResult(String response) { - JsonObject jo = (JsonObject) JsonParser.parseString(response); - JsonArray jsonDataArray = jo.getAsJsonObject(NODE_OCS).getAsJsonArray(NODE_DATA); - - Gson gson = new Gson(); - Type listType = new TypeToken>() { - }.getType(); - - return gson.fromJson(jsonDataArray, listType); - } -} diff --git a/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperation.kt new file mode 100644 index 0000000000..2cf965af4d --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperation.kt @@ -0,0 +1,105 @@ +/* Nextcloud Android Library is available under MIT license + * + * @author Andy Scherzinger + * @author Mario Danic + * Copyright (C) 2017 Andy Scherzinger + * Copyright (C) 2017 Mario Danic + * Copyright (C) 2017 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.owncloud.android.lib.resources.notifications + +import com.google.gson.Gson +import com.google.gson.JsonObject +import com.google.gson.JsonParser +import com.google.gson.reflect.TypeToken +import com.nextcloud.common.NextcloudClient +import com.nextcloud.operations.GetMethod +import com.owncloud.android.lib.common.operations.RemoteOperation +import com.owncloud.android.lib.common.operations.RemoteOperationResult +import com.owncloud.android.lib.common.utils.Log_OC +import com.owncloud.android.lib.resources.notifications.models.Notification +import org.apache.commons.httpclient.HttpStatus + +/** + * Provides the remote notifications from the server handling the following data structure + * accessible via the notifications endpoint at {@value OCS_ROUTE_LIST_V12_AND_UP}, specified at + * {@link "https://github.com/nextcloud/notifications/blob/master/docs/ocs-endpoint-v2.md"}. + */ +class GetNotificationsRemoteOperation : RemoteOperation>() { + override fun run(client: NextcloudClient): RemoteOperationResult> { + var result: RemoteOperationResult> + val status: Int + var get: GetMethod? = null + val notifications: List + val url = client.baseUri.toString() + OCS_ROUTE_LIST_V12_AND_UP + + // get the notifications + try { + get = GetMethod(url, true) + status = client.execute(get) + val response = get.getResponseBodyAsString() + if (isSuccess(status)) { + result = RemoteOperationResult(true, get) + Log_OC.d(TAG, "Successful response: $response") + + // Parse the response + notifications = parseResult(response) + result.setResultData(notifications) + } else { + result = RemoteOperationResult(false, get) + Log_OC.e(TAG, "Failed response while getting user notifications ") + Log_OC.e(TAG, "*** status code: $status ; response message: $response") + } + } catch (e: Exception) { + result = RemoteOperationResult(e) + Log_OC.e(TAG, "Exception while getting remote notifications", e) + } finally { + get?.releaseConnection() + } + return result + } + + private fun parseResult(response: String): List { + val jsonParser = JsonParser() + val jo = jsonParser.parse(response) as JsonObject + val jsonDataArray = jo.getAsJsonObject(NODE_OCS).getAsJsonArray(NODE_DATA) + val gson = Gson() + val listType = object : TypeToken?>() {}.type + return gson.fromJson(jsonDataArray, listType) + } + + private fun isSuccess(status: Int): Boolean { + return status == HttpStatus.SC_OK + } + + companion object { + // OCS Route + private const val OCS_ROUTE_LIST_V12_AND_UP = + "/ocs/v2.php/apps/notifications/api/v2/notifications" + JSON_FORMAT + private val TAG = GetNotificationsRemoteOperation::class.java.simpleName + + // JSON Node names + private const val NODE_OCS = "ocs" + private const val NODE_DATA = "data" + } +} From 0efe090335c98a6ca5fc403de9040fefebee81fc Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Wed, 8 Feb 2023 11:12:36 +0100 Subject: [PATCH 03/12] fix detekt Signed-off-by: tobiasKaminsky --- .../notifications/CreateNotificationRemoteOperation.kt | 3 ++- .../DeleteAllNotificationsRemoteOperation.kt | 5 +++-- .../notifications/DeleteNotificationRemoteOperation.kt | 5 +++-- .../notifications/GetNotificationRemoteOperation.kt | 6 +++--- .../notifications/GetNotificationsRemoteOperation.kt | 8 ++++---- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/notifications/CreateNotificationRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/notifications/CreateNotificationRemoteOperation.kt index 614cec5019..72cfc36677 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/notifications/CreateNotificationRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/notifications/CreateNotificationRemoteOperation.kt @@ -35,6 +35,7 @@ import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.notifications.models.Notification import okhttp3.FormBody import org.apache.commons.httpclient.HttpStatus +import java.io.IOException /** * Provides the remote notifications from the server handling the following data structure accessible via the @@ -67,7 +68,7 @@ class CreateNotificationRemoteOperation(private val userId: String, private val Log_OC.e(TAG, "Failed response while getting user notifications ") Log_OC.e(TAG, "*** status code: $status ; response message: $response") } - } catch (e: Exception) { + } catch (e: IOException) { result = RemoteOperationResult(e) Log_OC.e(TAG, "Exception while getting remote notifications", e) } finally { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperation.kt index 6e816d1858..93c21df2dc 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperation.kt @@ -14,7 +14,8 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; /** - * Delete all notification, specified at {@link "https://github.com/nextcloud/notifications/blob/master/docs/ocs-endpoint-v2.md"}. + * Delete all notification, specified at + * {@link "https://github.com/nextcloud/notifications/blob/master/docs/ocs-endpoint-v2.md"}. */ class DeleteAllNotificationsRemoteOperation : RemoteOperation() { override fun run(client: NextcloudClient): RemoteOperationResult { @@ -36,7 +37,7 @@ class DeleteAllNotificationsRemoteOperation : RemoteOperation() { Log_OC.e(this, "Failed response while deleting user notifications ") Log_OC.e(this, "*** status code: $status ;response message: $response") } - } catch (e: Exception) { + } catch (e: IOException) { result = RemoteOperationResult(e) Log_OC.e(this, "Exception while getting remote notifications", e) } finally { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperation.kt index 7edfb79f93..cbacea1212 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperation.kt @@ -14,7 +14,8 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; /** - * Delete a notification, specified at {@link "https://github.com/nextcloud/notifications/blob/master/docs/ocs-endpoint-v2.md"}. + * Delete a notification, specified at + * {@link "https://github.com/nextcloud/notifications/blob/master/docs/ocs-endpoint-v2.md"}. */ class DeleteNotificationRemoteOperation(private val id: Int) : RemoteOperation() { override fun run(client: NextcloudClient): RemoteOperationResult { @@ -36,7 +37,7 @@ class DeleteNotificationRemoteOperation(private val id: Int) : RemoteOperation() {}.type diff --git a/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperation.kt index 2cf965af4d..e220b78e86 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperation.kt @@ -39,6 +39,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.notifications.models.Notification import org.apache.commons.httpclient.HttpStatus +import java.io.IOException /** * Provides the remote notifications from the server handling the following data structure @@ -70,7 +71,7 @@ class GetNotificationsRemoteOperation : RemoteOperation>() { Log_OC.e(TAG, "Failed response while getting user notifications ") Log_OC.e(TAG, "*** status code: $status ; response message: $response") } - } catch (e: Exception) { + } catch (e: IOException) { result = RemoteOperationResult(e) Log_OC.e(TAG, "Exception while getting remote notifications", e) } finally { @@ -80,8 +81,7 @@ class GetNotificationsRemoteOperation : RemoteOperation>() { } private fun parseResult(response: String): List { - val jsonParser = JsonParser() - val jo = jsonParser.parse(response) as JsonObject + val jo = JsonParser.parseString(response) as JsonObject val jsonDataArray = jo.getAsJsonObject(NODE_OCS).getAsJsonArray(NODE_DATA) val gson = Gson() val listType = object : TypeToken?>() {}.type @@ -95,7 +95,7 @@ class GetNotificationsRemoteOperation : RemoteOperation>() { companion object { // OCS Route private const val OCS_ROUTE_LIST_V12_AND_UP = - "/ocs/v2.php/apps/notifications/api/v2/notifications" + JSON_FORMAT + "/ocs/v2.php/apps/notifications/api/v2/notifications$JSON_FORMAT" private val TAG = GetNotificationsRemoteOperation::class.java.simpleName // JSON Node names From 7deff088128dd10fd5a1820b1d6b3e167be38260 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Wed, 8 Feb 2023 13:46:23 +0100 Subject: [PATCH 04/12] fix sending test notification Signed-off-by: tobiasKaminsky --- .drone.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index 30eec7f8c7..abfa1c5396 100644 --- a/.drone.yml +++ b/.drone.yml @@ -101,7 +101,7 @@ services: - su www-data -c "php /var/www/html/occ groupfolders:group 1 users" - su www-data -c "git clone --depth 1 https://github.com/nextcloud/notifications.git /var/www/html/apps/notifications/" - su www-data -c "php /var/www/html/occ app:enable -f notifications" - - su www-data -c "php /var/www/html/occ notification:generate test -d test" + - su www-data -c "php /var/www/html/occ notification:generate 'test' 'test message'" - su www-data -c "git clone --depth 1 https://github.com/nextcloud/photos.git /var/www/html/apps/photos/" - su www-data -c "cd /var/www/html/apps/photos; composer install --no-dev" - su www-data -c "php /var/www/html/occ app:enable -f photos" @@ -216,7 +216,7 @@ services: - su www-data -c "php /var/www/html/occ groupfolders:group 1 users" - su www-data -c "git clone --depth 1 -b $SERVER_VERSION https://github.com/nextcloud/notifications.git /var/www/html/apps/notifications/" - su www-data -c "php /var/www/html/occ app:enable -f notifications" - - su www-data -c "php /var/www/html/occ notification:generate test test" + - su www-data -c "php /var/www/html/occ notification:generate 'test' 'test message'" - su www-data -c "git clone --depth 1 -b $SERVER_VERSION https://github.com/nextcloud/photos.git /var/www/html/apps/photos/" - su www-data -c "cd /var/www/html/apps/photos; composer install --no-dev" - su www-data -c "php /var/www/html/occ app:enable -f photos" From 32c09b3ed7efe9245dc322cb58073f7548f650b1 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Thu, 9 Feb 2023 10:13:49 +0100 Subject: [PATCH 05/12] test sending notification after startup Signed-off-by: tobiasKaminsky --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index abfa1c5396..c410105838 100644 --- a/.drone.yml +++ b/.drone.yml @@ -99,7 +99,7 @@ services: - su www-data -c "php /var/www/html/occ app:enable -f groupfolders" - su www-data -c "php /var/www/html/occ groupfolders:create groupfolder" - su www-data -c "php /var/www/html/occ groupfolders:group 1 users" - - su www-data -c "git clone --depth 1 https://github.com/nextcloud/notifications.git /var/www/html/apps/notifications/" + - su www-data -c "git clone --depth 1 -b master https://github.com/nextcloud/notifications.git /var/www/html/apps/notifications/" - su www-data -c "php /var/www/html/occ app:enable -f notifications" - su www-data -c "php /var/www/html/occ notification:generate 'test' 'test message'" - su www-data -c "git clone --depth 1 https://github.com/nextcloud/photos.git /var/www/html/apps/photos/" From 43669467c3807943c6b1056b5a3a1457149c4287 Mon Sep 17 00:00:00 2001 From: nextcloud-android-bot Date: Wed, 22 Feb 2023 14:00:48 +0000 Subject: [PATCH 06/12] Analysis: update Spotbugs results to reflect reduced error/warning count Signed-off-by: nextcloud-android-bot --- scripts/analysis/findbugs-results.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/analysis/findbugs-results.txt b/scripts/analysis/findbugs-results.txt index 2efea5198b..897bdc8200 100644 --- a/scripts/analysis/findbugs-results.txt +++ b/scripts/analysis/findbugs-results.txt @@ -1 +1 @@ -167 \ No newline at end of file +139 From 977ff27827970f3c4ad45d25fcb4d5ee0e3cbcba Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Fri, 13 Dec 2024 09:59:52 +0100 Subject: [PATCH 07/12] update Signed-off-by: tobiasKaminsky --- .../java/com/owncloud/android/AbstractIT.java | 2 +- .../resources/notifications/NotificationIT.kt | 1 + .../com/nextcloud/operations/PostMethod.kt | 2 +- .../CreateNotificationRemoteOperation.kt | 9 ++++--- .../DeleteAllNotificationsRemoteOperation.kt | 27 ++++++++++--------- .../DeleteNotificationRemoteOperation.kt | 20 ++++++-------- 6 files changed, 30 insertions(+), 31 deletions(-) diff --git a/library/src/androidTest/java/com/owncloud/android/AbstractIT.java b/library/src/androidTest/java/com/owncloud/android/AbstractIT.java index 7e2d1aba9d..2398a911f4 100644 --- a/library/src/androidTest/java/com/owncloud/android/AbstractIT.java +++ b/library/src/androidTest/java/com/owncloud/android/AbstractIT.java @@ -267,7 +267,7 @@ public static File extractAsset(String fileName, Context context) throws IOExcep @After public void after() { removeOnClient(client); - removeOnClient(client2); + // removeOnClient(client2); } private void removeOnClient(OwnCloudClient client) { diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/NotificationIT.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/NotificationIT.kt index ba34b46fba..c0e39786c0 100644 --- a/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/NotificationIT.kt +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/NotificationIT.kt @@ -22,6 +22,7 @@ class NotificationIT : AbstractIT() { val count = all.resultData.size // get one + assertTrue(count > 0) val firstNotification = all.resultData[0] val first = GetNotificationRemoteOperation(firstNotification.notificationId).execute(nextcloudClient) assertTrue(first.isSuccess) diff --git a/library/src/main/java/com/nextcloud/operations/PostMethod.kt b/library/src/main/java/com/nextcloud/operations/PostMethod.kt index 09fdc806e4..c4b1f4dd5d 100644 --- a/library/src/main/java/com/nextcloud/operations/PostMethod.kt +++ b/library/src/main/java/com/nextcloud/operations/PostMethod.kt @@ -16,7 +16,7 @@ import okhttp3.RequestBody * HTTP POST method that uses OkHttp with new NextcloudClient * UTF8 by default */ -class PostMethod( +open class PostMethod( uri: String, useOcsApiRequestHeader: Boolean, val body: RequestBody? diff --git a/library/src/main/java/com/owncloud/android/lib/resources/notifications/CreateNotificationRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/notifications/CreateNotificationRemoteOperation.kt index 72cfc36677..ab3092cfd1 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/notifications/CreateNotificationRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/notifications/CreateNotificationRemoteOperation.kt @@ -52,10 +52,11 @@ class CreateNotificationRemoteOperation(private val userId: String, private val client.baseUri.toString() + "/ocs/v2.php/apps/notifications/api/v2/admin_notifications/" try { - val bodyRequest = FormBody - .Builder() - .add("shortMessage", message) - .build() + val bodyRequest = + FormBody + .Builder() + .add("shortMessage", message) + .build() post = PostMethod(url + userId, true, bodyRequest) status = client.execute(post) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperation.kt index 93c21df2dc..67fa3fe858 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperation.kt @@ -5,13 +5,14 @@ * SPDX-FileCopyrightText: 2019 Tobias Kaminsky * SPDX-License-Identifier: MIT */ -package com.owncloud.android.lib.resources.notifications; +package com.owncloud.android.lib.resources.notifications -import com.nextcloud.common.NextcloudClient; -import com.nextcloud.operations.DeleteMethod; -import com.owncloud.android.lib.common.operations.RemoteOperation; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.utils.Log_OC; +import com.nextcloud.common.NextcloudClient +import com.nextcloud.operations.DeleteMethod +import com.owncloud.android.lib.common.operations.RemoteOperation +import com.owncloud.android.lib.common.operations.RemoteOperationResult +import com.owncloud.android.lib.common.utils.Log_OC +import java.io.IOException /** * Delete all notification, specified at @@ -24,17 +25,17 @@ class DeleteAllNotificationsRemoteOperation : RemoteOperation() { var delete: DeleteMethod? = null val url = client.baseUri.toString() + OCS_ROUTE_LIST_V12_AND_UP try { - delete = new DeleteMethod(url, true) + delete = DeleteMethod(url, true) - status = client.execute(delete); - String response = delete.getResponseBodyAsString() + status = client.execute(delete) + val response = delete.getResponseBodyAsString() if (delete.isSuccess()) { - result = new RemoteOperationResult<>(true, delete) - Log_OC.d(this, "Successful response: " + response) + result = RemoteOperationResult(true, delete) + Log_OC.d(this, "Successful response: $response") } else { - result = new RemoteOperationResult<>(false, delete) - Log_OC.e(this, "Failed response while deleting user notifications ") + result = RemoteOperationResult(false, delete) + Log_OC.e(this, "Failed response while deleting all user notifications") Log_OC.e(this, "*** status code: $status ;response message: $response") } } catch (e: IOException) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperation.kt index cbacea1212..af900f82e1 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperation.kt @@ -5,13 +5,14 @@ * SPDX-FileCopyrightText: 2019 Tobias Kaminsky * SPDX-License-Identifier: MIT */ -package com.owncloud.android.lib.resources.notifications; +package com.owncloud.android.lib.resources.notifications -import com.nextcloud.common.NextcloudClient; -import com.nextcloud.operations.DeleteMethod; -import com.owncloud.android.lib.common.operations.RemoteOperation; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.utils.Log_OC; +import com.nextcloud.common.NextcloudClient +import com.nextcloud.operations.DeleteMethod +import com.owncloud.android.lib.common.operations.RemoteOperation +import com.owncloud.android.lib.common.operations.RemoteOperationResult +import com.owncloud.android.lib.common.utils.Log_OC +import java.io.IOException /** * Delete a notification, specified at @@ -46,13 +47,8 @@ class DeleteNotificationRemoteOperation(private val id: Int) : RemoteOperation Date: Fri, 13 Dec 2024 10:05:23 +0100 Subject: [PATCH 08/12] revert Signed-off-by: tobiasKaminsky --- .../src/androidTest/java/com/owncloud/android/AbstractIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/src/androidTest/java/com/owncloud/android/AbstractIT.java b/library/src/androidTest/java/com/owncloud/android/AbstractIT.java index 2398a911f4..7e2d1aba9d 100644 --- a/library/src/androidTest/java/com/owncloud/android/AbstractIT.java +++ b/library/src/androidTest/java/com/owncloud/android/AbstractIT.java @@ -267,7 +267,7 @@ public static File extractAsset(String fileName, Context context) throws IOExcep @After public void after() { removeOnClient(client); - // removeOnClient(client2); + removeOnClient(client2); } private void removeOnClient(OwnCloudClient client) { From ce9d301831ab1f9f24ab0f7b1f536271fa1ab3e8 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Fri, 13 Dec 2024 10:47:44 +0100 Subject: [PATCH 09/12] update licences Signed-off-by: tobiasKaminsky --- .../nextcloud/operations/Utf8PostMethod.kt | 22 +++---------- .../CreateNotificationRemoteOperation.kt | 29 +++------------- .../GetNotificationRemoteOperation.kt | 30 ++++------------- .../GetNotificationsRemoteOperation.kt | 33 ++++--------------- 4 files changed, 22 insertions(+), 92 deletions(-) diff --git a/library/src/main/java/com/nextcloud/operations/Utf8PostMethod.kt b/library/src/main/java/com/nextcloud/operations/Utf8PostMethod.kt index 5cad35c10d..1c322af6b0 100644 --- a/library/src/main/java/com/nextcloud/operations/Utf8PostMethod.kt +++ b/library/src/main/java/com/nextcloud/operations/Utf8PostMethod.kt @@ -1,23 +1,9 @@ /* - * Nextcloud Android client application - * - * @author Tobias Kaminsky - * Copyright (C) 2022 Tobias Kaminsky - * Copyright (C) 2022 Nextcloud GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * Nextcloud Android Library * + * SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2022 Tobias Kaminsky + * SPDX-License-Identifier: MIT */ package com.nextcloud.operations diff --git a/library/src/main/java/com/owncloud/android/lib/resources/notifications/CreateNotificationRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/notifications/CreateNotificationRemoteOperation.kt index ab3092cfd1..e97ab474cb 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/notifications/CreateNotificationRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/notifications/CreateNotificationRemoteOperation.kt @@ -1,28 +1,9 @@ -/* Nextcloud Android Library is available under MIT license - * - * @author Tobias Kaminsky - * Copyright (C) 2022 Tobias Kaminsky - * Copyright (C) 2022 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. +/* + * Nextcloud Android Library * + * SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2022 Tobias Kaminsky + * SPDX-License-Identifier: MIT */ package com.owncloud.android.lib.resources.notifications diff --git a/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperation.kt index 9800e80f0e..74c5c375ef 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperation.kt @@ -1,29 +1,11 @@ -/* Nextcloud Android Library is available under MIT license - * - * @author Tobias Kaminsky - * Copyright (C) 2019 Tobias Kaminsky - * Copyright (C) 2019 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. +/* + * Nextcloud Android Library * + * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2019 Tobias Kaminsky + * SPDX-License-Identifier: MIT */ + package com.owncloud.android.lib.resources.notifications import com.google.gson.Gson diff --git a/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperation.kt index e220b78e86..13f02a8258 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperation.kt @@ -1,31 +1,12 @@ -/* Nextcloud Android Library is available under MIT license - * - * @author Andy Scherzinger - * @author Mario Danic - * Copyright (C) 2017 Andy Scherzinger - * Copyright (C) 2017 Mario Danic - * Copyright (C) 2017 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. +/* + * Nextcloud Android Library * + * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2017 Mario Danic + * SPDX-FileCopyrightText: 2017 Andy Scherzinger + * SPDX-License-Identifier: MIT */ + package com.owncloud.android.lib.resources.notifications import com.google.gson.Gson From 43dd213ea993da054ead0a008925ed2cab4e7b66 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Fri, 13 Dec 2024 10:59:50 +0100 Subject: [PATCH 10/12] update licences Signed-off-by: tobiasKaminsky --- ...DeleteAllNotificationsRemoteOperationIT.kt | 29 ++++--------------- .../DeleteNotificationRemoteOperationIT.kt | 29 ++++--------------- .../GetNotificationRemoteOperationIT.kt | 29 ++++--------------- .../GetNotificationsRemoteOperationIT.kt | 23 ++++----------- 4 files changed, 20 insertions(+), 90 deletions(-) diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperationIT.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperationIT.kt index 2374bba681..aa9f6e51f6 100644 --- a/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperationIT.kt +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/DeleteAllNotificationsRemoteOperationIT.kt @@ -1,28 +1,9 @@ -/* Nextcloud Android Library is available under MIT license - * - * @author Tobias Kaminsky - * Copyright (C) 2022 Tobias Kaminsky - * Copyright (C) 2022 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. +/* + * Nextcloud Android Library * + * SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2022 Tobias Kaminsky + * SPDX-License-Identifier: MIT */ package com.owncloud.android.lib.resources.notifications diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperationIT.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperationIT.kt index b80973bac8..ecd952e34d 100644 --- a/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperationIT.kt +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/DeleteNotificationRemoteOperationIT.kt @@ -1,28 +1,9 @@ -/* Nextcloud Android Library is available under MIT license - * - * @author Tobias Kaminsky - * Copyright (C) 2022 Tobias Kaminsky - * Copyright (C) 2022 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. +/* + * Nextcloud Android Library * + * SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2022 Tobias Kaminsky + * SPDX-License-Identifier: MIT */ package com.owncloud.android.lib.resources.notifications diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperationIT.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperationIT.kt index aab7bc0fd9..e41dd25569 100644 --- a/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperationIT.kt +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperationIT.kt @@ -1,28 +1,9 @@ -/* Nextcloud Android Library is available under MIT license - * - * @author Tobias Kaminsky - * Copyright (C) 2022 Tobias Kaminsky - * Copyright (C) 2022 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. +/* + * Nextcloud Android Library * + * SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2022 Tobias Kaminsky + * SPDX-License-Identifier: MIT */ package com.owncloud.android.lib.resources.notifications diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperationIT.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperationIT.kt index 5f0425937e..f228b5423b 100644 --- a/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperationIT.kt +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/GetNotificationsRemoteOperationIT.kt @@ -1,24 +1,11 @@ /* - * Nextcloud Android client application - * - * @author Tobias Kaminsky - * Copyright (C) 2022 Tobias Kaminsky - * Copyright (C) 2022 Nextcloud GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * Nextcloud Android Library * + * SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2022 Tobias Kaminsky + * SPDX-License-Identifier: MIT */ + package com.owncloud.android.lib.resources.notifications import com.owncloud.android.AbstractIT From 2df66e2babe773c2de3a6819592929aa8a6c94ff Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Mon, 16 Dec 2024 09:48:56 +0100 Subject: [PATCH 11/12] sign drone Signed-off-by: tobiasKaminsky --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index c410105838..f2ad8f2fe7 100644 --- a/.drone.yml +++ b/.drone.yml @@ -235,6 +235,6 @@ trigger: - pull_request --- kind: signature -hmac: 3e71a44f6f57a4d4d853c586c0c322bf0b718d96627906b92864e12353e5a014 +hmac: 889fb47b6c7f4ba0f7b0297f697e29152099b18b6f5073ad02a503ab9046fbcd ... From 8e2079f50b6f1d26f060ba6d8be71120dbab2ce4 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Fri, 20 Dec 2024 10:52:13 +0100 Subject: [PATCH 12/12] Ensure reliability of test Signed-off-by: tobiasKaminsky --- .../notifications/GetNotificationRemoteOperationIT.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperationIT.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperationIT.kt index e41dd25569..f3e8fa769a 100644 --- a/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperationIT.kt +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/notifications/GetNotificationRemoteOperationIT.kt @@ -18,6 +18,16 @@ import org.junit.Test class GetNotificationRemoteOperationIT : AbstractIT() { @Test fun testSingleNotification() { + // create one notification + assertTrue( + nextcloudClientAdmin.execute( + CreateNotificationRemoteOperation( + nextcloudClient.userId, + "test" + ) + ).isSuccess + ) + // get all notifications val resultAll = nextcloudClient.execute(GetNotificationsRemoteOperation()) assertTrue(resultAll.isSuccess)