Search in sources :

Example 6 with Ticket

use of alfio.model.Ticket in project alf.io by alfio-event.

the class EventManagerIntegrationTest method testUnboundedTicketsGeneration.

@Test
public void testUnboundedTicketsGeneration() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null));
    Event event = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository).getKey();
    List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
    assertNotNull(tickets);
    assertFalse(tickets.isEmpty());
    assertEquals(AVAILABLE_SEATS, tickets.size());
    assertTrue(tickets.stream().allMatch(t -> t.getCategoryId() == null));
}
Also used : alfio.repository(alfio.repository) java.util(java.util) BeforeClass(org.junit.BeforeClass) ZonedDateTime(java.time.ZonedDateTime) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) RepositoryConfiguration(alfio.config.RepositoryConfiguration) BigDecimal(java.math.BigDecimal) ErrorCode(alfio.model.result.ErrorCode) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) Pair(org.apache.commons.lang3.tuple.Pair) LocalTime(java.time.LocalTime) OrganizationRepository(alfio.repository.user.OrganizationRepository) Test(org.junit.Test) IntegrationTestUtil(alfio.test.util.IntegrationTestUtil) ZoneId(java.time.ZoneId) ConfigurationRepository(alfio.repository.system.ConfigurationRepository) DateUtils(org.apache.commons.lang3.time.DateUtils) Result(alfio.model.result.Result) TicketCategory(alfio.model.TicketCategory) Initializer(alfio.config.Initializer) Ticket(alfio.model.Ticket) UserManager(alfio.manager.user.UserManager) ContextConfiguration(org.springframework.test.context.ContextConfiguration) LocalDate(java.time.LocalDate) DataSourceConfiguration(alfio.config.DataSourceConfiguration) Event(alfio.model.Event) TestConfiguration(alfio.TestConfiguration) Assert(org.junit.Assert) alfio.model.modification(alfio.model.modification) Transactional(org.springframework.transaction.annotation.Transactional) Ticket(alfio.model.Ticket) Event(alfio.model.Event) Test(org.junit.Test)

Example 7 with Ticket

use of alfio.model.Ticket in project alf.io by alfio-event.

the class EventManagerIntegrationTest method testUpdateBoundedCategory.

@Test
public void testUpdateBoundedCategory() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", 10, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null));
    Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
    Event event = pair.getKey();
    TicketCategory category = ticketCategoryRepository.findByEventId(event.getId()).get(0);
    TicketCategoryModification tcm = new TicketCategoryModification(category.getId(), "default", 20, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null);
    eventManager.updateCategory(category.getId(), event.getId(), tcm, pair.getValue());
    waitingQueueSubscriptionProcessor.distributeAvailableSeats(event);
    List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
    assertNotNull(tickets);
    assertFalse(tickets.isEmpty());
    assertEquals(AVAILABLE_SEATS, tickets.size());
    assertEquals(0, tickets.stream().filter(t -> t.getCategoryId() == null).count());
}
Also used : Ticket(alfio.model.Ticket) Event(alfio.model.Event) TicketCategory(alfio.model.TicketCategory) Test(org.junit.Test)

Example 8 with Ticket

use of alfio.model.Ticket in project alf.io by alfio-event.

the class AttendeeManager method registerSponsorScan.

public TicketAndCheckInResult registerSponsorScan(String eventShortName, String ticketUid, String username) {
    int userId = userRepository.getByUsername(username).getId();
    Optional<Event> maybeEvent = eventRepository.findOptionalByShortName(eventShortName);
    if (!maybeEvent.isPresent()) {
        return new TicketAndCheckInResult(null, new DefaultCheckInResult(CheckInStatus.EVENT_NOT_FOUND, "event not found"));
    }
    Event event = maybeEvent.get();
    Optional<Ticket> maybeTicket = ticketRepository.findOptionalByUUID(ticketUid);
    if (!maybeTicket.isPresent()) {
        return new TicketAndCheckInResult(null, new DefaultCheckInResult(CheckInStatus.TICKET_NOT_FOUND, "ticket not found"));
    }
    Ticket ticket = maybeTicket.get();
    if (ticket.getStatus() != Ticket.TicketStatus.CHECKED_IN) {
        return new TicketAndCheckInResult(ticket, new DefaultCheckInResult(CheckInStatus.INVALID_TICKET_STATE, "not checked-in"));
    }
    Optional<ZonedDateTime> existingRegistration = sponsorScanRepository.getRegistrationTimestamp(userId, event.getId(), ticket.getId());
    if (!existingRegistration.isPresent()) {
        sponsorScanRepository.insert(userId, ZonedDateTime.now(event.getZoneId()), event.getId(), ticket.getId());
    }
    return new TicketAndCheckInResult(ticket, new DefaultCheckInResult(CheckInStatus.SUCCESS, "success"));
}
Also used : Ticket(alfio.model.Ticket) TicketAndCheckInResult(alfio.manager.support.TicketAndCheckInResult) ZonedDateTime(java.time.ZonedDateTime) Event(alfio.model.Event) DefaultCheckInResult(alfio.manager.support.DefaultCheckInResult)

Example 9 with Ticket

use of alfio.model.Ticket in project alf.io by alfio-event.

the class AttendeeManager method retrieveTicket.

public Result<Ticket> retrieveTicket(String eventShortName, String ticketUid, String username) {
    Optional<Event> maybeEvent = eventRepository.findOptionalByShortName(eventShortName).filter(e -> userManager.findUserOrganizations(username).stream().anyMatch(o -> o.getId() == e.getOrganizationId()));
    if (!maybeEvent.isPresent()) {
        return Result.error(ErrorCode.EventError.NOT_FOUND);
    }
    Event event = maybeEvent.get();
    Optional<Ticket> maybeTicket = ticketRepository.findOptionalByUUID(ticketUid).filter(t -> t.getEventId() == event.getId());
    return new Result.Builder<Ticket>().checkPrecondition(maybeTicket::isPresent, ErrorCode.custom("ticket_not_found", "ticket not found")).build(maybeTicket::get);
}
Also used : TicketRepository(alfio.repository.TicketRepository) ZonedDateTime(java.time.ZonedDateTime) DefaultCheckInResult(alfio.manager.support.DefaultCheckInResult) TicketAndCheckInResult(alfio.manager.support.TicketAndCheckInResult) EventRepository(alfio.repository.EventRepository) Collectors(java.util.stream.Collectors) Result(alfio.model.result.Result) Component(org.springframework.stereotype.Component) List(java.util.List) CheckInStatus(alfio.manager.support.CheckInStatus) ErrorCode(alfio.model.result.ErrorCode) Ticket(alfio.model.Ticket) UserRepository(alfio.repository.user.UserRepository) SponsorAttendeeData(alfio.manager.support.SponsorAttendeeData) UserManager(alfio.manager.user.UserManager) SponsorScanRepository(alfio.repository.SponsorScanRepository) EventUtil(alfio.util.EventUtil) Optional(java.util.Optional) Event(alfio.model.Event) AllArgsConstructor(lombok.AllArgsConstructor) Ticket(alfio.model.Ticket) Event(alfio.model.Event)

Example 10 with Ticket

use of alfio.model.Ticket in project alf.io by alfio-event.

the class TicketController method generateTicketPdf.

@RequestMapping(value = "/event/{eventName}/ticket/{ticketIdentifier}/download-ticket", method = RequestMethod.GET)
public void generateTicketPdf(@PathVariable("eventName") String eventName, @PathVariable("ticketIdentifier") String ticketIdentifier, HttpServletRequest request, HttpServletResponse response) throws IOException, WriterException {
    Optional<Triple<Event, TicketReservation, Ticket>> oData = ticketReservationManager.fetchCompleteAndAssigned(eventName, ticketIdentifier);
    if (!oData.isPresent()) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return;
    }
    Triple<Event, TicketReservation, Ticket> data = oData.get();
    Ticket ticket = data.getRight();
    response.setContentType("application/pdf");
    response.addHeader("Content-Disposition", "attachment; filename=ticket-" + ticketIdentifier + ".pdf");
    try (OutputStream os = response.getOutputStream()) {
        PdfBoxRenderer renderer = preparePdfTicket(request, data.getLeft(), data.getMiddle(), ticket).generate(ticket);
        if (renderer != null) {
            renderer.createPDF(os);
        }
    }
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) Ticket(alfio.model.Ticket) OutputStream(java.io.OutputStream) Event(alfio.model.Event) TicketReservation(alfio.model.TicketReservation) PdfBoxRenderer(com.openhtmltopdf.pdfboxout.PdfBoxRenderer)

Aggregations

Event (alfio.model.Event)24 Ticket (alfio.model.Ticket)24 Test (org.junit.Test)13 TicketCategory (alfio.model.TicketCategory)10 TicketReservation (alfio.model.TicketReservation)7 Organization (alfio.model.user.Organization)6 ZonedDateTime (java.time.ZonedDateTime)5 java.util (java.util)5 Triple (org.apache.commons.lang3.tuple.Triple)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 UserManager (alfio.manager.user.UserManager)4 ErrorCode (alfio.model.result.ErrorCode)4 Result (alfio.model.result.Result)4 TestConfiguration (alfio.TestConfiguration)3 DataSourceConfiguration (alfio.config.DataSourceConfiguration)3 Initializer (alfio.config.Initializer)3 RepositoryConfiguration (alfio.config.RepositoryConfiguration)3 TicketRepository (alfio.repository.TicketRepository)3 Collectors (java.util.stream.Collectors)3 Component (org.springframework.stereotype.Component)3