Subversion Repositories SmartDukaan

Rev

Rev 24838 | Rev 29264 | 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
22925 ashik.ali 19
	private Mongo mongoClient;
22162 amit.gupta 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) {
24838 amit.gupta 27
			//e.printStackTrace();
21545 ashik.ali 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
	}
22384 amit.gupta 44
 
45
	public ProductPojo getShortContent(String brand, String modelName, String modelNumber) {
46
		String name = getProductName(brand, modelName, modelNumber);
47
		return getShortContent(name);
48
	}
49
 
50
	private String getProductName(String brand, String modelName, String modelNumber){
51
		StringBuilder sb = new StringBuilder();
52
 
53
		sb.append(((brand != null) ? brand + " " : ""))
54
		.append(((modelName != null) ? modelName + " " : ""))
55
		.append((( modelNumber != null ) ? modelNumber : "" ));	
56
		return sb.toString();
57
	}
58
 
59
 
60
	public ProductPojo getShortContent(String name) {
61
		ContentPojo cp=null;
62
		ProductPojo pp = null;
63
 
64
		try {
25380 amit.gupta 65
			cp = mongoClient.getEntityByName(name);
22384 amit.gupta 66
		} catch (Exception e) {
67
			e.printStackTrace();
68
			return null;
69
		}
70
		try {
71
			pp = new ProductPojo();
72
			pp.setId(cp.getId());
73
			pp.setDefaultImgUrl(cp.getDefaultImageUrl());
74
			pp.setDescription(String.join(", ", cp.getKeySpecs().subList(0, Math.min(cp.getKeySpecs().size(), 3))));
75
			pp.setTitle(pp.getTitle());
76
			pp.setImageUrl(cp.getIconImageUrl());
77
			pp.setUrl(cp.getUrl());
78
			pp.setTitle(cp.getTitle());
79
			pp.setThumbnailImageUrl(cp.getThumbnailImageUrl());
80
		} catch (Exception e) {
81
			e.printStackTrace();
82
			pp = null;
83
		}
84
		return pp;
85
	}
21545 ashik.ali 86
 
87
}