| 24472 |
amit.gupta |
1 |
|
| 21165 |
ashik.ali |
2 |
package com.spice.profitmandi.web.config;
|
|
|
3 |
|
| 21343 |
kshitij.so |
4 |
import java.io.IOException;
|
| 29637 |
amit.gupta |
5 |
import java.time.LocalDate;
|
| 25300 |
tejbeer |
6 |
import java.time.LocalDateTime;
|
| 21343 |
kshitij.so |
7 |
import java.util.Properties;
|
|
|
8 |
|
| 24472 |
amit.gupta |
9 |
import org.apache.logging.log4j.LogManager;
|
| 23568 |
govind |
10 |
import org.apache.logging.log4j.Logger;
|
| 27028 |
tejbeer |
11 |
import org.apache.velocity.app.VelocityEngine;
|
|
|
12 |
import org.apache.velocity.exception.VelocityException;
|
| 21165 |
ashik.ali |
13 |
import org.springframework.context.annotation.Bean;
|
|
|
14 |
import org.springframework.context.annotation.ComponentScan;
|
|
|
15 |
import org.springframework.context.annotation.Configuration;
|
| 21304 |
kshitij.so |
16 |
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
| 21165 |
ashik.ali |
17 |
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
|
| 21304 |
kshitij.so |
18 |
import org.springframework.core.io.ClassPathResource;
|
|
|
19 |
import org.springframework.core.io.Resource;
|
| 22398 |
amit.gupta |
20 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
21 |
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
| 27028 |
tejbeer |
22 |
import org.springframework.ui.velocity.VelocityEngineFactoryBean;
|
| 21165 |
ashik.ali |
23 |
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
|
|
24 |
|
| 25300 |
tejbeer |
25 |
import com.google.gson.Gson;
|
|
|
26 |
import com.google.gson.GsonBuilder;
|
| 29637 |
amit.gupta |
27 |
import com.spice.profitmandi.dao.convertor.LocalDateJsonConverter;
|
| 25300 |
tejbeer |
28 |
import com.spice.profitmandi.dao.convertor.LocalDateTimeJsonConverter;
|
|
|
29 |
|
| 21165 |
ashik.ali |
30 |
@Configuration
|
|
|
31 |
@ComponentScan("com.spice.profitmandi.*")
|
|
|
32 |
public class AppConfig {
|
| 21304 |
kshitij.so |
33 |
|
| 25300 |
tejbeer |
34 |
private static final String PATH_PREFIX = "/WEB-INF/views/";
|
|
|
35 |
private static final String PATH_SUFFIX = ".jsp";
|
|
|
36 |
private static final String MESSAGE_PATH_SOURCE_NAME = "classpath:message";
|
|
|
37 |
private static final Logger LOGGER = LogManager.getLogger(AppConfig.class);
|
| 21362 |
kshitij.so |
38 |
private static Resource resource;
|
| 25300 |
tejbeer |
39 |
|
| 21362 |
kshitij.so |
40 |
public static Resource getResource() {
|
|
|
41 |
return resource;
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
public void setResource(Resource resource) {
|
|
|
45 |
AppConfig.resource = resource;
|
|
|
46 |
}
|
|
|
47 |
|
| 27028 |
tejbeer |
48 |
/*
|
|
|
49 |
* @Bean(name = "viewResolver") public InternalResourceViewResolver
|
|
|
50 |
* getViewResolver() { LOGGER.debug("creating view resolver bean with prefix : "
|
|
|
51 |
* + PATH_PREFIX + " and suffix : " + PATH_SUFFIX); InternalResourceViewResolver
|
|
|
52 |
* viewResolver = new InternalResourceViewResolver();
|
|
|
53 |
* viewResolver.setPrefix(PATH_PREFIX); viewResolver.setSuffix(PATH_SUFFIX);
|
|
|
54 |
* return viewResolver; }
|
|
|
55 |
*/
|
| 21304 |
kshitij.so |
56 |
|
| 25300 |
tejbeer |
57 |
@Bean(name = "messageSource")
|
| 21165 |
ashik.ali |
58 |
public ReloadableResourceBundleMessageSource getReloadableResourceBundleMessageSource() {
|
| 25300 |
tejbeer |
59 |
LOGGER.debug("creating messageSource bean with message path source name : " + MESSAGE_PATH_SOURCE_NAME);
|
|
|
60 |
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
|
| 21165 |
ashik.ali |
61 |
messageSource.setBasename(MESSAGE_PATH_SOURCE_NAME);
|
|
|
62 |
return messageSource;
|
|
|
63 |
}
|
| 21304 |
kshitij.so |
64 |
|
| 25300 |
tejbeer |
65 |
@Bean(name = "multipartResolver")
|
| 21165 |
ashik.ali |
66 |
public CommonsMultipartResolver getCommonsMultipartResolver() {
|
|
|
67 |
LOGGER.info("creating common multipart resolver bean");
|
| 24472 |
amit.gupta |
68 |
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
|
|
|
69 |
multipartResolver.setMaxUploadSizePerFile(5000000);
|
|
|
70 |
multipartResolver.setMaxUploadSize(5000000);
|
|
|
71 |
return multipartResolver;
|
| 21304 |
kshitij.so |
72 |
}
|
|
|
73 |
|
|
|
74 |
@Bean
|
| 21643 |
ashik.ali |
75 |
public PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
|
| 21304 |
kshitij.so |
76 |
String activeProfile;
|
|
|
77 |
|
| 25300 |
tejbeer |
78 |
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
|
|
|
79 |
|
| 21343 |
kshitij.so |
80 |
Properties properties = new Properties();
|
|
|
81 |
try {
|
|
|
82 |
properties.load(this.getClass().getClassLoader().getResourceAsStream("META-INF/env.property"));
|
|
|
83 |
} catch (IOException e) {
|
| 25300 |
tejbeer |
84 |
LOGGER.error("Error in reading env property file.Adding default property" + e);
|
| 21343 |
kshitij.so |
85 |
properties.put("profile", "dev");
|
|
|
86 |
}
|
|
|
87 |
activeProfile = (String) properties.get("profile");
|
| 21304 |
kshitij.so |
88 |
|
| 35385 |
amit |
89 |
Resource appResource;
|
|
|
90 |
Resource sharedResource;
|
|
|
91 |
|
| 21304 |
kshitij.so |
92 |
if ("prod".equals(activeProfile)) {
|
| 35385 |
amit |
93 |
appResource = new ClassPathResource("/META-INF/prod.properties");
|
|
|
94 |
sharedResource = new ClassPathResource("/shared-prod.properties");
|
| 21304 |
kshitij.so |
95 |
} else if ("staging".equals(activeProfile)) {
|
| 35385 |
amit |
96 |
appResource = new ClassPathResource("/META-INF/staging.properties");
|
|
|
97 |
sharedResource = new ClassPathResource("/shared-staging.properties");
|
| 21304 |
kshitij.so |
98 |
} else {
|
| 35385 |
amit |
99 |
appResource = new ClassPathResource("/META-INF/dev.properties");
|
|
|
100 |
sharedResource = new ClassPathResource("/shared-dev.properties");
|
| 21304 |
kshitij.so |
101 |
}
|
|
|
102 |
|
| 35385 |
amit |
103 |
resource = appResource;
|
| 21304 |
kshitij.so |
104 |
|
| 35385 |
amit |
105 |
// Load shared properties from dao first, then app-specific (app-specific can override)
|
|
|
106 |
propertySourcesPlaceholderConfigurer.setLocations(sharedResource, appResource);
|
|
|
107 |
propertySourcesPlaceholderConfigurer.setIgnoreResourceNotFound(true);
|
|
|
108 |
|
| 21304 |
kshitij.so |
109 |
return propertySourcesPlaceholderConfigurer;
|
|
|
110 |
}
|
| 25300 |
tejbeer |
111 |
|
| 32978 |
amit.gupta |
112 |
@Bean
|
| 31514 |
amit.gupta |
113 |
public JavaMailSender googleMailSender() {
|
| 25300 |
tejbeer |
114 |
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
|
| 34635 |
ranu |
115 |
mailSender.setHost("smtp.gmail.com");
|
|
|
116 |
mailSender.setPort(465);
|
|
|
117 |
mailSender.setUsername("sdtech@smartdukaan.com");
|
|
|
118 |
mailSender.setPassword("gpdschroalhhirox"); // App Password
|
|
|
119 |
|
|
|
120 |
Properties props = mailSender.getJavaMailProperties();
|
|
|
121 |
props.put("mail.smtp.auth", "true");
|
|
|
122 |
props.put("mail.smtp.ssl.enable", "true");
|
|
|
123 |
props.put("mail.smtp.ssl.trust", "smtp.gmail.com");
|
|
|
124 |
props.put("mail.smtp.socketFactory.port", "465");
|
|
|
125 |
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
|
|
|
126 |
props.put("mail.debug", "true");
|
|
|
127 |
|
|
|
128 |
return mailSender;
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
/*@Bean
|
|
|
132 |
public JavaMailSender googleMailSender() {
|
|
|
133 |
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
|
| 31514 |
amit.gupta |
134 |
// Using gmail
|
|
|
135 |
mailSender.setHost("smtp.gmail.com");
|
|
|
136 |
mailSender.setPort(587);
|
|
|
137 |
mailSender.setUsername("build@shop2020.in");
|
|
|
138 |
mailSender.setPassword("cafe@nes");
|
| 25300 |
tejbeer |
139 |
|
| 31514 |
amit.gupta |
140 |
Properties javaMailProperties = new Properties();
|
|
|
141 |
javaMailProperties.put("mail.smtp.starttls.enable", "true");
|
|
|
142 |
javaMailProperties.put("mail.smtp.auth", "true");
|
|
|
143 |
javaMailProperties.put("mail.transport.protocol", "smtp");
|
|
|
144 |
javaMailProperties.put("mail.debug", "true");// Prints out everything on screen
|
|
|
145 |
mailSender.setJavaMailProperties(javaMailProperties);
|
|
|
146 |
return mailSender;
|
| 34635 |
ranu |
147 |
}*/
|
| 31514 |
amit.gupta |
148 |
|
| 34711 |
amit.gupta |
149 |
/*@Bean(name = "mailSender")
|
| 31514 |
amit.gupta |
150 |
public JavaMailSender getSendgridMailSender() {
|
| 34634 |
ranu |
151 |
return googleMailSender();
|
| 34711 |
amit.gupta |
152 |
}*/
|
| 34634 |
ranu |
153 |
|
| 34711 |
amit.gupta |
154 |
@Bean(name = "mailSender")
|
| 34634 |
ranu |
155 |
public JavaMailSender getSendgridMailSender() {
|
| 31514 |
amit.gupta |
156 |
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
|
|
|
157 |
|
| 25300 |
tejbeer |
158 |
// Using gmail
|
|
|
159 |
mailSender.setHost("smtp.sendgrid.net");
|
|
|
160 |
mailSender.setPort(587);
|
| 27626 |
amit.gupta |
161 |
mailSender.setUsername("apikey");
|
| 34711 |
amit.gupta |
162 |
mailSender.setPassword("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");
|
| 25300 |
tejbeer |
163 |
|
|
|
164 |
Properties javaMailProperties = new Properties();
|
|
|
165 |
javaMailProperties.put("mail.smtp.starttls.enable", "false");
|
|
|
166 |
javaMailProperties.put("mail.smtp.auth", "true");
|
|
|
167 |
javaMailProperties.put("mail.transport.protocol", "smtp");
|
|
|
168 |
javaMailProperties.put("mail.debug", "true");// Prints out everything on screen
|
|
|
169 |
|
|
|
170 |
mailSender.setJavaMailProperties(javaMailProperties);
|
|
|
171 |
return mailSender;
|
| 34711 |
amit.gupta |
172 |
}
|
| 25300 |
tejbeer |
173 |
|
|
|
174 |
@Bean(name = "gson")
|
|
|
175 |
public Gson gson() {
|
|
|
176 |
|
|
|
177 |
Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls()
|
| 29637 |
amit.gupta |
178 |
.registerTypeAdapter(LocalDate.class, new LocalDateJsonConverter())
|
|
|
179 |
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeJsonConverter())
|
|
|
180 |
.create();
|
| 25300 |
tejbeer |
181 |
|
|
|
182 |
return gson;
|
|
|
183 |
|
|
|
184 |
}
|
|
|
185 |
|
| 27028 |
tejbeer |
186 |
@Bean(name = "veloctyEngine")
|
|
|
187 |
public VelocityEngine velocityEngine() throws VelocityException, IOException {
|
|
|
188 |
VelocityEngineFactoryBean factory = new VelocityEngineFactoryBean();
|
|
|
189 |
// Properties props = new Properties();
|
|
|
190 |
// props.put("resource.loader", "file");
|
|
|
191 |
|
|
|
192 |
// props.put("file.resource.loader.description", "Velocity File Resource
|
|
|
193 |
// Loader");
|
|
|
194 |
// props.put("file.resource.loader.class",
|
|
|
195 |
// "org.apache.velocity.runtime.resource.loader.FileResourceLoader");
|
|
|
196 |
// props.put("file.resource.loader.cache", true);
|
|
|
197 |
// props.put("file.resource.loader.path", ".");
|
|
|
198 |
|
|
|
199 |
Properties velocityProperties = new Properties();
|
|
|
200 |
velocityProperties.put("resource.loader", "class");
|
|
|
201 |
velocityProperties.put("class.resource.loader.class",
|
|
|
202 |
"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
|
|
|
203 |
velocityProperties.put("file.resource.loader.cache", true);
|
|
|
204 |
velocityProperties.put("file.resource.loader.unicode", true);
|
|
|
205 |
velocityProperties.put("input.encoding", "UTF-8");
|
|
|
206 |
velocityProperties.put("output.encoding", "UTF-8");
|
|
|
207 |
velocityProperties.put("overrideLogging", true);
|
|
|
208 |
|
|
|
209 |
// velocityProperties.put("file.resource.loader.path", ".");
|
|
|
210 |
|
|
|
211 |
factory.setVelocityProperties(velocityProperties);
|
|
|
212 |
|
|
|
213 |
return factory.createVelocityEngine();
|
|
|
214 |
|
|
|
215 |
}
|
| 21165 |
ashik.ali |
216 |
}
|