Subversion Repositories SmartDukaan

Rev

Rev 29350 | Rev 29355 | 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
 
29264 tejbeer 3
import org.apache.logging.log4j.LogManager;
4
import org.apache.logging.log4j.Logger;
22162 amit.gupta 5
import org.springframework.beans.factory.annotation.Autowired;
6
import org.springframework.stereotype.Component;
7
 
21545 ashik.ali 8
import com.google.gson.Gson;
9
import com.spice.profitmandi.dao.model.ContentPojo;
10
import com.spice.profitmandi.dao.model.ProductPojo;
21727 ashik.ali 11
import com.spice.profitmandi.dao.repository.dtr.Mongo;
21545 ashik.ali 12
 
22162 amit.gupta 13
@Component
21545 ashik.ali 14
public class ContentPojoPopulator {
15
 
16
	private static final Gson gs = new Gson();
17
 
29264 tejbeer 18
	private static final Logger LOGGER = LogManager.getLogger(CustomTransactionConvertorUtil.class);
22162 amit.gupta 19
 
20
	@Autowired
29350 tejbeer 21
	private Mongo contentMongoClient;
29264 tejbeer 22
 
22162 amit.gupta 23
	public ProductPojo getShortContent(long entityId) {
29264 tejbeer 24
		ContentPojo cp = null;
21545 ashik.ali 25
		ProductPojo pp = null;
26
		try {
29350 tejbeer 27
			cp = gs.fromJson(contentMongoClient.getEntityById(entityId).toString(), ContentPojo.class);
21545 ashik.ali 28
		} catch (Exception e) {
29264 tejbeer 29
			// e.printStackTrace();
21545 ashik.ali 30
			return null;
31
		}
29264 tejbeer 32
 
33
		LOGGER.info("cp" + cp);
21545 ashik.ali 34
		try {
35
			pp = new ProductPojo();
36
			pp.setId(entityId);
37
			pp.setDefaultImgUrl(cp.getDefaultImageUrl());
22067 ashik.ali 38
			pp.setDescription(String.join(", ", cp.getKeySpecs().subList(0, Math.min(cp.getKeySpecs().size(), 3))));
29354 tejbeer 39
			pp.setImageUrl(cp.getDefaultImageUrl());
21545 ashik.ali 40
			pp.setUrl(cp.getUrl());
41
			pp.setTitle(cp.getTitle());
42
		} catch (Exception e) {
43
			e.printStackTrace();
44
			pp = null;
45
		}
46
		return pp;
47
	}
29264 tejbeer 48
 
22384 amit.gupta 49
	public ProductPojo getShortContent(String brand, String modelName, String modelNumber) {
50
		String name = getProductName(brand, modelName, modelNumber);
51
		return getShortContent(name);
52
	}
29264 tejbeer 53
 
54
	private String getProductName(String brand, String modelName, String modelNumber) {
22384 amit.gupta 55
		StringBuilder sb = new StringBuilder();
29264 tejbeer 56
 
57
		sb.append(((brand != null) ? brand + " " : "")).append(((modelName != null) ? modelName + " " : ""))
58
				.append(((modelNumber != null) ? modelNumber : ""));
22384 amit.gupta 59
		return sb.toString();
60
	}
29264 tejbeer 61
 
22384 amit.gupta 62
	public ProductPojo getShortContent(String name) {
29264 tejbeer 63
		ContentPojo cp = null;
22384 amit.gupta 64
		ProductPojo pp = null;
29264 tejbeer 65
 
22384 amit.gupta 66
		try {
29350 tejbeer 67
			cp = contentMongoClient.getEntityByName(name);
22384 amit.gupta 68
		} catch (Exception e) {
69
			e.printStackTrace();
70
			return null;
71
		}
72
		try {
73
			pp = new ProductPojo();
74
			pp.setId(cp.getId());
75
			pp.setDefaultImgUrl(cp.getDefaultImageUrl());
76
			pp.setDescription(String.join(", ", cp.getKeySpecs().subList(0, Math.min(cp.getKeySpecs().size(), 3))));
77
			pp.setTitle(pp.getTitle());
78
			pp.setImageUrl(cp.getIconImageUrl());
79
			pp.setUrl(cp.getUrl());
80
			pp.setTitle(cp.getTitle());
81
			pp.setThumbnailImageUrl(cp.getThumbnailImageUrl());
82
		} catch (Exception e) {
83
			e.printStackTrace();
84
			pp = null;
85
		}
86
		return pp;
87
	}
21545 ashik.ali 88
 
89
}