From 5b3b94cf50e2a5cd5e39f8152ab0f249887b3d5b Mon Sep 17 00:00:00 2001 From: rushannanayakkara Date: Tue, 9 Jul 2024 23:09:27 +0530 Subject: [PATCH 1/9] Add notification template management functions --- .../NotificationTemplateManager.java | 214 ++++++++++++++++-- 1 file changed, 197 insertions(+), 17 deletions(-) diff --git a/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java b/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java index abf5eca938..a73ca294bb 100644 --- a/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java +++ b/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2019-2024, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,124 @@ */ public interface NotificationTemplateManager { + + /** + * Add a new notification template to the system (db/ registry). + * + * @param notificationChannel Notification channel + * @param displayName Notification template display name + * @param tenantDomain Tenant domain + * @throws NotificationTemplateManagerException If an error occurred while adding the template to the registry + */ + default void addNotificationTemplateType(String notificationChannel, String displayName, String tenantDomain) + throws NotificationTemplateManagerException { + + } + + /** + * Add a new notification template to the system (db/ registry). + * + * @param notificationChannel Notification channel (Eg: SMS, EMAIL). + * @param displayName Notification template display name. + * @param tenantDomain Tenant domain. + * @param applicationUuid Application UUID. + * @throws NotificationTemplateManagerException If an error occurred while adding the template to the registry. + */ + default void addNotificationTemplateType(String notificationChannel, String displayName, + String tenantDomain, String applicationUuid) + throws NotificationTemplateManagerException { + + } + + /** + * Get all available notification template types for the tenant. + * + * @param notificationChannel Notification channel (Eg: SMS, EMAIL). + * @param tenantDomain Tenant domain. + * @return List of notification template types. + * @throws NotificationTemplateManagerException If an error occurred while getting the notification template types. + */ + default List getAllNotificationTemplateTypes(String notificationChannel, String tenantDomain) + throws NotificationTemplateManagerException { + + return null; + } + + /** + * Delete a notification template type from the tenant registry. + * + * @param notificationChannel Notification channel. + * @param templateDisplayName Display name of the template type. + * @param tenantDomain Tenant domain. + * @throws NotificationTemplateManagerException If an error occurred while deleting the notification template type. + */ + default void deleteNotificationTemplateType(String notificationChannel, String templateDisplayName, + String tenantDomain) + throws NotificationTemplateManagerException { + + } + + /** + * Check whether the given notification template type exists in the system. + * + * @param notificationChannel Notification channel. + * @param templateTypeDisplayName Display name of the template type. + * @param tenantDomain Tenant Domain. + * @throws NotificationTemplateManagerException If an error occurred while checking if template type exists. + */ + default boolean isNotificationTemplateTypeExists(String notificationChannel, String templateTypeDisplayName, + String tenantDomain) + throws NotificationTemplateManagerException { + + return false; + } + + /** + * Get all available notification template types for the tenant. + * + * @param notificationChannel Notification channel (Eg: SMS, EMAIL). + * @param tenantDomain Tenant domain. + * @throws NotificationTemplateManagerException If an error occurred while getting the notification template types. + */ + default List getAllNotificationTemplates(String notificationChannel, String tenantDomain) + throws NotificationTemplateManagerException { + + return null; + } + + /** + * Get all notification templates of the given type. + * + * @param notificationChannel Notification channel (Eg: SMS, EMAIL). + * @param templateDisplayName Display name of the template. + * @param tenantDomain Tenant domain. + * @return List of notification templates. + * @throws NotificationTemplateManagerException If an error occurred while getting the notification templates. + */ + default List getNotificationTemplatesOfType(String notificationChannel, + String templateDisplayName, String tenantDomain) + throws NotificationTemplateManagerException { + + return null; + } + + /** + * Get all notification templates of the given type. + * + * @param notificationChannel Notification channel (Eg: SMS, EMAIL). + * @param templateDisplayName Display name of the template. + * @param tenantDomain Tenant domain. + * @param applicationUuid Application UUID. + * @return List of notification templates. + * @throws NotificationTemplateManagerException If an error occurred while getting the notification templates. + */ + default List getNotificationTemplatesOfType(String notificationChannel, + String templateDisplayName, String tenantDomain, String applicationUuid) + throws NotificationTemplateManagerException { + + return null; + } + /** * Return the notification template from the tenant registry which matches the given channel and template name. * @@ -61,7 +179,7 @@ default NotificationTemplate getNotificationTemplate(String notificationChannel, } /** - * Add the notification template to the registry. + * Add the notification template. * * @param notificationTemplate Notification template * {@link org.wso2.carbon.identity.governance.model.NotificationTemplate} @@ -74,7 +192,7 @@ default void addNotificationTemplate(NotificationTemplate notificationTemplate, } /** - * Add the notification template to the registry. + * Add the notification template. * * @param notificationTemplate Notification template. * @param tenantDomain Tenant domain. @@ -87,14 +205,59 @@ default void addNotificationTemplate(NotificationTemplate notificationTemplate, } /** - * Add a new notification template to the registry to the corresponding notification channel root directory. + * Update notification template. * - * @param displayName Notification template display name - * @param notificationChannel Notification channel - * @param tenantDomain Tenant domain - * @throws NotificationTemplateManagerException If an error occurred while adding the template to the registry + * @param notificationTemplate Notification template + * {@link org.wso2.carbon.identity.governance.model.NotificationTemplate} + * @param tenantDomain Tenant domain + * @throws NotificationTemplateManagerException If an error occurred while updating the notification template */ - default void addNotificationTemplateType(String displayName, String notificationChannel, String tenantDomain) + default void updateNotificationTemplate(NotificationTemplate notificationTemplate, String tenantDomain) + throws NotificationTemplateManagerException { + + } + + /** + * Update notification template of application. + * + * @param notificationTemplate Notification template. + * @param tenantDomain Tenant domain. + * @param applicationUuid Application UUID. + * @throws NotificationTemplateManagerException If an error occurred while updating the notification template. + */ + default void updateNotificationTemplate(NotificationTemplate notificationTemplate, String tenantDomain, + String applicationUuid) throws NotificationTemplateManagerException { + + } + + /** + * Delete a notification template from the system. + * + * @param notificationChannel Notification channel (Eg: SMS, EMAIL). + * @param templateDisplayName Display name of the template. + * @param locale Locale of the template. + * @param tenantDomain Tenant domain. + * @throws NotificationTemplateManagerException If an error occurred while deleting the notification template. + */ + default void deleteNotificationTemplate(String notificationChannel, String templateDisplayName, String locale, + String tenantDomain) + throws NotificationTemplateManagerException { + + } + + + /** + * Delete an application notification template from the system. + * + * @param notificationChannel Notification channel (Eg: SMS, EMAIL). + * @param templateDisplayName Display name of the template. + * @param locale Locale of the template. + * @param tenantDomain Tenant domain. + * @param applicationUuid Application UUID. + * @throws NotificationTemplateManagerException If an error occurred while deleting the notification template. + */ + default void deleteNotificationTemplate(String notificationChannel, String templateDisplayName, String locale, + String tenantDomain, String applicationUuid) throws NotificationTemplateManagerException { } @@ -124,17 +287,34 @@ default List getDefaultNotificationTemplates(String notifi } /** - * Add a new notification template to the registry to the corresponding notification channel root directory. + * Check whether the given notification template exists in the system. * - * @param displayName Notification template display name. - * @param notificationChannel Notification channel (Eg: SMS, EMAIL). - * @param tenantDomain Tenant domain. - * @param applicationUuid Application UUID. - * @throws NotificationTemplateManagerException If an error occurred while adding the template to the registry. + * @param notificationChannel Notification channel. + * @param templateDisplayName Display name of the template. + * @param tenantDomain Tenant Domain. + * @throws NotificationTemplateManagerException If an error occurred while checking if template type exists. */ - default void addNotificationTemplateType(String displayName, String notificationChannel, - String tenantDomain, String applicationUuid) + default boolean isNotificationTemplateExists(String notificationChannel, String templateDisplayName, String locale, + String tenantDomain) + throws NotificationTemplateManagerException { + + return false; + } + + /** + * Check whether the given notification template exists in the system. + * + * @param notificationChannel Notification channel. + * @param templateDisplayName Display name of the template. + * @param tenantDomain Tenant Domain. + * @param applicationUuid Application UUID. + * @return True if the template exists, false otherwise. + * @throws NotificationTemplateManagerException If an error occurred while checking if template type exists. + */ + default boolean isNotificationTemplateExists(String notificationChannel, String templateDisplayName, String locale, + String tenantDomain, String applicationUuid) throws NotificationTemplateManagerException { + return false; } } From 513390b6c7973dda8ddac9110f012055538cad7e Mon Sep 17 00:00:00 2001 From: rushannanayakkara Date: Thu, 26 Sep 2024 22:36:37 +0530 Subject: [PATCH 2/9] Add NotificationTemplateManager.getSystemNotificationTemplate function --- .../NotificationTemplateManager.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java b/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java index a3f2be4ec1..30a92ba231 100644 --- a/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java +++ b/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java @@ -287,6 +287,22 @@ default List getDefaultNotificationTemplates(String notifi return null; } + /** + * Return the default system notification template which matches the given channel and template name. + * + * @param notificationChannel Notification Channel Name (Eg: SMS or EMAIL) + * @param templateType Display name of the template + * @param locale Locale + * @return Return {@link org.wso2.carbon.identity.governance.model.NotificationTemplate} object + * @throws NotificationTemplateManagerException If an error occurred while getting the notification template + */ + default NotificationTemplate getSystemNotificationTemplate(String notificationChannel, String templateType, + String locale) + throws NotificationTemplateManagerException { + + return null; + } + /** * Check whether the given notification template exists in the system. * From d08b1e59cc3525ed6dabe185bce9af884903a1b6 Mon Sep 17 00:00:00 2001 From: rushannanayakkara Date: Sun, 29 Sep 2024 19:01:55 +0530 Subject: [PATCH 3/9] Add NotificationTemplateManager.getAllSystemNotificationTemplatesOfType function --- .../notification/NotificationTemplateManager.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java b/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java index 30a92ba231..8b589ab3a2 100644 --- a/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java +++ b/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java @@ -110,6 +110,18 @@ default List getAllNotificationTemplates(String notificati return null; } + /** + * Get all available system notification templates of given type. + * + * @param notificationChannel Notification channel (Eg: SMS, EMAIL). + * @return List of system notification templates. + */ + default List getAllSystemNotificationTemplatesOfType(String notificationChannel, + String templateDisplayName) throws NotificationTemplateManagerException { + + return null; + } + /** * Get all notification templates of the given type. * From 86f7ee98b0a7e43d8f000920920d56a5c70a4db3 Mon Sep 17 00:00:00 2001 From: rushannanayakkara Date: Sat, 5 Oct 2024 09:26:46 +0530 Subject: [PATCH 4/9] Add NotificationTemplateManager.deleteCustomizedNotificationTemplates function --- .../notification/NotificationTemplateManager.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java b/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java index 8b589ab3a2..5b109633f0 100644 --- a/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java +++ b/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java @@ -274,6 +274,21 @@ default void deleteNotificationTemplate(String notificationChannel, String templ } + + /** + * Delete all organization and application notification templates of a type from the system. + * + * @param notificationChannel Notification channel (Eg: SMS, EMAIL). + * @param templateType Display name of the template. + * @param tenantDomain Tenant domain. + * @throws NotificationTemplateManagerException If an error occurred while deleting the notification template. + */ + default void deleteCustomizedNotificationTemplates(String notificationChannel, String templateType, + String tenantDomain) + throws NotificationTemplateManagerException { + + } + /** * Add the default notification templates which matches the given notification channel to the respective tenants * registry. From 575f1c521ab2495a730d2485be22da2ada53fa93 Mon Sep 17 00:00:00 2001 From: rushannanayakkara Date: Fri, 18 Oct 2024 07:13:59 +0530 Subject: [PATCH 5/9] Rename NotificationTemplateManager.deleteCustomizedNotificationTemplates function to resetNotificationTemplateType --- .../notification/NotificationTemplateManager.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java b/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java index 5b109633f0..3a37fb28a5 100644 --- a/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java +++ b/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java @@ -274,17 +274,16 @@ default void deleteNotificationTemplate(String notificationChannel, String templ } - /** - * Delete all organization and application notification templates of a type from the system. + * Deletes the template type in the database resulting in the deletion of all it's user defined templates + * and recreates the type. * * @param notificationChannel Notification channel (Eg: SMS, EMAIL). * @param templateType Display name of the template. * @param tenantDomain Tenant domain. - * @throws NotificationTemplateManagerException If an error occurred while deleting the notification template. + * @throws NotificationTemplateManagerException If an error occurred while resetting the notification template type. */ - default void deleteCustomizedNotificationTemplates(String notificationChannel, String templateType, - String tenantDomain) + default void resetNotificationTemplateType(String notificationChannel, String templateType, String tenantDomain) throws NotificationTemplateManagerException { } From c8c976bc5437803da61c64a765bcb5e1a1077cc3 Mon Sep 17 00:00:00 2001 From: rushannanayakkara Date: Fri, 18 Oct 2024 10:12:39 +0530 Subject: [PATCH 6/9] Fix typos in function descriptions. --- .../NotificationTemplateManager.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java b/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java index 3a37fb28a5..bbef05dd37 100644 --- a/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java +++ b/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java @@ -27,9 +27,9 @@ public interface NotificationTemplateManager { /** - * Add a new notification template to the system (db/ registry). + * Add new notification template type to the system. * - * @param notificationChannel Notification channel + * @param notificationChannel Notification channel (Eg: SMS, EMAIL). * @param displayName Notification template display name * @param tenantDomain Tenant domain * @throws NotificationTemplateManagerException If an error occurred while adding the template to the registry @@ -40,7 +40,7 @@ default void addNotificationTemplateType(String notificationChannel, String disp } /** - * Add a new notification template to the system (db/ registry). + * Add new notification template type to the system. * * @param notificationChannel Notification channel (Eg: SMS, EMAIL). * @param displayName Notification template display name. @@ -71,7 +71,7 @@ default List getAllNotificationTemplateTypes(String notificationChannel, /** * Delete a notification template type from the tenant registry. * - * @param notificationChannel Notification channel. + * @param notificationChannel Notification channel (Eg: SMS, EMAIL). * @param templateDisplayName Display name of the template type. * @param tenantDomain Tenant domain. * @throws NotificationTemplateManagerException If an error occurred while deleting the notification template type. @@ -85,7 +85,7 @@ default void deleteNotificationTemplateType(String notificationChannel, String t /** * Check whether the given notification template type exists in the system. * - * @param notificationChannel Notification channel. + * @param notificationChannel Notification channel (Eg: SMS, EMAIL). * @param templateTypeDisplayName Display name of the template type. * @param tenantDomain Tenant Domain. * @throws NotificationTemplateManagerException If an error occurred while checking if template type exists. @@ -98,7 +98,7 @@ default boolean isNotificationTemplateTypeExists(String notificationChannel, Str } /** - * Get all available notification template types for the tenant. + * Get all available notification template types in the tenant for a given notification channel. * * @param notificationChannel Notification channel (Eg: SMS, EMAIL). * @param tenantDomain Tenant domain. @@ -275,8 +275,7 @@ default void deleteNotificationTemplate(String notificationChannel, String templ } /** - * Deletes the template type in the database resulting in the deletion of all it's user defined templates - * and recreates the type. + * Resets the template type in the database by deleting of all it's user defined templates. * * @param notificationChannel Notification channel (Eg: SMS, EMAIL). * @param templateType Display name of the template. @@ -332,9 +331,9 @@ default NotificationTemplate getSystemNotificationTemplate(String notificationCh /** * Check whether the given notification template exists in the system. * - * @param notificationChannel Notification channel. - * @param templateDisplayName Display name of the template. - * @param tenantDomain Tenant Domain. + * @param notificationChannel Notification channel. + * @param templateDisplayName Display name of the template. + * @param tenantDomain Tenant Domain. * @throws NotificationTemplateManagerException If an error occurred while checking if template type exists. */ default boolean isNotificationTemplateExists(String notificationChannel, String templateDisplayName, String locale, From b607f12610316c1103b4e713cd689e420ebf4df0 Mon Sep 17 00:00:00 2001 From: rushannanayakkara Date: Mon, 21 Oct 2024 09:49:01 +0530 Subject: [PATCH 7/9] Refactor code --- .../NotificationTemplateManager.java | 74 +++++++++---------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java b/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java index bbef05dd37..31a618c1f5 100644 --- a/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java +++ b/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java @@ -98,26 +98,27 @@ default boolean isNotificationTemplateTypeExists(String notificationChannel, Str } /** - * Get all available notification template types in the tenant for a given notification channel. + * Resets the template type in the database by deleting of all it's user defined templates. * * @param notificationChannel Notification channel (Eg: SMS, EMAIL). + * @param templateType Display name of the template. * @param tenantDomain Tenant domain. - * @throws NotificationTemplateManagerException If an error occurred while getting the notification template types. + * @throws NotificationTemplateManagerException If an error occurred while resetting the notification template type. */ - default List getAllNotificationTemplates(String notificationChannel, String tenantDomain) + default void resetNotificationTemplateType(String notificationChannel, String templateType, String tenantDomain) throws NotificationTemplateManagerException { - return null; } /** - * Get all available system notification templates of given type. + * Get all available notification template types in the tenant for a given notification channel. * * @param notificationChannel Notification channel (Eg: SMS, EMAIL). - * @return List of system notification templates. + * @param tenantDomain Tenant domain. + * @throws NotificationTemplateManagerException If an error occurred while getting the notification template types. */ - default List getAllSystemNotificationTemplatesOfType(String notificationChannel, - String templateDisplayName) throws NotificationTemplateManagerException { + default List getAllNotificationTemplates(String notificationChannel, String tenantDomain) + throws NotificationTemplateManagerException { return null; } @@ -274,19 +275,6 @@ default void deleteNotificationTemplate(String notificationChannel, String templ } - /** - * Resets the template type in the database by deleting of all it's user defined templates. - * - * @param notificationChannel Notification channel (Eg: SMS, EMAIL). - * @param templateType Display name of the template. - * @param tenantDomain Tenant domain. - * @throws NotificationTemplateManagerException If an error occurred while resetting the notification template type. - */ - default void resetNotificationTemplateType(String notificationChannel, String templateType, String tenantDomain) - throws NotificationTemplateManagerException { - - } - /** * Add the default notification templates which matches the given notification channel to the respective tenants * registry. @@ -312,22 +300,6 @@ default List getDefaultNotificationTemplates(String notifi return null; } - /** - * Return the default system notification template which matches the given channel and template name. - * - * @param notificationChannel Notification Channel Name (Eg: SMS or EMAIL) - * @param templateType Display name of the template - * @param locale Locale - * @return Return {@link org.wso2.carbon.identity.governance.model.NotificationTemplate} object - * @throws NotificationTemplateManagerException If an error occurred while getting the notification template - */ - default NotificationTemplate getSystemNotificationTemplate(String notificationChannel, String templateType, - String locale) - throws NotificationTemplateManagerException { - - return null; - } - /** * Check whether the given notification template exists in the system. * @@ -359,4 +331,32 @@ default boolean isNotificationTemplateExists(String notificationChannel, String return false; } + + /** + * Get all available system notification templates of given type. + * + * @param notificationChannel Notification channel (Eg: SMS, EMAIL). + * @return List of system notification templates. + */ + default List getAllSystemNotificationTemplatesOfType(String notificationChannel, + String templateDisplayName) throws NotificationTemplateManagerException { + + return null; + } + + /** + * Return the default system notification template which matches the given channel and template name. + * + * @param notificationChannel Notification Channel Name (Eg: SMS or EMAIL) + * @param templateType Display name of the template + * @param locale Locale + * @return Return {@link org.wso2.carbon.identity.governance.model.NotificationTemplate} object + * @throws NotificationTemplateManagerException If an error occurred while getting the notification template + */ + default NotificationTemplate getSystemNotificationTemplate(String notificationChannel, String templateType, + String locale) + throws NotificationTemplateManagerException { + + return null; + } } From e758d90169687bb3796336378c74086d8a054449 Mon Sep 17 00:00:00 2001 From: rushannanayakkara Date: Tue, 22 Oct 2024 17:14:00 +0530 Subject: [PATCH 8/9] Addressing comments --- .../NotificationTemplateManager.java | 55 ++++++++++++------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java b/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java index 31a618c1f5..fd14026260 100644 --- a/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java +++ b/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/service/notification/NotificationTemplateManager.java @@ -1,18 +1,21 @@ /* - * Copyright (c) 2019-2024, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2019-2024, WSO2 LLC. (http://www.wso2.com). * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ + package org.wso2.carbon.identity.governance.service.notification; import org.wso2.carbon.identity.governance.exceptions.notiification.NotificationTemplateManagerException; @@ -37,6 +40,7 @@ public interface NotificationTemplateManager { default void addNotificationTemplateType(String notificationChannel, String displayName, String tenantDomain) throws NotificationTemplateManagerException { + throw new UnsupportedOperationException("Not implemented yet"); } /** @@ -48,10 +52,12 @@ default void addNotificationTemplateType(String notificationChannel, String disp * @param applicationUuid Application UUID. * @throws NotificationTemplateManagerException If an error occurred while adding the template to the registry. */ + @Deprecated default void addNotificationTemplateType(String notificationChannel, String displayName, String tenantDomain, String applicationUuid) throws NotificationTemplateManagerException { + throw new UnsupportedOperationException("Not implemented yet"); } /** @@ -65,7 +71,7 @@ default void addNotificationTemplateType(String notificationChannel, String disp default List getAllNotificationTemplateTypes(String notificationChannel, String tenantDomain) throws NotificationTemplateManagerException { - return null; + throw new UnsupportedOperationException("Not implemented yet"); } /** @@ -80,6 +86,7 @@ default void deleteNotificationTemplateType(String notificationChannel, String t String tenantDomain) throws NotificationTemplateManagerException { + throw new UnsupportedOperationException("Not implemented yet"); } /** @@ -94,7 +101,7 @@ default boolean isNotificationTemplateTypeExists(String notificationChannel, Str String tenantDomain) throws NotificationTemplateManagerException { - return false; + throw new UnsupportedOperationException("Not implemented yet"); } /** @@ -108,6 +115,7 @@ default boolean isNotificationTemplateTypeExists(String notificationChannel, Str default void resetNotificationTemplateType(String notificationChannel, String templateType, String tenantDomain) throws NotificationTemplateManagerException { + throw new UnsupportedOperationException("Not implemented yet"); } /** @@ -120,7 +128,7 @@ default void resetNotificationTemplateType(String notificationChannel, String te default List getAllNotificationTemplates(String notificationChannel, String tenantDomain) throws NotificationTemplateManagerException { - return null; + throw new UnsupportedOperationException("Not implemented yet"); } /** @@ -136,7 +144,7 @@ default List getNotificationTemplatesOfType(String notific String templateDisplayName, String tenantDomain) throws NotificationTemplateManagerException { - return null; + throw new UnsupportedOperationException("Not implemented yet"); } /** @@ -153,7 +161,7 @@ default List getNotificationTemplatesOfType(String notific String templateDisplayName, String tenantDomain, String applicationUuid) throws NotificationTemplateManagerException { - return null; + throw new UnsupportedOperationException("Not implemented yet"); } /** @@ -170,7 +178,7 @@ default NotificationTemplate getNotificationTemplate(String notificationChannel, String tenantDomain) throws NotificationTemplateManagerException { - return null; + throw new UnsupportedOperationException("Not implemented yet"); } /** @@ -188,7 +196,7 @@ default NotificationTemplate getNotificationTemplate(String notificationChannel, String tenantDomain, String applicationUuid) throws NotificationTemplateManagerException { - return null; + throw new UnsupportedOperationException("Not implemented yet"); } /** @@ -202,6 +210,7 @@ default NotificationTemplate getNotificationTemplate(String notificationChannel, default void addNotificationTemplate(NotificationTemplate notificationTemplate, String tenantDomain) throws NotificationTemplateManagerException { + throw new UnsupportedOperationException("Not implemented yet"); } /** @@ -215,6 +224,7 @@ default void addNotificationTemplate(NotificationTemplate notificationTemplate, default void addNotificationTemplate(NotificationTemplate notificationTemplate, String tenantDomain, String applicationUuid) throws NotificationTemplateManagerException { + throw new UnsupportedOperationException("Not implemented yet"); } /** @@ -228,6 +238,7 @@ default void addNotificationTemplate(NotificationTemplate notificationTemplate, default void updateNotificationTemplate(NotificationTemplate notificationTemplate, String tenantDomain) throws NotificationTemplateManagerException { + throw new UnsupportedOperationException("Not implemented yet"); } /** @@ -241,6 +252,7 @@ default void updateNotificationTemplate(NotificationTemplate notificationTemplat default void updateNotificationTemplate(NotificationTemplate notificationTemplate, String tenantDomain, String applicationUuid) throws NotificationTemplateManagerException { + throw new UnsupportedOperationException("Not implemented yet"); } /** @@ -256,6 +268,7 @@ default void deleteNotificationTemplate(String notificationChannel, String templ String tenantDomain) throws NotificationTemplateManagerException { + throw new UnsupportedOperationException("Not implemented yet"); } @@ -273,6 +286,7 @@ default void deleteNotificationTemplate(String notificationChannel, String templ String tenantDomain, String applicationUuid) throws NotificationTemplateManagerException { + throw new UnsupportedOperationException("Not implemented yet"); } /** @@ -287,6 +301,7 @@ default void deleteNotificationTemplate(String notificationChannel, String templ default void addDefaultNotificationTemplates(String notificationChannel, String tenantDomain) throws NotificationTemplateManagerException { + throw new UnsupportedOperationException("Not implemented yet"); } /** @@ -297,7 +312,7 @@ default void addDefaultNotificationTemplates(String notificationChannel, String */ default List getDefaultNotificationTemplates(String notificationChannel) { - return null; + throw new UnsupportedOperationException("Not implemented yet"); } /** @@ -312,7 +327,7 @@ default boolean isNotificationTemplateExists(String notificationChannel, String String tenantDomain) throws NotificationTemplateManagerException { - return false; + throw new UnsupportedOperationException("Not implemented yet"); } /** @@ -329,7 +344,7 @@ default boolean isNotificationTemplateExists(String notificationChannel, String String tenantDomain, String applicationUuid) throws NotificationTemplateManagerException { - return false; + throw new UnsupportedOperationException("Not implemented yet"); } /** @@ -341,7 +356,7 @@ default boolean isNotificationTemplateExists(String notificationChannel, String default List getAllSystemNotificationTemplatesOfType(String notificationChannel, String templateDisplayName) throws NotificationTemplateManagerException { - return null; + throw new UnsupportedOperationException("Not implemented yet"); } /** @@ -357,6 +372,6 @@ default NotificationTemplate getSystemNotificationTemplate(String notificationCh String locale) throws NotificationTemplateManagerException { - return null; + throw new UnsupportedOperationException("Not implemented yet"); } } From e2e9ff286089e7007a86a4943b1a64462166c3c2 Mon Sep 17 00:00:00 2001 From: rushannanayakkara Date: Wed, 23 Oct 2024 14:50:57 +0530 Subject: [PATCH 9/9] Add unit tests to NotificationTemplateManager through NotificationTemplateManagerTest class. --- .../NotificationTemplateManagerTest.java | 171 ++++++++++++++++++ .../src/test/resources/testng.xml | 1 + 2 files changed, 172 insertions(+) create mode 100644 components/org.wso2.carbon.identity.governance/src/test/java/org/wso2/carbon/identity/governance/listener/NotificationTemplateManagerTest.java diff --git a/components/org.wso2.carbon.identity.governance/src/test/java/org/wso2/carbon/identity/governance/listener/NotificationTemplateManagerTest.java b/components/org.wso2.carbon.identity.governance/src/test/java/org/wso2/carbon/identity/governance/listener/NotificationTemplateManagerTest.java new file mode 100644 index 0000000000..913f246aaa --- /dev/null +++ b/components/org.wso2.carbon.identity.governance/src/test/java/org/wso2/carbon/identity/governance/listener/NotificationTemplateManagerTest.java @@ -0,0 +1,171 @@ +package org.wso2.carbon.identity.governance.listener; + +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; +import org.wso2.carbon.identity.governance.exceptions.notiification.NotificationTemplateManagerException; +import org.wso2.carbon.identity.governance.model.NotificationTemplate; +import org.wso2.carbon.identity.governance.service.notification.NotificationTemplateManager; + +public class NotificationTemplateManagerTest { + + private NotificationTemplateManager notificationTemplateManager; + private final String notificationChannel = "EMAIL"; + private final String displayName = "Sample Template"; + private final String tenantDomain = "carbon.super"; + private final String locale = "en_US"; + private final String applicationUuid = "app-1234"; + private final NotificationTemplate notificationTemplate = new NotificationTemplate(); + + @BeforeTest + public void setUp() { + notificationTemplateManager = new NotificationTemplateManager() { + // No implementation needed, using default methods which throw UnsupportedOperationException + }; + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testAddNotificationTemplateType() throws NotificationTemplateManagerException { + + notificationTemplateManager.addNotificationTemplateType(notificationChannel, displayName, tenantDomain); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testAddNotificationTemplateTypeWithAppId() throws NotificationTemplateManagerException { + + notificationTemplateManager.addNotificationTemplateType(notificationChannel, displayName, tenantDomain, + applicationUuid); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testGetAllNotificationTemplateTypes() throws NotificationTemplateManagerException { + + notificationTemplateManager.getAllNotificationTemplateTypes(notificationChannel, tenantDomain); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testDeleteNotificationTemplateType() throws NotificationTemplateManagerException { + + notificationTemplateManager.deleteNotificationTemplateType(notificationChannel, displayName, tenantDomain); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testIsNotificationTemplateTypeExists() throws NotificationTemplateManagerException { + + notificationTemplateManager.isNotificationTemplateTypeExists(notificationChannel, displayName, tenantDomain); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testResetNotificationTemplateType() throws NotificationTemplateManagerException { + + notificationTemplateManager.resetNotificationTemplateType(notificationChannel, displayName, tenantDomain); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testGetAllNotificationTemplates() throws NotificationTemplateManagerException { + + notificationTemplateManager.getAllNotificationTemplates(notificationChannel, tenantDomain); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testGetNotificationTemplatesOfType() throws NotificationTemplateManagerException { + + notificationTemplateManager.getNotificationTemplatesOfType(notificationChannel, displayName, + tenantDomain); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testGetNotificationTemplatesOfTypeWithApplicationId() throws NotificationTemplateManagerException { + + notificationTemplateManager.getNotificationTemplatesOfType(notificationChannel, displayName, + tenantDomain, applicationUuid); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testGetNotificationTemplate() throws NotificationTemplateManagerException { + + notificationTemplateManager.getNotificationTemplate(notificationChannel, displayName, locale, tenantDomain); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testGetNotificationTemplateWithApplicationId() throws NotificationTemplateManagerException { + + notificationTemplateManager.getNotificationTemplate(notificationChannel, displayName, locale, tenantDomain, + applicationUuid); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testAddNotificationTemplate() throws NotificationTemplateManagerException { + + notificationTemplateManager.addNotificationTemplate(notificationTemplate, tenantDomain); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testAddNotificationTemplateWithApplicationId() throws NotificationTemplateManagerException { + + notificationTemplateManager.addNotificationTemplate(notificationTemplate, tenantDomain, applicationUuid); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testUpdateNotificationTemplate() throws NotificationTemplateManagerException { + + notificationTemplateManager.updateNotificationTemplate(notificationTemplate, tenantDomain); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testUpdateNotificationTemplateWithApplicationId() throws NotificationTemplateManagerException { + + notificationTemplateManager.updateNotificationTemplate(notificationTemplate, tenantDomain, applicationUuid); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testDeleteNotificationTemplate() throws NotificationTemplateManagerException { + + notificationTemplateManager.deleteNotificationTemplate(notificationChannel, displayName, locale, + tenantDomain); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testDeleteNotificationTemplateWithApplicationId() throws NotificationTemplateManagerException { + + notificationTemplateManager.deleteNotificationTemplate(notificationChannel, displayName, locale, + tenantDomain, applicationUuid); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testAddDefaultNotificationTemplates() throws NotificationTemplateManagerException { + + notificationTemplateManager.addDefaultNotificationTemplates(notificationChannel, tenantDomain); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testGetDefaultNotificationTemplates() { + + notificationTemplateManager.getDefaultNotificationTemplates(notificationChannel); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testIsNotificationTemplateExists() throws NotificationTemplateManagerException { + + notificationTemplateManager.isNotificationTemplateExists(notificationChannel, displayName, locale, + tenantDomain); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testIsNotificationTemplateExistsWithApplicationId() throws NotificationTemplateManagerException { + + notificationTemplateManager.isNotificationTemplateExists(notificationChannel, displayName, locale, + tenantDomain, applicationUuid); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testGetAllSystemNotificationTemplatesOfType() throws NotificationTemplateManagerException { + + notificationTemplateManager.getAllSystemNotificationTemplatesOfType(notificationChannel, displayName); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testGetSystemNotificationTemplate() throws NotificationTemplateManagerException { + + notificationTemplateManager.getSystemNotificationTemplate(notificationChannel, displayName, locale); + } +} diff --git a/components/org.wso2.carbon.identity.governance/src/test/resources/testng.xml b/components/org.wso2.carbon.identity.governance/src/test/resources/testng.xml index c71153a736..6a4dc07448 100644 --- a/components/org.wso2.carbon.identity.governance/src/test/resources/testng.xml +++ b/components/org.wso2.carbon.identity.governance/src/test/resources/testng.xml @@ -25,6 +25,7 @@ +