Subversion Repositories SmartDukaan

Rev

Rev 25380 | Rev 29350 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 25380 Rev 29264
Line 1... Line 1...
1
package com.spice.profitmandi.dao.util;
1
package com.spice.profitmandi.dao.util;
2
 
2
 
-
 
3
import org.apache.logging.log4j.LogManager;
-
 
4
import org.apache.logging.log4j.Logger;
3
import org.springframework.beans.factory.annotation.Autowired;
5
import org.springframework.beans.factory.annotation.Autowired;
4
import org.springframework.stereotype.Component;
6
import org.springframework.stereotype.Component;
5
 
7
 
6
import com.google.gson.Gson;
8
import com.google.gson.Gson;
7
import com.spice.profitmandi.dao.model.ContentPojo;
9
import com.spice.profitmandi.dao.model.ContentPojo;
8
import com.spice.profitmandi.dao.model.ProductPojo;
10
import com.spice.profitmandi.dao.model.ProductPojo;
9
import com.spice.profitmandi.dao.repository.dtr.Mongo;
11
import com.spice.profitmandi.dao.repository.dtr.Mongo;
10
 
12
 
11
 
-
 
12
@Component
13
@Component
13
public class ContentPojoPopulator {
14
public class ContentPojoPopulator {
14
 
15
 
15
	private static final Gson gs = new Gson();
16
	private static final Gson gs = new Gson();
16
 
17
 
-
 
18
	private static final Logger LOGGER = LogManager.getLogger(CustomTransactionConvertorUtil.class);
17
 
19
 
18
	@Autowired
20
	@Autowired
19
	private Mongo mongoClient;
21
	private Mongo mongoClient;
20
	
22
 
21
	public ProductPojo getShortContent(long entityId) {
23
	public ProductPojo getShortContent(long entityId) {
22
		ContentPojo cp=null;
24
		ContentPojo cp = null;
23
		ProductPojo pp = null;
25
		ProductPojo pp = null;
24
		try {
26
		try {
25
			cp = gs.fromJson(mongoClient.getEntityById(entityId).toString(), ContentPojo.class);
27
			cp = gs.fromJson(mongoClient.getEntityById(entityId).toString(), ContentPojo.class);
26
		} catch (Exception e) {
28
		} catch (Exception e) {
27
			//e.printStackTrace();
29
			// e.printStackTrace();
28
			return null;
30
			return null;
29
		}
31
		}
-
 
32
 
-
 
33
		LOGGER.info("cp" + cp);
30
		try {
34
		try {
31
			pp = new ProductPojo();
35
			pp = new ProductPojo();
32
			pp.setId(entityId);
36
			pp.setId(entityId);
33
			pp.setDefaultImgUrl(cp.getDefaultImageUrl());
37
			pp.setDefaultImgUrl(cp.getDefaultImageUrl());
34
			pp.setDescription(String.join(", ", cp.getKeySpecs().subList(0, Math.min(cp.getKeySpecs().size(), 3))));
38
			pp.setDescription(String.join(", ", cp.getKeySpecs().subList(0, Math.min(cp.getKeySpecs().size(), 3))));
Line 39... Line 43...
39
			e.printStackTrace();
43
			e.printStackTrace();
40
			pp = null;
44
			pp = null;
41
		}
45
		}
42
		return pp;
46
		return pp;
43
	}
47
	}
44
	
48
 
45
	public ProductPojo getShortContent(String brand, String modelName, String modelNumber) {
49
	public ProductPojo getShortContent(String brand, String modelName, String modelNumber) {
46
		String name = getProductName(brand, modelName, modelNumber);
50
		String name = getProductName(brand, modelName, modelNumber);
47
		return getShortContent(name);
51
		return getShortContent(name);
48
	}
52
	}
49
	
53
 
50
	private String getProductName(String brand, String modelName, String modelNumber){
54
	private String getProductName(String brand, String modelName, String modelNumber) {
51
		StringBuilder sb = new StringBuilder();
55
		StringBuilder sb = new StringBuilder();
52
		
56
 
53
		sb.append(((brand != null) ? brand + " " : ""))
-
 
54
		.append(((modelName != null) ? modelName + " " : ""))
57
		sb.append(((brand != null) ? brand + " " : "")).append(((modelName != null) ? modelName + " " : ""))
55
		.append((( modelNumber != null ) ? modelNumber : "" ));	
58
				.append(((modelNumber != null) ? modelNumber : ""));
56
		return sb.toString();
59
		return sb.toString();
57
	}
60
	}
58
	
-
 
59
	
61
 
60
	public ProductPojo getShortContent(String name) {
62
	public ProductPojo getShortContent(String name) {
61
		ContentPojo cp=null;
63
		ContentPojo cp = null;
62
		ProductPojo pp = null;
64
		ProductPojo pp = null;
63
		
65
 
64
		try {
66
		try {
65
			cp = mongoClient.getEntityByName(name);
67
			cp = mongoClient.getEntityByName(name);
66
		} catch (Exception e) {
68
		} catch (Exception e) {
67
			e.printStackTrace();
69
			e.printStackTrace();
68
			return null;
70
			return null;