| 5314 |
varun.gupt |
1 |
package in.shop2020.util;
|
|
|
2 |
|
| 5346 |
amit.gupta |
3 |
import in.shop2020.metamodel.core.EntityState;
|
|
|
4 |
import in.shop2020.metamodel.core.EntityStatus;
|
|
|
5 |
import in.shop2020.metamodel.definitions.Category;
|
|
|
6 |
import in.shop2020.metamodel.util.CreationUtils;
|
|
|
7 |
import in.shop2020.metamodel.util.ExpandedEntity;
|
|
|
8 |
|
| 5425 |
amit.gupta |
9 |
import java.util.ArrayList;
|
|
|
10 |
import java.util.List;
|
| 5346 |
amit.gupta |
11 |
import java.util.Map;
|
|
|
12 |
|
|
|
13 |
import org.apache.commons.logging.Log;
|
|
|
14 |
import org.apache.commons.logging.LogFactory;
|
|
|
15 |
|
| 5314 |
varun.gupt |
16 |
public class MostComparedIndexGenerator {
|
|
|
17 |
private String[] indentation = {"", " ", " ", " "," "};
|
| 5346 |
amit.gupta |
18 |
private static Log log = LogFactory.getLog(MostComparedIndexGenerator.class);
|
| 5425 |
amit.gupta |
19 |
private List<Long> validEntityIds;
|
|
|
20 |
|
|
|
21 |
public MostComparedIndexGenerator(List<Long> valiEntityIds) {
|
|
|
22 |
super();
|
|
|
23 |
this.validEntityIds = valiEntityIds;
|
|
|
24 |
}
|
|
|
25 |
|
| 5314 |
varun.gupt |
26 |
public void generate() {
|
|
|
27 |
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&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&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&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&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&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&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&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&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&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&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&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&p2=1002160'>Samsung Galaxy Y Duos S6102 Vs Samsung Galaxy Y S5360</a>\n");
|
|
|
75 |
sb.append(indentation[1] + "</div>\n");
|
| 5346 |
amit.gupta |
76 |
/*
|
|
|
77 |
* Auto generated comparison links, data used from most compared products.
|
|
|
78 |
*/
|
|
|
79 |
try {
|
|
|
80 |
sb.append(getAutoGeneratedComparisonLinks());
|
|
|
81 |
} catch(Exception e){
|
|
|
82 |
log.error("Could not generate Autogenerated Comparison Links");
|
|
|
83 |
e.printStackTrace();
|
|
|
84 |
}
|
| 5314 |
varun.gupt |
85 |
String indexFilename = Utils.EXPORT_PARTNERS_CONTENT_PATH + "most-compared-index.html";
|
|
|
86 |
|
|
|
87 |
try {
|
|
|
88 |
DBUtils.store(sb.toString(), indexFilename);
|
|
|
89 |
|
|
|
90 |
} catch (Exception e) {
|
|
|
91 |
e.printStackTrace();
|
|
|
92 |
}
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
public static void main(String[] args) {
|
| 5425 |
amit.gupta |
96 |
List<Long> list = new ArrayList<Long>();
|
|
|
97 |
MostComparedIndexGenerator g = new MostComparedIndexGenerator(list);
|
| 5314 |
varun.gupt |
98 |
g.generate();
|
|
|
99 |
}
|
| 5346 |
amit.gupta |
100 |
|
|
|
101 |
private StringBuffer getAutoGeneratedComparisonLinks() throws Exception {
|
|
|
102 |
Map<Long, Map<Long, Long>> comparisonStats = null;
|
|
|
103 |
StringBuffer sb = new StringBuffer();
|
|
|
104 |
comparisonStats = CreationUtils.getComparisonStats();
|
|
|
105 |
if(comparisonStats != null){
|
|
|
106 |
for(Map.Entry<Long, Map<Long, Long>> entry : comparisonStats.entrySet()){
|
|
|
107 |
Long entityId = entry.getKey();
|
|
|
108 |
ExpandedEntity expandedEntity = new ExpandedEntity(CreationUtils.getEntity(entityId));
|
|
|
109 |
Category category = expandedEntity.getCategory();
|
|
|
110 |
if(category == null){
|
|
|
111 |
continue;
|
|
|
112 |
}
|
| 5425 |
amit.gupta |
113 |
if(this.validEntityIds.contains(entityId) && category.getParentCategory().getID()==Utils.MOBILE_PHONES_CATAGORY) {
|
| 5346 |
amit.gupta |
114 |
String entityName = EntityUtils.getProductName(expandedEntity);
|
| 5358 |
amit.gupta |
115 |
String hyphendatedName = entityName.replaceAll(" +", "-").replaceAll("/+", "-").replaceAll("-+", "-").toLowerCase();
|
| 5346 |
amit.gupta |
116 |
for (Long anotherEntityId : entry.getValue().keySet()) {
|
|
|
117 |
ExpandedEntity anotherExpandedEntity = new ExpandedEntity(CreationUtils.getEntity(anotherEntityId));
|
|
|
118 |
Category anotherCategory = anotherExpandedEntity.getCategory();
|
|
|
119 |
if(anotherCategory == null){
|
|
|
120 |
continue;
|
|
|
121 |
}
|
| 5425 |
amit.gupta |
122 |
if(this.validEntityIds.contains(anotherEntityId) && anotherCategory.getParentCategory().getID() == Utils.MOBILE_PHONES_CATAGORY){
|
| 5346 |
amit.gupta |
123 |
String anotherEntityName = EntityUtils.getProductName(anotherExpandedEntity);
|
| 5358 |
amit.gupta |
124 |
String anotherHyphenatedName = anotherEntityName.replaceAll(" +", "-").replaceAll("/+", "-").replaceAll("-+", "-").toLowerCase();
|
| 5346 |
amit.gupta |
125 |
sb.append(indentation[1] + "<div>\n");
|
|
|
126 |
sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones/" + hyphendatedName + "-vs-" + anotherHyphenatedName
|
|
|
127 |
+"?p1=" + entityId +"&p2="+ anotherEntityId+" '>" + entityName + " Vs "+ anotherEntityName + "</a>\n");
|
|
|
128 |
sb.append(indentation[1] + "</div>\n");
|
|
|
129 |
}
|
|
|
130 |
}
|
|
|
131 |
}
|
|
|
132 |
}
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
return sb;
|
|
|
136 |
|
|
|
137 |
}
|
| 5314 |
varun.gupt |
138 |
}
|