Subversion Repositories SmartDukaan

Rev

Rev 24472 | Rev 27028 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 24472 Rev 25300
Line 1... Line 1...
1
 
1
 
2
package com.spice.profitmandi.web.config;
2
package com.spice.profitmandi.web.config;
3
 
3
 
4
import java.io.IOException;
4
import java.io.IOException;
-
 
5
import java.time.LocalDateTime;
5
import java.util.Properties;
6
import java.util.Properties;
6
 
7
 
7
import javax.servlet.MultipartConfigElement;
-
 
8
 
-
 
9
import org.apache.logging.log4j.LogManager;
8
import org.apache.logging.log4j.LogManager;
10
import org.apache.logging.log4j.Logger;
9
import org.apache.logging.log4j.Logger;
11
import org.springframework.context.annotation.Bean;
10
import org.springframework.context.annotation.Bean;
12
import org.springframework.context.annotation.ComponentScan;
11
import org.springframework.context.annotation.ComponentScan;
13
import org.springframework.context.annotation.Configuration;
12
import org.springframework.context.annotation.Configuration;
Line 18... Line 17...
18
import org.springframework.mail.javamail.JavaMailSender;
17
import org.springframework.mail.javamail.JavaMailSender;
19
import org.springframework.mail.javamail.JavaMailSenderImpl;
18
import org.springframework.mail.javamail.JavaMailSenderImpl;
20
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
19
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
21
import org.springframework.web.servlet.view.InternalResourceViewResolver;
20
import org.springframework.web.servlet.view.InternalResourceViewResolver;
22
 
21
 
-
 
22
import com.google.gson.Gson;
-
 
23
import com.google.gson.GsonBuilder;
-
 
24
import com.spice.profitmandi.dao.convertor.LocalDateTimeJsonConverter;
-
 
25
 
23
@Configuration
26
@Configuration
24
@ComponentScan("com.spice.profitmandi.*")
27
@ComponentScan("com.spice.profitmandi.*")
25
public class AppConfig {
28
public class AppConfig {
26
 
29
 
27
	private static final String PATH_PREFIX="/WEB-INF/views/";
30
	private static final String PATH_PREFIX = "/WEB-INF/views/";
28
	private static final String PATH_SUFFIX=".jsp";
31
	private static final String PATH_SUFFIX = ".jsp";
29
	private static final String MESSAGE_PATH_SOURCE_NAME="classpath:message";
32
	private static final String MESSAGE_PATH_SOURCE_NAME = "classpath:message";
30
	private static final Logger LOGGER=LogManager.getLogger(AppConfig.class);
33
	private static final Logger LOGGER = LogManager.getLogger(AppConfig.class);
31
	private static Resource resource;
34
	private static Resource resource;
32
	
35
 
33
	public static Resource getResource() {
36
	public static Resource getResource() {
34
		return resource;
37
		return resource;
35
	}
38
	}
36
 
39
 
37
	public void setResource(Resource resource) {
40
	public void setResource(Resource resource) {
38
		AppConfig.resource = resource;
41
		AppConfig.resource = resource;
39
	}
42
	}
40
 
43
 
41
	@Bean(name = "viewResolver")
44
	@Bean(name = "viewResolver")
42
	public InternalResourceViewResolver getViewResolver() {
45
	public InternalResourceViewResolver getViewResolver() {
43
		LOGGER.debug("creating view resolver bean with prefix : "+PATH_PREFIX+" and suffix : "+PATH_SUFFIX);
46
		LOGGER.debug("creating view resolver bean with prefix : " + PATH_PREFIX + " and suffix : " + PATH_SUFFIX);
44
		InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
47
		InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
45
		viewResolver.setPrefix(PATH_PREFIX);
48
		viewResolver.setPrefix(PATH_PREFIX);
46
		viewResolver.setSuffix(PATH_SUFFIX);
49
		viewResolver.setSuffix(PATH_SUFFIX);
47
		return viewResolver;
50
		return viewResolver;
48
	}
51
	}
49
 
52
 
50
	@Bean(name="messageSource")
53
	@Bean(name = "messageSource")
51
	public ReloadableResourceBundleMessageSource getReloadableResourceBundleMessageSource() {
54
	public ReloadableResourceBundleMessageSource getReloadableResourceBundleMessageSource() {
52
		LOGGER.debug("creating messageSource bean with message path source name : "+MESSAGE_PATH_SOURCE_NAME);
55
		LOGGER.debug("creating messageSource bean with message path source name : " + MESSAGE_PATH_SOURCE_NAME);
53
		ReloadableResourceBundleMessageSource messageSource=new ReloadableResourceBundleMessageSource();
56
		ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
54
		messageSource.setBasename(MESSAGE_PATH_SOURCE_NAME);
57
		messageSource.setBasename(MESSAGE_PATH_SOURCE_NAME);
55
		return messageSource;
58
		return messageSource;
56
	}
59
	}
57
 
60
 
58
	@Bean(name="multipartResolver")
61
	@Bean(name = "multipartResolver")
59
	public CommonsMultipartResolver getCommonsMultipartResolver() {
62
	public CommonsMultipartResolver getCommonsMultipartResolver() {
60
		LOGGER.info("creating common multipart resolver bean");
63
		LOGGER.info("creating common multipart resolver bean");
61
		CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
64
		CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
62
		multipartResolver.setMaxUploadSizePerFile(5000000);
65
		multipartResolver.setMaxUploadSizePerFile(5000000);
63
		multipartResolver.setMaxUploadSize(5000000);
66
		multipartResolver.setMaxUploadSize(5000000);
Line 66... Line 69...
66
 
69
 
67
	@Bean
70
	@Bean
68
	public PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
71
	public PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
69
		String activeProfile;
72
		String activeProfile;
70
 
73
 
71
		PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer =  new PropertySourcesPlaceholderConfigurer();
74
		PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
72
		
75
 
73
		Properties properties = new Properties();
76
		Properties properties = new Properties();
74
		try {
77
		try {
75
			properties.load(this.getClass().getClassLoader().getResourceAsStream("META-INF/env.property"));
78
			properties.load(this.getClass().getClassLoader().getResourceAsStream("META-INF/env.property"));
76
		} catch (IOException e) {
79
		} catch (IOException e) {
77
			LOGGER.error("Error in reading env property file.Adding default property"+e);
80
			LOGGER.error("Error in reading env property file.Adding default property" + e);
78
			properties.put("profile", "dev");
81
			properties.put("profile", "dev");
79
		}
82
		}
80
		activeProfile = (String) properties.get("profile");
83
		activeProfile = (String) properties.get("profile");
81
		
-
 
82
 
84
 
83
		if ("prod".equals(activeProfile)) {
85
		if ("prod".equals(activeProfile)) {
84
			resource = new ClassPathResource("/META-INF/prod.properties");
86
			resource = new ClassPathResource("/META-INF/prod.properties");
85
		} else if ("staging".equals(activeProfile)) {
87
		} else if ("staging".equals(activeProfile)) {
86
			resource = new ClassPathResource("/META-INF/staging.properties");
88
			resource = new ClassPathResource("/META-INF/staging.properties");
Line 90... Line 92...
90
 
92
 
91
		propertySourcesPlaceholderConfigurer.setLocation(resource);
93
		propertySourcesPlaceholderConfigurer.setLocation(resource);
92
 
94
 
93
		return propertySourcesPlaceholderConfigurer;
95
		return propertySourcesPlaceholderConfigurer;
94
	}
96
	}
95
	
97
 
96
	@Bean(name="mailSender")
98
	@Bean(name = "mailSender")
97
    public JavaMailSender getGmailSender(){
99
	public JavaMailSender getGmailSender() {
98
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
100
		JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
99
         
101
 
100
        //Using gmail
102
		// Using gmail
101
        mailSender.setHost("smtp.sendgrid.net");
103
		mailSender.setHost("smtp.sendgrid.net");
102
        mailSender.setPort(587);
104
		mailSender.setPort(587);
103
        mailSender.setUsername("shop2020");
105
		mailSender.setUsername("shop2020");
104
        mailSender.setPassword("U2/=fP,t");
106
		mailSender.setPassword("U2/=fP,t");
105
         
107
 
106
        Properties javaMailProperties = new Properties();
108
		Properties javaMailProperties = new Properties();
107
        javaMailProperties.put("mail.smtp.starttls.enable", "false");
109
		javaMailProperties.put("mail.smtp.starttls.enable", "false");
108
        javaMailProperties.put("mail.smtp.auth", "true");
110
		javaMailProperties.put("mail.smtp.auth", "true");
109
        javaMailProperties.put("mail.transport.protocol", "smtp");
111
		javaMailProperties.put("mail.transport.protocol", "smtp");
110
        javaMailProperties.put("mail.debug", "true");//Prints out everything on screen
112
		javaMailProperties.put("mail.debug", "true");// Prints out everything on screen
111
         
113
 
112
        mailSender.setJavaMailProperties(javaMailProperties);
114
		mailSender.setJavaMailProperties(javaMailProperties);
113
        return mailSender;
115
		return mailSender;
114
    }
116
	}
-
 
117
 
-
 
118
	@Bean(name = "gson")
-
 
119
	public Gson gson() {
-
 
120
 
-
 
121
		Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls()
-
 
122
				.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeJsonConverter()).create();
-
 
123
 
-
 
124
		return gson;
-
 
125
 
115
	
126
	}
116
	
127
 
117
}
128
}
118
129