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