Search in sources :

Example 11 with MailTemplate

use of org.rembx.jeeshop.user.model.MailTemplate in project jeeshop by remibantos.

the class MailTemplatesCT method create_shouldThrowConflictException_WhenThereIsAlreadyAMailTemplateWithSameLocaleAndName.

@Test
public void create_shouldThrowConflictException_WhenThereIsAlreadyAMailTemplateWithSameLocaleAndName() {
    MailTemplate mailTemplate = new MailTemplate("Newsletter1", "fr_FR", "test content", "Test Subject");
    try {
        service.create(mailTemplate);
        fail("Should have thrown exception");
    } catch (WebApplicationException e) {
        assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.CONFLICT);
    }
}
Also used : WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) TestMailTemplate(org.rembx.jeeshop.user.test.TestMailTemplate) MailTemplate(org.rembx.jeeshop.user.model.MailTemplate) Test(org.junit.jupiter.api.Test)

Example 12 with MailTemplate

use of org.rembx.jeeshop.user.model.MailTemplate in project jeeshop by remibantos.

the class DefaultPaymentTransactionEngine method sendOrderConfirmationMail.

protected void sendOrderConfirmationMail(Order order) {
    User user = order.getUser();
    MailTemplate mailTemplate = mailTemplateFinder.findByNameAndLocale(orderValidated.name(), user.getPreferredLocale());
    if (mailTemplate == null) {
        LOG.warn("orderValidated e-mail template does not exist. Configure this missing template to allow user e-mail notification");
        return;
    }
    try {
        Template mailContentTpl = new Template(orderValidated.name(), mailTemplate.getContent(), new Configuration(Configuration.VERSION_2_3_21));
        final StringWriter mailBody = new StringWriter();
        mailContentTpl.process(order, mailBody);
        mailer.sendMail(mailTemplate.getSubject(), user.getLogin(), mailBody.toString());
    } catch (Exception e) {
        LOG.error("Unable to send mail " + orderValidated + " to user " + user.getLogin(), e);
    }
}
Also used : User(org.rembx.jeeshop.user.model.User) Configuration(freemarker.template.Configuration) StringWriter(java.io.StringWriter) MailTemplate(org.rembx.jeeshop.user.model.MailTemplate) MailTemplate(org.rembx.jeeshop.user.model.MailTemplate) Template(freemarker.template.Template)

Example 13 with MailTemplate

use of org.rembx.jeeshop.user.model.MailTemplate in project jeeshop by remibantos.

the class MailTemplates method create.

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed(ADMIN)
public MailTemplate create(MailTemplate mailTemplate) {
    MailTemplate existingTpl = mailTemplateFinder.findByNameAndLocale(mailTemplate.getName(), mailTemplate.getLocale());
    if (existingTpl != null) {
        throw new WebApplicationException(Response.Status.CONFLICT);
    }
    entityManager.persist(mailTemplate);
    return mailTemplate;
}
Also used : WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) MailTemplate(org.rembx.jeeshop.user.model.MailTemplate) RolesAllowed(javax.annotation.security.RolesAllowed)

Example 14 with MailTemplate

use of org.rembx.jeeshop.user.model.MailTemplate in project jeeshop by remibantos.

the class MailTemplateFinder method findAll.

public List<MailTemplate> findAll(Integer offset, Integer limit, String orderBy, Boolean isDesc) {
    JPAQuery<MailTemplate> query = new JPAQueryFactory(entityManager).selectFrom(mailTemplate);
    if (offset != null)
        query.offset(offset);
    if (limit != null)
        query.limit(limit);
    sortBy(orderBy, isDesc, query);
    return query.fetch();
}
Also used : MailTemplate(org.rembx.jeeshop.user.model.MailTemplate) JPAQueryFactory(com.querydsl.jpa.impl.JPAQueryFactory)

Aggregations

MailTemplate (org.rembx.jeeshop.user.model.MailTemplate)14 Test (org.junit.jupiter.api.Test)6 TestMailTemplate (org.rembx.jeeshop.user.test.TestMailTemplate)6 WebApplicationException (org.rembx.jeeshop.rest.WebApplicationException)5 RolesAllowed (javax.annotation.security.RolesAllowed)3 Configuration (freemarker.template.Configuration)2 Template (freemarker.template.Template)2 StringWriter (java.io.StringWriter)2 EntityManager (javax.persistence.EntityManager)2 Transactional (javax.transaction.Transactional)2 JPAQueryFactory (com.querydsl.jpa.impl.JPAQueryFactory)1 User (org.rembx.jeeshop.user.model.User)1