Subversion Repositories SmartDukaan

Rev

Rev 29359 | 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) {
29360 tejbeer 29
			e.printStackTrace();
21545 ashik.ali 30
			return null;
31
		}
29264 tejbeer 32
 
33
		LOGGER.info("cp" + cp);
29358 tejbeer 34
 
29359 tejbeer 35
		pp = new ProductPojo();
36
		pp.setId(entityId);
37
		pp.setDefaultImgUrl(cp.getDefaultImageUrl());
38
		pp.setDescription(String.join(", ", cp.getKeySpecs().subList(0, Math.min(cp.getKeySpecs().size(), 3))));
39
		pp.setImageUrl(cp.getDefaultImageUrl());
40
		pp.setUrl(cp.getUrl());
41
		pp.setTitle(cp.getTitle());
29358 tejbeer 42
 
21545 ashik.ali 43
		return pp;
44
	}
29264 tejbeer 45
 
22384 amit.gupta 46
	public ProductPojo getShortContent(String brand, String modelName, String modelNumber) {
47
		String name = getProductName(brand, modelName, modelNumber);
48
		return getShortContent(name);
49
	}
29264 tejbeer 50
 
51
	private String getProductName(String brand, String modelName, String modelNumber) {
22384 amit.gupta 52
		StringBuilder sb = new StringBuilder();
29264 tejbeer 53
 
54
		sb.append(((brand != null) ? brand + " " : "")).append(((modelName != null) ? modelName + " " : ""))
55
				.append(((modelNumber != null) ? modelNumber : ""));
22384 amit.gupta 56
		return sb.toString();
57
	}
29264 tejbeer 58
 
22384 amit.gupta 59
	public ProductPojo getShortContent(String name) {
29264 tejbeer 60
		ContentPojo cp = null;
22384 amit.gupta 61
		ProductPojo pp = null;
29264 tejbeer 62
 
22384 amit.gupta 63
		try {
29350 tejbeer 64
			cp = contentMongoClient.getEntityByName(name);
22384 amit.gupta 65
		} catch (Exception e) {
66
			e.printStackTrace();
67
			return null;
68
		}
69
		try {
70
			pp = new ProductPojo();
71
			pp.setId(cp.getId());
72
			pp.setDefaultImgUrl(cp.getDefaultImageUrl());
73
			pp.setDescription(String.join(", ", cp.getKeySpecs().subList(0, Math.min(cp.getKeySpecs().size(), 3))));
74
			pp.setTitle(pp.getTitle());
29355 tejbeer 75
			pp.setImageUrl(cp.getDefaultImageUrl());
22384 amit.gupta 76
			pp.setUrl(cp.getUrl());
77
			pp.setTitle(cp.getTitle());
78
			pp.setThumbnailImageUrl(cp.getThumbnailImageUrl());
79
		} catch (Exception e) {
80
			e.printStackTrace();
81
			pp = null;
82
		}
83
		return pp;
84
	}
21545 ashik.ali 85
 
86
}