Subversion Repositories SmartDukaan

Rev

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