use of org.wso2.carbon.identity.mgt.stub.dto.EmailTemplateDTO in project carbon-identity-framework by wso2.
the class AccountCredentialMgtConfigService method getEmailConfig.
/**
* This method is used to load the tenant specific Email template configurations.
*
* @return an array of templates.
* @throws IdentityMgtServiceException
*/
public EmailTemplateDTO[] getEmailConfig() throws IdentityMgtServiceException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
Config emailConfig = null;
EmailTemplateDTO[] templates = null;
ConfigBuilder configBuilder = ConfigBuilder.getInstance();
try {
emailConfig = configBuilder.loadConfiguration(ConfigType.EMAIL, StorageType.REGISTRY, tenantId);
if (emailConfig != null) {
templates = EmailConfigTransformer.transform(emailConfig.getProperties());
}
} catch (Exception e) {
log.error("Error occurred while loading email configuration", e);
throw new IdentityMgtServiceException("Error occurred while loading email configuration");
}
return templates;
}
use of org.wso2.carbon.identity.mgt.stub.dto.EmailTemplateDTO in project carbon-identity-framework by wso2.
the class AccountCredentialMgtConfigService method saveEmailConfig.
/**
* This method is used to save the Email template configurations which is specific to tenant.
*
* @param emailTemplates - Email templates to be saved.
* @throws IdentityMgtServiceException
*/
public void saveEmailConfig(EmailTemplateDTO[] emailTemplates) throws IdentityMgtServiceException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
EmailNotificationConfig emailConfig = new EmailNotificationConfig();
ConfigBuilder configBuilder = ConfigBuilder.getInstance();
try {
Properties props = EmailConfigTransformer.transform(emailTemplates);
emailConfig.setProperties(props);
configBuilder.saveConfiguration(StorageType.REGISTRY, tenantId, emailConfig);
} catch (Exception e) {
log.error("Error occurred while saving email configuration", e);
throw new IdentityMgtServiceException("Error occurred while saving email configuration");
}
}
use of org.wso2.carbon.identity.mgt.stub.dto.EmailTemplateDTO in project carbon-identity-framework by wso2.
the class EmailConfigTransformer method transform.
public static Properties transform(EmailTemplateDTO[] templates) throws IdentityException {
if (log.isDebugEnabled()) {
log.debug("Transforming EmailTemplateDTO[] to Properties");
}
Properties props = new Properties();
for (EmailTemplateDTO template : templates) {
StringBuilder contents = new StringBuilder();
if (log.isDebugEnabled()) {
log.debug("Properties info - subject:" + template.getSubject() + " " + "body:" + template.getBody() + " footer:" + template.getFooter());
}
contents.append(template.getSubject()).append("|").append(template.getBody()).append("|").append(template.getFooter());
props.setProperty(template.getName(), contents.toString());
}
return props;
}
use of org.wso2.carbon.identity.mgt.stub.dto.EmailTemplateDTO in project carbon-identity-framework by wso2.
the class EmailConfigTransformer method transform.
public static EmailTemplateDTO[] transform(Properties props) throws IdentityException {
List<EmailTemplateDTO> emailTemplates = new ArrayList<EmailTemplateDTO>();
if (log.isDebugEnabled()) {
log.debug("Transforming Properties to EmailTemplateDTO[]");
}
Set<String> keySet = props.stringPropertyNames();
for (String key : keySet) {
EmailTemplateDTO template = new EmailTemplateDTO();
if (IdentityMgtConstants.Notification.PASSWORD_RESET_RECOVERY.equals(key)) {
template.setDisplayName("Password Reset");
} else if (IdentityMgtConstants.Notification.ACCOUNT_CONFORM.equals(key)) {
template.setDisplayName("Account Confirm");
} else if (IdentityMgtConstants.Notification.ACCOUNT_ID_RECOVERY.equals(key)) {
template.setDisplayName("Account Id Recovery");
} else if (IdentityMgtConstants.Notification.ACCOUNT_UNLOCK.equals(key)) {
template.setDisplayName("Account Unlock");
} else if (IdentityMgtConstants.Notification.ACCOUNT_ENABLE.equals(key)) {
template.setDisplayName("Account Enable");
} else if (IdentityMgtConstants.Notification.ACCOUNT_DISABLE.equals(key)) {
template.setDisplayName("Account Disable");
} else if (IdentityMgtConstants.Notification.ASK_PASSWORD.equals(key)) {
template.setDisplayName("Ask Password");
} else if (IdentityMgtConstants.Notification.OTP_PASSWORD.equals(key)) {
template.setDisplayName("One Time Password");
} else if (IdentityMgtConstants.Notification.TEMPORARY_PASSWORD.equals(key)) {
template.setDisplayName("Temporary Password");
} else if (IdentityMgtConstants.Notification.PASSWORD_EXPIRES.equals(key)) {
template.setDisplayName("Password Expires");
} else if (IdentityMgtConstants.Notification.PASSWORD_EXPIRED.equals(key)) {
template.setDisplayName("Password Expired");
} else if (IdentityMgtConstants.Notification.RESEND_NOTIFICATION.equals(key)) {
template.setDisplayName("Resend Notification");
} else {
// Ignore all other keys in the registry mount.
continue;
}
template.setName(key);
String[] contents = props.getProperty(key).split("\\|");
if (contents.length > 3) {
throw IdentityException.error("Cannot have | character in the template");
}
String subject = contents[0];
String body = contents[1];
String footer = contents[2];
if (log.isDebugEnabled()) {
log.debug("Template info - name:" + key + " subject:" + subject + " " + "body:" + body + " footer:" + footer);
}
template.setSubject(subject);
template.setBody(body);
template.setFooter(footer);
emailTemplates.add(template);
}
return emailTemplates.toArray(new EmailTemplateDTO[emailTemplates.size()]);
}
use of org.wso2.carbon.identity.mgt.stub.dto.EmailTemplateDTO in project product-is by wso2.
the class AccountCredentialMgtConfigServiceTestCase method testSaveEmailConfigs.
@Test(groups = "wso2.is", description = "Test saving the Email template configurations")
public void testSaveEmailConfigs() throws RemoteException, AccountCredentialMgtConfigServiceIdentityMgtServiceExceptionException {
// retrieve email templates
EmailTemplateDTO[] currentEmailTemplates = accCredentialMgtConfigServiceClient.getEmailConfig();
Assert.assertNotNull(currentEmailTemplates, "Retrieving current email templates failed");
// add update {testConfigName} email template with test values
for (EmailTemplateDTO emailTemplate : currentEmailTemplates) {
if (emailTemplate.getName().equals(testConfigName)) {
emailTemplate.setName(testConfigName);
emailTemplate.setBody(testConfigBody);
emailTemplate.setDisplayName(testDisplayName);
emailTemplate.setFooter(testFooter);
emailTemplate.setSubject(testSubject);
break;
}
}
// save new email template list
accCredentialMgtConfigServiceClient.saveEmailConfigs(currentEmailTemplates);
// retrieve email templates to verify
EmailTemplateDTO[] updatedEmailTemplates = accCredentialMgtConfigServiceClient.getEmailConfig();
Assert.assertNotNull(updatedEmailTemplates, "Retrieving updated email templates failed");
log.info("Received email templates : " + updatedEmailTemplates.length);
EmailTemplateDTO emailTemplate = null;
for (EmailTemplateDTO emailTemplateDTO : updatedEmailTemplates) {
if (emailTemplateDTO.getName().equals(testConfigName)) {
emailTemplate = emailTemplateDTO;
break;
}
}
Assert.assertNotNull(emailTemplate, "Email template '" + testConfigName + "' is not found");
if (emailTemplate != null) {
Assert.assertEquals(emailTemplate.getName(), testConfigName, "Email template name mismatch");
Assert.assertEquals(emailTemplate.getSubject(), testSubject, "Email template Subject update failed");
Assert.assertEquals(emailTemplate.getBody(), testConfigBody, "Email template Body update failed");
Assert.assertEquals(emailTemplate.getDisplayName(), testDisplayName, "Email template display name mismatch");
Assert.assertEquals(emailTemplate.getFooter(), testFooter, "Email template footer update failed");
}
}
Aggregations