Search in sources :

Example 1 with EventModification

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

the class ConfigurationManagerIntegrationTest method prepareEnv.

@Before
public void prepareEnv() {
    // setup...
    organizationRepository.create("org", "org", "email@example.com");
    Organization organization = organizationRepository.findByName("org").get();
    userManager.insertUser(organization.getId(), USERNAME, "test", "test", "test@example.com", Role.OWNER, User.Type.INTERNAL);
    Map<String, String> desc = new HashMap<>();
    desc.put("en", "muh description");
    desc.put("it", "muh description");
    desc.put("de", "muh description");
    List<TicketCategoryModification> ticketsCategory = Collections.singletonList(new TicketCategoryModification(null, "default", 20, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), Collections.singletonMap("en", "desc"), BigDecimal.TEN, false, "", false, null, null, null, null, null));
    EventModification em = new EventModification(null, Event.EventType.INTERNAL, "url", "url", "url", null, null, "eventShortName", "displayName", organization.getId(), "muh location", "0.0", "0.0", ZoneId.systemDefault().getId(), desc, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), BigDecimal.TEN, "CHF", 20, BigDecimal.ONE, true, null, ticketsCategory, false, new LocationDescriptor("", "", "", ""), 7, null, null);
    eventManager.createEvent(em);
    event = eventManager.getSingleEvent("eventShortName", "test");
    ticketCategory = ticketCategoryRepository.findAllTicketCategories(event.getId()).get(0);
}
Also used : Organization(alfio.model.user.Organization) DateTimeModification(alfio.model.modification.DateTimeModification) LocationDescriptor(alfio.model.modification.support.LocationDescriptor) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) EventModification(alfio.model.modification.EventModification) Before(org.junit.Before)

Example 2 with EventModification

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

the class WaitingQueueProcessorIntegrationTest method testAddSeatsAfterSoldOutWithoutUnbounded.

@Test
public void testAddSeatsAfterSoldOutWithoutUnbounded() throws InterruptedException {
    Pair<String, Event> pair = initSoldOutEvent(false);
    Event event = pair.getRight();
    EventModification eventModification = new EventModification(event.getId(), event.getType(), event.getWebsiteUrl(), event.getExternalUrl(), event.getTermsAndConditionsUrl(), event.getImageUrl(), event.getFileBlobId(), event.getShortName(), event.getDisplayName(), event.getOrganizationId(), event.getLocation(), event.getLatitude(), event.getLongitude(), event.getZoneId().getId(), emptyMap(), fromZonedDateTime(event.getBegin()), fromZonedDateTime(event.getEnd()), event.getRegularPrice(), event.getCurrency(), eventRepository.countExistingTickets(event.getId()) + 1, event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(), Collections.emptyList(), event.isFreeOfCharge(), null, event.getLocales(), Collections.emptyList(), Collections.emptyList());
    eventManager.updateEventPrices(event, eventModification, "admin");
    // that should create an additional "RELEASED" ticket, but it won't be linked to any category, so the following call won't have any effect
    waitingQueueSubscriptionProcessor.distributeAvailableSeats(event);
    List<WaitingQueueSubscription> subscriptions = waitingQueueRepository.loadAll(event.getId());
    assertEquals(0, subscriptions.stream().filter(w -> StringUtils.isNotBlank(w.getReservationId())).count());
    // explicitly expand the category
    TicketCategory category = eventManager.loadTicketCategories(event).get(0);
    eventManager.updateCategory(category.getId(), event.getId(), new TicketCategoryModification(category.getId(), category.getName(), category.getMaxTickets() + 1, fromZonedDateTime(category.getInception(event.getZoneId())), fromZonedDateTime(category.getExpiration(event.getZoneId())), emptyMap(), category.getPrice(), category.isAccessRestricted(), "", category.isBounded(), null, null, null, null, null), "admin");
    // now the waiting queue processor should create the reservation for the first in line
    waitingQueueSubscriptionProcessor.distributeAvailableSeats(event);
    subscriptions = waitingQueueRepository.loadAll(event.getId());
    assertEquals(1, subscriptions.stream().filter(w -> StringUtils.isNotBlank(w.getReservationId())).count());
    Optional<WaitingQueueSubscription> first = subscriptions.stream().filter(w -> w.getStatus().equals(WaitingQueueSubscription.Status.PENDING)).findFirst();
    assertTrue(first.isPresent());
    assertEquals("Giuseppe Garibaldi", first.get().getFullName());
}
Also used : java.util(java.util) BeforeClass(org.junit.BeforeClass) WaitingQueueRepository(alfio.repository.WaitingQueueRepository) TicketReservationRepository(alfio.repository.TicketReservationRepository) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) ConfigurationManager(alfio.manager.system.ConfigurationManager) EventModification(alfio.model.modification.EventModification) StringUtils(org.apache.commons.lang3.StringUtils) DateTimeModification(alfio.model.modification.DateTimeModification) RepositoryConfiguration(alfio.config.RepositoryConfiguration) BigDecimal(java.math.BigDecimal) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) Pair(org.apache.commons.lang3.tuple.Pair) LocalTime(java.time.LocalTime) AuthorityRepository(alfio.repository.user.AuthorityRepository) Before(org.junit.Before) DateTimeModification.fromZonedDateTime(alfio.model.modification.DateTimeModification.fromZonedDateTime) Collections.emptyMap(java.util.Collections.emptyMap) OrganizationRepository(alfio.repository.user.OrganizationRepository) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) TicketRepository(alfio.repository.TicketRepository) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) EventRepository(alfio.repository.EventRepository) IntegrationTestUtil(alfio.test.util.IntegrationTestUtil) ConfigurationRepository(alfio.repository.system.ConfigurationRepository) DateUtils(org.apache.commons.lang3.time.DateUtils) Initializer(alfio.config.Initializer) alfio.model(alfio.model) UserRepository(alfio.repository.user.UserRepository) UserManager(alfio.manager.user.UserManager) ContextConfiguration(org.springframework.test.context.ContextConfiguration) LocalDate(java.time.LocalDate) DataSourceConfiguration(alfio.config.DataSourceConfiguration) TestConfiguration(alfio.TestConfiguration) ConfigurationKeys(alfio.model.system.ConfigurationKeys) Assert.assertEquals(org.junit.Assert.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) EventModification(alfio.model.modification.EventModification) Test(org.junit.Test)

Example 3 with EventModification

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

the class WaitingQueueProcessorIntegrationTest method testAddSeatsAfterSoldOut.

@Test
public void testAddSeatsAfterSoldOut() throws InterruptedException {
    Pair<String, Event> pair = initSoldOutEvent(true);
    Event event = pair.getRight();
    EventModification eventModification = new EventModification(event.getId(), event.getType(), event.getWebsiteUrl(), event.getExternalUrl(), event.getTermsAndConditionsUrl(), event.getImageUrl(), event.getFileBlobId(), event.getShortName(), event.getDisplayName(), event.getOrganizationId(), event.getLocation(), event.getLatitude(), event.getLongitude(), event.getZoneId().getId(), emptyMap(), fromZonedDateTime(event.getBegin()), fromZonedDateTime(event.getEnd()), event.getRegularPrice(), event.getCurrency(), eventRepository.countExistingTickets(event.getId()) + 1, event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(), Collections.emptyList(), event.isFreeOfCharge(), null, event.getLocales(), Collections.emptyList(), Collections.emptyList());
    eventManager.updateEventPrices(event, eventModification, "admin");
    // that should create an additional "RELEASED" ticket
    waitingQueueSubscriptionProcessor.distributeAvailableSeats(event);
    List<WaitingQueueSubscription> subscriptions = waitingQueueRepository.loadAll(event.getId());
    assertEquals(1, subscriptions.stream().filter(w -> StringUtils.isNotBlank(w.getReservationId())).count());
    Optional<WaitingQueueSubscription> first = subscriptions.stream().filter(w -> w.getStatus().equals(WaitingQueueSubscription.Status.PENDING)).findFirst();
    assertTrue(first.isPresent());
    assertEquals("Giuseppe Garibaldi", first.get().getFullName());
}
Also used : java.util(java.util) BeforeClass(org.junit.BeforeClass) WaitingQueueRepository(alfio.repository.WaitingQueueRepository) TicketReservationRepository(alfio.repository.TicketReservationRepository) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) ConfigurationManager(alfio.manager.system.ConfigurationManager) EventModification(alfio.model.modification.EventModification) StringUtils(org.apache.commons.lang3.StringUtils) DateTimeModification(alfio.model.modification.DateTimeModification) RepositoryConfiguration(alfio.config.RepositoryConfiguration) BigDecimal(java.math.BigDecimal) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) Pair(org.apache.commons.lang3.tuple.Pair) LocalTime(java.time.LocalTime) AuthorityRepository(alfio.repository.user.AuthorityRepository) Before(org.junit.Before) DateTimeModification.fromZonedDateTime(alfio.model.modification.DateTimeModification.fromZonedDateTime) Collections.emptyMap(java.util.Collections.emptyMap) OrganizationRepository(alfio.repository.user.OrganizationRepository) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) TicketRepository(alfio.repository.TicketRepository) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) EventRepository(alfio.repository.EventRepository) IntegrationTestUtil(alfio.test.util.IntegrationTestUtil) ConfigurationRepository(alfio.repository.system.ConfigurationRepository) DateUtils(org.apache.commons.lang3.time.DateUtils) Initializer(alfio.config.Initializer) alfio.model(alfio.model) UserRepository(alfio.repository.user.UserRepository) UserManager(alfio.manager.user.UserManager) ContextConfiguration(org.springframework.test.context.ContextConfiguration) LocalDate(java.time.LocalDate) DataSourceConfiguration(alfio.config.DataSourceConfiguration) TestConfiguration(alfio.TestConfiguration) ConfigurationKeys(alfio.model.system.ConfigurationKeys) Assert.assertEquals(org.junit.Assert.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) EventModification(alfio.model.modification.EventModification) Test(org.junit.Test)

Example 4 with EventModification

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

the class IntegrationTestUtil method initEvent.

public static Pair<Event, String> initEvent(List<TicketCategoryModification> categories, OrganizationRepository organizationRepository, UserManager userManager, EventManager eventManager, EventRepository eventRepository, List<EventModification.AdditionalService> additionalServices) {
    String organizationName = UUID.randomUUID().toString();
    String username = UUID.randomUUID().toString();
    String eventName = UUID.randomUUID().toString();
    userManager.createOrganization(organizationName, "org", "email@example.com");
    Organization organization = organizationRepository.findByName(organizationName).get();
    userManager.insertUser(organization.getId(), username, "test", "test", "test@example.com", Role.OPERATOR, User.Type.INTERNAL);
    userManager.insertUser(organization.getId(), username + "_owner", "test", "test", "test@example.com", Role.OWNER, User.Type.INTERNAL);
    LocalDateTime expiration = LocalDateTime.now().plusDays(5).plusHours(1);
    Map<String, String> desc = new HashMap<>();
    desc.put("en", "muh description");
    desc.put("it", "muh description");
    desc.put("de", "muh description");
    EventModification em = new EventModification(null, Event.EventType.INTERNAL, "url", "url", "url", "url", null, eventName, "event display name", organization.getId(), "muh location", "0.0", "0.0", ZoneId.systemDefault().getId(), desc, new DateTimeModification(LocalDate.now().plusDays(5), LocalTime.now()), new DateTimeModification(expiration.toLocalDate(), expiration.toLocalTime()), BigDecimal.TEN, "CHF", AVAILABLE_SEATS, BigDecimal.ONE, true, Collections.singletonList(PaymentProxy.OFFLINE), categories, false, new LocationDescriptor("", "", "", ""), 7, null, additionalServices);
    eventManager.createEvent(em);
    Event event = eventManager.getSingleEvent(eventName, username);
    Assert.assertEquals(AVAILABLE_SEATS, eventRepository.countExistingTickets(event.getId()).intValue());
    return Pair.of(event, username);
}
Also used : LocalDateTime(java.time.LocalDateTime) Organization(alfio.model.user.Organization) DateTimeModification(alfio.model.modification.DateTimeModification) LocationDescriptor(alfio.model.modification.support.LocationDescriptor) EventModification(alfio.model.modification.EventModification) Event(alfio.model.Event)

Example 5 with EventModification

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

the class Validator method validateAdditionalService.

public static ValidationResult validateAdditionalService(EventModification.AdditionalService additionalService, EventModification eventModification, Errors errors) {
    if (additionalService.isFixPrice() && !Optional.ofNullable(additionalService.getPrice()).filter(p -> p.compareTo(BigDecimal.ZERO) >= 0).isPresent()) {
        errors.rejectValue("additionalServices", "error.price");
    }
    List<EventModification.AdditionalServiceText> descriptions = additionalService.getDescription();
    List<EventModification.AdditionalServiceText> titles = additionalService.getTitle();
    if (descriptions == null || titles == null || titles.size() != descriptions.size()) {
        errors.rejectValue("additionalServices", "error.title");
        errors.rejectValue("additionalServices", "error.description");
    } else {
        if (!validateDescriptionList(titles) || !containsAllRequiredTranslations(eventModification, titles)) {
            errors.rejectValue("additionalServices", "error.title");
        }
        if (!validateDescriptionList(descriptions) || !containsAllRequiredTranslations(eventModification, descriptions)) {
            errors.rejectValue("additionalServices", "error.description");
        }
    }
    DateTimeModification inception = additionalService.getInception();
    DateTimeModification expiration = additionalService.getExpiration();
    if (inception == null || expiration == null || expiration.isBefore(inception)) {
        errors.rejectValue("additionalServices", "error.inception");
        errors.rejectValue("additionalServices", "error.expiration");
    } else if (eventModification != null && expiration.isAfter(eventModification.getEnd())) {
        errors.rejectValue("additionalServices", "error.expiration");
    }
    return evaluateValidationResult(errors);
}
Also used : ValidationResult(alfio.model.result.ValidationResult) Errors(org.springframework.validation.Errors) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) WaitingQueueSubscriptionForm(alfio.controller.form.WaitingQueueSubscriptionForm) Collection(java.util.Collection) UpdateTicketOwnerForm(alfio.controller.form.UpdateTicketOwnerForm) ContentLanguage(alfio.model.ContentLanguage) EventModification(alfio.model.modification.EventModification) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) DateTimeModification(alfio.model.modification.DateTimeModification) BigDecimal(java.math.BigDecimal) List(java.util.List) ErrorCode(alfio.model.result.ErrorCode) ValidationUtils(org.springframework.validation.ValidationUtils) CollectionUtils(org.apache.commons.collections.CollectionUtils) TicketFieldConfiguration(alfio.model.TicketFieldConfiguration) Optional(java.util.Optional) Event(alfio.model.Event) Pattern(java.util.regex.Pattern) DateTimeModification(alfio.model.modification.DateTimeModification)

Aggregations

DateTimeModification (alfio.model.modification.DateTimeModification)5 EventModification (alfio.model.modification.EventModification)5 TicketCategoryModification (alfio.model.modification.TicketCategoryModification)4 BigDecimal (java.math.BigDecimal)3 StringUtils (org.apache.commons.lang3.StringUtils)3 Before (org.junit.Before)3 TestConfiguration (alfio.TestConfiguration)2 DataSourceConfiguration (alfio.config.DataSourceConfiguration)2 Initializer (alfio.config.Initializer)2 RepositoryConfiguration (alfio.config.RepositoryConfiguration)2 ConfigurationManager (alfio.manager.system.ConfigurationManager)2 UserManager (alfio.manager.user.UserManager)2 alfio.model (alfio.model)2 DateTimeModification.fromZonedDateTime (alfio.model.modification.DateTimeModification.fromZonedDateTime)2 LocationDescriptor (alfio.model.modification.support.LocationDescriptor)2 ConfigurationKeys (alfio.model.system.ConfigurationKeys)2 Organization (alfio.model.user.Organization)2 EventRepository (alfio.repository.EventRepository)2 TicketRepository (alfio.repository.TicketRepository)2 TicketReservationRepository (alfio.repository.TicketReservationRepository)2