| 21561 |
ashik.ali |
1 |
package com.spice.profitmandi.web.config;
|
| 21555 |
kshitij.so |
2 |
|
|
|
3 |
import java.io.IOException;
|
| 25300 |
tejbeer |
4 |
import java.time.LocalDateTime;
|
| 23869 |
amit.gupta |
5 |
import java.time.format.DateTimeFormatter;
|
|
|
6 |
import java.util.HashMap;
|
|
|
7 |
import java.util.Map;
|
| 21555 |
kshitij.so |
8 |
import java.util.Properties;
|
|
|
9 |
|
| 23869 |
amit.gupta |
10 |
import org.apache.logging.log4j.LogManager;
|
| 23568 |
govind |
11 |
import org.apache.logging.log4j.Logger;
|
| 21555 |
kshitij.so |
12 |
import org.springframework.context.annotation.Bean;
|
|
|
13 |
import org.springframework.context.annotation.ComponentScan;
|
|
|
14 |
import org.springframework.context.annotation.Configuration;
|
|
|
15 |
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
|
|
16 |
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
|
|
|
17 |
import org.springframework.core.io.ClassPathResource;
|
|
|
18 |
import org.springframework.core.io.Resource;
|
| 23985 |
tejbeer |
19 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
20 |
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
| 21555 |
kshitij.so |
21 |
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
| 21625 |
kshitij.so |
22 |
import org.springframework.web.servlet.ViewResolver;
|
| 24507 |
amit.gupta |
23 |
import org.springframework.web.servlet.view.BeanNameViewResolver;
|
| 21625 |
kshitij.so |
24 |
import org.springframework.web.servlet.view.velocity.VelocityConfigurer;
|
|
|
25 |
import org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver;
|
| 21555 |
kshitij.so |
26 |
|
| 25300 |
tejbeer |
27 |
import com.google.gson.Gson;
|
|
|
28 |
import com.google.gson.GsonBuilder;
|
|
|
29 |
import com.spice.profitmandi.dao.convertor.LocalDateTimeJsonConverter;
|
|
|
30 |
|
| 21625 |
kshitij.so |
31 |
@SuppressWarnings("deprecation")
|
| 21555 |
kshitij.so |
32 |
@Configuration
|
|
|
33 |
@ComponentScan("com.spice.profitmandi.*")
|
|
|
34 |
public class AppConfig {
|
|
|
35 |
|
| 24639 |
tejbeer |
36 |
private static final String VELOCITY_PATH_PREFIX = "/WEB-INF/views/ftl/";
|
|
|
37 |
private static final String VELOCITY_PATH_SUFFIX = ".vm";
|
|
|
38 |
private static final String MESSAGE_PATH_SOURCE_NAME = "classpath:message";
|
|
|
39 |
private static final Logger LOGGER = LogManager.getLogger(AppConfig.class);
|
| 21555 |
kshitij.so |
40 |
private static Resource resource;
|
| 24639 |
tejbeer |
41 |
|
| 21555 |
kshitij.so |
42 |
public static Resource getResource() {
|
|
|
43 |
return resource;
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
public void setResource(Resource resource) {
|
|
|
47 |
AppConfig.resource = resource;
|
|
|
48 |
}
|
| 21625 |
kshitij.so |
49 |
|
|
|
50 |
@Bean
|
| 24639 |
tejbeer |
51 |
public ViewResolver viewResolver() {
|
| 21625 |
kshitij.so |
52 |
VelocityLayoutViewResolver bean = new VelocityLayoutViewResolver();
|
|
|
53 |
bean.setPrefix("");
|
|
|
54 |
bean.setSuffix(VELOCITY_PATH_SUFFIX);
|
| 22108 |
amit.gupta |
55 |
bean.setRequestContextAttribute("rc");
|
| 23869 |
amit.gupta |
56 |
Map<String, Object> attributesMap = new HashMap<>();
|
|
|
57 |
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
|
| 25213 |
amit.gupta |
58 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy H:m");
|
| 23869 |
amit.gupta |
59 |
attributesMap.put("dateFormatter", dateFormatter);
|
|
|
60 |
attributesMap.put("dateTimeFormatter", dateTimeFormatter);
|
| 25689 |
amit.gupta |
61 |
attributesMap.put("version", "63");
|
| 25290 |
amit.gupta |
62 |
attributesMap.put("cssVersion", "8");
|
| 23869 |
amit.gupta |
63 |
bean.setAttributesMap(attributesMap);
|
| 21625 |
kshitij.so |
64 |
return bean;
|
| 21555 |
kshitij.so |
65 |
}
|
| 21625 |
kshitij.so |
66 |
|
| 24639 |
tejbeer |
67 |
@Bean
|
|
|
68 |
public ViewResolver beanNameViewResolver() {
|
|
|
69 |
BeanNameViewResolver resolver = new BeanNameViewResolver();
|
|
|
70 |
return resolver;
|
|
|
71 |
}
|
| 24507 |
amit.gupta |
72 |
|
| 21555 |
kshitij.so |
73 |
@Bean
|
| 21625 |
kshitij.so |
74 |
public VelocityConfigurer velocityConfig() {
|
|
|
75 |
VelocityConfigurer velocityConfigurer = new VelocityConfigurer();
|
|
|
76 |
velocityConfigurer.setResourceLoaderPath(VELOCITY_PATH_PREFIX);
|
|
|
77 |
return velocityConfigurer;
|
| 21555 |
kshitij.so |
78 |
}
|
|
|
79 |
|
| 24639 |
tejbeer |
80 |
@Bean(name = "messageSource")
|
| 21555 |
kshitij.so |
81 |
public ReloadableResourceBundleMessageSource getReloadableResourceBundleMessageSource() {
|
| 24639 |
tejbeer |
82 |
LOGGER.debug("creating messageSource bean with message path source name : " + MESSAGE_PATH_SOURCE_NAME);
|
|
|
83 |
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
|
| 21555 |
kshitij.so |
84 |
messageSource.setBasename(MESSAGE_PATH_SOURCE_NAME);
|
|
|
85 |
return messageSource;
|
|
|
86 |
}
|
|
|
87 |
|
| 24639 |
tejbeer |
88 |
@Bean(name = "multipartResolver")
|
| 21555 |
kshitij.so |
89 |
public CommonsMultipartResolver getCommonsMultipartResolver() {
|
|
|
90 |
LOGGER.info("creating common multipart resolver bean");
|
|
|
91 |
return new CommonsMultipartResolver();
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
@Bean
|
|
|
95 |
public PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
|
|
|
96 |
String activeProfile;
|
|
|
97 |
|
| 24639 |
tejbeer |
98 |
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
|
| 21625 |
kshitij.so |
99 |
|
| 21555 |
kshitij.so |
100 |
Properties properties = new Properties();
|
|
|
101 |
try {
|
|
|
102 |
properties.load(this.getClass().getClassLoader().getResourceAsStream("META-INF/env.property"));
|
|
|
103 |
} catch (IOException e) {
|
| 24639 |
tejbeer |
104 |
LOGGER.error("Error in reading env property file.Adding default property" + e);
|
| 21555 |
kshitij.so |
105 |
properties.put("profile", "dev");
|
|
|
106 |
}
|
|
|
107 |
activeProfile = (String) properties.get("profile");
|
|
|
108 |
|
|
|
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 |
}
|
| 21625 |
kshitij.so |
121 |
|
| 24639 |
tejbeer |
122 |
@Bean(name = "mailSender")
|
| 25091 |
amit.gupta |
123 |
public JavaMailSender getSendgridMailSender() {
|
| 24639 |
tejbeer |
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
|
|
|
137 |
// screen
|
|
|
138 |
|
|
|
139 |
mailSender.setJavaMailProperties(javaMailProperties);
|
|
|
140 |
return mailSender;
|
|
|
141 |
}
|
|
|
142 |
|
| 25300 |
tejbeer |
143 |
@Bean(name = "gson")
|
|
|
144 |
public Gson gson() {
|
|
|
145 |
|
|
|
146 |
Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls()
|
|
|
147 |
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeJsonConverter()).create();
|
|
|
148 |
|
|
|
149 |
return gson;
|
|
|
150 |
|
|
|
151 |
}
|
|
|
152 |
|
| 21555 |
kshitij.so |
153 |
}
|