Search in sources :

Example 1 with Ticket

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

the class TicketController method generateTicketCode.

@RequestMapping(value = "/event/{eventName}/ticket/{ticketIdentifier}/code.png", method = RequestMethod.GET)
public void generateTicketCode(@PathVariable("eventName") String eventName, @PathVariable("ticketIdentifier") String ticketIdentifier, 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();
    Event event = data.getLeft();
    Ticket ticket = data.getRight();
    String qrCodeText = ticket.ticketCode(event.getPrivateKey());
    response.setContentType("image/png");
    response.getOutputStream().write(ImageUtil.createQRCode(qrCodeText));
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) Ticket(alfio.model.Ticket) Event(alfio.model.Event) TicketReservation(alfio.model.TicketReservation)

Example 2 with Ticket

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

the class TicketController method internalSendTicketByEmail.

private Ticket internalSendTicketByEmail(HttpServletRequest request, Triple<Event, TicketReservation, Ticket> data) throws IOException {
    Ticket ticket = data.getRight();
    Event event = data.getLeft();
    Locale locale = LocaleUtil.getTicketLanguage(ticket, request);
    TicketReservation reservation = data.getMiddle();
    Organization organization = organizationRepository.getById(event.getOrganizationId());
    TicketCategory category = ticketCategoryRepository.getById(ticket.getCategoryId());
    notificationManager.sendTicketByEmail(ticket, event, locale, TemplateProcessor.buildPartialEmail(event, organization, reservation, category, templateManager, ticketReservationManager.ticketUpdateUrl(event, ticket.getUuid()), request), reservation, ticketCategoryRepository.getByIdAndActive(ticket.getCategoryId(), event.getId()));
    return ticket;
}
Also used : Locale(java.util.Locale) Ticket(alfio.model.Ticket) Organization(alfio.model.user.Organization) Event(alfio.model.Event) TicketCategory(alfio.model.TicketCategory) TicketReservation(alfio.model.TicketReservation)

Example 3 with Ticket

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

the class EventManagerIntegrationTest method testDecreaseEventSeatsWithABoundedCategory.

@Test
public void testDecreaseEventSeatsWithABoundedCategory() {
    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, "", true, null, null, null, null, null));
    Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
    Event event = pair.getKey();
    EventModification update = new EventModification(event.getId(), Event.EventType.INTERNAL, null, null, null, null, null, null, null, event.getOrganizationId(), null, "0.0", "0.0", ZoneId.systemDefault().getId(), null, DateTimeModification.fromZonedDateTime(event.getBegin()), DateTimeModification.fromZonedDateTime(event.getEnd()), event.getRegularPrice(), event.getCurrency(), 10, event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(), null, event.isFreeOfCharge(), null, 7, null, null);
    eventManager.updateEventPrices(event, update, pair.getValue());
    List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
    assertNotNull(tickets);
    assertFalse(tickets.isEmpty());
    assertEquals(10, 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 4 with Ticket

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

the class EventManagerIntegrationTest method testIncreaseEventSeatsWithAnUnboundedCategory.

@Test
public void testIncreaseEventSeatsWithAnUnboundedCategory() {
    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();
    EventModification update = new EventModification(event.getId(), Event.EventType.INTERNAL, null, null, null, null, null, null, null, event.getOrganizationId(), null, "0.0", "0.0", ZoneId.systemDefault().getId(), null, DateTimeModification.fromZonedDateTime(event.getBegin()), DateTimeModification.fromZonedDateTime(event.getEnd()), event.getRegularPrice(), event.getCurrency(), 40, event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(), null, event.isFreeOfCharge(), null, 7, null, null);
    eventManager.updateEventPrices(event, update, pair.getValue());
    List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
    assertNotNull(tickets);
    assertFalse(tickets.isEmpty());
    assertEquals(20, tickets.size());
    assertEquals(20, ticketRepository.countReleasedUnboundedTickets(event.getId()).intValue());
    waitingQueueSubscriptionProcessor.distributeAvailableSeats(event);
    tickets = ticketRepository.findFreeByEventId(event.getId());
    assertEquals(40, tickets.size());
    assertEquals(40, tickets.stream().filter(t -> t.getCategoryId() == null).count());
}
Also used : Ticket(alfio.model.Ticket) Event(alfio.model.Event) Test(org.junit.Test)

Example 5 with Ticket

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

the class PassBookManager method getPassBook.

byte[] getPassBook(Map<String, String> model) {
    try {
        Ticket ticket = Json.fromJson(model.get("ticket"), Ticket.class);
        int eventId = ticket.getEventId();
        Event event = eventRepository.findById(eventId);
        Organization organization = organizationRepository.getById(Integer.valueOf(model.get("organizationId"), 10));
        int organizationId = organization.getId();
        Function<ConfigurationKeys, Configuration.ConfigurationPathKey> partial = Configuration.from(organizationId, eventId);
        Map<ConfigurationKeys, Optional<String>> pbookConf = configurationManager.getStringConfigValueFrom(partial.apply(ConfigurationKeys.PASSBOOK_TYPE_IDENTIFIER), partial.apply(ConfigurationKeys.PASSBOOK_KEYSTORE), partial.apply(ConfigurationKeys.PASSBOOK_KEYSTORE_PASSWORD), partial.apply(ConfigurationKeys.PASSBOOK_TEAM_IDENTIFIER));
        // check if all are set
        if (pbookConf.values().stream().anyMatch(o -> !o.isPresent())) {
            log.trace("Cannot generate Passbook. Missing configuration keys, check if all 4 are presents");
            return null;
        }
        // 
        String teamIdentifier = pbookConf.get(ConfigurationKeys.PASSBOOK_TEAM_IDENTIFIER).orElseThrow(IllegalStateException::new);
        String typeIdentifier = pbookConf.get(ConfigurationKeys.PASSBOOK_TYPE_IDENTIFIER).orElseThrow(IllegalStateException::new);
        byte[] keystoreRaw = Base64.getDecoder().decode(pbookConf.get(ConfigurationKeys.PASSBOOK_KEYSTORE).orElseThrow(IllegalStateException::new));
        String keystorePwd = pbookConf.get(ConfigurationKeys.PASSBOOK_KEYSTORE_PASSWORD).orElseThrow(IllegalStateException::new);
        // ugly, find an alternative way?
        Optional<KeyStore> ksJks = loadKeyStore(keystoreRaw);
        if (ksJks.isPresent()) {
            return buildPass(ticket, event, organization, teamIdentifier, typeIdentifier, keystorePwd, ksJks.get());
        } else {
            log.warn("Cannot generate Passbook. Not able to load keystore. Please check configuration.");
            return null;
        }
    } catch (Exception ex) {
        log.warn("Got Exception while generating Passbook. Please check configuration.", ex);
        return null;
    }
}
Also used : Ticket(alfio.model.Ticket) ConfigurationKeys(alfio.model.system.ConfigurationKeys) Organization(alfio.model.user.Organization) KeyStore(java.security.KeyStore) PassSigningException(com.ryantenney.passkit4j.sign.PassSigningException) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) Event(alfio.model.Event)

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