diff --git a/src/main/java/ch/wisv/events/core/service/mail/MailServiceImpl.java b/src/main/java/ch/wisv/events/core/service/mail/MailServiceImpl.java index 4636a87c..65d20e39 100644 --- a/src/main/java/ch/wisv/events/core/service/mail/MailServiceImpl.java +++ b/src/main/java/ch/wisv/events/core/service/mail/MailServiceImpl.java @@ -59,6 +59,7 @@ public class MailServiceImpl implements MailService { * * @param mailSender of type JavaMailSender * @param templateEngine of type templateEngine + * @param ticketService of type TicketService */ @Autowired public MailServiceImpl(JavaMailSender mailSender, SpringTemplateEngine templateEngine, TicketService ticketService) { @@ -193,6 +194,7 @@ private void sendMailWithContent(String recipientEmail, String subject, String c message.addAttachment("ch-" + uniqueCode + ".pkpass", new ByteArrayResource(walletPass), "application/vnd.apple.pkpass"); } catch (Exception e) { // Do nothing + System.out.println("Unable to generate wallet pass: " + e.getMessage()); } } } diff --git a/src/main/java/ch/wisv/events/core/service/ticket/TicketService.java b/src/main/java/ch/wisv/events/core/service/ticket/TicketService.java index b6040816..9ec8348d 100644 --- a/src/main/java/ch/wisv/events/core/service/ticket/TicketService.java +++ b/src/main/java/ch/wisv/events/core/service/ticket/TicketService.java @@ -114,7 +114,7 @@ public interface TicketService { * @param currentCustomer of type Customer * @param newCustomer of type Customer */ - void transfer(Ticket ticket, Customer currentCustomer, Customer newCustomer) throws TicketNotTransferableException; + Ticket transfer(Ticket ticket, Customer currentCustomer, Customer newCustomer) throws TicketNotTransferableException; /** * Generate a QR code for a Ticket. @@ -125,6 +125,12 @@ public interface TicketService { */ BufferedImage generateQrCode(Ticket ticket) throws WriterException, IllegalArgumentException; + /** + * Get Apple Wallet pass for a Ticket. + * @param ticket of type Ticket + * @return byte[] + * @throws TicketPassFailedException when pass is not generated + */ byte[] getApplePass(Ticket ticket) throws TicketPassFailedException; } diff --git a/src/main/java/ch/wisv/events/core/service/ticket/TicketServiceImpl.java b/src/main/java/ch/wisv/events/core/service/ticket/TicketServiceImpl.java index ea81ac2a..14bd68f8 100644 --- a/src/main/java/ch/wisv/events/core/service/ticket/TicketServiceImpl.java +++ b/src/main/java/ch/wisv/events/core/service/ticket/TicketServiceImpl.java @@ -18,7 +18,6 @@ import java.util.*; import ch.wisv.events.core.service.event.EventService; -import ch.wisv.events.core.service.mail.MailService; import ch.wisv.events.core.util.QrCode; import com.google.zxing.WriterException; import org.springframework.beans.factory.annotation.Value; @@ -42,11 +41,6 @@ public class TicketServiceImpl implements TicketService { */ private final EventService eventService; - /** - * MailService. - */ - private final MailService mailService; - @Value("${links.passes}") @NotNull private String passesLink; @@ -55,11 +49,10 @@ public class TicketServiceImpl implements TicketService { * TicketServiceImpl constructor. * * @param ticketRepository of type TicketRepository - * @param mailService of type MailService + * @param eventService of type EventService */ - public TicketServiceImpl(TicketRepository ticketRepository, EventService eventService, MailService mailService) { + public TicketServiceImpl(TicketRepository ticketRepository, EventService eventService) { this.ticketRepository = ticketRepository; - this.mailService = mailService; this.eventService = eventService; } @@ -239,7 +232,7 @@ public BufferedImage generateQrCode(Ticket ticket) throws IllegalArgumentExcepti * @param currentCustomer of type Customer * @param newCustomer of type Customer */ - public void transfer(Ticket ticket, Customer currentCustomer, Customer newCustomer) throws TicketNotTransferableException { + public Ticket transfer(Ticket ticket, Customer currentCustomer, Customer newCustomer) throws TicketNotTransferableException { // Get event from ticket product Event event = null; try { @@ -259,10 +252,16 @@ public void transfer(Ticket ticket, Customer currentCustomer, Customer newCustom ticketRepository.saveAndFlush(ticket); - // Send email to new customer - mailService.sendTransferConfirmation(ticket, currentCustomer, newCustomer); + return ticket; } + /** + * Get the Apple Pass of a Ticket. + * + * @param ticket of type Ticket + * @return byte[] + * @throws TicketPassFailedException when the Apple Pass is not generated + */ public byte[] getApplePass(Ticket ticket) throws TicketPassFailedException { try { RestTemplate restTemplate = new RestTemplate(); diff --git a/src/main/java/ch/wisv/events/webshop/controller/WebshopTicketController.java b/src/main/java/ch/wisv/events/webshop/controller/WebshopTicketController.java index 98af38f8..39913a96 100644 --- a/src/main/java/ch/wisv/events/webshop/controller/WebshopTicketController.java +++ b/src/main/java/ch/wisv/events/webshop/controller/WebshopTicketController.java @@ -8,6 +8,7 @@ import ch.wisv.events.core.model.ticket.Ticket; import ch.wisv.events.core.service.auth.AuthenticationService; import ch.wisv.events.core.service.customer.CustomerService; +import ch.wisv.events.core.service.mail.MailService; import ch.wisv.events.core.service.order.OrderService; import ch.wisv.events.core.service.ticket.TicketService; import ch.wisv.events.core.util.QrCode; @@ -38,6 +39,9 @@ public class WebshopTicketController extends WebshopController { /** CustomerService. */ private final CustomerService customerService; + /** MailService. */ + private final MailService mailService; + /** * @param authenticationService of type AuthenticationService * @param orderService of type OrderService @@ -47,11 +51,13 @@ public WebshopTicketController( AuthenticationService authenticationService, CustomerService customerService, OrderService orderService, - TicketService ticketService + TicketService ticketService, + MailService mailService ) { super(orderService, authenticationService); this.customerService = customerService; this.ticketService = ticketService; + this.mailService = mailService; } /** Get ticket transfer page. @@ -104,7 +110,11 @@ public String transferTicket(Model model, RedirectAttributes redirect, @PathVari Customer newCustomer = customerService.getByEmail(email); // Transfer the ticket - ticketService.transfer(ticket, currentCustomer, newCustomer); + Ticket newTicket = ticketService.transfer(ticket, currentCustomer, newCustomer); + + // Send email to new customer + mailService.sendTransferConfirmation(newTicket, currentCustomer, newCustomer); + redirect.addFlashAttribute(MODEL_ATTR_SUCCESS, "Ticket has been transferred to " + newCustomer.getEmail()); diff --git a/src/test/java/ch/wisv/events/core/service/TicketServiceTest.java b/src/test/java/ch/wisv/events/core/service/TicketServiceTest.java index be5ff333..a6b2db4f 100644 --- a/src/test/java/ch/wisv/events/core/service/TicketServiceTest.java +++ b/src/test/java/ch/wisv/events/core/service/TicketServiceTest.java @@ -10,7 +10,6 @@ import ch.wisv.events.core.model.ticket.TicketStatus; import ch.wisv.events.core.repository.TicketRepository; import ch.wisv.events.core.service.event.EventService; -import ch.wisv.events.core.service.mail.MailService; import ch.wisv.events.core.service.ticket.TicketService; import ch.wisv.events.core.service.ticket.TicketServiceImpl; import ch.wisv.events.core.util.VatRate; @@ -50,10 +49,6 @@ public class TicketServiceTest extends ServiceTest { /** EventService. */ private EventService eventService; - /** MailService. */ - @Mock - private MailService mailService; - /** TicketService. */ private TicketService ticketService; @@ -71,7 +66,7 @@ public class TicketServiceTest extends ServiceTest { */ @Before public void setUp() { - ticketService = new TicketServiceImpl(ticketRepository, eventService, mailService); + ticketService = new TicketServiceImpl(ticketRepository, eventService); ticket1 = new Ticket(); ticket2 = new Ticket(); diff --git a/src/test/java/ch/wisv/events/core/service/TicketTransferTest.java b/src/test/java/ch/wisv/events/core/service/TicketTransferTest.java index 3acbfd12..b44c45a1 100644 --- a/src/test/java/ch/wisv/events/core/service/TicketTransferTest.java +++ b/src/test/java/ch/wisv/events/core/service/TicketTransferTest.java @@ -44,10 +44,6 @@ public class TicketTransferTest extends ServiceTest { /** EventService. */ private EventService eventService; - /** MailService. */ - @Mock - private MailService mailService; - /** TicketService. */ private TicketService ticketService; @@ -65,7 +61,7 @@ public class TicketTransferTest extends ServiceTest { */ @Before public void setUp() { - ticketService = new TicketServiceImpl(ticketRepository, eventService, mailService); + ticketService = new TicketServiceImpl(ticketRepository, eventService); customer1 = new Customer(); customer1.setVerifiedChMember(true);