Skip to content

Commit

Permalink
Store content based on the unicode support flag
Browse files Browse the repository at this point in the history
  • Loading branch information
darshanasbg committed Nov 21, 2024
1 parent c94fe65 commit a1e2e4b
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ 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_ENABLE_UNICODE_SUPPORT =
"NotificationTemplates.EnableUnicodeSupport";

public static final String SERVICE_PROPERTY_KEY_SERVICE_NAME = "service.name";
public static final String SERVICE_PROPERTY_VAL_EMAIL_TEMPLATE_MANAGER = "EmailTemplateManager";
Expand Down Expand Up @@ -157,6 +159,9 @@ public static class NotificationTableColumns {
public static final String TENANT_ID = "TENANT_ID";
public static final String TEMPLATE_KEY = "TEMPLATE_KEY";
public static final String LOCALE = "LOCALE";
public static final String SUBJECT = "SUBJECT";
public static final String BODY = "BODY";
public static final String FOOTER = "FOOTER";
public static final String CONTENT = "CONTENT";
public static final String CONTENT_TYPE = "CONTENT_TYPE";
public static final String TYPE_ID = "TYPE_ID";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,38 @@ public class SQLConstants {
"(TEMPLATE_KEY, LOCALE, CONTENT, CONTENT_TYPE, TYPE_ID, TENANT_ID) " +
"VALUES (:TEMPLATE_KEY;, :LOCALE;, :CONTENT;, :CONTENT_TYPE;, (" +
GET_NOTIFICATION_TYPE_ID_SQL + "), :TENANT_ID;)";
public static final String INSERT_ORG_NOTIFICATION_TEMPLATE_WITHOUT_UNICODE_SQL =
"INSERT INTO IDN_NOTIFICATION_ORG_TEMPLATE " +
"(TEMPLATE_KEY, LOCALE, SUBJECT, BODY, FOOTER, CONTENT_TYPE, TYPE_ID, TENANT_ID) " +
"VALUES (:TEMPLATE_KEY;, :LOCALE;, :SUBJECT;, :BODY;, :FOOTER;, :CONTENT_TYPE;, (" +
GET_NOTIFICATION_TYPE_ID_SQL + "), :TENANT_ID;)";
public static final String GET_ORG_NOTIFICATION_TEMPLATE_SQL =
"SELECT CONTENT, CONTENT_TYPE FROM IDN_NOTIFICATION_ORG_TEMPLATE " +
"WHERE TEMPLATE_KEY = :TEMPLATE_KEY; AND TYPE_ID = (" + GET_NOTIFICATION_TYPE_ID_SQL +
") AND TENANT_ID = :TENANT_ID;";
public static final String GET_ORG_NOTIFICATION_TEMPLATE_WITHOUT_UNICODE_SQL =
"SELECT SUBJECT, BODY, FOOTER, CONTENT_TYPE FROM IDN_NOTIFICATION_ORG_TEMPLATE " +
"WHERE TEMPLATE_KEY = :TEMPLATE_KEY; AND TYPE_ID = (" + GET_NOTIFICATION_TYPE_ID_SQL +
") AND TENANT_ID = :TENANT_ID;";
public static final String IS_ORG_NOTIFICATION_TEMPLATE_EXISTS_SQL =
"SELECT ID FROM IDN_NOTIFICATION_ORG_TEMPLATE " +
"WHERE TEMPLATE_KEY = :TEMPLATE_KEY; AND TYPE_ID = :TYPE_ID; AND TENANT_ID = :TENANT_ID;";
public static final String LIST_ORG_NOTIFICATION_TEMPLATES_BY_TYPE_SQL =
"SELECT CONTENT, CONTENT_TYPE, LOCALE FROM IDN_NOTIFICATION_ORG_TEMPLATE " +
"WHERE TYPE_ID = (" + GET_NOTIFICATION_TYPE_ID_SQL + ") AND TENANT_ID = :TENANT_ID;";
public static final String LIST_ORG_NOTIFICATION_TEMPLATES_BY_TYPE_WITHOUT_UNICODE_SQL =
"SELECT SUBJECT, BODY, FOOTER, CONTENT_TYPE, LOCALE FROM IDN_NOTIFICATION_ORG_TEMPLATE " +
"WHERE TYPE_ID = (" + GET_NOTIFICATION_TYPE_ID_SQL + ") AND TENANT_ID = :TENANT_ID;";
public static final String UPDATE_ORG_NOTIFICATION_TEMPLATE_SQL =
"UPDATE IDN_NOTIFICATION_ORG_TEMPLATE " +
"SET CONTENT = :CONTENT;, CONTENT_TYPE = :CONTENT_TYPE; " +
"WHERE TEMPLATE_KEY = :TEMPLATE_KEY; AND TYPE_ID = (" + GET_NOTIFICATION_TYPE_ID_SQL +
") AND TENANT_ID = :TENANT_ID;";
public static final String UPDATE_ORG_NOTIFICATION_TEMPLATE_WITHOUT_UNICODE_SQL =
"UPDATE IDN_NOTIFICATION_ORG_TEMPLATE " +
"SET SUBJECT = :SUBJECT;, BODY = :BODY;, FOOTER = :FOOTER;, CONTENT_TYPE = :CONTENT_TYPE; " +
"WHERE TEMPLATE_KEY = :TEMPLATE_KEY; AND TYPE_ID = (" + GET_NOTIFICATION_TYPE_ID_SQL +
") AND TENANT_ID = :TENANT_ID;";
public static final String DELETE_ORG_NOTIFICATION_TEMPLATE_SQL =
"DELETE FROM IDN_NOTIFICATION_ORG_TEMPLATE WHERE TEMPLATE_KEY = :TEMPLATE_KEY; AND TYPE_ID = (" +
GET_NOTIFICATION_TYPE_ID_SQL + ") AND TENANT_ID = :TENANT_ID;";
Expand All @@ -74,10 +91,19 @@ public class SQLConstants {
"(TEMPLATE_KEY, LOCALE, CONTENT, CONTENT_TYPE, TYPE_ID, APP_ID, TENANT_ID) " +
"VALUES (:TEMPLATE_KEY;, :LOCALE;, :CONTENT;, :CONTENT_TYPE;, (" +
GET_NOTIFICATION_TYPE_ID_SQL + "), :APP_ID;, :TENANT_ID;)";
public static final String INSERT_APP_NOTIFICATION_TEMPLATE_WITHOUT_UNICODE_SQL =
"INSERT INTO IDN_NOTIFICATION_APP_TEMPLATE " +
"(TEMPLATE_KEY, LOCALE, SUBJECT, BODY, FOOTER, CONTENT_TYPE, TYPE_ID, APP_ID, TENANT_ID) " +
"VALUES (:TEMPLATE_KEY;, :LOCALE;, :SUBJECT;, :BODY;, :FOOTER;, :CONTENT_TYPE;, (" +
GET_NOTIFICATION_TYPE_ID_SQL + "), :APP_ID;, :TENANT_ID;)";
public static final String GET_APP_NOTIFICATION_TEMPLATE_SQL =
"SELECT CONTENT, CONTENT_TYPE FROM IDN_NOTIFICATION_APP_TEMPLATE " +
"WHERE TEMPLATE_KEY = :TEMPLATE_KEY; AND TYPE_ID = (" + GET_NOTIFICATION_TYPE_ID_SQL +
") AND APP_ID = :APP_ID; AND TENANT_ID = :TENANT_ID;";
public static final String GET_APP_NOTIFICATION_TEMPLATE_WITHOUT_UNICODE_SQL =
"SELECT SUBJECT, BODY, FOOTER, CONTENT_TYPE FROM IDN_NOTIFICATION_APP_TEMPLATE " +
"WHERE TEMPLATE_KEY = :TEMPLATE_KEY; AND TYPE_ID = (" + GET_NOTIFICATION_TYPE_ID_SQL +
") AND APP_ID = :APP_ID; AND TENANT_ID = :TENANT_ID;";
public static final String IS_APP_NOTIFICATION_TEMPLATE_EXISTS_SQL =
"SELECT ID FROM IDN_NOTIFICATION_APP_TEMPLATE " +
"WHERE TEMPLATE_KEY = :TEMPLATE_KEY; AND TYPE_ID = :TYPE_ID; AND APP_ID = :APP_ID; " +
Expand All @@ -86,11 +112,20 @@ public class SQLConstants {
"SELECT CONTENT, CONTENT_TYPE, LOCALE FROM IDN_NOTIFICATION_APP_TEMPLATE " +
"WHERE TYPE_ID = (" + GET_NOTIFICATION_TYPE_ID_SQL +
") AND APP_ID = :APP_ID; AND TENANT_ID = :TENANT_ID;";
public static final String LIST_APP_NOTIFICATION_TEMPLATES_BY_APP_WITHOUT_UNICODE_SQL =
"SELECT SUBJECT, BODY, FOOTER, CONTENT_TYPE, LOCALE FROM IDN_NOTIFICATION_APP_TEMPLATE " +
"WHERE TYPE_ID = (" + GET_NOTIFICATION_TYPE_ID_SQL +
") AND APP_ID = :APP_ID; AND TENANT_ID = :TENANT_ID;";
public static final String UPDATE_APP_NOTIFICATION_TEMPLATE_SQL =
"UPDATE IDN_NOTIFICATION_APP_TEMPLATE " +
"SET CONTENT = :CONTENT;, CONTENT_TYPE = :CONTENT_TYPE; " +
"WHERE TEMPLATE_KEY = :TEMPLATE_KEY; AND TYPE_ID = (" + GET_NOTIFICATION_TYPE_ID_SQL +
") AND APP_ID = :APP_ID; AND TENANT_ID = :TENANT_ID;";
public static final String UPDATE_APP_NOTIFICATION_TEMPLATE_WITHOUT_UNICODE_SQL =
"UPDATE IDN_NOTIFICATION_APP_TEMPLATE " +
"SET SUBJECT = :SUBJECT;, BODY = :BODY;, FOOTER = :FOOTER;, CONTENT_TYPE = :CONTENT_TYPE; " +
"WHERE TEMPLATE_KEY = :TEMPLATE_KEY; AND TYPE_ID = (" + GET_NOTIFICATION_TYPE_ID_SQL +
") AND APP_ID = :APP_ID; AND TENANT_ID = :TENANT_ID;";
public static final String DELETE_APP_NOTIFICATION_TEMPLATE_SQL =
"DELETE FROM IDN_NOTIFICATION_APP_TEMPLATE WHERE TEMPLATE_KEY = :TEMPLATE_KEY; AND TYPE_ID = (" +
GET_NOTIFICATION_TYPE_ID_SQL + ") AND APP_ID = :APP_ID; AND TENANT_ID = :TENANT_ID;";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class I18nMgtDataHolder{
private List<NotificationTemplate> defaultEmailTemplates = new ArrayList<>();
private List<NotificationTemplate> defaultSMSTemplates = new ArrayList<>();
private List<String> legacyTenants = new ArrayList<>();
private boolean isUnicodeSupported = false;

private static I18nMgtDataHolder instance = new I18nMgtDataHolder();

Expand Down Expand Up @@ -160,4 +161,24 @@ public List<String> getLegacyTenants() {

return legacyTenants;
}

/**
* Sets whether the unicode support for template content is enabled or not.
*
* @param isUnicodeSupported true to enable Unicode support, false to disable.
*/
public void setUnicodeSupport(boolean isUnicodeSupported) {

isUnicodeSupported = isUnicodeSupported;
}

/**
* Gets whether the unicode support for template content is enabled.
*
* @return true if the unicode support for template content is enabled.
*/
public boolean isUnicodeSupported() {

return isUnicodeSupported;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,21 @@
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.email.mgt.EmailTemplateManager;
import org.wso2.carbon.email.mgt.EmailTemplateManagerImpl;
import org.wso2.carbon.email.mgt.NotificationTemplateManagerImpl;
import org.wso2.carbon.email.mgt.SMSProviderPayloadTemplateManager;
import org.wso2.carbon.email.mgt.SMSProviderPayloadTemplateManagerImpl;
import org.wso2.carbon.email.mgt.constants.I18nMgtConstants;
import org.wso2.carbon.email.mgt.exceptions.I18nEmailMgtException;
import org.wso2.carbon.email.mgt.model.SMSProviderTemplate;
import org.wso2.carbon.identity.application.mgt.ApplicationManagementService;
import org.wso2.carbon.identity.core.persistence.registry.RegistryResourceMgtService;
import org.wso2.carbon.identity.governance.exceptions.notiification.NotificationTemplateManagerException;
import org.wso2.carbon.identity.core.util.IdentityUtil;
import org.wso2.carbon.identity.governance.model.NotificationTemplate;
import org.wso2.carbon.identity.governance.service.notification.NotificationChannels;
import org.wso2.carbon.identity.governance.service.notification.NotificationTemplateManager;
import org.wso2.carbon.identity.organization.management.service.OrganizationManager;
import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.stratos.common.listeners.TenantMgtListener;
import org.wso2.carbon.user.core.service.RealmService;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
Expand Down Expand Up @@ -73,6 +69,7 @@
import javax.xml.stream.XMLStreamReader;

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;
import static org.wso2.carbon.email.mgt.constants.I18nMgtConstants.SERVICE_PROPERTY_VAL_EMAIL_TEMPLATE_MANAGER;
import static org.wso2.carbon.email.mgt.constants.I18nMgtConstants.SERVICE_PROPERTY_VAL_NOTIFICATION_TEMPLATE_MANAGER;
Expand Down Expand Up @@ -103,6 +100,9 @@ protected void activate(ComponentContext context) {
List<String> legacyTenants = IdentityUtil.getPropertyAsList(NOTIFICATION_TEMPLATES_LEGACY_TENANTS);
I18nMgtDataHolder.getInstance().setLegacyTenants(legacyTenants);

String enableUnicodeSupport = IdentityUtil.getProperty(NOTIFICATION_TEMPLATES_ENABLE_UNICODE_SUPPORT);
I18nMgtDataHolder.getInstance().setUnicodeSupport(Boolean.parseBoolean(enableUnicodeSupport));

// Register Email Mgt Service as an OSGi service.
EmailTemplateManagerImpl emailTemplateManager = new EmailTemplateManagerImpl();
ServiceRegistration emailTemplateSR = bundleCtx.registerService(EmailTemplateManager.class.getName(),
Expand Down
Loading

0 comments on commit a1e2e4b

Please sign in to comment.