Subversion Repositories SmartDukaan

Rev

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

Rev 5425 Rev 5497
Line 1... Line 1...
1
package in.shop2020.util;
1
package in.shop2020.util;
2
 
2
 
3
import in.shop2020.metamodel.core.EntityState;
3
import in.shop2020.metamodel.core.Bullet;
4
import in.shop2020.metamodel.core.EntityStatus;
4
import in.shop2020.metamodel.core.Feature;
-
 
5
import in.shop2020.metamodel.core.PrimitiveDataObject;
-
 
6
import in.shop2020.metamodel.core.Slide;
5
import in.shop2020.metamodel.definitions.Category;
7
import in.shop2020.metamodel.definitions.Category;
6
import in.shop2020.metamodel.util.CreationUtils;
8
import in.shop2020.metamodel.util.CreationUtils;
7
import in.shop2020.metamodel.util.ExpandedEntity;
9
import in.shop2020.metamodel.util.ExpandedEntity;
8
 
10
 
9
import java.util.ArrayList;
11
import java.util.ArrayList;
-
 
12
import java.util.Arrays;
-
 
13
import java.util.HashMap;
10
import java.util.List;
14
import java.util.List;
11
import java.util.Map;
15
import java.util.Map;
12
 
16
 
-
 
17
import org.apache.commons.lang.StringUtils;
13
import org.apache.commons.logging.Log;
18
import org.apache.commons.logging.Log;
14
import org.apache.commons.logging.LogFactory;
19
import org.apache.commons.logging.LogFactory;
15
 
20
 
16
public class MostComparedIndexGenerator {
21
public class MostComparedIndexGenerator {
-
 
22
	
17
	private String[] indentation = {"", "    ", "        ", "            ","                "};
23
	private String[] indentation = {"", "    ", "        ", "            ","                "};
-
 
24
	private Map<String, List<String>> brandSynonyms = new HashMap<String, List<String>>();
18
    private static Log log = LogFactory.getLog(MostComparedIndexGenerator.class);
25
	private static Log log = LogFactory.getLog(MostComparedIndexGenerator.class);
-
 
26
 
19
	private List<Long> validEntityIds;
27
	private List<Long> validEntityIds;
20
 
28
 
-
 
29
 
21
	public MostComparedIndexGenerator(List<Long> valiEntityIds) {
30
	public MostComparedIndexGenerator(List<Long> valiEntityIds) {
-
 
31
		Map<String, String> brSynonyms = new HashMap<String, String>();
22
		super();
32
 
23
		this.validEntityIds = valiEntityIds;
33
		this.validEntityIds = valiEntityIds;
-
 
34
		try {
-
 
35
			brSynonyms =  CreationUtils.getSynonyms().get("brand");
-
 
36
			for(String brand : brSynonyms.keySet()){
-
 
37
				List<String> brandSyns = Arrays.asList((brand + "," + StringUtils.defaultString(brSynonyms.get(brand))).split(","));
-
 
38
				brandSynonyms.put(brand, brandSyns);
-
 
39
			}
-
 
40
		} catch (Exception e) {
-
 
41
			// TODO: handle exception
-
 
42
		}
24
	}
43
	}
25
 
44
 
-
 
45
 
-
 
46
	
26
	public void generate()	{
47
	public void generate()	{
27
		StringBuilder sb = new StringBuilder();
48
		StringBuilder sb = new StringBuilder();
28
		
-
 
29
		sb.append(indentation[1] + "<div>\n");
-
 
30
		sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1002160&amp;p2=1000541'>Samsung Galaxy Y S5360 vs Samsung Galaxy Pop S5570</a>\n");
-
 
31
		sb.append(indentation[1] + "</div>\n");
-
 
32
		
-
 
33
		sb.append(indentation[1] + "<div>\n");
-
 
34
		sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1002151&amp;p2=1002160'>Samsung Galaxy Y S5360 Vs HTC Explorer (Pico) A310e</a>\n");
-
 
35
		sb.append(indentation[1] + "</div>\n");
-
 
36
		
-
 
37
		sb.append(indentation[1] + "<div>\n");
-
 
38
		sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1002444&amp;p2=1002153'>Samsung Galaxy Y S5360 Vs Nokia 500</a>\n");
-
 
39
		sb.append(indentation[1] + "</div>\n");
-
 
40
		
-
 
41
		sb.append(indentation[1] + "<div>\n");
-
 
42
		sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1000483&amp;p2=1002444'>Spice Mi-270 Vs Samsung Galaxy Y Color</a>\n");
-
 
43
		sb.append(indentation[1] + "</div>\n");
-
 
44
		
-
 
45
		sb.append(indentation[1] + "<div>\n");
-
 
46
		sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1001224&amp;p2=1002467'>Spice Mi-310 Vs Spice Mi-280</a>\n");
-
 
47
		sb.append(indentation[1] + "</div>\n");
-
 
48
		
-
 
49
		sb.append(indentation[1] + "<div>\n");
-
 
50
		sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1000483&amp;p2=1002467'>Spice Mi-270 Vs Spice Mi-280</a>\n");
-
 
51
		sb.append(indentation[1] + "</div>\n");
-
 
52
		
-
 
53
		sb.append(indentation[1] + "<div>\n");
-
 
54
		sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1002467&amp;p2=1000483'>Spice Mi-280 Vs Spice Mi-270</a>\n");
-
 
55
		sb.append(indentation[1] + "</div>\n");
-
 
56
		
-
 
57
		sb.append(indentation[1] + "<div>\n");
-
 
58
		sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1002575&amp;p2=1002444'>Samsung Galaxy Y Duos S6102 Vs Samsung Galaxy Y Color S5360s</a>\n");
-
 
59
		sb.append(indentation[1] + "</div>\n");
-
 
60
		
-
 
61
		sb.append(indentation[1] + "<div>\n");
-
 
62
		sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1001224&amp;p2=1000483'>Spice Mi-310 Vs Spice Mi-270</a>\n");
-
 
63
		sb.append(indentation[1] + "</div>\n");
-
 
64
		
-
 
65
		sb.append(indentation[1] + "<div>\n");
-
 
66
		sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1000483&amp;p2=1000357'>Spice Mi-270 Vs Micromax Andro A60</a>\n");
-
 
67
		sb.append(indentation[1] + "</div>\n");
-
 
68
		
-
 
69
		sb.append(indentation[1] + "<div>\n");
-
 
70
		sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1000483&amp;p2=1002124'>Spice Mi-270 Vs Karbonn A 1</a>\n");
-
 
71
		sb.append(indentation[1] + "</div>\n");
-
 
72
		
-
 
73
		sb.append(indentation[1] + "<div>\n");
-
 
74
		sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1002575&amp;p2=1002160'>Samsung Galaxy Y Duos S6102 Vs Samsung Galaxy Y S5360</a>\n");
-
 
75
		sb.append(indentation[1] + "</div>\n");
-
 
76
		/*
-
 
77
		 * Auto generated comparison links, data used from most compared products.
-
 
78
		 */
-
 
79
		try {
49
		try {
80
			sb.append(getAutoGeneratedComparisonLinks());
50
			sb.append(getAutoGeneratedComparisonLinks());
81
		} catch(Exception e){
51
		} catch(Exception e){
82
			log.error("Could not generate Autogenerated Comparison Links");
52
			log.error("Could not generate Autogenerated Comparison Links");
83
			e.printStackTrace();
53
			e.printStackTrace();
Line 98... Line 68...
98
		g.generate();
68
		g.generate();
99
	}
69
	}
100
	
70
	
101
	private StringBuffer getAutoGeneratedComparisonLinks() throws Exception {
71
	private StringBuffer getAutoGeneratedComparisonLinks() throws Exception {
102
		Map<Long, Map<Long, Long>> comparisonStats = null;
72
		Map<Long, Map<Long, Long>> comparisonStats = null;
103
		StringBuffer sb = new StringBuffer();
73
		StringBuffer sbProds = new StringBuffer();
104
		comparisonStats = CreationUtils.getComparisonStats();
74
		comparisonStats = CreationUtils.getComparisonStats();
105
		if(comparisonStats != null){
75
		if(comparisonStats != null){
106
			for(Map.Entry<Long, Map<Long, Long>> entry : comparisonStats.entrySet()){
76
			for(Map.Entry<Long, Map<Long, Long>> entry : comparisonStats.entrySet()){
107
				Long entityId = entry.getKey();
77
				Long entityId = entry.getKey();
108
				ExpandedEntity expandedEntity = new ExpandedEntity(CreationUtils.getEntity(entityId));
78
				ExpandedEntity expandedEntity = new ExpandedEntity(CreationUtils.getEntity(entityId));
109
				Category category = expandedEntity.getCategory();
79
				Category category = expandedEntity.getCategory();
110
				if(category == null){
80
				if(category == null){
111
					continue;
81
					continue;
112
				}
82
				}
113
				if(this.validEntityIds.contains(entityId) && category.getParentCategory().getID()==Utils.MOBILE_PHONES_CATAGORY) {
83
				if(this.validEntityIds.contains(entityId) && category.getParentCategory().getID()==Utils.MOBILE_PHONES_CATAGORY) {
-
 
84
					Slide slide = expandedEntity.getSlide(Utils.SUMMARY_SLIDE_DEFINITION_ID);
-
 
85
					List<String> modelNameSyn = new ArrayList<String>();
-
 
86
					modelNameSyn.add(expandedEntity.getModelName());
-
 
87
					List<String> modelNumberSyn = new ArrayList<String>();
-
 
88
					modelNumberSyn.add(expandedEntity.getModelNumber());
-
 
89
 
-
 
90
					for(Feature feature: slide.getFeatures())	{
-
 
91
						
-
 
92
						if(feature.getFeatureDefinitionID() == 120156)	{
-
 
93
							List<Bullet> bullets =  feature.getBullets();
-
 
94
							
-
 
95
							if(bullets != null)	{
-
 
96
								for(Bullet bullet: bullets){
-
 
97
									PrimitiveDataObject pdo = (PrimitiveDataObject) bullet.getDataObject();
-
 
98
									modelNameSyn.add(pdo.getValue());
-
 
99
								}
-
 
100
							}
-
 
101
						} else if(feature.getFeatureDefinitionID() == 120157)	{
-
 
102
							List<Bullet> bullets =  feature.getBullets();
-
 
103
							
-
 
104
							if(bullets != null)	{
-
 
105
								for(Bullet bullet: bullets)	{
-
 
106
									PrimitiveDataObject pdo = (PrimitiveDataObject)bullet.getDataObject();
-
 
107
									modelNumberSyn.add(pdo.getValue());
-
 
108
								}
-
 
109
							}
-
 
110
						}
-
 
111
					}
-
 
112
 
114
					String entityName = EntityUtils.getProductName(expandedEntity);
113
					String entityName = EntityUtils.getProductName(expandedEntity);
115
					String hyphendatedName = entityName.replaceAll(" +", "-").replaceAll("/+", "-").replaceAll("-+", "-").toLowerCase();
114
					String hyphendatedName = entityName.replaceAll(" +", "-").replaceAll("/+", "-").replaceAll("-+", "-").toLowerCase();
-
 
115
					sbProds.append(indentation[1] + "<div>\n");
-
 
116
					sbProds.append(indentation[2] + "<a href='http://www.saholic.com/generated/compare-" + hyphendatedName 
-
 
117
							+"?p1=" + entityId + "'>Compare " + entityName +"</a>\n");
-
 
118
					sbProds.append(indentation[1] + "</div>\n");
-
 
119
					StringBuffer sbProds1 = new StringBuffer();
-
 
120
					StringBuffer sbProds2 = new StringBuffer();
116
					for (Long anotherEntityId : entry.getValue().keySet()) {
121
					for (Long anotherEntityId : entry.getValue().keySet()) {
-
 
122
						if(entityId.equals(anotherEntityId)){
-
 
123
							continue;
-
 
124
						}
117
						ExpandedEntity anotherExpandedEntity = new ExpandedEntity(CreationUtils.getEntity(anotherEntityId));
125
						ExpandedEntity anotherExpandedEntity = new ExpandedEntity(CreationUtils.getEntity(anotherEntityId));
118
						Category anotherCategory = anotherExpandedEntity.getCategory();
126
						Category anotherCategory = anotherExpandedEntity.getCategory();
119
						if(anotherCategory == null){
127
						if(anotherCategory == null){
120
							continue;
128
							continue;
121
						}
129
						}
-
 
130
 
122
						if(this.validEntityIds.contains(anotherEntityId) && anotherCategory.getParentCategory().getID() == Utils.MOBILE_PHONES_CATAGORY){
131
						if(this.validEntityIds.contains(anotherEntityId) && anotherCategory.getParentCategory().getID() == Utils.MOBILE_PHONES_CATAGORY){
-
 
132
							Slide slide1 = anotherExpandedEntity.getSlide(Utils.SUMMARY_SLIDE_DEFINITION_ID);
-
 
133
							List<String> modelNameSyn1 = new ArrayList<String>();
-
 
134
							modelNameSyn1.add(anotherExpandedEntity.getModelName());
-
 
135
							List<String> modelNumberSyn1 = new ArrayList<String>();
-
 
136
							modelNumberSyn1.add(anotherExpandedEntity.getModelNumber());
-
 
137
							
-
 
138
							for(Feature feature: slide1.getFeatures())	{
-
 
139
								
-
 
140
								if(feature.getFeatureDefinitionID() == 120156)	{
-
 
141
									List<Bullet> bullets =  feature.getBullets();
-
 
142
									
-
 
143
									if(bullets != null)	{
-
 
144
										for(Bullet bullet: bullets){
-
 
145
											PrimitiveDataObject pdo = (PrimitiveDataObject) bullet.getDataObject();
-
 
146
											modelNameSyn1.add(pdo.getValue());
-
 
147
										}
-
 
148
									}
-
 
149
								} else if(feature.getFeatureDefinitionID() == 120157)	{
-
 
150
									List<Bullet> bullets =  feature.getBullets();
-
 
151
									
-
 
152
									if(bullets != null)	{
-
 
153
										for(Bullet bullet: bullets)	{
-
 
154
											PrimitiveDataObject pdo = (PrimitiveDataObject)bullet.getDataObject();
-
 
155
											modelNumberSyn1.add(pdo.getValue());
-
 
156
										}
-
 
157
									}
-
 
158
								}
-
 
159
							}
123
							String anotherEntityName = EntityUtils.getProductName(anotherExpandedEntity);
160
							String anotherEntityName = EntityUtils.getProductName(anotherExpandedEntity);
124
							String anotherHyphenatedName = anotherEntityName.replaceAll(" +", "-").replaceAll("/+", "-").replaceAll("-+", "-").toLowerCase();
161
							String anotherHyphenatedName = anotherEntityName.replaceAll(" +", "-").replaceAll("/+", "-").replaceAll("-+", "-").toLowerCase();
-
 
162
							
125
							sb.append(indentation[1] + "<div>\n");
163
							sbProds1.append(indentation[1] + "<div>\n");
126
							sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones/" + hyphendatedName + "-vs-" + anotherHyphenatedName 
164
							sbProds1.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones/" + hyphendatedName + "-vs-" + anotherHyphenatedName 
-
 
165
									+"?p1=" + entityId +"&p2="+ anotherEntityId+"'>" + entityName + " Vs "+ anotherEntityName + "</a>\n");
-
 
166
							sbProds1.append(indentation[1] + "</div>\n");
-
 
167
							sbProds2.append(indentation[1] + "<div>\n");
-
 
168
							sbProds2.append(indentation[2] + "<a href='http://www.saholic.com/generated/" + hyphendatedName + "-vs-" + anotherHyphenatedName 
127
										+"?p1=" + entityId +"&p2="+ anotherEntityId+" '>" + entityName + " Vs "+ anotherEntityName + "</a>\n");
169
									+"?p1=" + entityId +"&p2="+ anotherEntityId+" '>" + entityName + " Vs "+ anotherEntityName + "</a>\n");
-
 
170
							sbProds2.append(indentation[1] + "</div>\n");
-
 
171
 
-
 
172
							StringBuffer sb = new StringBuffer();
-
 
173
							for(String br : getBrandSynonyms(expandedEntity.getBrand())){
-
 
174
								for (String mName : modelNameSyn){
-
 
175
									for (String mNumber : modelNumberSyn){
-
 
176
										for(String br1 : getBrandSynonyms(anotherExpandedEntity.getBrand())) {
-
 
177
											for (String mName1 : modelNameSyn1){
-
 
178
												for (String mNumber1 : modelNumberSyn1){
-
 
179
													sb.append(indentation[1] + "<div>\n");
-
 
180
													sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones/" + hyphendatedName + "-vs-" + anotherHyphenatedName 
-
 
181
															+"?p1=" + entityId +"&p2="+ anotherEntityId+" '>" + br + " " + mName + " " + mNumber 
-
 
182
															+ " Vs "+ br1 + " " + mName1 + " " + mNumber1 + "</a>\n");
128
							sb.append(indentation[1] + "</div>\n");
183
													sb.append(indentation[1] + "</div>\n");
-
 
184
												}
-
 
185
											}
-
 
186
										}
-
 
187
									}
-
 
188
								}
-
 
189
							}
-
 
190
							String indexFilename = Utils.EXPORT_PARTNERS_CONTENT_PATH + "most-compared-" + entityId + "-vs-" + anotherEntityId + ".html";
-
 
191
							
-
 
192
							try	{
-
 
193
								DBUtils.store(sb.toString(), indexFilename);
-
 
194
								
-
 
195
							} catch (Exception e) {
-
 
196
								e.printStackTrace();
-
 
197
							}
129
						}
198
						}
130
					}
199
					}
-
 
200
					String indexFilename = Utils.EXPORT_PARTNERS_CONTENT_PATH + "most-compared-" + entityId + ".html";
-
 
201
					
-
 
202
					try	{
-
 
203
						DBUtils.store(sbProds1.append(sbProds2).toString(), indexFilename);
-
 
204
						
-
 
205
					} catch (Exception e) {
-
 
206
						e.printStackTrace();
-
 
207
					}
131
				}
208
				}
132
			}
209
			}
133
		}
210
		}
134
		
211
		
135
		return sb;
212
		return sbProds;
136
		
213
		
137
	}
214
	}
-
 
215
	
-
 
216
 
-
 
217
	private List<String> getBrandSynonyms(String brand) {
-
 
218
		if(!brandSynonyms.containsKey(brand)){
-
 
219
			List<String> list = new ArrayList<String>();
-
 
220
			list.add(brand);
-
 
221
			brandSynonyms.put(brand, list);
-
 
222
		}
-
 
223
		return brandSynonyms.get(brand);
-
 
224
	}
138
}
225
}
139
226