Subversion Repositories SmartDukaan

Rev

Rev 32978 | 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();
31514 amit.gupta 105
		// Using gmail
106
		mailSender.setHost("smtp.gmail.com");
107
		mailSender.setPort(587);
108
		mailSender.setUsername("build@shop2020.in");
109
		mailSender.setPassword("cafe@nes");
25300 tejbeer 110
 
31514 amit.gupta 111
		Properties javaMailProperties = new Properties();
112
		javaMailProperties.put("mail.smtp.starttls.enable", "true");
113
		javaMailProperties.put("mail.smtp.auth", "true");
114
		javaMailProperties.put("mail.transport.protocol", "smtp");
115
		javaMailProperties.put("mail.debug", "true");// Prints out everything on screen
116
		mailSender.setJavaMailProperties(javaMailProperties);
117
		return mailSender;
118
	}
119
 
31525 amit.gupta 120
	@Bean(name = "mailSender")
31514 amit.gupta 121
	public JavaMailSender getSendgridMailSender() {
34634 ranu 122
		return googleMailSender();
123
	}
124
 
125
	/*@Bean(name = "mailSender")
126
	public JavaMailSender getSendgridMailSender() {
31514 amit.gupta 127
		JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
128
 
25300 tejbeer 129
		// Using gmail
130
		mailSender.setHost("smtp.sendgrid.net");
131
		mailSender.setPort(587);
27626 amit.gupta 132
		mailSender.setUsername("apikey");
133
		mailSender.setPassword("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");
25300 tejbeer 134
 
135
		Properties javaMailProperties = new Properties();
136
		javaMailProperties.put("mail.smtp.starttls.enable", "false");
137
		javaMailProperties.put("mail.smtp.auth", "true");
138
		javaMailProperties.put("mail.transport.protocol", "smtp");
139
		javaMailProperties.put("mail.debug", "true");// Prints out everything on screen
140
 
141
		mailSender.setJavaMailProperties(javaMailProperties);
142
		return mailSender;
34634 ranu 143
	}*/
25300 tejbeer 144
 
145
	@Bean(name = "gson")
146
	public Gson gson() {
147
 
148
		Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls()
29637 amit.gupta 149
				.registerTypeAdapter(LocalDate.class, new LocalDateJsonConverter())
150
				.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeJsonConverter())
151
				.create();
25300 tejbeer 152
 
153
		return gson;
154
 
155
	}
156
 
27028 tejbeer 157
	@Bean(name = "veloctyEngine")
158
	public VelocityEngine velocityEngine() throws VelocityException, IOException {
159
		VelocityEngineFactoryBean factory = new VelocityEngineFactoryBean();
160
		// Properties props = new Properties();
161
		// props.put("resource.loader", "file");
162
 
163
		// props.put("file.resource.loader.description", "Velocity File Resource
164
		// Loader");
165
		// props.put("file.resource.loader.class",
166
		// "org.apache.velocity.runtime.resource.loader.FileResourceLoader");
167
		// props.put("file.resource.loader.cache", true);
168
		// props.put("file.resource.loader.path", ".");
169
 
170
		Properties velocityProperties = new Properties();
171
		velocityProperties.put("resource.loader", "class");
172
		velocityProperties.put("class.resource.loader.class",
173
				"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
174
		velocityProperties.put("file.resource.loader.cache", true);
175
		velocityProperties.put("file.resource.loader.unicode", true);
176
		velocityProperties.put("input.encoding", "UTF-8");
177
		velocityProperties.put("output.encoding", "UTF-8");
178
		velocityProperties.put("overrideLogging", true);
179
 
180
	//	velocityProperties.put("file.resource.loader.path", ".");
181
 
182
		factory.setVelocityProperties(velocityProperties);
183
 
184
		return factory.createVelocityEngine();
185
 
186
	}
21165 ashik.ali 187
}