Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add capability diagnose template content for specified tenants #294

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ private I18nMgtConstants() {}

public static final String NOTIFICATION_TEMPLATES_STORAGE_CONFIG = "DataStorageType.NotificationTemplates";
public static final String NOTIFICATION_TEMPLATES_LEGACY_TENANTS = "NotificationTemplates.LegacyTenants.Tenant";
public static final String NOTIFICATION_TEMPLATES_DEBUG_TENANTS = "NotificationTemplates.DebugTenants.Tenant";
public static final String NOTIFICATION_TEMPLATES_ENABLE_UNICODE_SUPPORT =
"NotificationTemplates.EnableUnicodeSupport";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class I18nMgtDataHolder{
private List<NotificationTemplate> defaultEmailTemplates = new ArrayList<>();
private List<NotificationTemplate> defaultSMSTemplates = new ArrayList<>();
private List<String> legacyTenants = new ArrayList<>();
private List<String> debugTenants = new ArrayList<>();
private boolean isUnicodeSupported = false;
private boolean isUnicodeSupportedInHybridMode = false;

Expand Down Expand Up @@ -165,6 +166,26 @@ public List<String> getLegacyTenants() {
return legacyTenants;
}

/**
* Set the list of debug tenants.
*
* @param debugTenants List of debug tenants.
*/
public void setDebugTenants(List<String> debugTenants) {

this.debugTenants = debugTenants;
}

/**
* Get the list of debug tenants.
*
* @return List of debug tenants.
*/
public List<String> getDebugTenants() {

return debugTenants == null ? new ArrayList<>() : debugTenants;
}

/**
* Get the organization resource resolver service.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

import static org.wso2.carbon.email.mgt.constants.I18nMgtConstants.NOTIFICATION_TEMPLATES_DEBUG_TENANTS;
import static org.wso2.carbon.email.mgt.constants.I18nMgtConstants.NOTIFICATION_TEMPLATES_LEGACY_TENANTS;
import static org.wso2.carbon.email.mgt.constants.I18nMgtConstants.NOTIFICATION_TEMPLATES_ENABLE_UNICODE_SUPPORT;
import static org.wso2.carbon.email.mgt.constants.I18nMgtConstants.SERVICE_PROPERTY_KEY_SERVICE_NAME;
Expand Down Expand Up @@ -100,6 +101,8 @@ protected void activate(ComponentContext context) {

List<String> legacyTenants = IdentityUtil.getPropertyAsList(NOTIFICATION_TEMPLATES_LEGACY_TENANTS);
I18nMgtDataHolder.getInstance().setLegacyTenants(legacyTenants);
List<String> debugTenants = IdentityUtil.getPropertyAsList(NOTIFICATION_TEMPLATES_DEBUG_TENANTS);
I18nMgtDataHolder.getInstance().setDebugTenants(debugTenants);

String unicodeSupportType = IdentityUtil.getProperty(NOTIFICATION_TEMPLATES_ENABLE_UNICODE_SUPPORT);
I18nMgtDataHolder.getInstance().setUnicodeSupport(Boolean.parseBoolean(unicodeSupportType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
public class DBBasedTemplateManager implements TemplatePersistenceManager {

private static final Log log = LogFactory.getLog(DBBasedTemplateManager.class);
private List<String> debugTenants = I18nMgtDataHolder.getInstance().getDebugTenants();

private final NotificationTypeDAO notificationTypeDAO = new CacheBackedNotificationTypeDAO();
private final OrgNotificationTemplateDAO orgNotificationTemplateDAO = new CacheBackedOrgNotificationTemplateDAO();
Expand Down Expand Up @@ -134,6 +135,11 @@ public void addOrUpdateNotificationTemplate(NotificationTemplate notificationTem
"Org %s template with locale: %s for type: %s for tenant: %s successfully added.",
notificationChannel, locale, displayName, tenantDomain));
}
if (debugTenants.contains(tenantId)) {
log.info(String.format(
"Org %s template with locale: %s for type: %s for tenant: %s successfully added.",
notificationChannel, locale, displayName, tenantDomain));
}
} else {
appNotificationTemplateDAO.addNotificationTemplate(notificationTemplate, applicationUuid, tenantId);
if (log.isDebugEnabled()) {
Expand All @@ -142,6 +148,19 @@ public void addOrUpdateNotificationTemplate(NotificationTemplate notificationTem
"successfully added.",
notificationChannel, locale, displayName, applicationUuid, tenantDomain));
}
if (debugTenants.contains(tenantId)) {
log.info(String.format(
"App %s template with locale: %s for type: %s for application: %s for tenant: %s " +
"successfully added.",
notificationChannel, locale, displayName, applicationUuid, tenantDomain));
}
}
if (debugTenants.contains(tenantId)) {
log.info("[" + tenantId + "][NotificationTemplate][ADD][" + tenantDomain + "]{"
+ "subject: " + notificationTemplate.getSubject()
+ ", footer: " + notificationTemplate.getFooter()
+ ", body: " + notificationTemplate.getBody()
+ "}");
}
} else {
// Registry impl updates the template if exists
Expand All @@ -152,6 +171,11 @@ public void addOrUpdateNotificationTemplate(NotificationTemplate notificationTem
"Org %s template with locale: %s for type: %s for tenant: %s successfully updated.",
notificationChannel, locale, displayName, tenantDomain));
}
if (debugTenants.contains(tenantId)) {
log.info(String.format(
"Org %s template with locale: %s for type: %s for tenant: %s successfully updated.",
notificationChannel, locale, displayName, tenantDomain));
}
} else {
appNotificationTemplateDAO.updateNotificationTemplate(notificationTemplate, applicationUuid, tenantId);
if (log.isDebugEnabled()) {
Expand All @@ -160,6 +184,19 @@ public void addOrUpdateNotificationTemplate(NotificationTemplate notificationTem
"successfully updated.",
notificationChannel, locale, displayName, applicationUuid, tenantDomain));
}
if (debugTenants.contains(tenantId)) {
log.info(String.format(
"App %s template with locale: %s for type: %s for application: %s for tenant: %s " +
"successfully updated.",
notificationChannel, locale, displayName, applicationUuid, tenantDomain));
}
}
if (debugTenants.contains(tenantId)) {
log.info("[" + tenantId + "][NotificationTemplate][UPDATE][" + tenantDomain + "]{"
+ "subject: " + notificationTemplate.getSubject()
+ ", footer: " + notificationTemplate.getFooter()
+ ", body: " + notificationTemplate.getBody()
+ "}");
}
}
}
Expand Down Expand Up @@ -216,6 +253,12 @@ public NotificationTemplate getNotificationTemplate(String displayName, String l
"Org %s template with locale: %s for type: %s for tenant: %s successfully retrieved.",
notificationChannel, locale, displayName, tenantDomain));
}

if (debugTenants.contains(tenantId)) {
log.info(String.format(
"Org %s template with locale: %s for type: %s for tenant: %s successfully retrieved.",
notificationChannel, locale, displayName, tenantDomain));
}
} else {
notificationTemplate =
appNotificationTemplateDAO.getNotificationTemplate(locale, templateTypeKey, notificationChannel,
Expand All @@ -226,8 +269,20 @@ public NotificationTemplate getNotificationTemplate(String displayName, String l
"for tenant: %s successfully retrieved.", notificationChannel, locale, displayName,
applicationUuid, tenantDomain));
}
if (debugTenants.contains(tenantId)) {
log.info(String.format("App %s template with locale: %s for type: %s for application: %s " +
"for tenant: %s successfully retrieved.", notificationChannel, locale, displayName,
applicationUuid, tenantDomain));
}
}

if (debugTenants.contains(tenantId)) {
log.info("[" + tenantId + "][NotificationTemplate][GET][" + tenantDomain + "]{"
+ "subject: " + notificationTemplate.getSubject()
+ ", footer: " + notificationTemplate.getFooter()
+ ", body: " + notificationTemplate.getBody()
+ "}");
}
return notificationTemplate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package org.wso2.carbon.email.mgt.store.dao;

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.internal.I18nMgtDataHolder;
Expand Down Expand Up @@ -66,8 +68,10 @@
*/
public class OrgNotificationTemplateDAO {

private static final Log log = LogFactory.getLog(OrgNotificationTemplateDAO.class);
private boolean isUnicodeSupported = I18nMgtDataHolder.getInstance().isUnicodeSupported();
private boolean isHybrid = I18nMgtDataHolder.getInstance().isHybrid();
private List<String> debugTenants = I18nMgtDataHolder.getInstance().getDebugTenants();

public void addNotificationTemplate(NotificationTemplate notificationTemplate, int tenantId)
throws NotificationTemplateManagerServerException {
Expand Down Expand Up @@ -112,6 +116,14 @@ public void addNotificationTemplate(NotificationTemplate notificationTemplate, i
} catch (IOException e) {
throw new NotificationTemplateManagerServerException("Error while processing content stream.", e);
}

if (debugTenants.contains(String.valueOf(tenantId))) {
log.info("[" + tenantId + "][NotificationTemplate][ADD] {"
+ "subject: " + notificationTemplate.getSubject()
+ ", footer: " + notificationTemplate.getFooter()
+ ", body: " + notificationTemplate.getBody()
+ "}");
}
}

public NotificationTemplate getNotificationTemplate(String locale, String templateType, String channelName,
Expand Down Expand Up @@ -164,6 +176,14 @@ public NotificationTemplate getNotificationTemplate(String locale, String templa
throw new NotificationTemplateManagerServerException(error, e);
}

if (debugTenants.contains(String.valueOf(tenantId))) {
log.info("[" + tenantId + "][NotificationTemplate][GET] {"
+ "subject: " + notificationTemplate.getSubject()
+ ", footer: " + notificationTemplate.getFooter()
+ ", body: " + notificationTemplate.getBody()
+ "}");
}

return notificationTemplate;
}

Expand Down Expand Up @@ -299,6 +319,14 @@ public void updateNotificationTemplate(NotificationTemplate notificationTemplate
throw new NotificationTemplateManagerServerException("Error while processing content stream.", e);
}

if (debugTenants.contains(String.valueOf(tenantId))) {
log.info("[" + tenantId + "][NotificationTemplate][UPDATE] {"
+ "subject: " + notificationTemplate.getSubject()
+ ", footer: " + notificationTemplate.getFooter()
+ ", body: " + notificationTemplate.getBody()
+ "}");
}

}

public void removeNotificationTemplate(String locale, String templateType, String channelName, int tenantId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.wso2.carbon.email.mgt.cache.OrgNotificationTemplateCacheKey;
import org.wso2.carbon.email.mgt.cache.OrgNotificationTemplateListCache;
import org.wso2.carbon.email.mgt.cache.OrgNotificationTemplateListCacheKey;
import org.wso2.carbon.email.mgt.internal.I18nMgtDataHolder;
import org.wso2.carbon.email.mgt.store.dao.OrgNotificationTemplateDAO;
import org.wso2.carbon.identity.governance.exceptions.notiification.NotificationTemplateManagerServerException;
import org.wso2.carbon.identity.governance.model.NotificationTemplate;
Expand All @@ -37,6 +38,7 @@
public class CacheBackedOrgNotificationTemplateDAO extends OrgNotificationTemplateDAO {

private static final Log log = LogFactory.getLog(CacheBackedOrgNotificationTemplateDAO.class);
private List<String> debugTenants = I18nMgtDataHolder.getInstance().getDebugTenants();
private final OrgNotificationTemplateCache orgNotificationTemplateCache =
OrgNotificationTemplateCache.getInstance();
private final OrgNotificationTemplateListCache templateListCache = OrgNotificationTemplateListCache.getInstance();
Expand All @@ -56,6 +58,14 @@ public void addNotificationTemplate(NotificationTemplate notificationTemplate, i

OrgNotificationTemplateListCacheKey listCacheKey = new OrgNotificationTemplateListCacheKey(type, channel);
templateListCache.clearCacheEntry(listCacheKey, tenantId);

if (debugTenants.contains(String.valueOf(tenantId))) {
log.info("[" + tenantId + "][NotificationTemplate][ADD] {"
+ "subject: " + notificationTemplate.getSubject()
+ ", footer: " + notificationTemplate.getFooter()
+ ", body: " + notificationTemplate.getBody()
+ "}");
}
}

@Override
Expand All @@ -71,17 +81,37 @@ public NotificationTemplate getNotificationTemplate(String locale, String templa
log.debug("Cache hit in OrgNotificationTemplateCache for locale: " + locale + ", template type: " +
templateType + " in channel: " + channelName + " for tenant: " + tenantId);
}
if (debugTenants.contains(String.valueOf(tenantId))) {
log.info("Cache hit in OrgNotificationTemplateCache for locale: " + locale + ", template type: " +
templateType + " in channel: " + channelName + " for tenant: " + tenantId);
log.info("[" + tenantId + "][NotificationTemplate][GET] {"
+ "subject: " + orgNotificationTemplate.getSubject()
+ ", footer: " + orgNotificationTemplate.getFooter()
+ ", body: " + orgNotificationTemplate.getBody()
+ "}");
}
return orgNotificationTemplate;
}

if (log.isDebugEnabled()) {
log.debug("Cache miss in OrgNotificationTemplateCache for locale: " + locale + ", template type: " +
templateType + " in channel: " + channelName + " for tenant: " + tenantId);
}
if (debugTenants.contains(String.valueOf(tenantId))) {
log.info("Cache miss in OrgNotificationTemplateCache for locale: " + locale + ", template type: " +
templateType + " in channel: " + channelName + " for tenant: " + tenantId);
}

orgNotificationTemplate = super.getNotificationTemplate(locale, templateType, channelName, tenantId);
orgNotificationTemplateCache.addToCache(key, orgNotificationTemplate, tenantId);

if (debugTenants.contains(String.valueOf(tenantId))) {
log.info("[" + tenantId + "][NotificationTemplate][GET] {"
+ "subject: " + orgNotificationTemplate.getSubject()
+ ", footer: " + orgNotificationTemplate.getFooter()
+ ", body: " + orgNotificationTemplate.getBody()
+ "}");
}
return orgNotificationTemplate;
}

Expand All @@ -97,6 +127,10 @@ public boolean isNotificationTemplateExists(String locale, String templateType,
log.debug("Cache hit in OrgNotificationTemplateCache for locale: " + locale + ", template type: " +
templateType + " in channel: " + channelName + " for tenant: " + tenantId);
}
if (debugTenants.contains(String.valueOf(tenantId))) {
log.info("Cache hit in OrgNotificationTemplateCache for locale: " + locale + ", template type: " +
templateType + " in channel: " + channelName + " for tenant: " + tenantId);
}
return true;
}

Expand All @@ -105,6 +139,12 @@ public boolean isNotificationTemplateExists(String locale, String templateType,
templateType + " in channel: " + channelName + " for tenant: " + tenantId);
}

if (debugTenants.contains(String.valueOf(tenantId))) {
log.info("Cache miss in OrgNotificationTemplateCache for locale: " + locale + ", template type: " +
templateType + " in channel: " + channelName + " for tenant: " + tenantId);
}


return super.isNotificationTemplateExists(locale, templateType, channelName, tenantId);
}

Expand All @@ -120,13 +160,21 @@ public List<NotificationTemplate> listNotificationTemplates(String templateType,
log.debug("Cache hit in OrgNotificationTemplateListCache for template type: " + templateType +
" in channel: " + channelName + " for tenant: " + tenantId);
}
if (debugTenants.contains(String.valueOf(tenantId))) {
log.info("Cache hit in OrgNotificationTemplateListCache for template type: " + templateType +
" in channel: " + channelName + " for tenant: " + tenantId);
}
return notificationTemplates;
}

if (log.isDebugEnabled()) {
log.debug("Cache miss in OrgNotificationTemplateListCache for template type: " + templateType +
" in channel: " + channelName + " for tenant: " + tenantId);
}
if (debugTenants.contains(String.valueOf(tenantId))) {
log.info("Cache miss in OrgNotificationTemplateListCache for template type: " + templateType +
" in channel: " + channelName + " for tenant: " + tenantId);
}

notificationTemplates = super.listNotificationTemplates(templateType, channelName, tenantId);
templateListCache.addToCache(key, (ArrayList<NotificationTemplate>) notificationTemplates, tenantId);
Expand All @@ -149,6 +197,14 @@ public void updateNotificationTemplate(NotificationTemplate notificationTemplate

OrgNotificationTemplateListCacheKey listCacheKey = new OrgNotificationTemplateListCacheKey(type, channel);
templateListCache.clearCacheEntry(listCacheKey, tenantId);

if (debugTenants.contains(String.valueOf(tenantId))) {
log.info("[" + tenantId + "][NotificationTemplate][UPDATE] {"
+ "subject: " + notificationTemplate.getSubject()
+ ", footer: " + notificationTemplate.getFooter()
+ ", body: " + notificationTemplate.getBody()
+ "}");
}
}

@Override
Expand Down
Loading