Search in sources :

Example 61 with Event

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

the class ConfigurationManager method saveCategoryConfiguration.

public void saveCategoryConfiguration(int categoryId, int eventId, List<ConfigurationModification> list, String username) {
    User user = userManager.findUserByUsername(username);
    Event event = eventRepository.findById(eventId);
    Validate.notNull(event, "event does not exist");
    Validate.isTrue(userManager.isOwnerOfOrganization(user, event.getOrganizationId()), "Cannot update settings, user is not owner of event");
    list.stream().filter(TO_BE_SAVED).forEach(c -> {
        Optional<Configuration> existing = configurationRepository.findByKeyAtCategoryLevel(eventId, event.getOrganizationId(), categoryId, c.getKey());
        Optional<String> value = evaluateValue(c.getKey(), c.getValue());
        if (!value.isPresent()) {
            configurationRepository.deleteCategoryLevelByKey(c.getKey(), eventId, categoryId);
        } else if (existing.isPresent()) {
            configurationRepository.updateCategoryLevel(eventId, event.getOrganizationId(), categoryId, c.getKey(), value.get());
        } else {
            configurationRepository.insertTicketCategoryLevel(event.getOrganizationId(), eventId, categoryId, c.getKey(), value.get(), ConfigurationKeys.fromString(c.getKey()).getDescription());
        }
    });
}
Also used : User(alfio.model.user.User) Configuration(alfio.model.system.Configuration) Event(alfio.model.Event)

Example 62 with Event

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

the class EventManagerIntegrationTest method testIncreaseRestrictedCategory.

@Test
public void testIncreaseRestrictedCategory() {
    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, 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());
    TicketCategoryModification tcm = new TicketCategoryModification(category.getId(), category.getName(), 11, DateTimeModification.fromZonedDateTime(category.getUtcInception()), DateTimeModification.fromZonedDateTime(category.getUtcExpiration()), categoryDescription, category.getPrice(), true, "", true, null, null, null, null, null);
    Result<TicketCategory> result = eventManager.updateCategory(category.getId(), event, tcm, username);
    assertTrue(result.isSuccess());
    assertEquals(11, ticketRepository.countFreeTickets(event.getId(), category.getId()).intValue());
}
Also used : Event(alfio.model.Event) TicketCategory(alfio.model.TicketCategory) Test(org.junit.Test)

Example 63 with Event

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

the class EventManagerIntegrationTest method testNewRestrictedCategory.

@Test
public void testNewRestrictedCategory() {
    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, true, "", true, null, null, null, null, null);
    Result<Integer> result = eventManager.insertCategory(event, tcm, username);
    assertTrue(result.isSuccess());
    assertEquals(20, ticketRepository.countFreeTickets(event.getId(), result.getData()).intValue());
}
Also used : Event(alfio.model.Event) Test(org.junit.Test)

Example 64 with Event

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

the class EventManagerIntegrationTest method testUpdateEventHeader.

@Test
public void testUpdateEventHeader() {
    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.getLeft();
    String username = pair.getRight();
    Map<String, String> desc = new HashMap<>();
    desc.put("en", "muh description new");
    desc.put("it", "muh description new");
    desc.put("de", "muh description new");
    EventModification em = new EventModification(event.getId(), Event.EventType.INTERNAL, "http://example.com/new", null, "http://example.com/tc", "https://example.com/img.png", null, event.getShortName(), "new display name", event.getOrganizationId(), event.getLocation(), "0.0", "0.0", ZoneId.systemDefault().getId(), desc, DateTimeModification.fromZonedDateTime(event.getBegin()), DateTimeModification.fromZonedDateTime(event.getEnd().plusDays(42)), event.getRegularPrice(), event.getCurrency(), eventRepository.countExistingTickets(event.getId()), event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(), Collections.emptyList(), false, null, 7, null, null);
    eventManager.updateEventHeader(event, em, username);
    Event updatedEvent = eventRepository.findById(event.getId());
    Assert.assertEquals("http://example.com/new", updatedEvent.getWebsiteUrl());
    Assert.assertEquals("http://example.com/tc", updatedEvent.getTermsAndConditionsUrl());
    Assert.assertEquals("https://example.com/img.png", updatedEvent.getImageUrl());
    Assert.assertEquals("new display name", updatedEvent.getDisplayName());
}
Also used : Event(alfio.model.Event) Test(org.junit.Test)

Example 65 with Event

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

the class EventManagerIntegrationTest method testAddUnboundedCategory.

/**
 * When adding an unbounded category, we won't update the tickets status, because:
 * 1) if the unbounded category is using existing seats, the event cannot be already sold-out
 * 2) if the unbounded category has been added after an event edit (add seats), then the tickets are already "RELEASED"
 * 3) if there is another unbounded category, then it is safe not to update the tickets' status, in order to not
 *    interfere with the existing category
 */
@Test
public void testAddUnboundedCategory() {
    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();
    TicketCategoryModification tcm = new TicketCategoryModification(null, "default", -1, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null);
    eventManager.insertCategory(event.getId(), tcm, pair.getValue());
    List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
    assertNotNull(tickets);
    assertFalse(tickets.isEmpty());
    assertEquals(AVAILABLE_SEATS, tickets.size());
    assertEquals(10, tickets.stream().filter(t -> t.getCategoryId() == null).count());
}
Also used : Ticket(alfio.model.Ticket) Event(alfio.model.Event) Test(org.junit.Test)

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