use of alfio.model.Event in project alf.io by alfio-event.
the class DynamicResourcesController method getGoogleAnalyticsScript.
@RequestMapping("/resources/js/google-analytics")
public void getGoogleAnalyticsScript(HttpSession session, HttpServletResponse response, @RequestParam("e") Integer eventId) throws IOException {
response.setContentType("application/javascript");
Optional<Event> ev = Optional.ofNullable(eventId).flatMap(id -> Optional.ofNullable(eventRepository.findById(id)));
ConfigurationPathKey pathKey = ev.map(e -> Configuration.from(e.getOrganizationId(), e.getId(), GOOGLE_ANALYTICS_KEY)).orElseGet(() -> Configuration.getSystemConfiguration(GOOGLE_ANALYTICS_KEY));
final Optional<String> id = configurationManager.getStringConfigValue(pathKey);
final String script;
ConfigurationPathKey anonymousPathKey = ev.map(e -> Configuration.from(e.getOrganizationId(), e.getId(), GOOGLE_ANALYTICS_ANONYMOUS_MODE)).orElseGet(() -> Configuration.getSystemConfiguration(GOOGLE_ANALYTICS_ANONYMOUS_MODE));
if (id.isPresent() && configurationManager.getBooleanConfigValue(anonymousPathKey, true)) {
String trackingId = Optional.ofNullable(StringUtils.trimToNull((String) session.getAttribute("GA_TRACKING_ID"))).orElseGet(() -> UUID.randomUUID().toString());
Map<String, Object> model = new HashMap<>();
model.put("clientId", trackingId);
model.put("account", id.get());
script = templateManager.renderTemplate(TemplateResource.GOOGLE_ANALYTICS, model, Locale.ENGLISH);
} else {
script = id.map(x -> String.format(GOOGLE_ANALYTICS_SCRIPT, x)).orElse(EMPTY);
}
response.getWriter().write(script);
}
use of alfio.model.Event 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.Event 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.Event in project alf.io by alfio-event.
the class CustomMessageManager method generatePreview.
public Map<String, Object> generatePreview(String eventName, Optional<Integer> categoryId, List<MessageModification> input, String username) {
Map<String, Object> result = new HashMap<>();
Event event = eventManager.getSingleEvent(eventName, username);
result.put("affectedUsers", categoryId.map(id -> ticketRepository.countAssignedTickets(event.getId(), id)).orElseGet(() -> ticketRepository.countAllAssigned(event.getId())));
result.put("preview", preview(event, input, username));
return result;
}
use of alfio.model.Event in project alf.io by alfio-event.
the class ConfigurationManager method deleteCategoryLevelByKey.
public void deleteCategoryLevelByKey(String key, int eventId, int categoryId, String username) {
Event event = eventRepository.findById(eventId);
Validate.notNull(event, "Wrong event id");
Validate.isTrue(userManager.isOwnerOfOrganization(userManager.findUserByUsername(username), event.getOrganizationId()), "User is not owner of the organization. Therefore, delete is not allowed.");
configurationRepository.deleteCategoryLevelByKey(key, eventId, categoryId);
}
Aggregations