Skip to content

Commit

Permalink
remove a sendSimpleEmail variant
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Aug 19, 2015
1 parent ff18617 commit 9f4965a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
15 changes: 9 additions & 6 deletions src/main/java/alfio/controller/ReservationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -394,18 +394,21 @@ public String assignTicketToPerson(@PathVariable("eventName") String eventName,
private void sendReservationCompleteEmail(HttpServletRequest request, Event event, TicketReservation reservation) {

Locale locale = RequestContextUtils.getLocale(request);
String reservationTxt = templateManager.renderClassPathResource("/alfio/templates/confirmation-email-txt.ms",
ticketReservationManager.prepareModelForReservationEmail(event, reservation), locale, TemplateOutput.TEXT);

String shortReservationID = ticketReservationManager.getShortReservationID(reservation.getId());

notificationManager.sendSimpleEmail(event, reservation.getEmail(), messageSource.getMessage("reservation-email-subject",
new Object[] { shortReservationID, event.getDisplayName() }, locale), reservationTxt);
new Object[] { shortReservationID, event.getDisplayName() }, locale), () -> {
return templateManager.renderClassPathResource("/alfio/templates/confirmation-email-txt.ms", ticketReservationManager.prepareModelForReservationEmail(event, reservation), locale, TemplateOutput.TEXT);
});
}

private void sendReservationCompleteEmailToOrganizer(HttpServletRequest request, Event event, TicketReservation reservation) {
Organization organization = organizationRepository.getById(event.getOrganizationId());
String reservationInfo = templateManager.renderClassPathResource("/alfio/templates/confirmation-email-for-organizer-txt.ms",
ticketReservationManager.prepareModelForReservationEmail(event, reservation), RequestContextUtils.getLocale(request), TemplateOutput.TEXT);
notificationManager.sendSimpleEmail(event, organization.getEmail(), "Reservation complete " + reservation.getId(), reservationInfo);
notificationManager.sendSimpleEmail(event, organization.getEmail(), "Reservation complete " + reservation.getId(), () -> {
return templateManager.renderClassPathResource("/alfio/templates/confirmation-email-for-organizer-txt.ms", ticketReservationManager.prepareModelForReservationEmail(event, reservation),
RequestContextUtils.getLocale(request), TemplateOutput.TEXT);
});
}

}
6 changes: 0 additions & 6 deletions src/main/java/alfio/manager/NotificationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,6 @@ public void sendSimpleEmail(Event event, String recipient, String subject, TextT
messages.offer(new EmailMessage(-1, event.getId(), WAITING.name(), recipient, subject, text, null, checksum));
}

public void sendSimpleEmail(Event event, String recipient, String subject, String text) {
String checksum = calculateChecksum(recipient, null, subject, text);
emailMessageRepository.insert(event.getId(), recipient, subject, text, null, checksum, ZonedDateTime.now(UTC));
messages.offer(new EmailMessage(-1, event.getId(), WAITING.name(), recipient, subject, text, null, checksum));
}

void sendWaitingMessages() {
Set<EmailMessage> toBeSent = messages.poll(configurationManager.getIntConfigValue(Configuration.maxEmailPerCycle(), 10));
toBeSent.forEach(m -> {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/alfio/manager/TicketReservationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ public void updateTicketOwner(Ticket ticket,
if (!admin && StringUtils.isNotBlank(ticket.getEmail()) && !StringUtils.equalsIgnoreCase(newEmail, ticket.getEmail())) {
Locale oldUserLocale = Locale.forLanguageTag(ticket.getUserLanguage());
String subject = messageSource.getMessage("ticket-has-changed-owner-subject", new Object[] {event.getDisplayName()}, oldUserLocale);
notificationManager.sendSimpleEmail(event, ticket.getEmail(), subject, ownerChangeTextBuilder.generate(newTicket));
notificationManager.sendSimpleEmail(event, ticket.getEmail(), subject, () -> ownerChangeTextBuilder.generate(newTicket));
}

if(admin) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public int sendMessages(String eventName, Optional<Integer> categoryId, List<Mes
String subject = renderResource(m.getSubject(), model, m.getLocale(), templateManager);
String text = renderResource(m.getText(), model, m.getLocale(), templateManager);
counter.incrementAndGet();
notificationManager.sendSimpleEmail(event, triple.getMiddle(), subject, text);
notificationManager.sendSimpleEmail(event, triple.getMiddle(), subject, () -> text);
});
return counter.get();

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/alfio/manager/TicketReservationManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public class TicketReservationManagerTest {{
when(original.getUserLanguage()).thenReturn("it");
trm.updateTicketOwner(original, Locale.ENGLISH, event, form, (a) -> null, ownerChangeTextBuilder, (c) -> null, Optional.empty());
verify(messageSource, times(1)).getMessage(eq("ticket-has-changed-owner-subject"), any(), eq(Locale.ITALIAN));
verify(notificationManager, times(1)).sendSimpleEmail(eq(event), eq(originalEmail), anyString(), eq("Hello, world"));
verify(notificationManager, times(1)).sendSimpleEmail(eq(event), eq(originalEmail), anyString(), any(TextTemplateGenerator.class));
});

it.should("fall back to the current locale", expect -> {
Expand All @@ -107,7 +107,7 @@ public class TicketReservationManagerTest {{
trm.updateTicketOwner(original, Locale.ENGLISH, event, form, (a) -> null, ownerChangeTextBuilder, (c) -> null, Optional.empty());
verify(messageSource, times(1)).getMessage(eq("ticket-has-changed-owner-subject"), any(), eq(Locale.ITALIAN));
verify(notificationManager, times(1)).sendTicketByEmail(eq(modified), eq(event), eq(Locale.ENGLISH), any(), any());
verify(notificationManager, times(1)).sendSimpleEmail(eq(event), eq(originalEmail), anyString(), eq("Hello, world"));
verify(notificationManager, times(1)).sendSimpleEmail(eq(event), eq(originalEmail), anyString(), any(TextTemplateGenerator.class));
});
});

Expand Down

0 comments on commit 9f4965a

Please sign in to comment.