Search in sources :

Example 6 with IdmNotificationAttachmentDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationAttachmentDto in project CzechIdMng by bcvsolutions.

the class DefaultNotificationServiceIntegrationTest method testReferentialIntegrity.

@Test
public void testReferentialIntegrity() {
    // delete recipients and children
    NotificationConfigurationDto config = createConfig();
    IdmNotificationTemplateDto template = createTestTemplate();
    IdmIdentityDto identityOne = getHelper().createIdentity((GuardedString) null);
    IdmIdentityDto identityTwo = getHelper().createIdentity((GuardedString) null);
    IdmIdentityDto identitySender = getHelper().createIdentity((GuardedString) null);
    List<IdmNotificationLogDto> notifications = notificationManager.send(config.getTopic(), new IdmMessageDto.Builder().setTemplate(template).build(), identitySender, Lists.newArrayList(identityOne, identityTwo));
    Assert.assertEquals(1, notifications.size());
    List<IdmNotificationLogDto> notificationOthers = notificationManager.send(config.getTopic(), new IdmMessageDto.Builder().setTemplate(template).build(), identitySender, Lists.newArrayList(identityOne, identityTwo));
    Assert.assertEquals(1, notificationOthers.size());
    IdmNotificationLogDto notificationOther = notificationLogService.get(notificationOthers.get(0));
    // 
    IdmNotificationLogDto notification = notificationLogService.get(notifications.get(0));
    Assert.assertNotNull(notification);
    Assert.assertEquals(identitySender.getId(), notification.getIdentitySender());
    IdmNotificationFilter notificationFilter = new IdmNotificationFilter();
    notificationFilter.setParent(notification.getId());
    List<IdmEmailLogDto> emails = emailLogService.find(notificationFilter, null).getContent();
    Assert.assertEquals(1, emails.size());
    IdmEmailLogDto emailNotification = emails.get(0);
    Assert.assertEquals(notification.getId(), emailNotification.getParent());
    // 
    IdmNotificationRecipientFilter recipientFilter = new IdmNotificationRecipientFilter();
    recipientFilter.setNotification(notification.getId());
    List<IdmNotificationRecipientDto> notificationRecipients = recipientService.find(recipientFilter, null).getContent();
    Assert.assertEquals(2, notificationRecipients.size());
    Assert.assertTrue(notificationRecipients.stream().anyMatch(r -> r.getIdentityRecipient().equals(identityOne.getId())));
    Assert.assertTrue(notificationRecipients.stream().anyMatch(r -> r.getIdentityRecipient().equals(identityTwo.getId())));
    recipientFilter.setNotification(emailNotification.getId());
    List<IdmNotificationRecipientDto> emailRecipients = recipientService.find(recipientFilter, null).getContent();
    Assert.assertEquals(2, emailRecipients.size());
    Assert.assertTrue(emailRecipients.stream().anyMatch(r -> r.getIdentityRecipient().equals(identityOne.getId())));
    Assert.assertTrue(emailRecipients.stream().anyMatch(r -> r.getIdentityRecipient().equals(identityTwo.getId())));
    // 
    // sender is removed from notifications when sender identity was deleted
    IdmNotificationFilter senderFilter = new IdmNotificationFilter();
    senderFilter.setIdentitySender(identitySender.getId());
    List<IdmNotificationLogDto> notificationLogDtos = notificationLogService.find(senderFilter, null).getContent();
    Assert.assertFalse(notificationLogDtos.isEmpty());
    notificationLogDtos.forEach(notif -> {
        Assert.assertEquals(identitySender.getId(), notif.getIdentitySender());
    });
    identityService.delete(identitySender);
    Assert.assertNull(identityService.get(identitySender.getId()));
    // shouldn't throw despite the fact that identitySender contained in notificationLogDtos has been deleted
    notificationLogDtos = notificationLogService.find(senderFilter, null).getContent();
    // 
    // create notifications and attachments
    // other owner
    IdmAttachmentDto attachmentOther = attachmentManager.save(DefaultAttachmentManagerIntegrationTest.prepareDto());
    IdmAttachmentDto attachment = DefaultAttachmentManagerIntegrationTest.prepareDto();
    attachment.setOwnerType(null);
    attachment.setInputData(IOUtils.toInputStream("mock content"));
    attachment = attachmentManager.saveAttachment(notification, attachment);
    // 
    IdmNotificationAttachmentDto notificationAttachment = new IdmNotificationAttachmentDto();
    notificationAttachment.setAttachment(attachment.getId());
    notificationAttachment.setName(attachment.getName());
    notificationAttachment.setNotification(notification.getId());
    notificationAttachment = notificationAttachmentService.save(notificationAttachment);
    Assert.assertNotNull(attachmentManager.get(attachment));
    Assert.assertNotNull(notificationAttachmentService.get(notificationAttachment));
    // 
    IdmNotificationAttachmentDto notificationAttachmentOther = new IdmNotificationAttachmentDto();
    notificationAttachmentOther.setAttachment(attachmentOther.getId());
    notificationAttachmentOther.setName(attachmentOther.getName());
    notificationAttachmentOther.setNotification(notificationOther.getId());
    notificationAttachmentOther = notificationAttachmentService.save(notificationAttachmentOther);
    Assert.assertNotNull(attachmentManager.get(attachmentOther));
    Assert.assertNotNull(notificationAttachmentService.get(notificationAttachmentOther));
    // 
    // delete parent notification
    notificationLogService.delete(notification);
    // 
    // all removed
    Assert.assertNull(notificationLogService.get(notification));
    Assert.assertNull(notificationLogService.get(emailNotification));
    recipientFilter.setNotification(notification.getId());
    Assert.assertTrue(recipientService.find(recipientFilter, null).getContent().isEmpty());
    recipientFilter.setNotification(emailNotification.getId());
    Assert.assertTrue(recipientService.find(recipientFilter, null).getContent().isEmpty());
    Assert.assertNull(attachmentManager.get(attachment));
    Assert.assertNotNull(attachmentManager.get(attachmentOther));
    Assert.assertNull(notificationAttachmentService.get(notificationAttachment));
    Assert.assertNotNull(notificationAttachmentService.get(notificationAttachmentOther));
    // 
    notificationLogService.delete(notificationOther);
}
Also used : Arrays(java.util.Arrays) IdmNotificationRecipientService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationRecipientService) NotificationManager(eu.bcvsolutions.idm.core.notification.api.service.NotificationManager) ZonedDateTime(java.time.ZonedDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) NotificationState(eu.bcvsolutions.idm.core.notification.api.domain.NotificationState) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmNotificationConfiguration(eu.bcvsolutions.idm.core.notification.entity.IdmNotificationConfiguration) IdmEmailLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmEmailLogDto) IdmNotificationAttachmentFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationAttachmentFilter) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) IdmNotificationDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto) IdmEmailLogService(eu.bcvsolutions.idm.core.notification.api.service.IdmEmailLogService) Page(org.springframework.data.domain.Page) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) IdmEmailLogRepository(eu.bcvsolutions.idm.core.notification.repository.IdmEmailLogRepository) IdmNotificationTemplateService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationTemplateService) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmNotificationAttachmentDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationAttachmentDto) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) IdmConsoleLog(eu.bcvsolutions.idm.core.notification.entity.IdmConsoleLog) IdmNotificationLogRepository(eu.bcvsolutions.idm.core.notification.repository.IdmNotificationLogRepository) IdmNotificationConfigurationRepository(eu.bcvsolutions.idm.core.notification.repository.IdmNotificationConfigurationRepository) IdmNotificationConfigurationService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationConfigurationService) Lists(com.google.common.collect.Lists) NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) InitTestDataProcessor(eu.bcvsolutions.idm.core.model.event.processor.module.InitTestDataProcessor) IdmNotificationRecipientDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) EmailNotificationSender(eu.bcvsolutions.idm.core.notification.api.service.EmailNotificationSender) Before(org.junit.Before) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) IdmNotificationRecipientFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationRecipientFilter) IdmNotificationLog(eu.bcvsolutions.idm.core.notification.entity.IdmNotificationLog) IdmNotificationLogService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationLogService) IdmEmailLog(eu.bcvsolutions.idm.core.notification.entity.IdmEmailLog) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) IdmNotificationAttachmentService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationAttachmentService) Transactional(org.springframework.transaction.annotation.Transactional) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) IdmEmailLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmEmailLogDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) IdmNotificationRecipientFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationRecipientFilter) IdmNotificationAttachmentDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationAttachmentDto) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmNotificationRecipientDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 7 with IdmNotificationAttachmentDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationAttachmentDto in project CzechIdMng by bcvsolutions.

the class DefaultNotificationServiceIntegrationTest method testSendWithAttachments.

@Test
public void testSendWithAttachments() {
    NotificationConfigurationDto config = createConfig();
    IdmNotificationTemplateDto template = createTestTemplate();
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    // 
    IdmAttachmentDto attachmentOne = DefaultAttachmentManagerIntegrationTest.prepareDtoWithoutContent();
    // prepared attachment
    attachmentOne.setInputData(IOUtils.toInputStream("mock-content"));
    IdmAttachmentDto attachment = DefaultAttachmentManagerIntegrationTest.prepareDtoWithoutContent();
    attachment.setInputData(IOUtils.toInputStream("mock-content"));
    IdmAttachmentDto attachmentTwo = attachmentManager.saveAttachment(identity, attachment);
    List<IdmAttachmentDto> attachments = Lists.newArrayList(attachmentOne, attachmentTwo);
    // 
    List<IdmNotificationLogDto> notifications = notificationManager.send(config.getTopic(), new IdmMessageDto.Builder().setTemplate(template).build(), null, Lists.newArrayList(identity), attachments);
    Assert.assertEquals(1, notifications.size());
    Assert.assertTrue(notifications.stream().anyMatch(n -> n.getType().equals(IdmEmailLog.NOTIFICATION_TYPE)));
    // 
    IdmNotificationLogDto notification = notifications.get(0);
    // 
    IdmNotificationAttachmentFilter notificationAttachmentFilter = new IdmNotificationAttachmentFilter();
    notificationAttachmentFilter.setNotification(notification.getId());
    List<IdmNotificationAttachmentDto> notificationAttachments = notificationAttachmentService.find(notificationAttachmentFilter, null).getContent();
    Assert.assertEquals(2, notificationAttachments.size());
    Assert.assertTrue(notificationAttachments.stream().allMatch(na -> na.getAttachment() != null));
    Assert.assertTrue(notificationAttachments.stream().anyMatch(na -> na.getAttachment().equals(attachmentTwo.getId())));
    // 
    notificationLogService.delete(notification);
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) Arrays(java.util.Arrays) IdmNotificationRecipientService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationRecipientService) NotificationManager(eu.bcvsolutions.idm.core.notification.api.service.NotificationManager) ZonedDateTime(java.time.ZonedDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) NotificationState(eu.bcvsolutions.idm.core.notification.api.domain.NotificationState) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmNotificationConfiguration(eu.bcvsolutions.idm.core.notification.entity.IdmNotificationConfiguration) IdmEmailLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmEmailLogDto) IdmNotificationAttachmentFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationAttachmentFilter) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) IdmNotificationDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto) IdmEmailLogService(eu.bcvsolutions.idm.core.notification.api.service.IdmEmailLogService) Page(org.springframework.data.domain.Page) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) IdmEmailLogRepository(eu.bcvsolutions.idm.core.notification.repository.IdmEmailLogRepository) IdmNotificationTemplateService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationTemplateService) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmNotificationAttachmentDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationAttachmentDto) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) IdmConsoleLog(eu.bcvsolutions.idm.core.notification.entity.IdmConsoleLog) IdmNotificationLogRepository(eu.bcvsolutions.idm.core.notification.repository.IdmNotificationLogRepository) IdmNotificationConfigurationRepository(eu.bcvsolutions.idm.core.notification.repository.IdmNotificationConfigurationRepository) IdmNotificationConfigurationService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationConfigurationService) Lists(com.google.common.collect.Lists) NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) InitTestDataProcessor(eu.bcvsolutions.idm.core.model.event.processor.module.InitTestDataProcessor) IdmNotificationRecipientDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) EmailNotificationSender(eu.bcvsolutions.idm.core.notification.api.service.EmailNotificationSender) Before(org.junit.Before) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) IdmNotificationRecipientFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationRecipientFilter) IdmNotificationLog(eu.bcvsolutions.idm.core.notification.entity.IdmNotificationLog) IdmNotificationLogService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationLogService) IdmEmailLog(eu.bcvsolutions.idm.core.notification.entity.IdmEmailLog) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) IdmNotificationAttachmentService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationAttachmentService) Transactional(org.springframework.transaction.annotation.Transactional) NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) IdmNotificationAttachmentDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationAttachmentDto) IdmNotificationAttachmentFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationAttachmentFilter) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 8 with IdmNotificationAttachmentDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationAttachmentDto in project CzechIdMng by bcvsolutions.

the class IdmNotificationAttachmentControllerTest method testFindByText.

@Test
public void testFindByText() {
    IdmNotificationAttachmentDto attachmentOne = createDto();
    // other
    createDto();
    // 
    IdmNotificationAttachmentFilter filter = new IdmNotificationAttachmentFilter();
    filter.setText(attachmentOne.getName());
    List<IdmNotificationAttachmentDto> attachments = find(filter);
    Assert.assertEquals(1, attachments.size());
    Assert.assertTrue(attachments.stream().anyMatch(r -> r.getId().equals(attachmentOne.getId())));
}
Also used : IdmNotificationAttachmentDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationAttachmentDto) NotificationManager(eu.bcvsolutions.idm.core.notification.api.service.NotificationManager) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) IdmNotificationConfigurationService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationConfigurationService) Lists(com.google.common.collect.Lists) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) SecurityMockMvcRequestPostProcessors.authentication(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmNotificationAttachmentFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationAttachmentFilter) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) UUID(java.util.UUID) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) MockMvcRequestBuilders(org.springframework.test.web.servlet.request.MockMvcRequestBuilders) IdmNotificationLogService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationLogService) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) IdmNotificationTemplateService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationTemplateService) IdmEmailLog(eu.bcvsolutions.idm.core.notification.entity.IdmEmailLog) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) IdmNotificationAttachmentService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationAttachmentService) IdmNotificationAttachmentDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationAttachmentDto) IdmNotificationAttachmentFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationAttachmentFilter) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) Test(org.junit.Test)

Example 9 with IdmNotificationAttachmentDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationAttachmentDto in project CzechIdMng by bcvsolutions.

the class IdmNotificationAttachmentControllerTest method prepareDto.

@Override
protected IdmNotificationAttachmentDto prepareDto() {
    IdmNotificationLogDto notification = new IdmNotificationLogDto();
    notification.setMessage(new IdmMessageDto.Builder(NotificationLevel.SUCCESS).setMessage(getHelper().createName()).build());
    // related notification
    notification = notificationLogService.save(notification);
    // 
    IdmAttachmentDto attachment = attachmentManager.save(DefaultAttachmentManagerIntegrationTest.prepareDto());
    // 
    IdmNotificationAttachmentDto dto = new IdmNotificationAttachmentDto();
    dto.setAttachment(attachment.getId());
    dto.setName(attachment.getName());
    dto.setNotification(notification.getId());
    // 
    return dto;
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) IdmNotificationAttachmentDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationAttachmentDto) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)

Example 10 with IdmNotificationAttachmentDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationAttachmentDto in project CzechIdMng by bcvsolutions.

the class DefaultEmailer method send.

@Transactional
public boolean send(IdmEmailLogDto emailLog) {
    LOG.debug("Sending email [{}]", emailLog);
    // 
    UUID notificationId = emailLog.getId();
    if (ObjectUtils.isEmpty(emailLog.getRecipients())) {
        LOG.info("Email recipiets is empty. Email [{}] is logged only.", emailLog);
        emailLogService.setEmailSentLog(notificationId, "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);
        for (IdmAttachmentDto attachment : emailLog.getAttachments()) {
            // charset is required for the 'text/*' mime types - TODO: append encoding only there.
            UUID attachmentId = attachment.getId();
            String attachmentName = attachment.getName();
            String mimeTypeWithCharset = String.format("%s; charset=%s", attachment.getMimetype(), attachment.getEncoding());
            InputStream attachmentData = attachmentManager.getAttachmentData(attachmentId);
            DataSource dataSource = new javax.mail.util.ByteArrayDataSource(attachmentData, mimeTypeWithCharset);
            // TODO: check attachment with same names?
            LOG.info("Sending attachment [{}] for email [{}]", attachment.getName(), notificationId);
            // 
            in.addAttachment(attachment.getName(), new DataHandler(dataSource));
            // 
            IdmNotificationAttachmentDto notificationAttachment = new IdmNotificationAttachmentDto();
            notificationAttachment.setNotification(notificationId);
            notificationAttachment.setName(attachmentName);
            notificationAttachment.setAttachment(attachment.getId());
            notificationAttachmentService.save(notificationAttachment);
        }
        // 
        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 : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) Message(org.apache.camel.Message) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) InputStream(java.io.InputStream) DataHandler(javax.activation.DataHandler) DataSource(javax.activation.DataSource) Exchange(org.apache.camel.Exchange) IdmNotificationAttachmentDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationAttachmentDto) Endpoint(org.apache.camel.Endpoint) UUID(java.util.UUID) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmNotificationAttachmentDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationAttachmentDto)10 IdmAttachmentDto (eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto)9 IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)8 IdmNotificationLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto)8 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)7 IdmNotificationAttachmentFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationAttachmentFilter)7 Test (org.junit.Test)7 Lists (com.google.common.collect.Lists)6 AttachmentManager (eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager)6 DefaultAttachmentManagerIntegrationTest (eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest)6 NotificationLevel (eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel)6 IdmNotificationTemplateDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto)6 NotificationConfigurationDto (eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto)6 IdmNotificationAttachmentService (eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationAttachmentService)6 IdmNotificationConfigurationService (eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationConfigurationService)6 IdmNotificationLogService (eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationLogService)6 IdmNotificationTemplateService (eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationTemplateService)6 NotificationManager (eu.bcvsolutions.idm.core.notification.api.service.NotificationManager)6 IdmEmailLog (eu.bcvsolutions.idm.core.notification.entity.IdmEmailLog)6 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)6