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