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;
});
}
}
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());
}
}
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());
}
}
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());
}
}
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());
}
}
Aggregations