use of io.gravitee.am.common.email.Email in project gravitee-access-management by gravitee-io.
the class EmailServiceImpl method send.
@Override
public void send(io.gravitee.am.model.Template template, User user, Client client) {
if (enabled) {
// get raw email template
io.gravitee.am.model.Email emailTemplate = getEmailTemplate(template, client);
// prepare email
Email email = prepareEmail(template, emailTemplate, user, client);
// send email
sendEmail(email, user, client);
}
}
use of io.gravitee.am.common.email.Email in project gravitee-access-management by gravitee-io.
the class EmailServiceImpl method sendEmail.
private void sendEmail(Email email, User user, Client client) {
try {
final Template template = freemarkerConfiguration.getTemplate(email.getTemplate());
final Template plainTextTemplate = new Template("subject", new StringReader(email.getSubject()), freemarkerConfiguration);
// compute email subject
final String subject = processTemplateIntoString(plainTextTemplate, email.getParams());
// compute email content
final String content = processTemplateIntoString(template, email.getParams());
final Email emailToSend = new Email(email);
emailToSend.setSubject(subject);
emailToSend.setContent(content);
emailService.send(emailToSend);
auditService.report(AuditBuilder.builder(EmailAuditBuilder.class).domain(domain.getId()).client(client).email(email).user(user));
} catch (final Exception ex) {
auditService.report(AuditBuilder.builder(EmailAuditBuilder.class).domain(domain.getId()).client(client).email(email).throwable(ex));
}
}
use of io.gravitee.am.common.email.Email in project gravitee-access-management by gravitee-io.
the class EmailServiceImpl method createEmail.
@Override
public EmailWrapper createEmail(io.gravitee.am.model.Template template, Client client, List<String> recipients, Map<String, Object> params) throws IOException, TemplateException {
io.gravitee.am.model.Email emailTpl = getEmailTemplate(template, client);
params.put("expireAfterSeconds", emailTpl.getExpiresAfter());
final long expiresAt = Instant.now().plus(emailTpl.getExpiresAfter(), ChronoUnit.SECONDS).toEpochMilli();
params.put("expireAt", expiresAt);
io.gravitee.am.common.email.Email email = new EmailBuilder().from(emailTpl.getFrom()).fromName(emailTpl.getFromName()).template(emailTpl.getTemplate()).to(recipients.toArray(new String[recipients.size()])).build();
// compute email subject
final Template plainTextTemplate = new Template("subject", new StringReader(emailTpl.getSubject()), freemarkerConfiguration);
email.setSubject(processTemplateIntoString(plainTextTemplate, params));
// compute email content
final Template subjectTemplate = freemarkerConfiguration.getTemplate(email.getTemplate());
email.setContent(processTemplateIntoString(subjectTemplate, params));
EmailWrapper wrapper = new EmailWrapper(email);
wrapper.setExpireAt(expiresAt);
return wrapper;
}
use of io.gravitee.am.common.email.Email in project gravitee-access-management by gravitee-io.
the class EmailServiceImpl method prepareEmail.
private Email prepareEmail(io.gravitee.am.model.Template template, io.gravitee.am.model.Email emailTemplate, User user, Client client) {
Map<String, Object> params = prepareEmailParams(user, client, emailTemplate.getExpiresAfter(), template.redirectUri());
Email email = new EmailBuilder().to(user.getEmail()).from(emailTemplate.getFrom()).fromName(emailTemplate.getFromName()).subject(emailTemplate.getSubject()).template(emailTemplate.getTemplate()).params(params).build();
return email;
}
use of io.gravitee.am.common.email.Email in project gravitee-access-management by gravitee-io.
the class DomainNotificationServiceTest method shouldNotifyUserFromGroup.
@Test
public void shouldNotifyUserFromGroup() throws Exception {
final Membership member = new Membership();
member.setMemberType(MemberType.GROUP);
member.setMemberId("groupId");
when(membershipService.findByCriteria(eq(ReferenceType.DOMAIN), eq(DOMAIN_ID), any())).thenReturn(Flowable.just(member), Flowable.empty());
final List<User> tenUsers = IntStream.range(0, 10).mapToObj(x -> {
final User user = new User();
user.setId("" + x);
user.setEmail(x + "@acme.fr");
return user;
}).collect(Collectors.toList());
final User singleUser = new User();
singleUser.setId("single");
singleUser.setEmail("single@acme.fr");
when(groupService.findMembers(any(), any(), any(), anyInt(), anyInt())).thenReturn(Single.just(new Page<>(tenUsers, 0, 11)), Single.just(new Page<>(Arrays.asList(singleUser), 1, 11)));
when(emailService.getFinalEmail(any(), any(), any(), any(), any())).thenReturn(new Email());
cut.registerCertificateExpiration(certificate);
// wait subscription execution
Thread.sleep(1000);
verify(notifierService, times(11)).register(any(), any(), any());
verify(userService, never()).findById(any(), any(), any());
}
Aggregations