use of eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto in project CzechIdMng by bcvsolutions.
the class IdmMessageDtoUnitTest method testModelOveloadLevel.
@Test
public void testModelOveloadLevel() {
ResultModel model = new DefaultResultModel(CoreResultCode.INTERNAL_SERVER_ERROR);
IdmMessageDto message = new IdmMessageDto.Builder().setModel(model).setLevel(NotificationLevel.SUCCESS).build();
Assert.assertEquals(NotificationLevel.SUCCESS, message.getLevel());
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto in project CzechIdMng by bcvsolutions.
the class IdmMessageDtoUnitTest method testTemplate.
@Test
public void testTemplate() {
IdmNotificationTemplateDto template = new IdmNotificationTemplateDto();
template.setSubject(PARAMETER_SUBJECT);
template.setBodyText(PARAMETER_TEXT);
IdmMessageDto message = new IdmMessageDto.Builder().setTemplate(template).build();
//
Assert.assertEquals(PARAMETER_SUBJECT, message.getSubject());
Assert.assertEquals(PARAMETER_TEXT, message.getTextMessage());
Assert.assertEquals(PARAMETER_TEXT, message.getHtmlMessage());
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto in project CzechIdMng by bcvsolutions.
the class IdmMessageDtoUnitTest method testModelError.
@Test
public void testModelError() {
ResultModel model = new DefaultResultModel(CoreResultCode.INTERNAL_SERVER_ERROR);
IdmMessageDto message = new IdmMessageDto.Builder().setModel(model).build();
Assert.assertEquals(model.getStatusEnum(), message.getSubject());
Assert.assertEquals(model.getMessage(), message.getTextMessage());
Assert.assertEquals(model.getMessage(), message.getHtmlMessage());
Assert.assertEquals(NotificationLevel.ERROR, message.getLevel());
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto in project CzechIdMng by bcvsolutions.
the class IdmMessageDtoUnitTest method testModelWarning.
@Test
public void testModelWarning() {
ResultModel model = new DefaultResultModel(CoreResultCode.BAD_VALUE);
IdmMessageDto message = new IdmMessageDto.Builder().setModel(model).build();
Assert.assertEquals(model.getStatusEnum(), message.getSubject());
Assert.assertEquals(model.getMessage(), message.getTextMessage());
Assert.assertEquals(model.getMessage(), message.getHtmlMessage());
Assert.assertEquals(NotificationLevel.WARNING, message.getLevel());
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto in project CzechIdMng by bcvsolutions.
the class DefaultEmailer method send.
@Transactional
public boolean send(IdmEmailLogDto emailLog) {
log.debug("Sending email [{}]", emailLog);
if (ObjectUtils.isEmpty(emailLog.getRecipients())) {
log.info("Email recipiets is empty. Email [{}] is logged only.", emailLog);
emailLogService.setEmailSentLog(emailLog.getId(), "Email recipients is empty. Email was logged only.");
return false;
}
try {
Endpoint endpoint = configureEndpoint();
//
// If message contain template transform message, otherwise get simple message
IdmMessageDto idmMessage = notificationTemplateService.buildMessage(emailLog.getMessage(), true);
// create the exchange with the mail message that is multipart with a file and a Hello World text/plain message.
Exchange exchange = endpoint.createExchange();
Message in = exchange.getIn();
in.setHeaders(createEmailHeaders(emailLog));
// message - html has higher priority
String message = idmMessage.getHtmlMessage();
if (StringUtils.isEmpty(message)) {
message = idmMessage.getTextMessage();
}
in.setBody(message);
/* TODO: attachment preparations
DataSource ds = new javax.mail.util.ByteArrayDataSource("test txt content", "text/plain; charset=UTF-8");
in.addAttachment("rest.txt", new DataHandler(ds));
*/
entityEventManager.publishEvent(new DefaultSendOperation(emailLog, endpoint, exchange));
return true;
} catch (Exception ex) {
log.error("Sending email [{}] failed: [{}]", emailLog, ex);
emailLogService.setEmailSentLog(emailLog.getId(), StringUtils.abbreviate(ex.toString(), DefaultFieldLengths.LOG));
return false;
}
}
Aggregations