Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
21545 ashik.ali 1
package com.spice.profitmandi.dao.util;
2
 
22162 amit.gupta 3
import org.springframework.beans.factory.annotation.Autowired;
4
import org.springframework.stereotype.Component;
5
 
21545 ashik.ali 6
import com.google.gson.Gson;
7
import com.spice.profitmandi.dao.model.ContentPojo;
8
import com.spice.profitmandi.dao.model.ProductPojo;
21727 ashik.ali 9
import com.spice.profitmandi.dao.repository.dtr.Mongo;
21545 ashik.ali 10
 
11
 
22162 amit.gupta 12
@Component
21545 ashik.ali 13
public class ContentPojoPopulator {
14
 
15
	private static final Gson gs = new Gson();
16
 
22162 amit.gupta 17
 
18
	@Autowired
19
	Mongo mongoClient;
20
 
21
	public ProductPojo getShortContent(long entityId) {
21545 ashik.ali 22
		ContentPojo cp=null;
23
		ProductPojo pp = null;
24
		try {
22162 amit.gupta 25
			cp = gs.fromJson(mongoClient.getEntityById(entityId).toString(), ContentPojo.class);
21545 ashik.ali 26
		} catch (Exception e) {
27
			e.printStackTrace();
28
			return null;
29
		}
30
		try {
31
			pp = new ProductPojo();
32
			pp.setId(entityId);
33
			pp.setDefaultImgUrl(cp.getDefaultImageUrl());
22067 ashik.ali 34
			pp.setDescription(String.join(", ", cp.getKeySpecs().subList(0, Math.min(cp.getKeySpecs().size(), 3))));
21545 ashik.ali 35
			pp.setImageUrl(cp.getIconImageUrl());
36
			pp.setUrl(cp.getUrl());
37
			pp.setTitle(cp.getTitle());
38
		} catch (Exception e) {
39
			e.printStackTrace();
40
			pp = null;
41
		}
42
		return pp;
43
	}
44
 
45
}