Subversion Repositories SmartDukaan

Rev

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