From 5cba88543d229a7468031deaf39e76d6c6a36954 Mon Sep 17 00:00:00 2001 From: Darshana Gunawardana Date: Mon, 11 Nov 2024 14:03:59 +0530 Subject: [PATCH] Fix sonar warnings for store package --- .../carbon/email/mgt/EmailTemplateManager.java | 3 +++ .../email/mgt/EmailTemplateManagerImpl.java | 4 +++- .../mgt/store/RegistryBasedTemplateManager.java | 3 +-- .../mgt/store/SystemDefaultTemplateManager.java | 2 +- .../CacheBackedAppNotificationTemplateDAO.java | 17 ++++++++--------- .../cache/CacheBackedNotificationTypeDAO.java | 4 ++++ .../CacheBackedOrgNotificationTemplateDAO.java | 7 +++++++ 7 files changed, 27 insertions(+), 13 deletions(-) diff --git a/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/EmailTemplateManager.java b/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/EmailTemplateManager.java index f4f3b102..3b971230 100644 --- a/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/EmailTemplateManager.java +++ b/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/EmailTemplateManager.java @@ -156,6 +156,9 @@ default List getEmailTemplateType( /** * Add default email templates to a tenant's registry. * + * @deprecated Adding default templates not needed anymore due to the introduction of + * {@link org.wso2.carbon.email.mgt.store.SystemDefaultTemplateManager}. + * * @param tenantDomain * @throws I18nEmailMgtException */ diff --git a/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/EmailTemplateManagerImpl.java b/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/EmailTemplateManagerImpl.java index c16b1111..9e59caf1 100644 --- a/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/EmailTemplateManagerImpl.java +++ b/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/EmailTemplateManagerImpl.java @@ -23,7 +23,6 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.email.mgt.constants.I18nMgtConstants; import org.wso2.carbon.email.mgt.store.TemplatePersistenceManagerFactory; -import org.wso2.carbon.email.mgt.store.UnifiedTemplateManager; import org.wso2.carbon.email.mgt.store.TemplatePersistenceManager; import org.wso2.carbon.email.mgt.exceptions.I18nEmailMgtClientException; import org.wso2.carbon.email.mgt.exceptions.I18nEmailMgtException; @@ -455,6 +454,9 @@ public void addDefaultEmailTemplates(String tenantDomain) throws I18nEmailMgtExc * Add the default notification templates which matches the given notification channel to the respective tenants * registry. * + * @deprecated Adding default templates not needed anymore due to the introduction of + * {@link org.wso2.carbon.email.mgt.store.SystemDefaultTemplateManager}. + * * @param notificationChannel Notification channel (Eg: SMS, EMAIL) * @param tenantDomain Tenant domain * @throws NotificationTemplateManagerException Error adding the default notification templates diff --git a/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/RegistryBasedTemplateManager.java b/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/RegistryBasedTemplateManager.java index e1beb019..5a67255c 100644 --- a/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/RegistryBasedTemplateManager.java +++ b/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/RegistryBasedTemplateManager.java @@ -41,7 +41,6 @@ import org.wso2.carbon.registry.core.ResourceImpl; import org.wso2.carbon.registry.core.exceptions.RegistryException; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -376,7 +375,7 @@ private String[] getTemplateElements(Resource templateResource, String notificat Object content = templateResource.getContent(); if (content != null) { byte[] templateContentArray = (byte[]) content; - String templateContent = new String(templateContentArray, Charset.forName("UTF-8")); + String templateContent = new String(templateContentArray, StandardCharsets.UTF_8); String[] templateContentElements; try { diff --git a/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/SystemDefaultTemplateManager.java b/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/SystemDefaultTemplateManager.java index d340a305..cb84cbed 100644 --- a/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/SystemDefaultTemplateManager.java +++ b/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/SystemDefaultTemplateManager.java @@ -283,6 +283,6 @@ boolean hasSameTemplate(NotificationTemplate template) { Map defaultTemplatesForScenario = getTemplateMap(template.getNotificationChannel()).get(template.getDisplayName().toLowerCase()); - return defaultTemplatesForScenario == null ? false : defaultTemplatesForScenario.containsValue(template); + return defaultTemplatesForScenario != null && defaultTemplatesForScenario.containsValue(template); } } diff --git a/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/dao/cache/CacheBackedAppNotificationTemplateDAO.java b/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/dao/cache/CacheBackedAppNotificationTemplateDAO.java index 4c3c0bee..24d157c2 100644 --- a/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/dao/cache/CacheBackedAppNotificationTemplateDAO.java +++ b/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/dao/cache/CacheBackedAppNotificationTemplateDAO.java @@ -20,26 +20,17 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.database.utils.jdbc.NamedJdbcTemplate; -import org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException; import org.wso2.carbon.email.mgt.cache.AppNotificationTemplateCache; import org.wso2.carbon.email.mgt.cache.AppNotificationTemplateCacheKey; import org.wso2.carbon.email.mgt.cache.AppNotificationTemplateListCache; import org.wso2.carbon.email.mgt.cache.AppNotificationTemplateListCacheKey; -import org.wso2.carbon.email.mgt.cache.OrgNotificationTemplateListCacheKey; import org.wso2.carbon.email.mgt.store.dao.AppNotificationTemplateDAO; -import org.wso2.carbon.identity.core.util.JdbcUtils; import org.wso2.carbon.identity.governance.exceptions.notiification.NotificationTemplateManagerServerException; import org.wso2.carbon.identity.governance.model.NotificationTemplate; import java.util.ArrayList; import java.util.List; -import static org.wso2.carbon.email.mgt.constants.I18nMgtConstants.NotificationTableColumns.CHANNEL; -import static org.wso2.carbon.email.mgt.constants.I18nMgtConstants.NotificationTableColumns.TENANT_ID; -import static org.wso2.carbon.email.mgt.constants.I18nMgtConstants.NotificationTableColumns.TYPE_KEY; -import static org.wso2.carbon.email.mgt.constants.SQLConstants.DELETE_ALL_APP_NOTIFICATION_TEMPLATES_BY_TYPE_SQL; - /** * This class provides the cache backed implementation for {@link AppNotificationTemplateDAO}. */ @@ -50,6 +41,7 @@ public class CacheBackedAppNotificationTemplateDAO extends AppNotificationTempla AppNotificationTemplateCache.getInstance(); private final AppNotificationTemplateListCache templateListCache = AppNotificationTemplateListCache.getInstance(); + @Override public void addNotificationTemplate(NotificationTemplate notificationTemplate, String applicationUuid, int tenantId) throws NotificationTemplateManagerServerException { @@ -68,6 +60,7 @@ public void addNotificationTemplate(NotificationTemplate notificationTemplate, S templateListCache.clearCacheEntry(listCacheKey, tenantId); } + @Override public NotificationTemplate getNotificationTemplate(String locale, String templateType, String channelName, String applicationUuid, int tenantId) throws NotificationTemplateManagerServerException { @@ -98,6 +91,7 @@ public NotificationTemplate getNotificationTemplate(String locale, String templa return appNotificationTemplate; } + @Override public boolean isNotificationTemplateExists(String locale, String templateType, String channelName, String applicationUuid, int tenantId) throws NotificationTemplateManagerServerException { @@ -124,6 +118,7 @@ public boolean isNotificationTemplateExists(String locale, String templateType, return super.isNotificationTemplateExists(locale, templateType, channelName, applicationUuid, tenantId); } + @Override public List listNotificationTemplates(String templateType, String channelName, String applicationUuid, int tenantId) throws NotificationTemplateManagerServerException { @@ -151,6 +146,7 @@ public List listNotificationTemplates(String templateType, return notificationTemplates; } + @Override public void updateNotificationTemplate(NotificationTemplate notificationTemplate, String applicationUuid, int tenantId) throws NotificationTemplateManagerServerException { @@ -169,6 +165,7 @@ public void updateNotificationTemplate(NotificationTemplate notificationTemplate templateListCache.clearCacheEntry(listCacheKey, tenantId); } + @Override public void removeNotificationTemplate(String locale, String templateType, String channelName, String applicationUuid, int tenantId) throws NotificationTemplateManagerServerException { @@ -184,6 +181,7 @@ public void removeNotificationTemplate(String locale, String templateType, Strin templateListCache.clearCacheEntry(listCacheKey, tenantId); } + @Override public void removeNotificationTemplates(String templateType, String channelName, String applicationUuid, int tenantId) throws NotificationTemplateManagerServerException { @@ -196,6 +194,7 @@ public void removeNotificationTemplates(String templateType, String channelName, templateListCache.clearCacheEntry(listCacheKey, tenantId); } + @Override public void removeAllNotificationTemplates(String templateType, String channelName, int tenantId) throws NotificationTemplateManagerServerException { diff --git a/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/dao/cache/CacheBackedNotificationTypeDAO.java b/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/dao/cache/CacheBackedNotificationTypeDAO.java index c1ad3b4a..598f974a 100644 --- a/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/dao/cache/CacheBackedNotificationTypeDAO.java +++ b/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/dao/cache/CacheBackedNotificationTypeDAO.java @@ -51,6 +51,7 @@ public class CacheBackedNotificationTypeDAO extends NotificationTypeDAO { private final AppNotificationTemplateListCache appNotificationTemplateListCache = AppNotificationTemplateListCache.getInstance(); + @Override public void addNotificationTemplateType(String type, String displayName, String channelName, int tenantId) throws NotificationTemplateManagerServerException { @@ -61,6 +62,7 @@ public void addNotificationTemplateType(String type, String displayName, String notificationTypeListCache.clearCacheEntry(channelName, tenantId); } + @Override public String getNotificationTemplateType(String type, String channelName, int tenantId) throws NotificationTemplateManagerServerException { @@ -86,6 +88,7 @@ public String getNotificationTemplateType(String type, String channelName, int t return templateTypeDisplayName; } + @Override public List listNotificationTemplateTypes(String channelName, int tenantId) throws NotificationTemplateManagerServerException { @@ -110,6 +113,7 @@ public List listNotificationTemplateTypes(String channelName, int tenant return templateTypes; } + @Override public void deleteNotificationTemplateType(String type, String channelName, int tenantId) throws NotificationTemplateManagerServerException { diff --git a/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/dao/cache/CacheBackedOrgNotificationTemplateDAO.java b/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/dao/cache/CacheBackedOrgNotificationTemplateDAO.java index 755430c8..25f327ab 100644 --- a/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/dao/cache/CacheBackedOrgNotificationTemplateDAO.java +++ b/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/dao/cache/CacheBackedOrgNotificationTemplateDAO.java @@ -41,6 +41,7 @@ public class CacheBackedOrgNotificationTemplateDAO extends OrgNotificationTempla OrgNotificationTemplateCache.getInstance(); private final OrgNotificationTemplateListCache templateListCache = OrgNotificationTemplateListCache.getInstance(); + @Override public void addNotificationTemplate(NotificationTemplate notificationTemplate, int tenantId) throws NotificationTemplateManagerServerException { @@ -57,6 +58,7 @@ public void addNotificationTemplate(NotificationTemplate notificationTemplate, i templateListCache.clearCacheEntry(listCacheKey, tenantId); } + @Override public NotificationTemplate getNotificationTemplate(String locale, String templateType, String channelName, int tenantId) throws NotificationTemplateManagerServerException { @@ -83,6 +85,7 @@ public NotificationTemplate getNotificationTemplate(String locale, String templa return orgNotificationTemplate; } + @Override public boolean isNotificationTemplateExists(String locale, String templateType, String channelName, int tenantId) throws NotificationTemplateManagerServerException { @@ -105,6 +108,7 @@ public boolean isNotificationTemplateExists(String locale, String templateType, return super.isNotificationTemplateExists(locale, templateType, channelName, tenantId); } + @Override public List listNotificationTemplates(String templateType, String channelName, int tenantId) throws NotificationTemplateManagerServerException { @@ -130,6 +134,7 @@ public List listNotificationTemplates(String templateType, return notificationTemplates; } + @Override public void updateNotificationTemplate(NotificationTemplate notificationTemplate, int tenantId) throws NotificationTemplateManagerServerException { @@ -146,6 +151,7 @@ public void updateNotificationTemplate(NotificationTemplate notificationTemplate templateListCache.clearCacheEntry(listCacheKey, tenantId); } + @Override public void removeNotificationTemplate(String locale, String templateType, String channelName, int tenantId) throws NotificationTemplateManagerServerException { @@ -161,6 +167,7 @@ public void removeNotificationTemplate(String locale, String templateType, Strin } + @Override public void removeNotificationTemplates(String templateType, String channelName, int tenantId) throws NotificationTemplateManagerServerException {