Search in sources :

Example 11 with Event

use of alfio.model.Event 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 12 with Event

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

the class EventManagerIntegrationTest method testDecreaseRestrictedCategoryWithAlreadySentToken.

// https://github.com/exteso/alf.io/issues/335
@Test
public void testDecreaseRestrictedCategoryWithAlreadySentToken() {
    ensureMinimalConfiguration(configurationRepository);
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", 4, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, true, "", true, null, null, null, null, null));
    Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
    Event event = pair.getLeft();
    String username = pair.getRight();
    TicketCategory category = ticketCategoryRepository.findByEventId(event.getId()).get(0);
    Map<String, String> categoryDescription = ticketCategoryDescriptionRepository.descriptionForTicketCategory(category.getId());
    specialPriceTokenGenerator.generatePendingCodesForCategory(category.getId());
    List<SendCodeModification> linked = specialPriceManager.linkAssigneeToCode(Arrays.asList(new SendCodeModification(null, "test1", "test@test.com", "it"), new SendCodeModification(null, "test2", "test@test.com", "it")), event.getShortName(), category.getId(), username);
    specialPriceManager.sendCodeToAssignee(linked, event.getShortName(), category.getId(), username);
    TicketCategoryModification tcmOk = new TicketCategoryModification(category.getId(), category.getName(), 2, DateTimeModification.fromZonedDateTime(category.getUtcInception()), DateTimeModification.fromZonedDateTime(category.getUtcExpiration()), categoryDescription, category.getPrice(), true, "", true, null, null, null, null, null);
    Result<TicketCategory> resOk = eventManager.updateCategory(category.getId(), event, tcmOk, username);
    Assert.assertTrue(resOk.isSuccess());
    TicketCategoryModification tcm = new TicketCategoryModification(category.getId(), category.getName(), 1, DateTimeModification.fromZonedDateTime(category.getUtcInception()), DateTimeModification.fromZonedDateTime(category.getUtcExpiration()), categoryDescription, category.getPrice(), true, "", true, null, null, null, null, null);
    Result<TicketCategory> res = eventManager.updateCategory(category.getId(), event, tcm, username);
    Assert.assertFalse(res.isSuccess());
    Assert.assertTrue(res.getErrors().contains(ErrorCode.CategoryError.NOT_ENOUGH_FREE_TOKEN_FOR_SHRINK));
}
Also used : Event(alfio.model.Event) TicketCategory(alfio.model.TicketCategory) Test(org.junit.Test)

Example 13 with Event

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

the class EventManagerIntegrationTest method testNewCategoryBoundedAddReleasedTickets.

@Test
public void testNewCategoryBoundedAddReleasedTickets() {
    Pair<Event, String> eventAndUser = generateAndEditEvent(AVAILABLE_SEATS + 10);
    // now we have 20 free seats, 10 of which RELEASED
    Event event = eventAndUser.getLeft();
    String username = eventAndUser.getRight();
    TicketCategoryModification tcm = new TicketCategoryModification(null, "additional", 20, DateTimeModification.fromZonedDateTime(ZonedDateTime.now(event.getZoneId()).minusMinutes(1)), DateTimeModification.fromZonedDateTime(ZonedDateTime.now(event.getZoneId()).plusDays(5)), Collections.emptyMap(), BigDecimal.TEN, false, "", true, null, null, null, null, null);
    Result<Integer> result = eventManager.insertCategory(event, tcm, username);
    assertTrue(result.isSuccess());
    assertEquals(20, ticketRepository.countReleasedTicketInCategory(event.getId(), result.getData()).intValue());
}
Also used : Event(alfio.model.Event) Test(org.junit.Test)

Example 14 with Event

use of alfio.model.Event 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 15 with Event

use of alfio.model.Event 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)71 Test (org.junit.Test)28 Ticket (alfio.model.Ticket)24 TicketCategory (alfio.model.TicketCategory)21 Organization (alfio.model.user.Organization)13 java.util (java.util)11 ZonedDateTime (java.time.ZonedDateTime)10 Autowired (org.springframework.beans.factory.annotation.Autowired)10 BigDecimal (java.math.BigDecimal)9 TicketReservation (alfio.model.TicketReservation)7 ConfigurationKeys (alfio.model.system.ConfigurationKeys)7 Collectors (java.util.stream.Collectors)7 Log4j2 (lombok.extern.log4j.Log4j2)7 StringUtils (org.apache.commons.lang3.StringUtils)7 ConfigurationManager (alfio.manager.system.ConfigurationManager)6 Configuration (alfio.model.system.Configuration)5 TicketRepository (alfio.repository.TicketRepository)5 Pair (org.apache.commons.lang3.tuple.Pair)5 Triple (org.apache.commons.lang3.tuple.Triple)5 UserManager (alfio.manager.user.UserManager)4