Subversion Repositories SmartDukaan

Rev

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