use of alfio.model.user.Organization in project alf.io by alfio-event.
the class NotificationManager method sendTicketByEmail.
public void sendTicketByEmail(Ticket ticket, Event event, Locale locale, PartialTicketTextGenerator textBuilder, TicketReservation reservation, TicketCategory ticketCategory) throws IOException {
Organization organization = organizationRepository.getById(event.getOrganizationId());
List<Mailer.Attachment> attachments = new ArrayList<>();
attachments.add(CustomMessageManager.generateTicketAttachment(ticket, reservation, ticketCategory, organization));
String encodedAttachments = encodeAttachments(attachments.toArray(new Mailer.Attachment[attachments.size()]));
String subject = messageSource.getMessage("ticket-email-subject", new Object[] { event.getDisplayName() }, locale);
String text = textBuilder.generate(ticket);
String checksum = calculateChecksum(ticket.getEmail(), encodedAttachments, subject, text);
String recipient = ticket.getEmail();
// TODO handle HTML
tx.execute(status -> emailMessageRepository.insert(event.getId(), recipient, null, subject, text, encodedAttachments, checksum, ZonedDateTime.now(UTC)));
}
use of alfio.model.user.Organization 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;
}
}
use of alfio.model.user.Organization in project alf.io by alfio-event.
the class TicketReservationManager method sendReminderForOfflinePaymentsToEventManagers.
// called each hour
void sendReminderForOfflinePaymentsToEventManagers() {
eventRepository.findAllActives(ZonedDateTime.now(Clock.systemUTC())).stream().filter(event -> {
ZonedDateTime dateTimeForEvent = ZonedDateTime.now(event.getZoneId());
// only for the events at 5:00 local time
return dateTimeForEvent.truncatedTo(ChronoUnit.HOURS).getHour() == 5;
}).forEachOrdered(event -> {
ZonedDateTime dateTimeForEvent = ZonedDateTime.now(event.getZoneId()).truncatedTo(ChronoUnit.DAYS).plusDays(1);
List<TicketReservationInfo> reservations = ticketReservationRepository.findAllOfflinePaymentReservationWithExpirationBefore(dateTimeForEvent, event.getId());
log.info("for event {} there are {} pending offline payments to handle", event.getId(), reservations.size());
if (!reservations.isEmpty()) {
Organization organization = organizationRepository.getById(event.getOrganizationId());
List<String> cc = notificationManager.getCCForEventOrganizer(event);
String subject = String.format("There are %d pending offline payments that will expire in event: %s", reservations.size(), event.getDisplayName());
String baseUrl = configurationManager.getRequiredValue(Configuration.from(event.getOrganizationId(), event.getId(), BASE_URL));
Map<String, Object> model = TemplateResource.prepareModelForOfflineReservationExpiringEmailForOrganizer(event, reservations, baseUrl);
notificationManager.sendSimpleEmail(event, organization.getEmail(), cc, subject, () -> templateManager.renderTemplate(event, TemplateResource.OFFLINE_RESERVATION_EXPIRING_EMAIL_FOR_ORGANIZER, model, Locale.ENGLISH));
extensionManager.handleOfflineReservationsWillExpire(event, reservations);
}
});
}
use of alfio.model.user.Organization in project alf.io by alfio-event.
the class TicketReservationManager method releaseTicket.
public void releaseTicket(Event event, TicketReservation ticketReservation, final Ticket ticket) {
TicketCategory category = ticketCategoryRepository.getByIdAndActive(ticket.getCategoryId(), event.getId());
if (!CategoryEvaluator.isTicketCancellationAvailable(ticketCategoryRepository, ticket)) {
throw new IllegalStateException("Cannot release reserved tickets");
}
String reservationId = ticketReservation.getId();
// #365 - reset UUID when releasing a ticket
int result = ticketRepository.releaseTicket(reservationId, UUID.randomUUID().toString(), event.getId(), ticket.getId());
Validate.isTrue(result == 1, String.format("Expected 1 row to be updated, got %d", result));
if (category.isAccessRestricted() || !category.isBounded()) {
ticketRepository.unbindTicketsFromCategory(event.getId(), category.getId(), singletonList(ticket.getId()));
}
Organization organization = organizationRepository.getById(event.getOrganizationId());
Map<String, Object> model = TemplateResource.buildModelForTicketHasBeenCancelled(organization, event, ticket);
Locale locale = Locale.forLanguageTag(Optional.ofNullable(ticket.getUserLanguage()).orElse("en"));
notificationManager.sendSimpleEmail(event, ticket.getEmail(), messageSource.getMessage("email-ticket-released.subject", new Object[] { event.getDisplayName() }, locale), () -> templateManager.renderTemplate(event, TemplateResource.TICKET_HAS_BEEN_CANCELLED, model, locale));
String ticketCategoryDescription = ticketCategoryDescriptionRepository.findByTicketCategoryIdAndLocale(category.getId(), ticket.getUserLanguage()).orElse("");
List<AdditionalServiceItem> additionalServiceItems = additionalServiceItemRepository.findByReservationUuid(reservationId);
Map<String, Object> adminModel = TemplateResource.buildModelForTicketHasBeenCancelledAdmin(organization, event, ticket, ticketCategoryDescription, additionalServiceItems, asi -> additionalServiceTextRepository.findByLocaleAndType(asi.getAdditionalServiceId(), locale.getLanguage(), AdditionalServiceText.TextType.TITLE));
notificationManager.sendSimpleEmail(event, organization.getEmail(), messageSource.getMessage("email-ticket-released.admin.subject", new Object[] { ticket.getId(), event.getDisplayName() }, locale), () -> templateManager.renderTemplate(event, TemplateResource.TICKET_HAS_BEEN_CANCELLED_ADMIN, adminModel, locale));
int deletedValues = ticketFieldRepository.deleteAllValuesForTicket(ticket.getId());
log.debug("deleting {} field values for ticket {}", deletedValues, ticket.getId());
auditingRepository.insert(reservationId, null, event.getId(), Audit.EventType.CANCEL_TICKET, new Date(), Audit.EntityType.TICKET, Integer.toString(ticket.getId()));
if (ticketRepository.countTicketsInReservation(reservationId) == 0 && !transactionRepository.loadOptionalByReservationId(reservationId).isPresent()) {
deleteReservation(event, reservationId, false);
auditingRepository.insert(reservationId, null, event.getId(), Audit.EventType.CANCEL_RESERVATION, new Date(), Audit.EntityType.RESERVATION, reservationId);
} else {
extensionManager.handleTicketCancelledForEvent(event, Collections.singletonList(ticket.getUuid()));
}
}
use of alfio.model.user.Organization in project alf.io by alfio-event.
the class TicketReservationManager method markExpiredInPaymentReservationAsStuck.
/**
* Finds all the reservations that are "stuck" in payment status.
* This could happen when there is an internal error after a successful credit card charge.
*
* @param expirationDate expiration date
*/
public void markExpiredInPaymentReservationAsStuck(Date expirationDate) {
List<String> stuckReservations = ticketReservationRepository.findStuckReservations(expirationDate);
if (!stuckReservations.isEmpty()) {
ticketReservationRepository.updateReservationsStatus(stuckReservations, TicketReservationStatus.STUCK.name());
Map<Integer, List<ReservationIdAndEventId>> reservationsGroupedByEvent = ticketReservationRepository.getReservationIdAndEventId(stuckReservations).stream().collect(Collectors.groupingBy(ReservationIdAndEventId::getEventId));
reservationsGroupedByEvent.forEach((eventId, reservationIds) -> {
Event event = eventRepository.findById(eventId);
Organization organization = organizationRepository.getById(event.getOrganizationId());
notificationManager.sendSimpleEmail(event, organization.getEmail(), STUCK_TICKETS_SUBJECT, () -> String.format(STUCK_TICKETS_MSG, event.getShortName()));
extensionManager.handleStuckReservations(event, reservationIds.stream().map(ReservationIdAndEventId::getId).collect(toList()));
});
}
}
Aggregations