Subversion Repositories SmartDukaan

Rev

Rev 5155 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5004 varun.gupt 1
package in.shop2020.util;
2
 
3
import in.shop2020.metamodel.core.Bullet;
4
import in.shop2020.metamodel.core.Entity;
5
import in.shop2020.metamodel.core.Feature;
6
import in.shop2020.metamodel.core.PrimitiveDataObject;
7
import in.shop2020.metamodel.core.Slide;
8
import in.shop2020.metamodel.definitions.Catalog;
9
import in.shop2020.metamodel.definitions.DefinitionsContainer;
10
 
11
import java.util.ArrayList;
12
import java.util.List;
13
 
14
import com.google.gson.Gson;
15
 
16
public class ProductIndexGenerator {
17
	private String[] indentation = {"", "    ", "        ", "            ","                "};
18
	private List<Entity> entities;
19
	private DefinitionsContainer defContainer = Catalog.getInstance().getDefinitionsContainer();
20
 
21
	public ProductIndexGenerator(List<Entity> entities)	{
22
		this.entities = entities;
23
	}
24
 
25
	private String getProductURL(Entity entity){
26
		in.shop2020.metamodel.definitions.Category parentCategory = defContainer.getCategory(entity.getCategoryID()).getParentCategory();
27
 
28
		String url = "http://www.saholic.com/" + parentCategory.getLabel().toLowerCase().replace(' ', '-') + "/";
29
		String productUrl = ((entity.getBrand() != null) ? entity.getBrand().trim() + " " : "").toLowerCase().replace(' ', '-')
30
        + "-" + ((entity.getModelName() != null) ? entity.getModelName().trim() + " " : "").toLowerCase().replace(' ', '-') 
31
	    + "-" + ((entity.getModelNumber() != null ) ? entity.getModelNumber().trim() + " ": "" ).toLowerCase().replace(' ', '-')
32
        + "-" + entity.getID();
33
		productUrl = productUrl.replaceAll("/", "-");
34
		url = url + productUrl;
35
		url = url.replaceAll("-+", "-");
36
		return url;
37
	}
38
 
39
	public void generate()	{
40
		StringBuilder sb = new StringBuilder();
41
 
42
		for (Entity entity: entities)	{
43
			String brand = entity.getBrand();
44
			String modelName = entity.getModelName();
45
			String modelNumber = entity.getModelNumber();
46
			String url = getProductURL(entity);
47
 
48
			sb.append("<div>\n");
49
			sb.append(indentation[1] + "<a href='" + url + "'>");
50
			sb.append(indentation[2] + brand + " " + modelName + " " + modelNumber);
51
			sb.append(indentation[1] + "</a>\n");
52
			sb.append("</div>\n");
53
 
54
			Slide slide = entity.getSlide(Utils.SUMMARY_SLIDE_DEFINITION_ID);
55
 
56
			for(Feature feature: slide.getFeatures())	{
57
 
58
				if(feature.getFeatureDefinitionID() == 120156)	{
59
					List<Bullet> bullets =  feature.getBullets();
60
 
61
					if(bullets != null)	{
62
						for(Bullet bullet: bullets){
63
							PrimitiveDataObject pdo = (PrimitiveDataObject) bullet.getDataObject();
64
 
65
							sb.append("<div>\n");
66
							sb.append(indentation[1] + "<a href='" + url + "'>");
67
							sb.append(indentation[2] + brand + " " + pdo.getValue() + " " + modelNumber);
68
							sb.append(indentation[1] + "</a>\n");
69
							sb.append("</div>\n");
70
						}
71
					}
72
				} else if(feature.getFeatureDefinitionID() == 120157)	{
73
					List<Bullet> bullets =  feature.getBullets();
74
 
75
					if(bullets != null)	{
76
						for(Bullet bullet: bullets)	{
77
							PrimitiveDataObject pdo = (PrimitiveDataObject)bullet.getDataObject();
78
 
79
							sb.append("<div>\n");
80
							sb.append(indentation[1] + "<a href='" + url + "'>");
81
							sb.append(indentation[2] + brand + " " + modelName + " " + pdo.getValue());
82
							sb.append(indentation[1] + "</a>\n");
83
							sb.append("</div>\n");
84
						}
85
					}
86
				}
87
			}
88
		}
89
		String indexFilename = Utils.EXPORT_PARTNERS_CONTENT_PATH + "productindex.html";
90
 
91
		try	{
92
			DBUtils.store(sb.toString(), indexFilename);
93
 
94
		} catch (Exception e) {
95
			e.printStackTrace();
96
		}
97
	}
98
}