Search in sources :

Example 16 with IdmMessageDto

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());
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest) Test(org.junit.Test)

Example 17 with IdmMessageDto

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());
}
Also used : IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest) Test(org.junit.Test)

Example 18 with IdmMessageDto

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());
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest) Test(org.junit.Test)

Example 19 with IdmMessageDto

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());
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest) Test(org.junit.Test)

Example 20 with IdmMessageDto

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;
    }
}
Also used : Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) Message(org.apache.camel.Message) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)22 Test (org.junit.Test)14 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)10 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)6 ResultModel (eu.bcvsolutions.idm.core.api.dto.ResultModel)6 IdmNotificationTemplateDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto)6 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)5 IdmNotificationLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto)5 IdmNotificationDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto)3 IdmNotificationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter)3 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)3 ArrayList (java.util.ArrayList)3 IdmNotificationRecipientDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto)2 StringWriter (java.io.StringWriter)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 Lists (com.google.common.collect.Lists)1 InitTestData (eu.bcvsolutions.idm.InitTestData)1 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1