Subversion Repositories SmartDukaan

Rev

Rev 32051 | Rev 32065 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 32051 Rev 32054
Line 46... Line 46...
46
@Configuration
46
@Configuration
47
@ComponentScan("com.spice.profitmandi.*")
47
@ComponentScan("com.spice.profitmandi.*")
48
//@Import(RepositoryRestMvcConfiguration.class)
48
//@Import(RepositoryRestMvcConfiguration.class)
49
public class AppConfig {
49
public class AppConfig {
50
 
50
 
51
	private static final String VELOCITY_PATH_PREFIX = "/WEB-INF/views/ftl/";
51
    private static final String VELOCITY_PATH_PREFIX = "/WEB-INF/views/ftl/";
52
	private static final String VELOCITY_PATH_SUFFIX = ".vm";
52
    private static final String VELOCITY_PATH_SUFFIX = ".vm";
53
	private static final String MESSAGE_PATH_SOURCE_NAME = "classpath:message";
53
    private static final String MESSAGE_PATH_SOURCE_NAME = "classpath:message";
54
	private static final Logger LOGGER = LogManager.getLogger(AppConfig.class);
54
    private static final Logger LOGGER = LogManager.getLogger(AppConfig.class);
55
	private static Resource resource;
55
    private static Resource resource;
56
 
56
 
57
	public static Resource getResource() {
57
    public static Resource getResource() {
58
		return resource;
58
        return resource;
59
	}
59
    }
60
 
60
 
61
	public void setResource(Resource resource) {
61
    public void setResource(Resource resource) {
62
		AppConfig.resource = resource;
62
        AppConfig.resource = resource;
63
	}
63
    }
64
 
64
 
65
	@Bean(value = "velocityAttributesMap")
65
    @Bean(value = "velocityAttributesMap")
66
	public Map<String, Object> velocityAttributesMap() {
66
    public Map<String, Object> velocityAttributesMap() {
67
		Map<String, Object> attributesMap = new HashMap<>();
67
        Map<String, Object> attributesMap = new HashMap<>();
68
		DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
68
        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
69
		DateTimeFormatter dateMonthFormatter = DateTimeFormatter.ofPattern("dd''MMM");
69
        DateTimeFormatter dateMonthFormatter = DateTimeFormatter.ofPattern("dd''MMM");
70
		DateTimeFormatter datehiphenFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
70
        DateTimeFormatter datehiphenFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
71
		DateTimeFormatter dateMonthYearFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
71
        DateTimeFormatter dateMonthYearFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
72
		DateTimeFormatter dateYearMonthFormatter = DateTimeFormatter.ofPattern("MMM''uu");
72
        DateTimeFormatter dateYearMonthFormatter = DateTimeFormatter.ofPattern("MMM''uu");
73
 
73
 
74
		DateTimeFormatter dateMonthChYear = DateTimeFormatter.ofPattern("d''MMM''uu");
74
        DateTimeFormatter dateMonthChYear = DateTimeFormatter.ofPattern("d''MMM''uu");
75
		DecimalFormat decimalFormatter = new DecimalFormat("0.#");
75
        DecimalFormat decimalFormatter = new DecimalFormat("0.#");
76
 
76
 
77
		NumberFormat numberformat = NumberFormat.getNumberInstance(new Locale("en", "IN"));
77
        NumberFormat numberformat = NumberFormat.getNumberInstance(new Locale("en", "IN"));
78
 
78
 
79
		numberformat.setRoundingMode(RoundingMode.HALF_DOWN);
79
        numberformat.setRoundingMode(RoundingMode.HALF_DOWN);
80
		numberformat.setMaximumFractionDigits(2);
80
        numberformat.setMaximumFractionDigits(2);
81
		numberformat.setMinimumFractionDigits(0);
81
        numberformat.setMinimumFractionDigits(0);
82
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
82
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
83
		attributesMap.put("dateFormatter", dateFormatter);
83
        attributesMap.put("dateFormatter", dateFormatter);
84
		attributesMap.put("nf", numberformat);
84
        attributesMap.put("nf", numberformat);
85
		attributesMap.put("dateMonthFormatter", dateMonthFormatter);
85
        attributesMap.put("dateMonthFormatter", dateMonthFormatter);
86
		attributesMap.put("datehiphenFormatter", datehiphenFormatter);
86
        attributesMap.put("datehiphenFormatter", datehiphenFormatter);
87
		attributesMap.put("dateYearMonthFormatter", dateYearMonthFormatter);
87
        attributesMap.put("dateYearMonthFormatter", dateYearMonthFormatter);
88
 
88
 
89
		attributesMap.put("dateMonthYearFormatter", dateMonthYearFormatter);
89
        attributesMap.put("dateMonthYearFormatter", dateMonthYearFormatter);
90
		attributesMap.put("dateMonthChYear", dateMonthChYear);
90
        attributesMap.put("dateMonthChYear", dateMonthChYear);
91
		attributesMap.put("decimalFormatter", decimalFormatter);
91
        attributesMap.put("decimalFormatter", decimalFormatter);
92
		attributesMap.put("noData",
-
 
93
				"<tr><td colspan=\"20\" style=\"text-align:center;\">No results found for the given criteria</td></tr>");
92
        attributesMap.put("noData", "<tr><td colspan=\"20\" style=\"text-align:center;\">No results found for the given criteria</td></tr>");
94
		attributesMap.put("dateTimeFormatter", dateTimeFormatter);
93
        attributesMap.put("dateTimeFormatter", dateTimeFormatter);
95
		attributesMap.put("version", "168");
94
        attributesMap.put("version", "169");
96
		attributesMap.put("cssVersion", "10");
95
        attributesMap.put("cssVersion", "10");
97
		attributesMap.put("isDev", getActiveProfile().equals("dev"));
96
        attributesMap.put("isDev", getActiveProfile().equals("dev"));
98
		attributesMap.put("vmUtils", new Utils());
97
        attributesMap.put("vmUtils", new Utils());
99
		//attributesMap.put("esc", new EscapeTool());
98
        //attributesMap.put("esc", new EscapeTool());
100
		attributesMap.put("ru", RoundingMode.HALF_UP);
99
        attributesMap.put("ru", RoundingMode.HALF_UP);
101
		return attributesMap;
100
        return attributesMap;
102
	}
101
    }
103
 
102
 
104
	@Bean
103
    @Bean
105
	public ViewResolver viewResolver() {
104
    public ViewResolver viewResolver() {
106
		VelocityLayoutViewResolver bean = new VelocityLayoutViewResolver();
105
        VelocityLayoutViewResolver bean = new VelocityLayoutViewResolver();
107
		bean.setPrefix("");
106
        bean.setPrefix("");
108
		bean.setSuffix(VELOCITY_PATH_SUFFIX);
107
        bean.setSuffix(VELOCITY_PATH_SUFFIX);
109
		bean.setRequestContextAttribute("rc");
108
        bean.setRequestContextAttribute("rc");
110
		bean.setAttributesMap(this.velocityAttributesMap());
109
        bean.setAttributesMap(this.velocityAttributesMap());
111
		return bean;
110
        return bean;
112
	}
111
    }
113
 
112
 
114
//	@Bean
113
//	@Bean
115
//	public ViewResolver freemarkerViewResolver() {
114
//	public ViewResolver freemarkerViewResolver() {
116
//		FreeMarkerViewResolver resolver = new FreeMarkerViewResolver();
115
//		FreeMarkerViewResolver resolver = new FreeMarkerViewResolver();
117
//		resolver.setCache(true);
116
//		resolver.setCache(true);
118
//		resolver.setPrefix("");
117
//		resolver.setPrefix("");
119
//		resolver.setSuffix(".ftl");
118
//		resolver.setSuffix(".ftl");
120
//		return resolver;
119
//		return resolver;
121
//	}
120
//	}
122
 
121
 
123
	@Bean
122
    @Bean
124
	public ViewResolver beanNameViewResolver() {
123
    public ViewResolver beanNameViewResolver() {
125
		BeanNameViewResolver resolver = new BeanNameViewResolver();
124
        BeanNameViewResolver resolver = new BeanNameViewResolver();
126
		return resolver;
125
        return resolver;
127
	}
126
    }
128
 
127
 
129
	@Bean
128
    @Bean
130
	public VelocityConfigurer velocityConfig() {
129
    public VelocityConfigurer velocityConfig() {
131
		VelocityConfigurer velocityConfigurer = new VelocityConfigurer();
130
        VelocityConfigurer velocityConfigurer = new VelocityConfigurer();
132
		Properties velocityProperties = new Properties();
131
        Properties velocityProperties = new Properties();
133
		velocityProperties.put("directive.set.null.allowed", "true");
132
        velocityProperties.put("directive.set.null.allowed", "true");
134
		velocityConfigurer.setVelocityProperties(velocityProperties);
133
        velocityConfigurer.setVelocityProperties(velocityProperties);
135
		velocityConfigurer.setResourceLoaderPath(VELOCITY_PATH_PREFIX);
134
        velocityConfigurer.setResourceLoaderPath(VELOCITY_PATH_PREFIX);
136
		return velocityConfigurer;
135
        return velocityConfigurer;
137
	}
136
    }
138
 
137
 
139
	@Bean(name = "messageSource")
138
    @Bean(name = "messageSource")
140
	public ReloadableResourceBundleMessageSource getReloadableResourceBundleMessageSource() {
139
    public ReloadableResourceBundleMessageSource getReloadableResourceBundleMessageSource() {
141
		LOGGER.debug("creating messageSource bean with message path source name : " + MESSAGE_PATH_SOURCE_NAME);
140
        LOGGER.debug("creating messageSource bean with message path source name : " + MESSAGE_PATH_SOURCE_NAME);
142
		ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
141
        ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
143
		messageSource.setBasename(MESSAGE_PATH_SOURCE_NAME);
142
        messageSource.setBasename(MESSAGE_PATH_SOURCE_NAME);
144
		return messageSource;
143
        return messageSource;
145
	}
144
    }
146
 
145
 
147
	@Bean(name = "multipartResolver")
146
    @Bean(name = "multipartResolver")
148
	public CommonsMultipartResolver getCommonsMultipartResolver() {
147
    public CommonsMultipartResolver getCommonsMultipartResolver() {
149
		LOGGER.info("creating common multipart resolver bean");
148
        LOGGER.info("creating common multipart resolver bean");
150
		return new CommonsMultipartResolver();
149
        return new CommonsMultipartResolver();
151
	}
150
    }
152
 
151
 
153
	@Bean
152
    @Bean
154
	public PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
153
    public PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
155
		String activeProfile = getActiveProfile();
154
        String activeProfile = getActiveProfile();
156
 
155
 
157
		PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
156
        PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
158
 
157
 
159
		if ("prod".equals(activeProfile)) {
158
        if ("prod".equals(activeProfile)) {
160
			resource = new ClassPathResource("/META-INF/prod.properties");
159
            resource = new ClassPathResource("/META-INF/prod.properties");
161
		} else if ("staging".equals(activeProfile)) {
160
        } else if ("staging".equals(activeProfile)) {
162
			resource = new ClassPathResource("/META-INF/staging.properties");
161
            resource = new ClassPathResource("/META-INF/staging.properties");
163
		} else {
162
        } else {
164
			resource = new ClassPathResource("/META-INF/dev.properties");
163
            resource = new ClassPathResource("/META-INF/dev.properties");
165
		}
164
        }
166
 
165
 
167
		propertySourcesPlaceholderConfigurer.setLocation(resource);
166
        propertySourcesPlaceholderConfigurer.setLocation(resource);
168
 
167
 
169
		return propertySourcesPlaceholderConfigurer;
168
        return propertySourcesPlaceholderConfigurer;
170
	}
169
    }
171
 
170
 
172
	private String getActiveProfile() {
171
    private String getActiveProfile() {
173
		Properties properties = new Properties();
172
        Properties properties = new Properties();
174
		try {
173
        try {
175
			properties.load(this.getClass().getClassLoader().getResourceAsStream("META-INF/env.property"));
174
            properties.load(this.getClass().getClassLoader().getResourceAsStream("META-INF/env.property"));
176
		} catch (IOException e) {
175
        } catch (IOException e) {
177
			LOGGER.error("Error in reading env property file.Adding default property" + e);
176
            LOGGER.error("Error in reading env property file.Adding default property" + e);
178
			properties.put("profile", "dev");
177
            properties.put("profile", "dev");
179
		}
178
        }
180
		LOGGER.info("Profile is [{}]", properties.get("profile"));
179
        LOGGER.info("Profile is [{}]", properties.get("profile"));
181
		return (String) properties.get("profile");
180
        return (String) properties.get("profile");
182
	}
181
    }
183
 
182
 
184
	@Bean(name = "mailSender")
183
    @Bean(name = "mailSender")
185
	public JavaMailSender getSendgridMailSender() {
184
    public JavaMailSender getSendgridMailSender() {
186
		JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
185
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
187
 
186
 
188
		// Using gmail
187
        // Using gmail
189
		mailSender.setHost("smtp.sendgrid.net");
188
        mailSender.setHost("smtp.sendgrid.net");
190
		mailSender.setPort(587);
189
        mailSender.setPort(587);
191
		mailSender.setUsername("apikey");
190
        mailSender.setUsername("apikey");
192
		mailSender.setPassword("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");
191
        mailSender.setPassword("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");
193
 
192
 
194
		Properties javaMailProperties = new Properties();
193
        Properties javaMailProperties = new Properties();
195
		javaMailProperties.put("mail.smtp.starttls.enable", "false");
194
        javaMailProperties.put("mail.smtp.starttls.enable", "false");
196
		javaMailProperties.put("mail.smtp.auth", "true");
195
        javaMailProperties.put("mail.smtp.auth", "true");
197
		javaMailProperties.put("mail.transport.protocol", "smtp");
196
        javaMailProperties.put("mail.transport.protocol", "smtp");
198
		javaMailProperties.put("mail.debug", "true");// Prints out everything on
197
        javaMailProperties.put("mail.debug", "true");// Prints out everything on
199
		// screen
198
        // screen
200
 
199
 
201
		mailSender.setJavaMailProperties(javaMailProperties);
200
        mailSender.setJavaMailProperties(javaMailProperties);
202
		return mailSender;
201
        return mailSender;
203
	}
202
    }
204
 
203
 
205
	//@Bean(name = "mailSender")
204
    //@Bean(name = "mailSender")
206
	public JavaMailSender googleMailSender() {
205
    public JavaMailSender googleMailSender() {
207
		JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
206
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
208
		// Using gmail
207
        // Using gmail
209
		mailSender.setHost("smtp.gmail.com");
208
        mailSender.setHost("smtp.gmail.com");
210
		mailSender.setPort(587);
209
        mailSender.setPort(587);
211
		mailSender.setUsername("build@shop2020.in");
210
        mailSender.setUsername("build@shop2020.in");
212
		mailSender.setPassword("cafe@nes");
211
        mailSender.setPassword("cafe@nes");
213
 
212
 
214
		Properties javaMailProperties = new Properties();
213
        Properties javaMailProperties = new Properties();
215
		javaMailProperties.put("mail.smtp.starttls.enable", "true");
214
        javaMailProperties.put("mail.smtp.starttls.enable", "true");
216
		javaMailProperties.put("mail.smtp.auth", "true");
215
        javaMailProperties.put("mail.smtp.auth", "true");
217
		javaMailProperties.put("mail.transport.protocol", "smtp");
216
        javaMailProperties.put("mail.transport.protocol", "smtp");
218
		javaMailProperties.put("mail.debug", "true");// Prints out everything on screen
217
        javaMailProperties.put("mail.debug", "true");// Prints out everything on screen
219
		mailSender.setJavaMailProperties(javaMailProperties);
218
        mailSender.setJavaMailProperties(javaMailProperties);
220
		return mailSender;
219
        return mailSender;
221
	}
220
    }
222
 
221
 
223
	@Bean(name = "gson")
222
    @Bean(name = "gson")
224
	public Gson gson() {
223
    public Gson gson() {
225
 
224
 
226
		Gson gson = new GsonBuilder().serializeNulls()
225
        Gson gson = new GsonBuilder().serializeNulls().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeJsonConverter()).create();
227
				.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeJsonConverter()).create();
226
 
228
 
227
        return gson;
229
		return gson;
228
 
230
 
229
    }
231
	}
230
 
232
 
231
    @Bean(name = "veloctyEngine")
233
	@Bean(name = "veloctyEngine")
232
    public VelocityEngine velocityEngine() throws VelocityException, IOException {
234
	public VelocityEngine velocityEngine() throws VelocityException, IOException {
233
        VelocityEngineFactoryBean factory = new VelocityEngineFactoryBean();
235
		VelocityEngineFactoryBean factory = new VelocityEngineFactoryBean();
234
        // Properties props = new Properties();
236
		// Properties props = new Properties();
235
        // props.put("resource.loader", "file");
237
		// props.put("resource.loader", "file");
236
 
238
 
237
        // props.put("file.resource.loader.description", "Velocity File Resource
239
		// props.put("file.resource.loader.description", "Velocity File Resource
238
        // Loader");
240
		// Loader");
239
        // props.put("file.resource.loader.class",
241
		// props.put("file.resource.loader.class",
240
        // "org.apache.velocity.runtime.resource.loader.FileResourceLoader");
242
		// "org.apache.velocity.runtime.resource.loader.FileResourceLoader");
241
        // props.put("file.resource.loader.cache", true);
243
		// props.put("file.resource.loader.cache", true);
242
        // props.put("file.resource.loader.path", ".");
244
		// props.put("file.resource.loader.path", ".");
243
 
245
 
244
        Properties velocityProperties = new Properties();
246
		Properties velocityProperties = new Properties();
245
        velocityProperties.put("resource.loader", "class");
247
		velocityProperties.put("resource.loader", "class");
246
        velocityProperties.put("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
248
		velocityProperties.put("class.resource.loader.class",
247
        velocityProperties.put("file.resource.loader.cache", true);
249
				"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
248
        velocityProperties.put("file.resource.loader.unicode", true);
250
		velocityProperties.put("file.resource.loader.cache", true);
249
        velocityProperties.put("input.encoding", "UTF-8");
251
		velocityProperties.put("file.resource.loader.unicode", true);
250
        velocityProperties.put("output.encoding", "UTF-8");
252
		velocityProperties.put("input.encoding", "UTF-8");
251
        velocityProperties.put("overrideLogging", true);
253
		velocityProperties.put("output.encoding", "UTF-8");
252
 
254
		velocityProperties.put("overrideLogging", true);
253
        // velocityProperties.put("file.resource.loader.path", ".");
255
 
254
 
256
		// velocityProperties.put("file.resource.loader.path", ".");
255
        factory.setVelocityProperties(velocityProperties);
257
 
256
        return factory.createVelocityEngine();
258
		factory.setVelocityProperties(velocityProperties);
257
 
259
		return factory.createVelocityEngine();
258
    }
260
 
259
 
261
	}
260
    @Bean
262
 
261
    public ObjectMapper objectMapper() {
263
	@Bean
262
        DateTimeFormatter df = new DateTimeFormatterBuilder().parseCaseInsensitive().append(DateTimeFormatter.ISO_LOCAL_DATE).optionalStart().appendLiteral('T').optionalEnd().appendLiteral(' ').append(DateTimeFormatter.ISO_LOCAL_TIME).toFormatter();
264
	public ObjectMapper objectMapper() {
263
        DateTimeFormatter sf = new DateTimeFormatterBuilder().parseCaseInsensitive().append(DateTimeFormatter.ISO_LOCAL_DATE).appendLiteral('T').append(DateTimeFormatter.ISO_LOCAL_TIME).toFormatter();
265
		DateTimeFormatter df = new DateTimeFormatterBuilder().parseCaseInsensitive()
264
        LocalDateTimeSerializer serializer = new LocalDateTimeSerializer(sf);
266
				.append(DateTimeFormatter.ISO_LOCAL_DATE).optionalStart().appendLiteral('T').optionalEnd()
265
        LocalDateTimeDeserializer deserializer = new LocalDateTimeDeserializer(df);
267
				.appendLiteral(' ').append(DateTimeFormatter.ISO_LOCAL_TIME).toFormatter();
266
        JavaTimeModule jtm = new JavaTimeModule();
268
		DateTimeFormatter sf = new DateTimeFormatterBuilder().parseCaseInsensitive()
267
        jtm.addSerializer(LocalDateTime.class, serializer);
269
				.append(DateTimeFormatter.ISO_LOCAL_DATE).appendLiteral('T').append(DateTimeFormatter.ISO_LOCAL_TIME)
268
        jtm.addDeserializer(LocalDateTime.class, deserializer);
270
				.toFormatter();
269
        ObjectMapper mapper = new ObjectMapper().registerModule(new ParameterNamesModule()).registerModule(new Jdk8Module()).registerModule(jtm); // new module, NOT JSR310Module
271
		LocalDateTimeSerializer serializer = new LocalDateTimeSerializer(sf);
270
        return mapper;
272
		LocalDateTimeDeserializer deserializer = new LocalDateTimeDeserializer(df);
271
    }
273
		JavaTimeModule jtm = new JavaTimeModule();
-
 
274
		jtm.addSerializer(LocalDateTime.class, serializer);
-
 
275
		jtm.addDeserializer(LocalDateTime.class, deserializer);
-
 
276
		ObjectMapper mapper = new ObjectMapper().registerModule(new ParameterNamesModule())
-
 
277
				.registerModule(new Jdk8Module()).registerModule(jtm); // new module, NOT JSR310Module
-
 
278
		return mapper;
-
 
279
	}
-
 
280
 
272
 
281
}
273
}
282
274