Subversion Repositories SmartDukaan

Rev

Rev 23869 | Rev 24072 | 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
 
3
import java.io.IOException;
23869 amit.gupta 4
import java.time.format.DateTimeFormatter;
5
import java.util.HashMap;
6
import java.util.Map;
21555 kshitij.so 7
import java.util.Properties;
8
 
23869 amit.gupta 9
import org.apache.logging.log4j.LogManager;
23568 govind 10
import org.apache.logging.log4j.Logger;
21555 kshitij.so 11
import org.springframework.context.annotation.Bean;
12
import org.springframework.context.annotation.ComponentScan;
13
import org.springframework.context.annotation.Configuration;
14
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
15
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
16
import org.springframework.core.io.ClassPathResource;
17
import org.springframework.core.io.Resource;
23985 tejbeer 18
import org.springframework.mail.javamail.JavaMailSender;
19
import org.springframework.mail.javamail.JavaMailSenderImpl;
21555 kshitij.so 20
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
21625 kshitij.so 21
import org.springframework.web.servlet.ViewResolver;
22
import org.springframework.web.servlet.view.velocity.VelocityConfigurer;
23
import org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver;
21555 kshitij.so 24
 
21625 kshitij.so 25
@SuppressWarnings("deprecation")
21555 kshitij.so 26
@Configuration
27
@ComponentScan("com.spice.profitmandi.*")
28
public class AppConfig {
29
 
21625 kshitij.so 30
	private static final String VELOCITY_PATH_PREFIX="/WEB-INF/views/ftl/";
31
	private static final String VELOCITY_PATH_SUFFIX=".vm";
21555 kshitij.so 32
	private static final String MESSAGE_PATH_SOURCE_NAME="classpath:message";
23568 govind 33
	private static final Logger LOGGER=LogManager.getLogger(AppConfig.class);
21555 kshitij.so 34
	private static Resource resource;
22171 amit.gupta 35
 
21555 kshitij.so 36
	public static Resource getResource() {
37
		return resource;
38
	}
39
 
40
	public void setResource(Resource resource) {
41
		AppConfig.resource = resource;
42
	}
21625 kshitij.so 43
 
44
	@Bean
45
	public ViewResolver viewResolver()
46
	{
47
		VelocityLayoutViewResolver bean = new VelocityLayoutViewResolver();
48
		bean.setPrefix("");
49
		bean.setSuffix(VELOCITY_PATH_SUFFIX);
22108 amit.gupta 50
		bean.setRequestContextAttribute("rc");
23869 amit.gupta 51
		Map<String, Object> attributesMap = new HashMap<>();
52
		DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
53
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
54
		attributesMap.put("dateFormatter", dateFormatter);
55
		attributesMap.put("dateTimeFormatter", dateTimeFormatter);
56
		bean.setAttributesMap(attributesMap);
21625 kshitij.so 57
		return bean;
21555 kshitij.so 58
	}
21625 kshitij.so 59
 
21555 kshitij.so 60
	@Bean
21625 kshitij.so 61
	public VelocityConfigurer velocityConfig() {
62
		VelocityConfigurer velocityConfigurer = new VelocityConfigurer();
63
		velocityConfigurer.setResourceLoaderPath(VELOCITY_PATH_PREFIX);
64
		return velocityConfigurer;
21555 kshitij.so 65
	}
66
 
67
	@Bean(name="messageSource")
68
	public ReloadableResourceBundleMessageSource getReloadableResourceBundleMessageSource() {
69
		LOGGER.debug("creating messageSource bean with message path source name : "+MESSAGE_PATH_SOURCE_NAME);
70
		ReloadableResourceBundleMessageSource messageSource=new ReloadableResourceBundleMessageSource();
71
		messageSource.setBasename(MESSAGE_PATH_SOURCE_NAME);
72
		return messageSource;
73
	}
74
 
75
	@Bean(name="multipartResolver")
76
	public CommonsMultipartResolver getCommonsMultipartResolver() {
77
		LOGGER.info("creating common multipart resolver bean");
78
		return new CommonsMultipartResolver();
79
	}
80
 
81
	@Bean
82
	public PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
83
		String activeProfile;
84
 
85
		PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer =  new PropertySourcesPlaceholderConfigurer();
21625 kshitij.so 86
 
21555 kshitij.so 87
		Properties properties = new Properties();
88
		try {
89
			properties.load(this.getClass().getClassLoader().getResourceAsStream("META-INF/env.property"));
90
		} catch (IOException e) {
91
			LOGGER.error("Error in reading env property file.Adding default property"+e);
92
			properties.put("profile", "dev");
93
		}
94
		activeProfile = (String) properties.get("profile");
95
 
21625 kshitij.so 96
 
21555 kshitij.so 97
		if ("prod".equals(activeProfile)) {
98
			resource = new ClassPathResource("/META-INF/prod.properties");
99
		} else if ("staging".equals(activeProfile)) {
100
			resource = new ClassPathResource("/META-INF/staging.properties");
101
		} else {
102
			resource = new ClassPathResource("/META-INF/dev.properties");
103
		}
104
 
105
		propertySourcesPlaceholderConfigurer.setLocation(resource);
106
 
107
		return propertySourcesPlaceholderConfigurer;
108
	}
23985 tejbeer 109
 
110
	@Bean(name="mailSender")
111
    public JavaMailSender getGmailSender(){
112
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
113
 
114
        //Using gmail
115
        mailSender.setHost("smtp.sendgrid.net");
116
        mailSender.setPort(587);
117
        mailSender.setUsername("shop2020");
118
        mailSender.setPassword("U2/=fP,t");
119
 
120
        Properties javaMailProperties = new Properties();
121
        javaMailProperties.put("mail.smtp.starttls.enable", "false");
122
        javaMailProperties.put("mail.smtp.auth", "true");
123
        javaMailProperties.put("mail.transport.protocol", "smtp");
124
        javaMailProperties.put("mail.debug", "true");//Prints out everything on screen
125
 
126
        mailSender.setJavaMailProperties(javaMailProperties);
127
        return mailSender;
128
    }
129
 
130
 
21625 kshitij.so 131
 
21555 kshitij.so 132
}