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