Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
21165 ashik.ali 1
package com.spice.profitmandi.web.config;
2
 
21220 ashik.ali 3
import org.springframework.beans.factory.annotation.Autowired;
21272 kshitij.so 4
import org.springframework.context.annotation.Bean;
21165 ashik.ali 5
import org.springframework.context.annotation.ComponentScan;
6
import org.springframework.context.annotation.Configuration;
21285 kshitij.so 7
import org.springframework.web.servlet.config.annotation.CorsRegistry;
21165 ashik.ali 8
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
9
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
10
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
11
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
12
 
21236 ashik.ali 13
import com.spice.profitmandi.common.model.ProfitMandiConstants;
14
import com.spice.profitmandi.web.interceptor.ApiRequestInterceptor;
21302 ashik.ali 15
import com.spice.profitmandi.web.interceptor.CreateRetailerRequestInterceptor;
21278 ashik.ali 16
import com.spice.profitmandi.web.interceptor.CreateUserRequestInterceptor;
21277 ashik.ali 17
import com.spice.profitmandi.web.interceptor.GoogleLoginRequestInterceptor;
21236 ashik.ali 18
import com.spice.profitmandi.web.interceptor.RoleRequestInterceptor;
21285 kshitij.so 19
import com.spice.profitmandi.web.interceptor.SimpleCORSInterceptor;
21220 ashik.ali 20
 
21272 kshitij.so 21
import springfox.documentation.builders.PathSelectors;
22
import springfox.documentation.builders.RequestHandlerSelectors;
23
import springfox.documentation.service.ApiInfo;
24
import springfox.documentation.spi.DocumentationType;
25
import springfox.documentation.spring.web.plugins.Docket;
26
import springfox.documentation.swagger2.annotations.EnableSwagger2;
27
 
21165 ashik.ali 28
@Configuration
29
@EnableWebMvc
21272 kshitij.so 30
@EnableSwagger2
21220 ashik.ali 31
@ComponentScan("com.spice.profitmandi.*")
21165 ashik.ali 32
public class WebMVCConfig extends WebMvcConfigurerAdapter{
33
 
34
	private static final String RESOURCES_PATTERN="/resources/**";
35
	private static final String RESOURCES_LOCATION="/resources/";
36
 
21220 ashik.ali 37
	@Autowired
21236 ashik.ali 38
	ApiRequestInterceptor apiRequestInterceptor;
21165 ashik.ali 39
 
21236 ashik.ali 40
	@Autowired
41
	RoleRequestInterceptor roleRequestInterceptor;
42
 
21277 ashik.ali 43
	@Autowired
44
	GoogleLoginRequestInterceptor googleLoginRequestInterceptor;
21272 kshitij.so 45
 
21278 ashik.ali 46
	@Autowired
47
	CreateUserRequestInterceptor createUserRequestInterceptor;
21277 ashik.ali 48
 
21285 kshitij.so 49
	@Autowired
50
	SimpleCORSInterceptor simpleCORSInterceptor;
51
 
21302 ashik.ali 52
	@Autowired
53
	CreateRetailerRequestInterceptor createRetailerRequestInterceptor;
54
 
55
 
21272 kshitij.so 56
	@Bean
57
	public Docket api() {
58
		return new Docket(DocumentationType.SWAGGER_2).select()
59
				.apis(RequestHandlerSelectors.any())
60
				.paths(PathSelectors.any()).build()
61
				.apiInfo(apiInfo());
62
	}
63
 
21165 ashik.ali 64
	@Override
21272 kshitij.so 65
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
66
	    registry.addResourceHandler("swagger-ui.html")
67
	      .addResourceLocations("classpath:/META-INF/resources/");
68
	    registry.addResourceHandler("/webjars/**")
69
	      .addResourceLocations("classpath:/META-INF/resources/webjars/");
70
	    registry.addResourceHandler(RESOURCES_PATTERN).addResourceLocations(RESOURCES_LOCATION);
71
	}
21165 ashik.ali 72
 
73
	@Override
74
	public void addInterceptors(InterceptorRegistry registry) {
21236 ashik.ali 75
		registry.addInterceptor(apiRequestInterceptor).addPathPatterns(ProfitMandiConstants.URL_API, ProfitMandiConstants.URL_API + "/");
76
		registry.addInterceptor(roleRequestInterceptor).addPathPatterns(ProfitMandiConstants.URL_ROLE, ProfitMandiConstants.URL_ROLE + "/");
21277 ashik.ali 77
		registry.addInterceptor(googleLoginRequestInterceptor).addPathPatterns(ProfitMandiConstants.URL_USER_GOOGLE_LOGIN, ProfitMandiConstants.URL_USER_GOOGLE_LOGIN + "/");
21278 ashik.ali 78
		registry.addInterceptor(createUserRequestInterceptor).addPathPatterns(ProfitMandiConstants.URL_USER, ProfitMandiConstants.URL_USER + "/");
21285 kshitij.so 79
		registry.addInterceptor(simpleCORSInterceptor).addPathPatterns("/**").excludePathPatterns("/swagger-ui.html");
21302 ashik.ali 80
		registry.addInterceptor(createRetailerRequestInterceptor).addPathPatterns(ProfitMandiConstants.URL_RETAILER, ProfitMandiConstants.URL_RETAILER + "/");
21165 ashik.ali 81
	}
21272 kshitij.so 82
 
21285 kshitij.so 83
	@Override
84
	public void addCorsMappings(CorsRegistry registry) {
85
		registry.addMapping("/**").allowedOrigins("*").allowedMethods("*").
86
		allowedHeaders("*").allowCredentials(false);
87
	}
88
 
21272 kshitij.so 89
	private ApiInfo apiInfo() {
90
	    @SuppressWarnings("deprecation")
91
		ApiInfo apiInfo = new ApiInfo(
92
	      "ProfitMandi API",
93
	      "Api's for profitmandi app",
94
	      "API TOS",
95
	      "Terms of service",
96
	      "New Spice Solutions Pvt. Ltd.",
97
	      "License of API",
98
	      "API license URL");
99
	    return apiInfo;
100
	}
21220 ashik.ali 101
}