Subversion Repositories SmartDukaan

Rev

Rev 24412 | Rev 24435 | 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);
24418 amit.gupta 56
		attributesMap.put("version", "27");
23869 amit.gupta 57
		bean.setAttributesMap(attributesMap);
21625 kshitij.so 58
		return bean;
21555 kshitij.so 59
	}
21625 kshitij.so 60
 
21555 kshitij.so 61
	@Bean
21625 kshitij.so 62
	public VelocityConfigurer velocityConfig() {
63
		VelocityConfigurer velocityConfigurer = new VelocityConfigurer();
64
		velocityConfigurer.setResourceLoaderPath(VELOCITY_PATH_PREFIX);
65
		return velocityConfigurer;
21555 kshitij.so 66
	}
67
 
68
	@Bean(name="messageSource")
69
	public ReloadableResourceBundleMessageSource getReloadableResourceBundleMessageSource() {
70
		LOGGER.debug("creating messageSource bean with message path source name : "+MESSAGE_PATH_SOURCE_NAME);
71
		ReloadableResourceBundleMessageSource messageSource=new ReloadableResourceBundleMessageSource();
72
		messageSource.setBasename(MESSAGE_PATH_SOURCE_NAME);
73
		return messageSource;
74
	}
75
 
76
	@Bean(name="multipartResolver")
77
	public CommonsMultipartResolver getCommonsMultipartResolver() {
78
		LOGGER.info("creating common multipart resolver bean");
79
		return new CommonsMultipartResolver();
80
	}
81
 
82
	@Bean
83
	public PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
84
		String activeProfile;
85
 
86
		PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer =  new PropertySourcesPlaceholderConfigurer();
21625 kshitij.so 87
 
21555 kshitij.so 88
		Properties properties = new Properties();
89
		try {
90
			properties.load(this.getClass().getClassLoader().getResourceAsStream("META-INF/env.property"));
91
		} catch (IOException e) {
92
			LOGGER.error("Error in reading env property file.Adding default property"+e);
93
			properties.put("profile", "dev");
94
		}
95
		activeProfile = (String) properties.get("profile");
96
 
21625 kshitij.so 97
 
21555 kshitij.so 98
		if ("prod".equals(activeProfile)) {
99
			resource = new ClassPathResource("/META-INF/prod.properties");
100
		} else if ("staging".equals(activeProfile)) {
101
			resource = new ClassPathResource("/META-INF/staging.properties");
102
		} else {
103
			resource = new ClassPathResource("/META-INF/dev.properties");
104
		}
105
 
106
		propertySourcesPlaceholderConfigurer.setLocation(resource);
107
 
108
		return propertySourcesPlaceholderConfigurer;
109
	}
23985 tejbeer 110
 
111
	@Bean(name="mailSender")
112
    public JavaMailSender getGmailSender(){
113
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
114
 
115
        //Using gmail
116
        mailSender.setHost("smtp.sendgrid.net");
117
        mailSender.setPort(587);
118
        mailSender.setUsername("shop2020");
119
        mailSender.setPassword("U2/=fP,t");
120
 
121
        Properties javaMailProperties = new Properties();
122
        javaMailProperties.put("mail.smtp.starttls.enable", "false");
123
        javaMailProperties.put("mail.smtp.auth", "true");
124
        javaMailProperties.put("mail.transport.protocol", "smtp");
125
        javaMailProperties.put("mail.debug", "true");//Prints out everything on screen
126
 
127
        mailSender.setJavaMailProperties(javaMailProperties);
128
        return mailSender;
129
    }
21625 kshitij.so 130
 
21555 kshitij.so 131
}