Search in sources :

Example 1 with EventMigration

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

the class DataMigrator method migrateEventToCurrentVersion.

private void migrateEventToCurrentVersion(Event event) {
    Optional<EventMigration> optional = optionally(() -> eventMigrationRepository.loadEventMigration(event.getId()));
    boolean alreadyDefined = optional.isPresent();
    if (!alreadyDefined || optional.filter(this::needsFixing).isPresent()) {
        transactionTemplate.execute(s -> {
            // optional.ifPresent(eventMigration -> eventMigrationRepository.lockEventMigrationForUpdate(eventMigration.getId()));
            if (ZonedDateTime.now(event.getZoneId()).isBefore(event.getEnd())) {
                fixAvailableSeats(event);
                fillDescriptions(event);
                fixCategoriesSize(event);
            }
            // migrate prices to new structure. This should be done for all events, regardless of the expiration date.
            migratePrices(event.getId());
            fixStuckTickets(event.getId());
            if (alreadyDefined) {
                EventMigration eventMigration = optional.get();
                int result = eventMigrationRepository.updateMigrationData(eventMigration.getId(), currentVersionAsString, buildTimestamp, EventMigration.Status.COMPLETE.name());
                Validate.isTrue(result == 1, "error during update " + result);
            } else {
                eventMigrationRepository.insertMigrationData(event.getId(), currentVersionAsString, buildTimestamp, EventMigration.Status.COMPLETE.name());
            }
            return null;
        });
    }
}
Also used : EventMigration(alfio.model.system.EventMigration)

Example 2 with EventMigration

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

the class DataMigratorIntegrationTest method testMigrationWithExistingRecord.

@Test
public void testMigrationWithExistingRecord() {
    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));
    Pair<Event, String> eventUsername = initEvent(categories);
    Event event = eventUsername.getKey();
    try {
        eventMigrationRepository.insertMigrationData(event.getId(), "1.4", ZonedDateTime.now(ZoneId.of("UTC")).minusDays(1), EventMigration.Status.COMPLETE.toString());
        eventRepository.updatePrices("CHF", 40, false, BigDecimal.ONE, "STRIPE", event.getId(), PriceContainer.VatStatus.NOT_INCLUDED, 1000);
        dataMigrator.migrateEventsToCurrentVersion();
        EventMigration eventMigration = eventMigrationRepository.loadEventMigration(event.getId());
        assertNotNull(eventMigration);
        // assertEquals(buildTimestamp, eventMigration.getBuildTimestamp().toString());
        assertEquals(currentVersion, eventMigration.getCurrentVersion());
        List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
        assertNotNull(tickets);
        assertFalse(tickets.isEmpty());
        assertEquals(20, tickets.size());
        assertTrue(tickets.stream().allMatch(t -> t.getCategoryId() == null));
    } finally {
        eventManager.deleteEvent(event.getId(), eventUsername.getValue());
    }
}
Also used : java.util(java.util) TicketCategoryRepository(alfio.repository.TicketCategoryRepository) PaymentProxy(alfio.model.transaction.PaymentProxy) BeforeClass(org.junit.BeforeClass) TemplateProcessor(alfio.controller.support.TemplateProcessor) TicketReservationRepository(alfio.repository.TicketReservationRepository) ZonedDateTime(java.time.ZonedDateTime) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) EventMigration(alfio.model.system.EventMigration) Value(org.springframework.beans.factory.annotation.Value) RepositoryConfiguration(alfio.config.RepositoryConfiguration) BigDecimal(java.math.BigDecimal) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) LocationDescriptor(alfio.model.modification.support.LocationDescriptor) Pair(org.apache.commons.lang3.tuple.Pair) LocalTime(java.time.LocalTime) EventMigrationRepository(alfio.repository.system.EventMigrationRepository) OrganizationRepository(alfio.repository.user.OrganizationRepository) TicketRepository(alfio.repository.TicketRepository) Organization(alfio.model.user.Organization) TemplateManager(alfio.util.TemplateManager) UpdateTicketOwnerForm(alfio.controller.form.UpdateTicketOwnerForm) User(alfio.model.user.User) Test(org.junit.Test) EventRepository(alfio.repository.EventRepository) IntegrationTestUtil(alfio.test.util.IntegrationTestUtil) ZoneId(java.time.ZoneId) DateUtils(org.apache.commons.lang3.time.DateUtils) TicketReservationManager(alfio.manager.TicketReservationManager) Role(alfio.model.user.Role) Initializer(alfio.config.Initializer) EventManager(alfio.manager.EventManager) PartialTicketPDFGenerator(alfio.manager.support.PartialTicketPDFGenerator) alfio.model(alfio.model) UserManager(alfio.manager.user.UserManager) ContextConfiguration(org.springframework.test.context.ContextConfiguration) LocalDate(java.time.LocalDate) DataSourceConfiguration(alfio.config.DataSourceConfiguration) FileUploadManager(alfio.manager.FileUploadManager) TestConfiguration(alfio.TestConfiguration) Assert(org.junit.Assert) alfio.model.modification(alfio.model.modification) EventMigration(alfio.model.system.EventMigration) Test(org.junit.Test)

Example 3 with EventMigration

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

the class DataMigratorIntegrationTest method testUpdateDisplayName.

@Test
public void testUpdateDisplayName() {
    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));
    Pair<Event, String> eventUsername = initEvent(categories, null);
    Event event = eventUsername.getKey();
    try {
        dataMigrator.migrateEventsToCurrentVersion();
        EventMigration eventMigration = eventMigrationRepository.loadEventMigration(event.getId());
        assertNotNull(eventMigration);
        // assertEquals(buildTimestamp, eventMigration.getBuildTimestamp().toString());
        assertEquals(currentVersion, eventMigration.getCurrentVersion());
        Event withDescription = eventRepository.findById(event.getId());
        assertNotNull(withDescription.getDisplayName());
        assertEquals(event.getShortName(), withDescription.getShortName());
        assertEquals(event.getShortName(), withDescription.getDisplayName());
    } finally {
        eventManager.deleteEvent(event.getId(), eventUsername.getValue());
    }
}
Also used : EventMigration(alfio.model.system.EventMigration) Test(org.junit.Test)

Example 4 with EventMigration

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

the class DataMigratorIntegrationTest method testAlreadyMigratedEvent.

@Test
public void testAlreadyMigratedEvent() {
    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));
    Pair<Event, String> eventUsername = initEvent(categories);
    Event event = eventUsername.getKey();
    try {
        ZonedDateTime migrationTs = ZonedDateTime.now(ZoneId.of("UTC"));
        eventMigrationRepository.insertMigrationData(event.getId(), currentVersion, migrationTs, EventMigration.Status.COMPLETE.toString());
        eventRepository.updatePrices("CHF", 40, false, BigDecimal.ONE, "STRIPE", event.getId(), PriceContainer.VatStatus.NOT_INCLUDED, 1000);
        dataMigrator.migrateEventsToCurrentVersion();
        EventMigration eventMigration = eventMigrationRepository.loadEventMigration(event.getId());
        assertNotNull(eventMigration);
        // assertEquals(migrationTs.toString(), eventMigration.getBuildTimestamp().toString());
        assertEquals(currentVersion, eventMigration.getCurrentVersion());
        List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
        assertNotNull(tickets);
        assertFalse(tickets.isEmpty());
        // <-- the migration has not been done
        assertEquals(AVAILABLE_SEATS, tickets.size());
        assertTrue(tickets.stream().allMatch(t -> t.getCategoryId() == null));
    } finally {
        eventManager.deleteEvent(event.getId(), eventUsername.getValue());
    }
}
Also used : java.util(java.util) TicketCategoryRepository(alfio.repository.TicketCategoryRepository) PaymentProxy(alfio.model.transaction.PaymentProxy) BeforeClass(org.junit.BeforeClass) TemplateProcessor(alfio.controller.support.TemplateProcessor) TicketReservationRepository(alfio.repository.TicketReservationRepository) ZonedDateTime(java.time.ZonedDateTime) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) EventMigration(alfio.model.system.EventMigration) Value(org.springframework.beans.factory.annotation.Value) RepositoryConfiguration(alfio.config.RepositoryConfiguration) BigDecimal(java.math.BigDecimal) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) LocationDescriptor(alfio.model.modification.support.LocationDescriptor) Pair(org.apache.commons.lang3.tuple.Pair) LocalTime(java.time.LocalTime) EventMigrationRepository(alfio.repository.system.EventMigrationRepository) OrganizationRepository(alfio.repository.user.OrganizationRepository) TicketRepository(alfio.repository.TicketRepository) Organization(alfio.model.user.Organization) TemplateManager(alfio.util.TemplateManager) UpdateTicketOwnerForm(alfio.controller.form.UpdateTicketOwnerForm) User(alfio.model.user.User) Test(org.junit.Test) EventRepository(alfio.repository.EventRepository) IntegrationTestUtil(alfio.test.util.IntegrationTestUtil) ZoneId(java.time.ZoneId) DateUtils(org.apache.commons.lang3.time.DateUtils) TicketReservationManager(alfio.manager.TicketReservationManager) Role(alfio.model.user.Role) Initializer(alfio.config.Initializer) EventManager(alfio.manager.EventManager) PartialTicketPDFGenerator(alfio.manager.support.PartialTicketPDFGenerator) alfio.model(alfio.model) UserManager(alfio.manager.user.UserManager) ContextConfiguration(org.springframework.test.context.ContextConfiguration) LocalDate(java.time.LocalDate) DataSourceConfiguration(alfio.config.DataSourceConfiguration) FileUploadManager(alfio.manager.FileUploadManager) TestConfiguration(alfio.TestConfiguration) Assert(org.junit.Assert) alfio.model.modification(alfio.model.modification) EventMigration(alfio.model.system.EventMigration) ZonedDateTime(java.time.ZonedDateTime) Test(org.junit.Test)

Example 5 with EventMigration

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

the class DataMigratorIntegrationTest method testMigration.

@Test
public void testMigration() {
    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));
    Pair<Event, String> eventUsername = initEvent(categories);
    Event event = eventUsername.getKey();
    try {
        eventRepository.updatePrices("CHF", 40, false, BigDecimal.ONE, "STRIPE", event.getId(), PriceContainer.VatStatus.NOT_INCLUDED, 1000);
        dataMigrator.migrateEventsToCurrentVersion();
        EventMigration eventMigration = eventMigrationRepository.loadEventMigration(event.getId());
        assertNotNull(eventMigration);
        // assertEquals(buildTimestamp, eventMigration.getBuildTimestamp().toString());
        assertEquals(currentVersion, eventMigration.getCurrentVersion());
        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));
    } finally {
        eventManager.deleteEvent(event.getId(), eventUsername.getValue());
    }
}
Also used : java.util(java.util) TicketCategoryRepository(alfio.repository.TicketCategoryRepository) PaymentProxy(alfio.model.transaction.PaymentProxy) BeforeClass(org.junit.BeforeClass) TemplateProcessor(alfio.controller.support.TemplateProcessor) TicketReservationRepository(alfio.repository.TicketReservationRepository) ZonedDateTime(java.time.ZonedDateTime) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) EventMigration(alfio.model.system.EventMigration) Value(org.springframework.beans.factory.annotation.Value) RepositoryConfiguration(alfio.config.RepositoryConfiguration) BigDecimal(java.math.BigDecimal) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) LocationDescriptor(alfio.model.modification.support.LocationDescriptor) Pair(org.apache.commons.lang3.tuple.Pair) LocalTime(java.time.LocalTime) EventMigrationRepository(alfio.repository.system.EventMigrationRepository) OrganizationRepository(alfio.repository.user.OrganizationRepository) TicketRepository(alfio.repository.TicketRepository) Organization(alfio.model.user.Organization) TemplateManager(alfio.util.TemplateManager) UpdateTicketOwnerForm(alfio.controller.form.UpdateTicketOwnerForm) User(alfio.model.user.User) Test(org.junit.Test) EventRepository(alfio.repository.EventRepository) IntegrationTestUtil(alfio.test.util.IntegrationTestUtil) ZoneId(java.time.ZoneId) DateUtils(org.apache.commons.lang3.time.DateUtils) TicketReservationManager(alfio.manager.TicketReservationManager) Role(alfio.model.user.Role) Initializer(alfio.config.Initializer) EventManager(alfio.manager.EventManager) PartialTicketPDFGenerator(alfio.manager.support.PartialTicketPDFGenerator) alfio.model(alfio.model) UserManager(alfio.manager.user.UserManager) ContextConfiguration(org.springframework.test.context.ContextConfiguration) LocalDate(java.time.LocalDate) DataSourceConfiguration(alfio.config.DataSourceConfiguration) FileUploadManager(alfio.manager.FileUploadManager) TestConfiguration(alfio.TestConfiguration) Assert(org.junit.Assert) alfio.model.modification(alfio.model.modification) EventMigration(alfio.model.system.EventMigration) Test(org.junit.Test)

Aggregations

EventMigration (alfio.model.system.EventMigration)5 Test (org.junit.Test)4 TestConfiguration (alfio.TestConfiguration)3 DataSourceConfiguration (alfio.config.DataSourceConfiguration)3 Initializer (alfio.config.Initializer)3 RepositoryConfiguration (alfio.config.RepositoryConfiguration)3 UpdateTicketOwnerForm (alfio.controller.form.UpdateTicketOwnerForm)3 TemplateProcessor (alfio.controller.support.TemplateProcessor)3 EventManager (alfio.manager.EventManager)3 FileUploadManager (alfio.manager.FileUploadManager)3 TicketReservationManager (alfio.manager.TicketReservationManager)3 PartialTicketPDFGenerator (alfio.manager.support.PartialTicketPDFGenerator)3 UserManager (alfio.manager.user.UserManager)3 alfio.model (alfio.model)3 alfio.model.modification (alfio.model.modification)3 LocationDescriptor (alfio.model.modification.support.LocationDescriptor)3 PaymentProxy (alfio.model.transaction.PaymentProxy)3 Organization (alfio.model.user.Organization)3 Role (alfio.model.user.Role)3 User (alfio.model.user.User)3