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);
}
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);
}
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());
}
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);
}
}
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);
}
Aggregations