| Line 1... |
Line 1... |
| 1 |
package in.shop2020.util;
|
1 |
package in.shop2020.util;
|
| 2 |
|
2 |
|
| - |
|
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 |
|
| - |
|
9 |
import java.util.Map;
|
| - |
|
10 |
|
| - |
|
11 |
import org.apache.commons.logging.Log;
|
| - |
|
12 |
import org.apache.commons.logging.LogFactory;
|
| - |
|
13 |
|
| 3 |
public class MostComparedIndexGenerator {
|
14 |
public class MostComparedIndexGenerator {
|
| 4 |
private String[] indentation = {"", " ", " ", " "," "};
|
15 |
private String[] indentation = {"", " ", " ", " "," "};
|
| - |
|
16 |
private static Log log = LogFactory.getLog(MostComparedIndexGenerator.class);
|
| 5 |
|
17 |
|
| 6 |
public void generate() {
|
18 |
public void generate() {
|
| 7 |
StringBuilder sb = new StringBuilder();
|
19 |
StringBuilder sb = new StringBuilder();
|
| 8 |
|
20 |
|
| 9 |
sb.append(indentation[1] + "<div>\n");
|
21 |
sb.append(indentation[1] + "<div>\n");
|
| Line 51... |
Line 63... |
| 51 |
sb.append(indentation[1] + "</div>\n");
|
63 |
sb.append(indentation[1] + "</div>\n");
|
| 52 |
|
64 |
|
| 53 |
sb.append(indentation[1] + "<div>\n");
|
65 |
sb.append(indentation[1] + "<div>\n");
|
| 54 |
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");
|
66 |
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");
|
| 55 |
sb.append(indentation[1] + "</div>\n");
|
67 |
sb.append(indentation[1] + "</div>\n");
|
| - |
|
68 |
/*
|
| - |
|
69 |
* Auto generated comparison links, data used from most compared products.
|
| - |
|
70 |
*/
|
| - |
|
71 |
try {
|
| - |
|
72 |
sb.append(getAutoGeneratedComparisonLinks());
|
| - |
|
73 |
} catch(Exception e){
|
| - |
|
74 |
log.error("Could not generate Autogenerated Comparison Links");
|
| - |
|
75 |
e.printStackTrace();
|
| 56 |
|
76 |
}
|
| 57 |
String indexFilename = Utils.EXPORT_PARTNERS_CONTENT_PATH + "most-compared-index.html";
|
77 |
String indexFilename = Utils.EXPORT_PARTNERS_CONTENT_PATH + "most-compared-index.html";
|
| 58 |
|
78 |
|
| 59 |
try {
|
79 |
try {
|
| 60 |
DBUtils.store(sb.toString(), indexFilename);
|
80 |
DBUtils.store(sb.toString(), indexFilename);
|
| 61 |
|
81 |
|
| Line 66... |
Line 86... |
| 66 |
|
86 |
|
| 67 |
public static void main(String[] args) {
|
87 |
public static void main(String[] args) {
|
| 68 |
MostComparedIndexGenerator g = new MostComparedIndexGenerator();
|
88 |
MostComparedIndexGenerator g = new MostComparedIndexGenerator();
|
| 69 |
g.generate();
|
89 |
g.generate();
|
| 70 |
}
|
90 |
}
|
| - |
|
91 |
|
| - |
|
92 |
private StringBuffer getAutoGeneratedComparisonLinks() throws Exception {
|
| - |
|
93 |
Map<Long, Map<Long, Long>> comparisonStats = null;
|
| - |
|
94 |
StringBuffer sb = new StringBuffer();
|
| - |
|
95 |
comparisonStats = CreationUtils.getComparisonStats();
|
| - |
|
96 |
if(comparisonStats != null){
|
| - |
|
97 |
for(Map.Entry<Long, Map<Long, Long>> entry : comparisonStats.entrySet()){
|
| - |
|
98 |
Long entityId = entry.getKey();
|
| - |
|
99 |
ExpandedEntity expandedEntity = new ExpandedEntity(CreationUtils.getEntity(entityId));
|
| - |
|
100 |
Category category = expandedEntity.getCategory();
|
| - |
|
101 |
if(category == null){
|
| - |
|
102 |
continue;
|
| - |
|
103 |
}
|
| - |
|
104 |
EntityState es = CreationUtils.getEntityState(entityId);
|
| - |
|
105 |
if(EntityStatus.READY.equals(es.getStatus()) && category.getParentCategory().getID()==Utils.MOBILE_PHONES_CATAGORY) {
|
| - |
|
106 |
String entityName = EntityUtils.getProductName(expandedEntity);
|
| - |
|
107 |
String hyphendatedName = entityName.replaceAll(" +", "-").toLowerCase();
|
| - |
|
108 |
for (Long anotherEntityId : entry.getValue().keySet()) {
|
| - |
|
109 |
EntityState es1 = CreationUtils.getEntityState(anotherEntityId);
|
| - |
|
110 |
ExpandedEntity anotherExpandedEntity = new ExpandedEntity(CreationUtils.getEntity(anotherEntityId));
|
| - |
|
111 |
Category anotherCategory = anotherExpandedEntity.getCategory();
|
| - |
|
112 |
if(anotherCategory == null){
|
| - |
|
113 |
continue;
|
| - |
|
114 |
}
|
| - |
|
115 |
if(EntityStatus.READY.equals(es1.getStatus()) && anotherCategory.getParentCategory().getID() == Utils.MOBILE_PHONES_CATAGORY){
|
| - |
|
116 |
String anotherEntityName = EntityUtils.getProductName(anotherExpandedEntity);
|
| - |
|
117 |
String anotherHyphenatedName = anotherEntityName.replaceAll(" +", "-").toLowerCase();
|
| - |
|
118 |
sb.append(indentation[1] + "<div>\n");
|
| - |
|
119 |
sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones/" + hyphendatedName + "-vs-" + anotherHyphenatedName
|
| - |
|
120 |
+"?p1=" + entityId +"&p2="+ anotherEntityId+" '>" + entityName + " Vs "+ anotherEntityName + "</a>\n");
|
| - |
|
121 |
sb.append(indentation[1] + "</div>\n");
|
| - |
|
122 |
}
|
| - |
|
123 |
}
|
| - |
|
124 |
}
|
| - |
|
125 |
}
|
| - |
|
126 |
}
|
| - |
|
127 |
|
| - |
|
128 |
return sb;
|
| - |
|
129 |
|
| - |
|
130 |
}
|
| 71 |
}
|
131 |
}
|
| 72 |
|
132 |
|