Search in sources :

Example 1 with MailTemplate

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

the class MailTemplates method delete.

@DELETE
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed(ADMIN)
@Transactional
@Path("/{id}")
public void delete(@PathParam("id") Long id) {
    MailTemplate mailTemplate = entityManager.find(MailTemplate.class, id);
    checkNotNull(mailTemplate);
    entityManager.remove(mailTemplate);
}
Also used : MailTemplate(org.rembx.jeeshop.user.model.MailTemplate) RolesAllowed(javax.annotation.security.RolesAllowed) Transactional(javax.transaction.Transactional)

Example 2 with MailTemplate

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

the class MailTemplates method modify.

@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Transactional
@RolesAllowed(ADMIN)
public MailTemplate modify(MailTemplate mailTemplate) {
    MailTemplate existingMailTemplate = entityManager.find(MailTemplate.class, mailTemplate.getId());
    checkNotNull(existingMailTemplate);
    MailTemplate existingTplWithSameLocaleAndName = mailTemplateFinder.findByNameAndLocale(mailTemplate.getName(), mailTemplate.getLocale());
    if (existingTplWithSameLocaleAndName != null && !existingTplWithSameLocaleAndName.getId().equals(mailTemplate.getId())) {
        throw new WebApplicationException(Response.Status.CONFLICT);
    }
    mailTemplate.setCreationDate(existingMailTemplate.getCreationDate());
    return entityManager.merge(mailTemplate);
}
Also used : WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) MailTemplate(org.rembx.jeeshop.user.model.MailTemplate) RolesAllowed(javax.annotation.security.RolesAllowed) Transactional(javax.transaction.Transactional)

Example 3 with MailTemplate

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

the class MailTemplates method sendMail.

private void sendMail(MailTemplate mailTemplate, String recipient, Object properties) throws Exception {
    Template mailContentTpl = new Template(mailTemplate.getName(), mailTemplate.getContent(), new Configuration(Configuration.VERSION_2_3_21));
    final StringWriter mailBody = new StringWriter();
    mailContentTpl.process(properties, mailBody);
    mailer.sendMail(mailTemplate.getSubject(), recipient, mailBody.toString());
}
Also used : Configuration(freemarker.template.Configuration) StringWriter(java.io.StringWriter) MailTemplate(org.rembx.jeeshop.user.model.MailTemplate) Template(freemarker.template.Template)

Example 4 with MailTemplate

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

the class MailTemplatesCT method create_shouldThrowConflictException_WhenThereIsAlreadyAMailTemplateWithSameLocaleAndNameAndDifferentID.

@Test
public void create_shouldThrowConflictException_WhenThereIsAlreadyAMailTemplateWithSameLocaleAndNameAndDifferentID() {
    MailTemplate mailTemplate = new MailTemplate(Mails.userRegistration.name(), "fr_FR", "test content", "Test Subject");
    mailTemplate.setId(testMailTemplate.firstMailTemplate().getId());
    try {
        service.modify(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 5 with MailTemplate

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

the class MailTemplatesCT method create_shouldPersist.

@Test
public void create_shouldPersist() {
    MailTemplate mailTemplate = new MailTemplate("TestNewsletter", "en_GB", "test content", "Test Subject");
    entityManager.getTransaction().begin();
    service.create(mailTemplate);
    entityManager.getTransaction().commit();
    assertThat(entityManager.find(MailTemplate.class, mailTemplate.getId())).isNotNull();
    entityManager.remove(mailTemplate);
}
Also used : TestMailTemplate(org.rembx.jeeshop.user.test.TestMailTemplate) MailTemplate(org.rembx.jeeshop.user.model.MailTemplate) Test(org.junit.jupiter.api.Test)

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