Subversion Repositories SmartDukaan

Rev

Rev 34635 | 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;
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
 
89
		if ("prod".equals(activeProfile)) {
90
			resource = new ClassPathResource("/META-INF/prod.properties");
91
		} else if ("staging".equals(activeProfile)) {
21342 kshitij.so 92
			resource = new ClassPathResource("/META-INF/staging.properties");
21304 kshitij.so 93
		} else {
94
			resource = new ClassPathResource("/META-INF/dev.properties");
95
		}
96
 
97
		propertySourcesPlaceholderConfigurer.setLocation(resource);
98
 
99
		return propertySourcesPlaceholderConfigurer;
100
	}
25300 tejbeer 101
 
32978 amit.gupta 102
	@Bean
31514 amit.gupta 103
	public JavaMailSender googleMailSender() {
25300 tejbeer 104
		JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
34635 ranu 105
		mailSender.setHost("smtp.gmail.com");
106
		mailSender.setPort(465);
107
		mailSender.setUsername("sdtech@smartdukaan.com");
108
		mailSender.setPassword("gpdschroalhhirox"); // App Password
109
 
110
		Properties props = mailSender.getJavaMailProperties();
111
		props.put("mail.smtp.auth", "true");
112
		props.put("mail.smtp.ssl.enable", "true");
113
		props.put("mail.smtp.ssl.trust", "smtp.gmail.com");
114
		props.put("mail.smtp.socketFactory.port", "465");
115
		props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
116
		props.put("mail.debug", "true");
117
 
118
		return mailSender;
119
	}
120
 
121
	/*@Bean
122
	public JavaMailSender googleMailSender() {
123
		JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
31514 amit.gupta 124
		// Using gmail
125
		mailSender.setHost("smtp.gmail.com");
126
		mailSender.setPort(587);
127
		mailSender.setUsername("build@shop2020.in");
128
		mailSender.setPassword("cafe@nes");
25300 tejbeer 129
 
31514 amit.gupta 130
		Properties javaMailProperties = new Properties();
131
		javaMailProperties.put("mail.smtp.starttls.enable", "true");
132
		javaMailProperties.put("mail.smtp.auth", "true");
133
		javaMailProperties.put("mail.transport.protocol", "smtp");
134
		javaMailProperties.put("mail.debug", "true");// Prints out everything on screen
135
		mailSender.setJavaMailProperties(javaMailProperties);
136
		return mailSender;
34635 ranu 137
	}*/
31514 amit.gupta 138
 
34711 amit.gupta 139
	/*@Bean(name = "mailSender")
31514 amit.gupta 140
	public JavaMailSender getSendgridMailSender() {
34634 ranu 141
		return googleMailSender();
34711 amit.gupta 142
	}*/
34634 ranu 143
 
34711 amit.gupta 144
	@Bean(name = "mailSender")
34634 ranu 145
	public JavaMailSender getSendgridMailSender() {
31514 amit.gupta 146
		JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
147
 
25300 tejbeer 148
		// Using gmail
149
		mailSender.setHost("smtp.sendgrid.net");
150
		mailSender.setPort(587);
27626 amit.gupta 151
		mailSender.setUsername("apikey");
34711 amit.gupta 152
		mailSender.setPassword("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");
25300 tejbeer 153
 
154
		Properties javaMailProperties = new Properties();
155
		javaMailProperties.put("mail.smtp.starttls.enable", "false");
156
		javaMailProperties.put("mail.smtp.auth", "true");
157
		javaMailProperties.put("mail.transport.protocol", "smtp");
158
		javaMailProperties.put("mail.debug", "true");// Prints out everything on screen
159
 
160
		mailSender.setJavaMailProperties(javaMailProperties);
161
		return mailSender;
34711 amit.gupta 162
	}
25300 tejbeer 163
 
164
	@Bean(name = "gson")
165
	public Gson gson() {
166
 
167
		Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls()
29637 amit.gupta 168
				.registerTypeAdapter(LocalDate.class, new LocalDateJsonConverter())
169
				.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeJsonConverter())
170
				.create();
25300 tejbeer 171
 
172
		return gson;
173
 
174
	}
175
 
27028 tejbeer 176
	@Bean(name = "veloctyEngine")
177
	public VelocityEngine velocityEngine() throws VelocityException, IOException {
178
		VelocityEngineFactoryBean factory = new VelocityEngineFactoryBean();
179
		// Properties props = new Properties();
180
		// props.put("resource.loader", "file");
181
 
182
		// props.put("file.resource.loader.description", "Velocity File Resource
183
		// Loader");
184
		// props.put("file.resource.loader.class",
185
		// "org.apache.velocity.runtime.resource.loader.FileResourceLoader");
186
		// props.put("file.resource.loader.cache", true);
187
		// props.put("file.resource.loader.path", ".");
188
 
189
		Properties velocityProperties = new Properties();
190
		velocityProperties.put("resource.loader", "class");
191
		velocityProperties.put("class.resource.loader.class",
192
				"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
193
		velocityProperties.put("file.resource.loader.cache", true);
194
		velocityProperties.put("file.resource.loader.unicode", true);
195
		velocityProperties.put("input.encoding", "UTF-8");
196
		velocityProperties.put("output.encoding", "UTF-8");
197
		velocityProperties.put("overrideLogging", true);
198
 
199
	//	velocityProperties.put("file.resource.loader.path", ".");
200
 
201
		factory.setVelocityProperties(velocityProperties);
202
 
203
		return factory.createVelocityEngine();
204
 
205
	}
21165 ashik.ali 206
}