Subversion Repositories SmartDukaan

Rev

Rev 37369 | Rev 37475 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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