Search in sources :

Example 1 with EventDescriptor

use of alfio.controller.decorator.EventDescriptor 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>"));
                }
            });
        }
    };
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PathVariable(org.springframework.web.bind.annotation.PathVariable) ZonedDateTime(java.time.ZonedDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) org.springframework.web.servlet.config.annotation(org.springframework.web.servlet.config.annotation) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) ModelMap(org.springframework.ui.ModelMap) HandlerInterceptorAdapter(org.springframework.web.servlet.handler.HandlerInterceptorAdapter) RequestContextUtils(org.springframework.web.servlet.support.RequestContextUtils) LocalizationMessageInterceptor(org.springframework.web.servlet.view.mustache.jmustache.LocalizationMessageInterceptor) HandlerMethod(org.springframework.web.method.HandlerMethod) Matcher(java.util.regex.Matcher) DefaultMessageSourceResolvable(org.springframework.context.support.DefaultMessageSourceResolvable) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) EventDescriptor(alfio.controller.decorator.EventDescriptor) JMustacheTemplateFactory(org.springframework.web.servlet.view.mustache.jmustache.JMustacheTemplateFactory) ConfigurationPathKey(alfio.model.system.Configuration.ConfigurationPathKey) MediaType(org.springframework.http.MediaType) ContentLanguage(alfio.model.ContentLanguage) Collectors(java.util.stream.Collectors) JMustacheTemplateLoader(org.springframework.web.servlet.view.mustache.jmustache.JMustacheTemplateLoader) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) Configuration(org.springframework.context.annotation.Configuration) LocaleChangeInterceptor(org.springframework.web.servlet.i18n.LocaleChangeInterceptor) Environment(org.springframework.core.env.Environment) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) Pattern(java.util.regex.Pattern) java.util(java.util) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ConfigurationManager(alfio.manager.system.ConfigurationManager) CommonsMultipartResolver(org.springframework.web.multipart.commons.CommonsMultipartResolver) MustacheViewResolver(org.springframework.web.servlet.view.mustache.MustacheViewResolver) HttpServletRequest(javax.servlet.http.HttpServletRequest) org.springframework.web.servlet(org.springframework.web.servlet) MessageSource(org.springframework.context.MessageSource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpServletResponse(javax.servlet.http.HttpServletResponse) SessionLocaleResolver(org.springframework.web.servlet.i18n.SessionLocaleResolver) Mustache(com.samskivert.mustache.Mustache) ComponentScan(org.springframework.context.annotation.ComponentScan) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) DateTimeFormatter(java.time.format.DateTimeFormatter) SerializationFeature(com.fasterxml.jackson.databind.SerializationFeature) I18nManager(alfio.manager.i18n.I18nManager) Event(alfio.model.Event) Bean(org.springframework.context.annotation.Bean) CsrfToken(org.springframework.security.web.csrf.CsrfToken) ConfigurationKeys(alfio.model.system.ConfigurationKeys) MustacheCustomTagInterceptor(alfio.util.MustacheCustomTagInterceptor) ConfigurationPathKey(alfio.model.system.Configuration.ConfigurationPathKey) EventDescriptor(alfio.controller.decorator.EventDescriptor) ModelMap(org.springframework.ui.ModelMap) HandlerInterceptorAdapter(org.springframework.web.servlet.handler.HandlerInterceptorAdapter) HttpServletResponse(javax.servlet.http.HttpServletResponse) Event(alfio.model.Event) Bean(org.springframework.context.annotation.Bean)

Aggregations

EventDescriptor (alfio.controller.decorator.EventDescriptor)1 I18nManager (alfio.manager.i18n.I18nManager)1 ConfigurationManager (alfio.manager.system.ConfigurationManager)1 ContentLanguage (alfio.model.ContentLanguage)1 Event (alfio.model.Event)1 ConfigurationPathKey (alfio.model.system.Configuration.ConfigurationPathKey)1 ConfigurationKeys (alfio.model.system.ConfigurationKeys)1 MustacheCustomTagInterceptor (alfio.util.MustacheCustomTagInterceptor)1 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)1 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)1 Mustache (com.samskivert.mustache.Mustache)1 ZonedDateTime (java.time.ZonedDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 java.util (java.util)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1