Skip to content

Commit

Permalink
Fix sonar warnings for store package
Browse files Browse the repository at this point in the history
  • Loading branch information
darshanasbg committed Nov 11, 2024
1 parent 21858bd commit 5cba885
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ default List<EmailTemplate> 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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,6 @@ boolean hasSameTemplate(NotificationTemplate template) {

Map<String, NotificationTemplate> defaultTemplatesForScenario =
getTemplateMap(template.getNotificationChannel()).get(template.getDisplayName().toLowerCase());
return defaultTemplatesForScenario == null ? false : defaultTemplatesForScenario.containsValue(template);
return defaultTemplatesForScenario != null && defaultTemplatesForScenario.containsValue(template);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
*/
Expand All @@ -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 {

Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -124,6 +118,7 @@ public boolean isNotificationTemplateExists(String locale, String templateType,
return super.isNotificationTemplateExists(locale, templateType, channelName, applicationUuid, tenantId);
}

@Override
public List<NotificationTemplate> listNotificationTemplates(String templateType, String channelName,
String applicationUuid, int tenantId)
throws NotificationTemplateManagerServerException {
Expand Down Expand Up @@ -151,6 +146,7 @@ public List<NotificationTemplate> listNotificationTemplates(String templateType,
return notificationTemplates;
}

@Override
public void updateNotificationTemplate(NotificationTemplate notificationTemplate, String applicationUuid,
int tenantId) throws NotificationTemplateManagerServerException {

Expand All @@ -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 {
Expand All @@ -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 {

Expand All @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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 {

Expand All @@ -86,6 +88,7 @@ public String getNotificationTemplateType(String type, String channelName, int t
return templateTypeDisplayName;
}

@Override
public List<String> listNotificationTemplateTypes(String channelName, int tenantId)
throws NotificationTemplateManagerServerException {

Expand All @@ -110,6 +113,7 @@ public List<String> listNotificationTemplateTypes(String channelName, int tenant
return templateTypes;
}

@Override
public void deleteNotificationTemplateType(String type, String channelName, int tenantId)
throws NotificationTemplateManagerServerException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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 {
Expand All @@ -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 {

Expand All @@ -105,6 +108,7 @@ public boolean isNotificationTemplateExists(String locale, String templateType,
return super.isNotificationTemplateExists(locale, templateType, channelName, tenantId);
}

@Override
public List<NotificationTemplate> listNotificationTemplates(String templateType, String channelName, int tenantId)
throws NotificationTemplateManagerServerException {

Expand All @@ -130,6 +134,7 @@ public List<NotificationTemplate> listNotificationTemplates(String templateType,
return notificationTemplates;
}

@Override
public void updateNotificationTemplate(NotificationTemplate notificationTemplate, int tenantId)
throws NotificationTemplateManagerServerException {

Expand All @@ -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 {

Expand All @@ -161,6 +167,7 @@ public void removeNotificationTemplate(String locale, String templateType, Strin

}

@Override
public void removeNotificationTemplates(String templateType, String channelName, int tenantId)
throws NotificationTemplateManagerServerException {

Expand Down

0 comments on commit 5cba885

Please sign in to comment.