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