use of alfio.model.system.Configuration.ConfigurationPathKey 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.system.Configuration.ConfigurationPathKey in project alf.io by alfio-event.
the class MvcConfiguration method getDefaultTemplateObjectsFiller.
@Bean
public HandlerInterceptorAdapter getDefaultTemplateObjectsFiller() {
return new HandlerInterceptorAdapter() {
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
Optional.ofNullable(modelAndView).filter(mv -> !StringUtils.startsWith(mv.getViewName(), "redirect:")).ifPresent(mv -> {
mv.addObject("request", request);
final ModelMap modelMap = mv.getModelMap();
boolean demoModeEnabled = environment.acceptsProfiles(Initializer.PROFILE_DEMO);
modelMap.put("demoModeEnabled", demoModeEnabled);
Optional.ofNullable(request.getAttribute("ALFIO_EVENT_NAME")).map(Object::toString).ifPresent(eventName -> {
List<?> availableLanguages = i18nManager.getEventLanguages(eventName);
modelMap.put("showAvailableLanguagesInPageTop", availableLanguages.size() > 1);
modelMap.put("availableLanguages", availableLanguages);
});
modelMap.putIfAbsent("event", null);
modelMap.putIfAbsent("pageTitle", "empty");
Event event = modelMap.get("event") == null ? null : modelMap.get("event") instanceof Event ? (Event) modelMap.get("event") : ((EventDescriptor) modelMap.get("event")).getEvent();
ConfigurationPathKey googleAnalyticsKey = Optional.ofNullable(event).map(e -> alfio.model.system.Configuration.from(e.getOrganizationId(), e.getId(), GOOGLE_ANALYTICS_KEY)).orElseGet(() -> alfio.model.system.Configuration.getSystemConfiguration(GOOGLE_ANALYTICS_KEY));
modelMap.putIfAbsent("analyticsEnabled", StringUtils.isNotBlank(configurationManager.getStringConfigValue(googleAnalyticsKey, "")));
if (demoModeEnabled) {
modelMap.putIfAbsent("paypalTestUsername", configurationManager.getStringConfigValue(alfio.model.system.Configuration.getSystemConfiguration(PAYPAL_DEMO_MODE_USERNAME), "<missing>"));
modelMap.putIfAbsent("paypalTestPassword", configurationManager.getStringConfigValue(alfio.model.system.Configuration.getSystemConfiguration(PAYPAL_DEMO_MODE_PASSWORD), "<missing>"));
}
});
}
};
}
Aggregations