Subversion Repositories SmartDukaan

Rev

Rev 26190 | Rev 26192 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21561 ashik.ali 1
package com.spice.profitmandi.web.config;
21555 kshitij.so 2
 
23951 amit.gupta 3
import java.time.LocalDateTime;
26191 amit.gupta 4
import java.time.chrono.IsoChronology;
23951 amit.gupta 5
import java.time.format.DateTimeFormatter;
6
import java.time.format.DateTimeFormatterBuilder;
26191 amit.gupta 7
import java.time.format.ResolverStyle;
23878 amit.gupta 8
import java.util.List;
9
 
21561 ashik.ali 10
import org.springframework.beans.factory.annotation.Autowired;
23951 amit.gupta 11
import org.springframework.context.annotation.Bean;
21555 kshitij.so 12
import org.springframework.context.annotation.ComponentScan;
13
import org.springframework.context.annotation.Configuration;
23886 amit.gupta 14
import org.springframework.format.FormatterRegistry;
15
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar;
23878 amit.gupta 16
import org.springframework.http.converter.HttpMessageConverter;
17
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
21555 kshitij.so 18
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
21561 ashik.ali 19
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
21555 kshitij.so 20
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
21
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
22
 
23878 amit.gupta 23
import com.fasterxml.jackson.databind.ObjectMapper;
24
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
25
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
23951 amit.gupta 26
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
27
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
23878 amit.gupta 28
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
21561 ashik.ali 29
import com.spice.profitmandi.web.interceptor.AuthenticationInterceptor;
22107 ashik.ali 30
import com.spice.profitmandi.web.interceptor.RoleInterceptor;
21561 ashik.ali 31
 
21555 kshitij.so 32
@EnableWebMvc
33
@Configuration
34
@ComponentScan({"com.spice.profitmandi.*"})
35
public class WebConfig extends WebMvcConfigurerAdapter{
36
 
37
	private static final String RESOURCES_PATTERN="/resources/**";
38
	private static final String RESOURCES_LOCATION="/resources/";
39
 
21561 ashik.ali 40
	@Autowired
41
	AuthenticationInterceptor authenticationInterceptor;
22107 ashik.ali 42
 
43
	@Autowired
44
	RoleInterceptor roleInterceptor;
45
 
21555 kshitij.so 46
	@Override
47
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
48
	   registry.addResourceHandler(RESOURCES_PATTERN).addResourceLocations(RESOURCES_LOCATION);
49
	}
50
 
21561 ashik.ali 51
	@Override
52
	public void addInterceptors(InterceptorRegistry registry) {
25976 amit.gupta 53
		//registry.addInterceptor()
54
		registry.addInterceptor(authenticationInterceptor).addPathPatterns("/**").excludePathPatterns(
55
				"/hdfctest/**", "/hdfc/**", 
56
				"/login", "/login/","/forgetPassword","/forgetPassword/", "/", "/checkplans", "/12dashboard34"
57
				);
58
		registry.addInterceptor(roleInterceptor).excludePathPatterns(
59
				"/hdfctest/**", "/hdfc/**", 
60
				"/login", "/login/", "/register", "/register/","/forgetPassword","/forgetPassword/", "/","", "/12dashboard34");
21561 ashik.ali 61
	}
62
 
23886 amit.gupta 63
	@Override
64
    public void addFormatters(FormatterRegistry registry) {
65
        DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
26186 amit.gupta 66
        DateTimeFormatter df = new DateTimeFormatterBuilder()
67
                .parseCaseInsensitive()
68
                .append(DateTimeFormatter.ISO_LOCAL_DATE)
69
                .appendLiteral(' ')
70
                .append(DateTimeFormatter.ISO_LOCAL_TIME)
71
                .toFormatter();
26187 amit.gupta 72
        registrar.setDateTimeFormatter(df);
73
        registrar.setDateFormatter(DateTimeFormatter.ISO_LOCAL_DATE);
74
        registrar.setTimeFormatter(DateTimeFormatter.ISO_LOCAL_TIME);
23886 amit.gupta 75
        registrar.registerFormatters(registry);
76
    }
77
 
23878 amit.gupta 78
 
23886 amit.gupta 79
 
23878 amit.gupta 80
	@Override
23925 amit.gupta 81
    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
23878 amit.gupta 82
        converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
83
    }
84
 
23951 amit.gupta 85
	@Bean
86
	public ObjectMapper objectMapper() {
87
		DateTimeFormatter df = new DateTimeFormatterBuilder()
88
                .parseCaseInsensitive()
89
                .append(DateTimeFormatter.ISO_LOCAL_DATE)
90
                .appendLiteral(' ')
91
                .append(DateTimeFormatter.ISO_LOCAL_TIME)
92
                .toFormatter();
26191 amit.gupta 93
 
23951 amit.gupta 94
		DateTimeFormatter sf = new DateTimeFormatterBuilder()
95
				.parseCaseInsensitive()
96
				.append(DateTimeFormatter.ISO_LOCAL_DATE)
97
				.appendLiteral('T')
98
				.append(DateTimeFormatter.ISO_LOCAL_TIME)
99
				.toFormatter();
100
		LocalDateTimeSerializer serializer = new LocalDateTimeSerializer(sf);
101
		LocalDateTimeDeserializer deserializer = new LocalDateTimeDeserializer(df);
102
		JavaTimeModule jtm = new JavaTimeModule();
103
		jtm.addSerializer(LocalDateTime.class, serializer);
104
		jtm.addDeserializer(LocalDateTime.class, deserializer);
23878 amit.gupta 105
		ObjectMapper mapper = new ObjectMapper()
106
				   .registerModule(new ParameterNamesModule())
107
				   .registerModule(new Jdk8Module())
23951 amit.gupta 108
				   .registerModule(jtm); // new module, NOT JSR310Module
23878 amit.gupta 109
		return mapper;
110
	}
111
 
21555 kshitij.so 112
}