Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
21561 ashik.ali 1
package com.spice.profitmandi.web.config;
21555 kshitij.so 2
 
3
import java.io.IOException;
23869 amit.gupta 4
import java.time.format.DateTimeFormatter;
5
import java.util.HashMap;
6
import java.util.Map;
21555 kshitij.so 7
import java.util.Properties;
8
 
23869 amit.gupta 9
import org.apache.logging.log4j.LogManager;
23568 govind 10
import org.apache.logging.log4j.Logger;
21555 kshitij.so 11
import org.springframework.context.annotation.Bean;
12
import org.springframework.context.annotation.ComponentScan;
13
import org.springframework.context.annotation.Configuration;
14
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
15
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
16
import org.springframework.core.io.ClassPathResource;
17
import org.springframework.core.io.Resource;
18
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
21625 kshitij.so 19
import org.springframework.web.servlet.ViewResolver;
20
import org.springframework.web.servlet.view.velocity.VelocityConfigurer;
21
import org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver;
21555 kshitij.so 22
 
21625 kshitij.so 23
@SuppressWarnings("deprecation")
21555 kshitij.so 24
@Configuration
25
@ComponentScan("com.spice.profitmandi.*")
26
public class AppConfig {
27
 
21625 kshitij.so 28
	private static final String VELOCITY_PATH_PREFIX="/WEB-INF/views/ftl/";
29
	private static final String VELOCITY_PATH_SUFFIX=".vm";
21555 kshitij.so 30
	private static final String MESSAGE_PATH_SOURCE_NAME="classpath:message";
23568 govind 31
	private static final Logger LOGGER=LogManager.getLogger(AppConfig.class);
21555 kshitij.so 32
	private static Resource resource;
22171 amit.gupta 33
 
21555 kshitij.so 34
	public static Resource getResource() {
35
		return resource;
36
	}
37
 
38
	public void setResource(Resource resource) {
39
		AppConfig.resource = resource;
40
	}
21625 kshitij.so 41
 
42
	@Bean
43
	public ViewResolver viewResolver()
44
	{
45
		VelocityLayoutViewResolver bean = new VelocityLayoutViewResolver();
46
		bean.setPrefix("");
47
		bean.setSuffix(VELOCITY_PATH_SUFFIX);
22108 amit.gupta 48
		bean.setRequestContextAttribute("rc");
23869 amit.gupta 49
		Map<String, Object> attributesMap = new HashMap<>();
50
		DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
51
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
52
		attributesMap.put("dateFormatter", dateFormatter);
53
		attributesMap.put("dateTimeFormatter", dateTimeFormatter);
54
		bean.setAttributesMap(attributesMap);
21625 kshitij.so 55
		return bean;
21555 kshitij.so 56
	}
21625 kshitij.so 57
 
21555 kshitij.so 58
	@Bean
21625 kshitij.so 59
	public VelocityConfigurer velocityConfig() {
60
		VelocityConfigurer velocityConfigurer = new VelocityConfigurer();
61
		velocityConfigurer.setResourceLoaderPath(VELOCITY_PATH_PREFIX);
62
		return velocityConfigurer;
21555 kshitij.so 63
	}
64
 
65
	@Bean(name="messageSource")
66
	public ReloadableResourceBundleMessageSource getReloadableResourceBundleMessageSource() {
67
		LOGGER.debug("creating messageSource bean with message path source name : "+MESSAGE_PATH_SOURCE_NAME);
68
		ReloadableResourceBundleMessageSource messageSource=new ReloadableResourceBundleMessageSource();
69
		messageSource.setBasename(MESSAGE_PATH_SOURCE_NAME);
70
		return messageSource;
71
	}
72
 
73
	@Bean(name="multipartResolver")
74
	public CommonsMultipartResolver getCommonsMultipartResolver() {
75
		LOGGER.info("creating common multipart resolver bean");
76
		return new CommonsMultipartResolver();
77
	}
78
 
79
	@Bean
80
	public PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
81
		String activeProfile;
82
 
83
		PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer =  new PropertySourcesPlaceholderConfigurer();
21625 kshitij.so 84
 
21555 kshitij.so 85
		Properties properties = new Properties();
86
		try {
87
			properties.load(this.getClass().getClassLoader().getResourceAsStream("META-INF/env.property"));
88
		} catch (IOException e) {
89
			LOGGER.error("Error in reading env property file.Adding default property"+e);
90
			properties.put("profile", "dev");
91
		}
92
		activeProfile = (String) properties.get("profile");
93
 
21625 kshitij.so 94
 
21555 kshitij.so 95
		if ("prod".equals(activeProfile)) {
96
			resource = new ClassPathResource("/META-INF/prod.properties");
97
		} else if ("staging".equals(activeProfile)) {
98
			resource = new ClassPathResource("/META-INF/staging.properties");
99
		} else {
100
			resource = new ClassPathResource("/META-INF/dev.properties");
101
		}
102
 
103
		propertySourcesPlaceholderConfigurer.setLocation(resource);
104
 
105
		return propertySourcesPlaceholderConfigurer;
106
	}
21625 kshitij.so 107
 
21555 kshitij.so 108
}