Subversion Repositories SmartDukaan

Rev

Rev 26183 | Rev 26185 | 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();
64
        registrar.setUseIsoFormat(true);
65
        registrar.registerFormatters(registry);
66
    }
67
 
23878 amit.gupta 68
 
23886 amit.gupta 69
 
23878 amit.gupta 70
	@Override
23925 amit.gupta 71
    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
23878 amit.gupta 72
        converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
73
    }
74
 
23951 amit.gupta 75
	@Bean
76
	public ObjectMapper objectMapper() {
77
		DateTimeFormatter df = new DateTimeFormatterBuilder()
78
                .parseCaseInsensitive()
79
                .append(DateTimeFormatter.ISO_LOCAL_DATE)
80
                .optionalStart()
81
                .appendLiteral('T')
82
                .optionalEnd()
26183 amit.gupta 83
                .optionalStart()
23951 amit.gupta 84
                .appendLiteral(' ')
26183 amit.gupta 85
                .optionalEnd()
23951 amit.gupta 86
                .append(DateTimeFormatter.ISO_LOCAL_TIME)
87
                .toFormatter();
88
		DateTimeFormatter sf = new DateTimeFormatterBuilder()
89
				.parseCaseInsensitive()
90
				.append(DateTimeFormatter.ISO_LOCAL_DATE)
26184 amit.gupta 91
				.optionalStart()
23951 amit.gupta 92
				.appendLiteral('T')
26184 amit.gupta 93
				.optionalEnd()
94
				.optionalStart()
95
				.appendLiteral(' ')
96
				.optionalEnd()
23951 amit.gupta 97
				.append(DateTimeFormatter.ISO_LOCAL_TIME)
98
				.toFormatter();
99
		LocalDateTimeSerializer serializer = new LocalDateTimeSerializer(sf);
100
		LocalDateTimeDeserializer deserializer = new LocalDateTimeDeserializer(df);
101
		JavaTimeModule jtm = new JavaTimeModule();
102
		jtm.addSerializer(LocalDateTime.class, serializer);
103
		jtm.addDeserializer(LocalDateTime.class, deserializer);
23878 amit.gupta 104
		ObjectMapper mapper = new ObjectMapper()
105
				   .registerModule(new ParameterNamesModule())
106
				   .registerModule(new Jdk8Module())
23951 amit.gupta 107
				   .registerModule(jtm); // new module, NOT JSR310Module
23878 amit.gupta 108
		return mapper;
109
	}
110
 
21555 kshitij.so 111
}