use of alfio.model.Ticket in project alf.io by alfio-event.
the class TicketController method generateTicketCode.
@RequestMapping(value = "/event/{eventName}/ticket/{ticketIdentifier}/code.png", method = RequestMethod.GET)
public void generateTicketCode(@PathVariable("eventName") String eventName, @PathVariable("ticketIdentifier") String ticketIdentifier, HttpServletResponse response) throws IOException, WriterException {
Optional<Triple<Event, TicketReservation, Ticket>> oData = ticketReservationManager.fetchCompleteAndAssigned(eventName, ticketIdentifier);
if (!oData.isPresent()) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
Triple<Event, TicketReservation, Ticket> data = oData.get();
Event event = data.getLeft();
Ticket ticket = data.getRight();
String qrCodeText = ticket.ticketCode(event.getPrivateKey());
response.setContentType("image/png");
response.getOutputStream().write(ImageUtil.createQRCode(qrCodeText));
}
use of alfio.model.Ticket in project alf.io by alfio-event.
the class TicketController method internalSendTicketByEmail.
private Ticket internalSendTicketByEmail(HttpServletRequest request, Triple<Event, TicketReservation, Ticket> data) throws IOException {
Ticket ticket = data.getRight();
Event event = data.getLeft();
Locale locale = LocaleUtil.getTicketLanguage(ticket, request);
TicketReservation reservation = data.getMiddle();
Organization organization = organizationRepository.getById(event.getOrganizationId());
TicketCategory category = ticketCategoryRepository.getById(ticket.getCategoryId());
notificationManager.sendTicketByEmail(ticket, event, locale, TemplateProcessor.buildPartialEmail(event, organization, reservation, category, templateManager, ticketReservationManager.ticketUpdateUrl(event, ticket.getUuid()), request), reservation, ticketCategoryRepository.getByIdAndActive(ticket.getCategoryId(), event.getId()));
return ticket;
}
use of alfio.model.Ticket 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.Ticket 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.Ticket 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