Search in sources :

Example 1 with IdmEmailLogDto

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

the class DefaultEmailNotificationSender method send.

@Override
@Transactional
public IdmEmailLogDto send(IdmMessageDto message, String[] emails) {
    Assert.notNull(message);
    Assert.notNull(emails);
    // 
    IdmEmailLogDto emailLog = new IdmEmailLogDto();
    // there is no parent
    // build message, without password
    emailLog.setMessage(notificationTemplateService.buildMessage(message, false));
    // 
    for (String email : emails) {
        // fill email to recipientDto
        emailLog.getRecipients().add(new IdmNotificationRecipientDto(email));
    }
    emailLog = this.emailLogService.save(emailLog);
    // 
    producerTemplate.sendBody("direct:emails", emailLog);
    // 
    return emailLog;
}
Also used : IdmEmailLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmEmailLogDto) IdmNotificationRecipientDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with IdmEmailLogDto

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

the class DefaultEmailNotificationSender method send.

@Override
@Transactional
public IdmEmailLogDto send(IdmNotificationDto notification) {
    Assert.notNull(notification, "Notification is required!");
    // 
    LOG.info("Adding email notification to queue [{}]", notification);
    IdmEmailLogDto log = createLog(notification);
    // send notification to routing, generate new message
    producerTemplate.sendBody("direct:emails", log);
    return log;
}
Also used : IdmEmailLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmEmailLogDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with IdmEmailLogDto

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

the class CustomMailActivityBehavior method execute.

/**
 * Sending email through {@link EmailNotificationSender}.
 */
@Override
public void execute(DelegateExecution execution) {
    LOG.trace("Sending email from workflow execution [{}]", execution.getId());
    IdmEmailLogDto emailLog = new IdmEmailLogDto();
    // recipients
    String[] tos = splitAndTrim(getStringFromField(to, execution));
    if (!ObjectUtils.isEmpty(tos)) {
        emailLog.setRecipients(Arrays.stream(tos).map(identityOrAddress -> {
            return prepareRecipient(identityOrAddress);
        }).collect(Collectors.toList()));
    }
    // sender
    emailLog.setIdentitySender(getIdentity(getStringFromField(from, execution)).getId());
    // message
    emailLog.setMessage(new IdmMessageDto.Builder().setSubject(getStringFromField(subject, execution)).setTextMessage(getStringFromField(text, execution)).setHtmlMessage(getStringFromField(html, execution)).build());
    IdmNotificationDto result = emailService.send(emailLog);
    LOG.trace("Email from workflow execution [{}] was sent with result [{}]", execution.getId(), result == null ? false : true);
    leave(execution);
}
Also used : IdmNotificationDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto) IdmEmailLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmEmailLogDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)

Example 4 with IdmEmailLogDto

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

the class CustomMailActivityBehavior method execute.

/**
 * Sending emails through {@link EmailNotificationSender}
 */
@Override
public void execute(ActivityExecution execution) {
    log.trace("Sending email from workflow execution [{}]", execution.getId());
    IdmEmailLogDto emailLog = new IdmEmailLogDto();
    // recipients
    String[] tos = splitAndTrim(getStringFromField(to, execution));
    if (!ObjectUtils.isEmpty(tos)) {
        emailLog.setRecipients(Arrays.stream(tos).map(identityOrAddress -> {
            return prepareRecipient(identityOrAddress);
        }).collect(Collectors.toList()));
    }
    // sender
    emailLog.setIdentitySender(getIdentity(getStringFromField(from, execution)).getId());
    // message
    emailLog.setMessage(new IdmMessageDto.Builder().setSubject(getStringFromField(subject, execution)).setTextMessage(getStringFromField(text, execution)).setHtmlMessage(getStringFromField(html, execution)).build());
    IdmNotificationDto result = emailService.send(emailLog);
    log.trace("Email from workflow execution [{}] was sent with result [{}]", execution.getId(), result == null ? false : true);
    leave(execution);
}
Also used : IdmNotificationDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto) IdmEmailLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmEmailLogDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)

Example 5 with IdmEmailLogDto

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

the class DefaultIdmEmailLogService method setEmailSent.

/**
 * Persists sent date to given emailLogId
 *
 * @param emailLogId
 * @param sent
 */
@Override
@Transactional
public void setEmailSent(UUID emailLogId, DateTime sent) {
    IdmEmailLogDto emailLog = get(emailLogId);
    Assert.notNull(emailLog, MessageFormat.format("Email log [id:{0}] does not exist", emailLogId));
    // 
    LOG.debug("Persist sent date [{}] to emailLogId [{}]", sent, emailLogId);
    emailLog.setSent(sent);
    save(emailLog);
}
Also used : IdmEmailLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmEmailLogDto) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmEmailLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmEmailLogDto)13 Transactional (org.springframework.transaction.annotation.Transactional)7 IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)6 IdmNotificationRecipientDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto)6 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 IdmNotificationDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto)3 Test (org.junit.Test)3 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)2 NotificationLevel (eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel)2 NotificationState (eu.bcvsolutions.idm.core.notification.api.domain.NotificationState)2 IdmNotificationTemplateDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto)2 NotificationConfigurationDto (eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto)2 IdmNotificationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter)2 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)2 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)2 ZonedDateTime (java.time.ZonedDateTime)2 List (java.util.List)2 Assert (org.junit.Assert)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Lists (com.google.common.collect.Lists)1