Subversion Repositories SmartDukaan

Rev

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