From 2abe16778cb77a0deacdfc01cbf05e7ba060fe58 Mon Sep 17 00:00:00 2001 From: dhaura Date: Wed, 4 Dec 2024 18:00:28 +0530 Subject: [PATCH 1/2] Add notification template retrieval methods with resolve param support. --- .../NotificationTemplateManager.java | 100 ++++++++++++++++++ .../NotificationTemplateManagerTest.java | 54 ++++++++++ 2 files changed, 154 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 fd1402626..e410da192 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 @@ -131,6 +131,37 @@ default List getAllNotificationTemplates(String notificati throw new UnsupportedOperationException("Not implemented yet"); } + /** + * Retrieves all notification templates for a given notification channel and tenant domain. + *

+ * This method fetches notification templates based on the specified notification channel + * (e.g., email, SMS) and tenant domain. The behavior of template retrieval depends on the + * {@code resolve} parameter: + *

+ * + * @param notificationChannel the type of notification channel for which templates are retrieved + * (e.g., "EMAIL", "SMS"). + * @param tenantDomain the tenant domain of the organization for which templates are retrieved. + * @param resolve a flag to indicate whether to retrieve resolved templates + * ({@code true}) or templates specific to the current organization + * ({@code false}). + * @return a list of {@link NotificationTemplate} templates matching the specified criteria. + * @throws NotificationTemplateManagerException if an error occurs while retrieving the templates. + */ + default List getAllNotificationTemplates(String notificationChannel, String tenantDomain, + boolean resolve) + throws NotificationTemplateManagerException { + + throw new UnsupportedOperationException( + "getAllNotificationTemplates method is not implemented in " + this.getClass()); + } + /** * Get all notification templates of the given type. * @@ -164,6 +195,42 @@ default List getNotificationTemplatesOfType(String notific throw new UnsupportedOperationException("Not implemented yet"); } + /** + * Retrieves notification templates of a specific type for a given notification channel and tenant domain. + *

+ * This method fetches notification templates based on the specified notification channel + * (e.g., email, SMS), template display name, tenant domain, and application UUID. The behavior + * of template retrieval depends on the {@code resolve} parameter: + *

    + *
  • Resolved templates (resolve = true): Retrieves templates resolved through the + * ancestor organization hierarchy, ensuring that templates applicable across the organizational + * structure are returned.
  • + *
  • Current org's or app's templates (resolve = false): Retrieves templates specific to the + * current organization or application, without considering the organization hierarchy.
  • + *
+ * + * @param notificationChannel the type of notification channel for which templates are retrieved + * (e.g., "EMAIL", "SMS"). + * @param templateDisplayName the display name of the notification template type (e.g., "Welcome Email"). + * @param tenantDomain the tenant domain of the organization for which templates are retrieved. + * @param applicationUuid the UUID of the application associated with the notification templates. + * @param resolve a flag to indicate whether to retrieve resolved templates + * ({@code true}) or templates specific to the current organization or application + * ({@code false}). + * + * @return a list of {@link NotificationTemplate} templates matching the specified criteria. + * + * @throws NotificationTemplateManagerException if an error occurs while retrieving the templates. + */ + default List getNotificationTemplatesOfType(String notificationChannel, + String templateDisplayName, String tenantDomain, + String applicationUuid, boolean resolve) + throws NotificationTemplateManagerException { + + throw new UnsupportedOperationException( + "getNotificationTemplatesOfType method is not implemented in " + this.getClass()); + } + /** * Return the notification template from the tenant registry which matches the given channel and template name. * @@ -199,6 +266,39 @@ default NotificationTemplate getNotificationTemplate(String notificationChannel, throw new UnsupportedOperationException("Not implemented yet"); } + /** + * Retrieves a specific notification template for a given notification channel, template type, + * locale, tenant domain, and application UUID. + *

+ * This method fetches a notification template based on the specified criteria. The behavior + * depends on the {@code resolve} parameter: + *

    + *
  • Resolved template (resolve = true): Retrieves the template resolved through the + * ancestor organization hierarchy.
  • + *
  • Current org's or app's template (resolve = false): Retrieves the template specific to + * the current organization or application only.
  • + *
+ * + * @param notificationChannel the notification channel (e.g., "EMAIL", "SMS"). + * @param templateType the type of the notification template (e.g., "Welcome Email"). + * @param locale the locale of the notification template (e.g., "en_US"). + * @param tenantDomain the tenant domain of the organization from which the template is retrieved. + * @param applicationUuid the UUID of the application associated with the template. + * @param resolve a flag indicating whether to retrieve resolved template + * ({@code true}) or template specific to the current organization or application + * ({@code false}). + * @return the {@link NotificationTemplate} template matching the specified criteria. + * @throws NotificationTemplateManagerException if an error occurs while retrieving the template + * or if no template is found in the specified or default locale. + */ + default NotificationTemplate getNotificationTemplate(String notificationChannel, String templateType, String locale, + String tenantDomain, String applicationUuid, boolean resolve) + throws NotificationTemplateManagerException { + + throw new UnsupportedOperationException( + "getNotificationTemplate method is not implemented in " + this.getClass()); + } + /** * Add the notification template. * 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 index 913f246aa..0dc033ec6 100644 --- 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 @@ -1,11 +1,33 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * 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. + */ + package org.wso2.carbon.identity.governance.listener; import org.testng.annotations.BeforeTest; +import org.testng.annotations.DataProvider; 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; +/** + * Unit tests for NotificationTemplateManager. + */ public class NotificationTemplateManagerTest { private NotificationTemplateManager notificationTemplateManager; @@ -23,6 +45,15 @@ public void setUp() { }; } + @DataProvider(name = "resolveDataProvider") + public Object[][] resolveDataProvider() { + + return new Object[][]{ + {true}, + {false} + }; + } + @Test(expectedExceptions = UnsupportedOperationException.class) public void testAddNotificationTemplateType() throws NotificationTemplateManagerException { @@ -66,6 +97,13 @@ public void testGetAllNotificationTemplates() throws NotificationTemplateManager notificationTemplateManager.getAllNotificationTemplates(notificationChannel, tenantDomain); } + @Test(dataProvider = "resolveDataProvider", expectedExceptions = UnsupportedOperationException.class) + public void testGetAllNotificationTemplatesWithResolve(boolean resolve) + throws NotificationTemplateManagerException { + + notificationTemplateManager.getAllNotificationTemplates(notificationChannel, tenantDomain, resolve); + } + @Test(expectedExceptions = UnsupportedOperationException.class) public void testGetNotificationTemplatesOfType() throws NotificationTemplateManagerException { @@ -80,6 +118,14 @@ public void testGetNotificationTemplatesOfTypeWithApplicationId() throws Notific tenantDomain, applicationUuid); } + @Test(dataProvider = "resolveDataProvider", expectedExceptions = UnsupportedOperationException.class) + public void testGetNotificationTemplatesOfTypeWithApplicationIdWithResolve(boolean resolve) + throws NotificationTemplateManagerException { + + notificationTemplateManager.getNotificationTemplatesOfType(notificationChannel, displayName, + tenantDomain, applicationUuid, resolve); + } + @Test(expectedExceptions = UnsupportedOperationException.class) public void testGetNotificationTemplate() throws NotificationTemplateManagerException { @@ -93,6 +139,14 @@ public void testGetNotificationTemplateWithApplicationId() throws NotificationTe applicationUuid); } + @Test(dataProvider = "resolveDataProvider", expectedExceptions = UnsupportedOperationException.class) + public void testGetNotificationTemplateWithApplicationIdWithResolve(boolean resolve) + throws NotificationTemplateManagerException { + + notificationTemplateManager.getNotificationTemplate(notificationChannel, displayName, locale, tenantDomain, + applicationUuid, resolve); + } + @Test(expectedExceptions = UnsupportedOperationException.class) public void testAddNotificationTemplate() throws NotificationTemplateManagerException { From 9588b8d6800c751b2817d17a9a9219c848581be0 Mon Sep 17 00:00:00 2001 From: dhaura Date: Fri, 6 Dec 2024 13:59:06 +0530 Subject: [PATCH 2/2] Deprecate NotificationTemplateManager methods without resolve param. --- .../notification/NotificationTemplateManager.java | 9 +++++++++ 1 file changed, 9 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 e410da192..a4045638d 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 @@ -119,12 +119,15 @@ default void resetNotificationTemplateType(String notificationChannel, String te } /** + * @deprecated Use {@link #getAllNotificationTemplates(String, String, boolean)} instead. + *

* 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. * @throws NotificationTemplateManagerException If an error occurred while getting the notification template types. */ + @Deprecated default List getAllNotificationTemplates(String notificationChannel, String tenantDomain) throws NotificationTemplateManagerException { @@ -179,6 +182,8 @@ default List getNotificationTemplatesOfType(String notific } /** + * @deprecated Use {@link #getNotificationTemplatesOfType(String, String, String, String, boolean)} instead. + *

* Get all notification templates of the given type. * * @param notificationChannel Notification channel (Eg: SMS, EMAIL). @@ -188,6 +193,7 @@ default List getNotificationTemplatesOfType(String notific * @return List of notification templates. * @throws NotificationTemplateManagerException If an error occurred while getting the notification templates. */ + @Deprecated default List getNotificationTemplatesOfType(String notificationChannel, String templateDisplayName, String tenantDomain, String applicationUuid) throws NotificationTemplateManagerException { @@ -249,6 +255,8 @@ default NotificationTemplate getNotificationTemplate(String notificationChannel, } /** + * @deprecated Use {@link #getNotificationTemplate(String, String, String, String, String, boolean)} instead. + *

* Return the notification template from the tenant registry which matches the given channel and template name. * * @param notificationChannel Notification Channel Name (Eg: SMS or EMAIL). @@ -259,6 +267,7 @@ default NotificationTemplate getNotificationTemplate(String notificationChannel, * @return Return {@link org.wso2.carbon.identity.governance.model.NotificationTemplate} object. * @throws NotificationTemplateManagerException If an error occurred while getting the notification template. */ + @Deprecated default NotificationTemplate getNotificationTemplate(String notificationChannel, String templateType, String locale, String tenantDomain, String applicationUuid) throws NotificationTemplateManagerException {