Subversion Repositories SmartDukaan

Rev

Rev 26184 | Rev 26186 | 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()
26185 amit.gupta 81
                .optionalStart()
23951 amit.gupta 82
                .appendLiteral('T')
83
                .optionalEnd()
26183 amit.gupta 84
                .optionalStart()
23951 amit.gupta 85
                .appendLiteral(' ')
26183 amit.gupta 86
                .optionalEnd()
26185 amit.gupta 87
                .optionalEnd()
23951 amit.gupta 88
                .append(DateTimeFormatter.ISO_LOCAL_TIME)
89
                .toFormatter();
90
		DateTimeFormatter sf = new DateTimeFormatterBuilder()
91
				.parseCaseInsensitive()
92
				.append(DateTimeFormatter.ISO_LOCAL_DATE)
26184 amit.gupta 93
				.optionalStart()
26185 amit.gupta 94
				.optionalStart()
23951 amit.gupta 95
				.appendLiteral('T')
26184 amit.gupta 96
				.optionalEnd()
97
				.optionalStart()
98
				.appendLiteral(' ')
99
				.optionalEnd()
26185 amit.gupta 100
				.optionalEnd()
23951 amit.gupta 101
				.append(DateTimeFormatter.ISO_LOCAL_TIME)
102
				.toFormatter();
103
		LocalDateTimeSerializer serializer = new LocalDateTimeSerializer(sf);
104
		LocalDateTimeDeserializer deserializer = new LocalDateTimeDeserializer(df);
105
		JavaTimeModule jtm = new JavaTimeModule();
106
		jtm.addSerializer(LocalDateTime.class, serializer);
107
		jtm.addDeserializer(LocalDateTime.class, deserializer);
23878 amit.gupta 108
		ObjectMapper mapper = new ObjectMapper()
109
				   .registerModule(new ParameterNamesModule())
110
				   .registerModule(new Jdk8Module())
23951 amit.gupta 111
				   .registerModule(jtm); // new module, NOT JSR310Module
23878 amit.gupta 112
		return mapper;
113
	}
114
 
21555 kshitij.so 115
}