| 22 |
naveen |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.ui.util;
|
|
|
5 |
|
| 109 |
naveen |
6 |
import in.shop2020.metamodel.core.Bullet;
|
| 451 |
rajveer |
7 |
import in.shop2020.metamodel.core.BulletDataObject;
|
| 457 |
rajveer |
8 |
import in.shop2020.metamodel.core.CompositeDataObject;
|
| 109 |
naveen |
9 |
import in.shop2020.metamodel.core.Entity;
|
| 457 |
rajveer |
10 |
import in.shop2020.metamodel.core.EnumDataObject;
|
| 109 |
naveen |
11 |
import in.shop2020.metamodel.core.Feature;
|
| 451 |
rajveer |
12 |
import in.shop2020.metamodel.core.FreeformContent;
|
| 512 |
rajveer |
13 |
import in.shop2020.metamodel.core.Media;
|
| 109 |
naveen |
14 |
import in.shop2020.metamodel.core.PrimitiveDataObject;
|
| 451 |
rajveer |
15 |
import in.shop2020.metamodel.core.Slide;
|
| 109 |
naveen |
16 |
import in.shop2020.metamodel.definitions.Catalog;
|
|
|
17 |
import in.shop2020.metamodel.definitions.DefinitionsContainer;
|
|
|
18 |
import in.shop2020.metamodel.definitions.EntityContainer;
|
| 110 |
naveen |
19 |
import in.shop2020.metamodel.definitions.SlideDefinition;
|
| 512 |
rajveer |
20 |
import in.shop2020.metamodel.util.CreationUtils;
|
| 457 |
rajveer |
21 |
import in.shop2020.metamodel.util.ExpandedBullet;
|
| 109 |
naveen |
22 |
import in.shop2020.metamodel.util.ExpandedCategory;
|
|
|
23 |
import in.shop2020.metamodel.util.ExpandedEntity;
|
| 457 |
rajveer |
24 |
import in.shop2020.metamodel.util.ExpandedFeature;
|
| 109 |
naveen |
25 |
import in.shop2020.metamodel.util.ExpandedSlide;
|
| 451 |
rajveer |
26 |
import in.shop2020.model.v1.catalog.Item;
|
|
|
27 |
import in.shop2020.model.v1.catalog.InventoryService.Client;
|
| 638 |
rajveer |
28 |
import in.shop2020.model.v1.catalog.Warehouse;
|
| 512 |
rajveer |
29 |
import in.shop2020.model.v1.catalog.status;
|
| 451 |
rajveer |
30 |
import in.shop2020.thrift.clients.CatalogServiceClient;
|
|
|
31 |
import in.shop2020.util.DBUtils;
|
| 109 |
naveen |
32 |
import in.shop2020.util.Utils;
|
|
|
33 |
|
| 22 |
naveen |
34 |
import java.io.BufferedWriter;
|
|
|
35 |
import java.io.File;
|
|
|
36 |
import java.io.FileOutputStream;
|
| 451 |
rajveer |
37 |
import java.io.IOException;
|
| 22 |
naveen |
38 |
import java.io.OutputStreamWriter;
|
| 451 |
rajveer |
39 |
import java.io.StringWriter;
|
| 108 |
naveen |
40 |
import java.util.ArrayList;
|
|
|
41 |
import java.util.Arrays;
|
| 110 |
naveen |
42 |
import java.util.Collection;
|
| 897 |
rajveer |
43 |
import java.util.Date;
|
| 451 |
rajveer |
44 |
import java.util.HashMap;
|
| 110 |
naveen |
45 |
import java.util.LinkedHashMap;
|
| 108 |
naveen |
46 |
import java.util.List;
|
| 110 |
naveen |
47 |
import java.util.Map;
|
| 22 |
naveen |
48 |
|
| 45 |
naveen |
49 |
import org.apache.commons.lang.StringUtils;
|
| 22 |
naveen |
50 |
import org.apache.velocity.Template;
|
|
|
51 |
import org.apache.velocity.VelocityContext;
|
|
|
52 |
import org.apache.velocity.app.Velocity;
|
| 451 |
rajveer |
53 |
import org.apache.velocity.exception.MethodInvocationException;
|
|
|
54 |
import org.apache.velocity.exception.ParseErrorException;
|
|
|
55 |
import org.apache.velocity.exception.ResourceNotFoundException;
|
| 22 |
naveen |
56 |
|
|
|
57 |
/**
|
| 49 |
naveen |
58 |
* Driver class to merge Java data objects with VTL script
|
|
|
59 |
*
|
| 22 |
naveen |
60 |
* @author naveen
|
|
|
61 |
*
|
|
|
62 |
*/
|
|
|
63 |
public class VUI {
|
|
|
64 |
|
|
|
65 |
/**
|
| 512 |
rajveer |
66 |
* Usage: VUI [entity|category|category_carousal|diff|entitysummary|entityhomesnippet|entitywidgetsnippet] [Entity ID|Category ID|EntityID1_EntityID2] {Template file name}
|
| 49 |
naveen |
67 |
*
|
| 22 |
naveen |
68 |
* @param args
|
|
|
69 |
*/
|
|
|
70 |
public static void main(String[] args) throws Exception {
|
| 163 |
naveen |
71 |
//diffAll();
|
|
|
72 |
//System.exit(0);
|
|
|
73 |
|
| 512 |
rajveer |
74 |
String[] commands = new String[] {"entity", "category", "category_carousal", "diff", "entities"};
|
|
|
75 |
String[] datatypes = new String[] {"Entity ID", "Category ID", "EntityID1_EntityID2"};
|
| 45 |
naveen |
76 |
|
|
|
77 |
String usage = "Usage: VUI ["+ StringUtils.join(commands, "|") +"] ["+
|
| 512 |
rajveer |
78 |
StringUtils.join(datatypes, "|") + "] ";
|
| 22 |
naveen |
79 |
|
| 512 |
rajveer |
80 |
if(args.length < 1) {
|
| 45 |
naveen |
81 |
System.out.println(usage);
|
|
|
82 |
System.exit(-1);
|
|
|
83 |
}
|
|
|
84 |
String inputCommand = args[0];
|
| 512 |
rajveer |
85 |
String inputID = null;
|
|
|
86 |
if(args.length == 2){
|
|
|
87 |
inputID = args[1];
|
|
|
88 |
}
|
|
|
89 |
//String templateFilename = args[2];
|
| 22 |
naveen |
90 |
|
| 109 |
naveen |
91 |
|
| 638 |
rajveer |
92 |
long catalogId = 0;
|
| 512 |
rajveer |
93 |
if(inputCommand.equals("entity") || inputCommand.equals("category") || inputCommand.equals("category_carousal")) {
|
| 109 |
naveen |
94 |
try {
|
| 638 |
rajveer |
95 |
catalogId = Long.parseLong(inputID);
|
| 109 |
naveen |
96 |
}
|
|
|
97 |
catch (NumberFormatException nfe) {
|
|
|
98 |
System.out.println("Invalid ID - " + inputID);
|
|
|
99 |
System.exit(-1);
|
|
|
100 |
}
|
| 45 |
naveen |
101 |
}
|
| 22 |
naveen |
102 |
|
| 45 |
naveen |
103 |
// Setup
|
| 59 |
naveen |
104 |
Velocity.init("src/in/shop2020/ui/util/velocity.properties");
|
| 45 |
naveen |
105 |
VelocityContext context = new VelocityContext();
|
|
|
106 |
|
| 512 |
rajveer |
107 |
String templateFile = null;
|
| 22 |
naveen |
108 |
|
| 45 |
naveen |
109 |
Template template = null;
|
|
|
110 |
String exportFileName = null;
|
| 22 |
naveen |
111 |
|
| 108 |
naveen |
112 |
DefinitionsContainer defs =
|
|
|
113 |
Catalog.getInstance().getDefinitionsContainer();
|
|
|
114 |
|
|
|
115 |
EntityContainer ents =
|
|
|
116 |
Catalog.getInstance().getEntityContainer();
|
| 451 |
rajveer |
117 |
|
| 457 |
rajveer |
118 |
|
| 45 |
naveen |
119 |
// Entities
|
|
|
120 |
if(inputCommand.equals("entity")) {
|
| 638 |
rajveer |
121 |
File exportFile = new File(Utils.EXPORT_ENTITIES_PATH + catalogId);
|
| 512 |
rajveer |
122 |
if(!exportFile.exists()) {
|
|
|
123 |
exportFile.mkdir();
|
| 457 |
rajveer |
124 |
}
|
| 638 |
rajveer |
125 |
/*
|
| 512 |
rajveer |
126 |
templateFile= Utils.VTL_SRC_PATH + "product_summary.vm";
|
| 638 |
rajveer |
127 |
getProductSummaryHtml(catalogId, templateFile);
|
| 512 |
rajveer |
128 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_widget.vm";
|
| 638 |
rajveer |
129 |
getEntitySnippetHtml(catalogId, templateFile);
|
| 512 |
rajveer |
130 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_homepage.vm";
|
| 638 |
rajveer |
131 |
getEntityHomeSnippetHtml(catalogId, templateFile);
|
| 516 |
rajveer |
132 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_searchpage.vm";
|
| 638 |
rajveer |
133 |
getEntitySearchSnippetHtml(catalogId, templateFile);
|
| 512 |
rajveer |
134 |
templateFile= Utils.VTL_SRC_PATH + "slideguide_img_video.vm";
|
| 638 |
rajveer |
135 |
getEntitySlideGuideHtml(catalogId, templateFile);
|
|
|
136 |
*/
|
| 512 |
rajveer |
137 |
}else
|
|
|
138 |
|
|
|
139 |
if(inputCommand.equals("entities")){
|
|
|
140 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
|
|
141 |
Client client = catalogServiceClient.getClient();
|
| 638 |
rajveer |
142 |
|
|
|
143 |
|
| 512 |
rajveer |
144 |
List<Item> items = client.getAllItemsByStatus(status.ACTIVE);
|
| 897 |
rajveer |
145 |
Date todate = new Date();
|
|
|
146 |
|
| 512 |
rajveer |
147 |
for(Item item: items){
|
| 897 |
rajveer |
148 |
if(todate.getTime() < item.getStartDate()){
|
|
|
149 |
continue;
|
|
|
150 |
}
|
| 638 |
rajveer |
151 |
long itemId = item.getId();
|
|
|
152 |
catalogId = item.getCatalogItemId();
|
|
|
153 |
File exportFile = new File(Utils.EXPORT_ENTITIES_PATH + catalogId);
|
| 512 |
rajveer |
154 |
if(!exportFile.exists()) {
|
|
|
155 |
exportFile.mkdir();
|
| 451 |
rajveer |
156 |
}
|
| 512 |
rajveer |
157 |
templateFile= Utils.VTL_SRC_PATH + "product_summary.vm";
|
| 638 |
rajveer |
158 |
getProductSummaryHtml(catalogId, itemId, templateFile);
|
| 512 |
rajveer |
159 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_widget.vm";
|
| 638 |
rajveer |
160 |
getEntitySnippetHtml(catalogId, itemId, templateFile);
|
| 512 |
rajveer |
161 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_homepage.vm";
|
| 638 |
rajveer |
162 |
getEntityHomeSnippetHtml(catalogId, itemId, templateFile);
|
| 516 |
rajveer |
163 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_searchpage.vm";
|
| 638 |
rajveer |
164 |
getEntitySearchSnippetHtml(catalogId, itemId, templateFile);
|
| 532 |
rajveer |
165 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_categorypage.vm";
|
| 638 |
rajveer |
166 |
getEntityCategorySnippetHtml(catalogId, itemId, templateFile);
|
| 512 |
rajveer |
167 |
templateFile= Utils.VTL_SRC_PATH + "slideguide_img_video.vm";
|
| 638 |
rajveer |
168 |
getEntitySlideGuideHtml(catalogId, itemId, templateFile);
|
| 975 |
vikas |
169 |
getEntityTitleSnippetHtml(catalogId);
|
|
|
170 |
getEntityMetaDescriptionSnippetHtml(catalogId);
|
|
|
171 |
getEntityMetaKeywordSnippetHtml(catalogId);
|
| 451 |
rajveer |
172 |
}
|
|
|
173 |
|
| 22 |
naveen |
174 |
}
|
|
|
175 |
|
| 163 |
naveen |
176 |
// Category definitions
|
| 108 |
naveen |
177 |
else if(inputCommand.equals("category")) {
|
| 638 |
rajveer |
178 |
ExpandedCategory expCategory = defs.getExpandedCategory(catalogId);
|
| 45 |
naveen |
179 |
Utils.info("expCategory=" + expCategory);
|
|
|
180 |
|
|
|
181 |
context.put("expcategory", expCategory);
|
|
|
182 |
template = Velocity.getTemplate(templateFile);
|
|
|
183 |
|
| 638 |
rajveer |
184 |
exportFileName = Utils.EXPORT_DEFINITIONS_PATH + catalogId + ".html";
|
| 45 |
naveen |
185 |
}
|
| 108 |
naveen |
186 |
|
|
|
187 |
// Category carousal
|
|
|
188 |
else if(inputCommand.equals("category_carousal")) {
|
| 638 |
rajveer |
189 |
String categoryName = defs.getCategory(catalogId).getLabel();
|
| 108 |
naveen |
190 |
|
| 1050 |
rajveer |
191 |
//FIXME get category wise entities
|
|
|
192 |
Collection<Entity> entities = CreationUtils.getEntities(catalogId);
|
| 108 |
naveen |
193 |
|
| 1050 |
rajveer |
194 |
|
| 108 |
naveen |
195 |
List<String[]> entitiesToShow = new ArrayList<String[]>();
|
|
|
196 |
|
|
|
197 |
for(Entity entity : entities) {
|
|
|
198 |
String snippets[] = new String[4];
|
|
|
199 |
|
|
|
200 |
// Entity ID
|
|
|
201 |
snippets[0] = new Long(entity.getID()).toString();
|
|
|
202 |
|
|
|
203 |
Feature feature = ents.getFeature(entity.getID(),
|
|
|
204 |
Utils.SNIPPETS_FEATURE_DEFINITIONID);
|
|
|
205 |
|
|
|
206 |
List<Bullet> bullets = feature.getBullets();
|
|
|
207 |
|
|
|
208 |
if(bullets.size() > 0) {
|
|
|
209 |
snippets[1] = ((PrimitiveDataObject)bullets.get(0).
|
|
|
210 |
getDataObject()).getValue();
|
|
|
211 |
}
|
|
|
212 |
|
|
|
213 |
if(bullets.size() > 1) {
|
|
|
214 |
snippets[2] = ((PrimitiveDataObject)bullets.get(1).
|
|
|
215 |
getDataObject()).getValue();
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
if(bullets.size() > 2) {
|
|
|
219 |
snippets[3] = ((PrimitiveDataObject)bullets.get(2).
|
|
|
220 |
getDataObject()).getValue();
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
Utils.info("snippets=" + Arrays.toString(snippets));
|
|
|
224 |
entitiesToShow.add(snippets);
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
Utils.info("categoryName=" + categoryName);
|
|
|
228 |
Utils.info("entitiesToShow=" + entitiesToShow);
|
|
|
229 |
|
|
|
230 |
context.put("categoryName", categoryName);
|
|
|
231 |
context.put("entitiesToShow", entitiesToShow);
|
|
|
232 |
|
|
|
233 |
template = Velocity.getTemplate(templateFile);
|
| 638 |
rajveer |
234 |
exportFileName = Utils.EXPORT_CATEGORY_HOMES_PATH + catalogId + ".html";
|
| 372 |
rajveer |
235 |
Utils.info("Export File Names " + exportFileName );
|
| 108 |
naveen |
236 |
}
|
| 109 |
naveen |
237 |
|
|
|
238 |
// Difference
|
|
|
239 |
else if(inputCommand.equals("diff")) {
|
|
|
240 |
String[] entityIDs = StringUtils.split(inputID, "_");
|
|
|
241 |
if(entityIDs.length < 2) {
|
|
|
242 |
System.out.println("Invalid IDs - " + inputID);
|
|
|
243 |
System.exit(-1);
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
long entityID1 = 0L;
|
|
|
247 |
long entityID2 = 0L;
|
|
|
248 |
try {
|
|
|
249 |
entityID1 = Long.parseLong(entityIDs[0]);
|
|
|
250 |
entityID2 = Long.parseLong(entityIDs[1]);
|
|
|
251 |
} catch(NumberFormatException nfe) {
|
|
|
252 |
System.out.println("Invalid IDs - " + inputID);
|
|
|
253 |
System.exit(-1);
|
|
|
254 |
}
|
|
|
255 |
|
|
|
256 |
Utils.info("entityIDs=" + Arrays.toString(entityIDs));
|
|
|
257 |
|
|
|
258 |
ExpandedEntity expEntity1 = ents.getExpandedEntity(entityID1);
|
|
|
259 |
ExpandedEntity expEntity2 = ents.getExpandedEntity(entityID2);
|
|
|
260 |
|
|
|
261 |
List<ExpandedSlide[]> mergedSlides =
|
|
|
262 |
getMergedSlides(expEntity1, expEntity2);
|
| 110 |
naveen |
263 |
Utils.info("mergedSlides=" + mergedSlides);
|
| 109 |
naveen |
264 |
|
| 110 |
naveen |
265 |
Collection<String[]> mergedComparisonScores =
|
|
|
266 |
getMergedComparisonScores(expEntity1, expEntity2);
|
|
|
267 |
Utils.info("mergedComparisonScores=" + mergedComparisonScores);
|
| 109 |
naveen |
268 |
|
| 1050 |
rajveer |
269 |
int scoreEntity1 = CreationUtils.getEntityComparisonScores(expEntity1.getID());
|
|
|
270 |
int scoreEntity2 = CreationUtils.getEntityComparisonScores(expEntity2.getID());
|
|
|
271 |
|
| 110 |
naveen |
272 |
|
| 109 |
naveen |
273 |
context.put("expEntity1", expEntity1);
|
|
|
274 |
context.put("expEntity2", expEntity2);
|
|
|
275 |
context.put("mergedSlides", mergedSlides);
|
| 110 |
naveen |
276 |
context.put("mergedComparisonScores", mergedComparisonScores);
|
|
|
277 |
context.put("scoreEntity1", scoreEntity1);
|
|
|
278 |
context.put("scoreEntity2", scoreEntity2);
|
| 109 |
naveen |
279 |
|
|
|
280 |
template = Velocity.getTemplate(templateFile);
|
|
|
281 |
exportFileName = Utils.EXPORT_DIFF_PATH + entityIDs[0] + "_" +
|
|
|
282 |
entityIDs[1] + ".html";
|
|
|
283 |
}
|
| 22 |
naveen |
284 |
|
| 45 |
naveen |
285 |
if(template != null) {
|
|
|
286 |
File exportFile = new File(exportFileName);
|
|
|
287 |
if(!exportFile.exists()) {
|
|
|
288 |
exportFile.createNewFile();
|
|
|
289 |
}
|
|
|
290 |
|
|
|
291 |
BufferedWriter writer = new BufferedWriter(
|
|
|
292 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
293 |
|
|
|
294 |
template.merge(context, writer);
|
|
|
295 |
|
|
|
296 |
writer.flush();
|
|
|
297 |
writer.close();
|
|
|
298 |
Utils.info("Export Complete!");
|
|
|
299 |
}
|
| 22 |
naveen |
300 |
}
|
| 110 |
naveen |
301 |
|
| 457 |
rajveer |
302 |
|
|
|
303 |
|
| 975 |
vikas |
304 |
private static void getEntityMetaDescriptionSnippetHtml(long catalogId) {
|
|
|
305 |
EntityContainer entContainer = Catalog.getInstance().getEntityContainer();
|
|
|
306 |
|
|
|
307 |
ExpandedEntity expEntity;
|
|
|
308 |
try {
|
|
|
309 |
expEntity = entContainer.getExpandedEntity(catalogId);
|
|
|
310 |
String description = "Best Price " + expEntity.getBrand() + " " + expEntity.getModelName()
|
| 988 |
vikas |
311 |
+ " " + expEntity.getModelNumber() + " ";
|
| 979 |
vikas |
312 |
|
|
|
313 |
if(expEntity.getCategory().getParentCategory().getID() == 10011) {
|
|
|
314 |
description += expEntity.getCategory().getLabel() + " in India.";
|
|
|
315 |
}
|
|
|
316 |
else {
|
|
|
317 |
description += ".";
|
|
|
318 |
}
|
|
|
319 |
description += " Experience n' buy online. FREE Next Day delivery."
|
| 975 |
vikas |
320 |
+ " Original product - Full manufacturer warranty. Comprehensive reviews.";
|
| 979 |
vikas |
321 |
|
| 975 |
vikas |
322 |
description = description.replaceAll("--", "-");
|
| 988 |
vikas |
323 |
String exportFileName = Utils.EXPORT_ENTITIES_PATH + catalogId + File.separator + "MetaDescriptionSnippet.html";
|
| 975 |
vikas |
324 |
File exportFile = new File(exportFileName);
|
|
|
325 |
if(!exportFile.exists()) {
|
|
|
326 |
exportFile.createNewFile();
|
|
|
327 |
}
|
|
|
328 |
|
|
|
329 |
BufferedWriter writer = new BufferedWriter(
|
|
|
330 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
331 |
|
|
|
332 |
writer.write(description);
|
|
|
333 |
|
|
|
334 |
writer.flush();
|
|
|
335 |
writer.close();
|
|
|
336 |
} catch (Exception e) {
|
|
|
337 |
// TODO Auto-generated catch block
|
|
|
338 |
e.printStackTrace();
|
|
|
339 |
}
|
|
|
340 |
}
|
|
|
341 |
|
|
|
342 |
private static void getEntityMetaKeywordSnippetHtml(long catalogId) {
|
|
|
343 |
EntityContainer entContainer = Catalog.getInstance().getEntityContainer();
|
|
|
344 |
|
|
|
345 |
ExpandedEntity expEntity;
|
|
|
346 |
try {
|
|
|
347 |
expEntity = entContainer.getExpandedEntity(catalogId);
|
| 979 |
vikas |
348 |
String keywords = expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber() + ", ";
|
| 975 |
vikas |
349 |
if(expEntity.getCategory().getParentCategory().getID() == 10001) {
|
| 988 |
vikas |
350 |
keywords += expEntity.getBrand() + " mobile phones, ";
|
| 975 |
vikas |
351 |
}
|
|
|
352 |
if(expEntity.getCategory().getParentCategory().getID() == 10011) {
|
| 988 |
vikas |
353 |
keywords += "phone accessories, ";
|
| 975 |
vikas |
354 |
}
|
| 979 |
vikas |
355 |
keywords += expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber() + " Price, ";
|
|
|
356 |
keywords += expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber() + " India, ";
|
| 975 |
vikas |
357 |
if(expEntity.getCategory().getParentCategory().getID() == 10001) {
|
| 979 |
vikas |
358 |
keywords += expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber() + " Review, ";
|
| 975 |
vikas |
359 |
}
|
|
|
360 |
|
| 988 |
vikas |
361 |
String exportFileName = Utils.EXPORT_ENTITIES_PATH + catalogId + File.separator + "MetaKeywordsSnippet.html";
|
| 975 |
vikas |
362 |
File exportFile = new File(exportFileName);
|
|
|
363 |
if(!exportFile.exists()) {
|
|
|
364 |
exportFile.createNewFile();
|
|
|
365 |
}
|
|
|
366 |
|
|
|
367 |
BufferedWriter writer = new BufferedWriter(
|
|
|
368 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
369 |
|
|
|
370 |
writer.write(keywords);
|
|
|
371 |
|
|
|
372 |
writer.flush();
|
|
|
373 |
writer.close();
|
|
|
374 |
} catch (Exception e) {
|
|
|
375 |
// TODO Auto-generated catch block
|
|
|
376 |
e.printStackTrace();
|
|
|
377 |
}
|
|
|
378 |
}
|
|
|
379 |
|
| 638 |
rajveer |
380 |
private static void getEntitySlideGuideHtml(long catalogId, long itemId, String templateFile) throws Exception {
|
| 512 |
rajveer |
381 |
EntityContainer entContainer =
|
|
|
382 |
Catalog.getInstance().getEntityContainer();
|
|
|
383 |
|
| 638 |
rajveer |
384 |
ExpandedEntity expEntity = entContainer.getExpandedEntity(catalogId);
|
| 512 |
rajveer |
385 |
Utils.logger.info("expEntity=" + expEntity);
|
|
|
386 |
|
| 1050 |
rajveer |
387 |
Map<String, Media> media= null;
|
|
|
388 |
|
|
|
389 |
//Map<String, Media> media = CreationUtils.getRawMedia(catalogId);
|
| 512 |
rajveer |
390 |
|
|
|
391 |
VelocityContext context = new VelocityContext();
|
|
|
392 |
|
|
|
393 |
context.put("expentity", expEntity);
|
|
|
394 |
context.put("media", media);
|
|
|
395 |
String exportFileName = null;
|
|
|
396 |
|
|
|
397 |
Template template = Velocity.getTemplate(templateFile);
|
| 638 |
rajveer |
398 |
exportFileName = Utils.EXPORT_ENTITIES_PATH + catalogId + File.separator + "SlideGuide.html";
|
| 512 |
rajveer |
399 |
|
|
|
400 |
File exportFile = new File(exportFileName);
|
|
|
401 |
if(!exportFile.exists()) {
|
|
|
402 |
exportFile.createNewFile();
|
|
|
403 |
}
|
|
|
404 |
|
|
|
405 |
BufferedWriter writer = new BufferedWriter(
|
|
|
406 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
407 |
|
|
|
408 |
//Template template = Velocity.getTemplate(templateFile);
|
|
|
409 |
template.merge(context, writer);
|
|
|
410 |
|
|
|
411 |
writer.flush();
|
|
|
412 |
writer.close();
|
|
|
413 |
Utils.info("Export Complete!");
|
|
|
414 |
|
|
|
415 |
}
|
|
|
416 |
|
|
|
417 |
|
| 451 |
rajveer |
418 |
|
|
|
419 |
/**
|
|
|
420 |
*
|
| 109 |
naveen |
421 |
* @param expEntity1
|
|
|
422 |
* @param expEntity2
|
| 110 |
naveen |
423 |
* @return
|
|
|
424 |
* @throws Exception
|
| 109 |
naveen |
425 |
*/
|
| 110 |
naveen |
426 |
private static Collection<String[]> getMergedComparisonScores(
|
|
|
427 |
ExpandedEntity expEntity1, ExpandedEntity expEntity2)
|
|
|
428 |
throws Exception {
|
|
|
429 |
EntityContainer ents = Catalog.getInstance().getEntityContainer();
|
|
|
430 |
DefinitionsContainer defs =
|
|
|
431 |
Catalog.getInstance().getDefinitionsContainer();
|
|
|
432 |
|
|
|
433 |
Map<String, String[]> mergedSlideScores =
|
|
|
434 |
new LinkedHashMap<String, String[]>();
|
|
|
435 |
|
| 1050 |
rajveer |
436 |
Map<Long, Integer> cmpSlideScores1 = CreationUtils.getSlideComparisonScores(expEntity1.getID());
|
| 110 |
naveen |
437 |
|
|
|
438 |
for(Long slideID : cmpSlideScores1.keySet()) {
|
|
|
439 |
SlideDefinition slideDef = defs.getSlideDefinition(
|
|
|
440 |
slideID.longValue());
|
|
|
441 |
|
|
|
442 |
String slideLabel = slideDef.getLabel();
|
|
|
443 |
String[] details = new String[3];
|
|
|
444 |
|
|
|
445 |
details[0] = slideLabel;
|
|
|
446 |
|
|
|
447 |
Integer score = cmpSlideScores1.get(slideID);
|
|
|
448 |
if(score != null) {
|
|
|
449 |
details[1] = score.toString();
|
|
|
450 |
}
|
|
|
451 |
else {
|
|
|
452 |
details[1] = "-1";
|
|
|
453 |
}
|
|
|
454 |
|
|
|
455 |
// To be determined in loop over 2nd entity's scores
|
|
|
456 |
details[2] = "-1";
|
|
|
457 |
|
|
|
458 |
mergedSlideScores.put(slideLabel, details);
|
|
|
459 |
}
|
|
|
460 |
|
| 1050 |
rajveer |
461 |
Map<Long, Integer> cmpSlideScores2 = CreationUtils.getSlideComparisonScores(expEntity2.getID());
|
| 110 |
naveen |
462 |
|
|
|
463 |
for(Long slideID : cmpSlideScores2.keySet()) {
|
|
|
464 |
SlideDefinition slideDef = defs.getSlideDefinition(
|
|
|
465 |
slideID.longValue());
|
|
|
466 |
|
|
|
467 |
String slideLabel = slideDef.getLabel();
|
|
|
468 |
|
|
|
469 |
String[] details = null;
|
|
|
470 |
if(mergedSlideScores.containsKey(slideLabel)) {
|
|
|
471 |
details = mergedSlideScores.get(slideLabel);
|
|
|
472 |
}
|
|
|
473 |
else {
|
|
|
474 |
details = new String[3];
|
|
|
475 |
|
|
|
476 |
details[0] = slideLabel;
|
|
|
477 |
details[1] = "-1";
|
|
|
478 |
|
|
|
479 |
mergedSlideScores.put(slideLabel, details);
|
|
|
480 |
}
|
|
|
481 |
|
|
|
482 |
Integer score = cmpSlideScores2.get(slideID);
|
|
|
483 |
if(score != null) {
|
|
|
484 |
details[2] = score.toString();
|
|
|
485 |
}
|
|
|
486 |
else {
|
|
|
487 |
details[2] = "-1";
|
|
|
488 |
}
|
|
|
489 |
}
|
|
|
490 |
|
|
|
491 |
return mergedSlideScores.values();
|
|
|
492 |
}
|
|
|
493 |
|
|
|
494 |
/**
|
|
|
495 |
*
|
|
|
496 |
* @param expEntity1
|
|
|
497 |
* @param expEntity2
|
|
|
498 |
*/
|
| 109 |
naveen |
499 |
private static List<ExpandedSlide[]> getMergedSlides(
|
|
|
500 |
ExpandedEntity expEntity1, ExpandedEntity expEntity2) {
|
|
|
501 |
List<ExpandedSlide[]> mergedSlides = new ArrayList<ExpandedSlide[]>();
|
|
|
502 |
|
|
|
503 |
EntityContainer ents = Catalog.getInstance().getEntityContainer();
|
|
|
504 |
|
|
|
505 |
List<ExpandedSlide> expSlidesEntity1 = expEntity1.getExpandedSlides();
|
|
|
506 |
|
|
|
507 |
for(ExpandedSlide expSlide1 : expSlidesEntity1) {
|
|
|
508 |
String slideLabel = expSlide1.getSlideDefinition().getLabel();
|
|
|
509 |
|
|
|
510 |
ExpandedSlide expSlide2 = ents.getParentExpandedSlide(
|
|
|
511 |
expEntity2, slideLabel);
|
|
|
512 |
|
|
|
513 |
if(expSlide2 != null) {
|
|
|
514 |
ExpandedSlide[] comparisonSlides = new ExpandedSlide[2];
|
|
|
515 |
comparisonSlides[0] = expSlide1;
|
|
|
516 |
comparisonSlides[1] = expSlide2;
|
|
|
517 |
|
|
|
518 |
mergedSlides.add(comparisonSlides);
|
|
|
519 |
}
|
|
|
520 |
}
|
|
|
521 |
|
|
|
522 |
return mergedSlides;
|
|
|
523 |
}
|
| 163 |
naveen |
524 |
|
|
|
525 |
public static void diffAll() throws Exception {
|
|
|
526 |
long[] entityIDs = new long[] {
|
|
|
527 |
1000001,
|
|
|
528 |
1000002,
|
|
|
529 |
1000003,
|
|
|
530 |
1000004,
|
|
|
531 |
1000005,
|
|
|
532 |
1000006,
|
|
|
533 |
1000007,
|
|
|
534 |
1000008,
|
|
|
535 |
1000009,
|
|
|
536 |
1000010,
|
|
|
537 |
1000011,
|
|
|
538 |
1000012,
|
|
|
539 |
1000013,
|
|
|
540 |
1000014,
|
|
|
541 |
1000015
|
|
|
542 |
};
|
|
|
543 |
|
|
|
544 |
for(int i=0;i<entityIDs.length;i++) {
|
|
|
545 |
for(int j=0;j<entityIDs.length;j++) {
|
|
|
546 |
diff(entityIDs[i], entityIDs[j]);
|
|
|
547 |
}
|
|
|
548 |
}
|
|
|
549 |
}
|
|
|
550 |
|
|
|
551 |
public static void diff(long entityID1, long entityID2) throws Exception {
|
|
|
552 |
// Setup
|
|
|
553 |
Velocity.init("src/in/shop2020/ui/util/velocity.properties");
|
|
|
554 |
VelocityContext context = new VelocityContext();
|
|
|
555 |
|
|
|
556 |
String templateFile = Utils.VTL_SRC_PATH + "jquery_diff_slideguide.vm";
|
|
|
557 |
|
|
|
558 |
Template template = null;
|
|
|
559 |
String exportFileName = null;
|
|
|
560 |
|
|
|
561 |
EntityContainer ents = Catalog.getInstance().getEntityContainer();
|
|
|
562 |
|
|
|
563 |
ExpandedEntity expEntity1 = ents.getExpandedEntity(entityID1);
|
|
|
564 |
ExpandedEntity expEntity2 = ents.getExpandedEntity(entityID2);
|
|
|
565 |
|
|
|
566 |
List<ExpandedSlide[]> mergedSlides =
|
|
|
567 |
getMergedSlides(expEntity1, expEntity2);
|
|
|
568 |
Utils.info("mergedSlides=" + mergedSlides);
|
|
|
569 |
|
|
|
570 |
Collection<String[]> mergedComparisonScores =
|
|
|
571 |
getMergedComparisonScores(expEntity1, expEntity2);
|
|
|
572 |
Utils.info("mergedComparisonScores=" + mergedComparisonScores);
|
|
|
573 |
|
| 1050 |
rajveer |
574 |
int scoreEntity1 = CreationUtils.getEntityComparisonScores(expEntity1.getID());
|
| 163 |
naveen |
575 |
|
| 1050 |
rajveer |
576 |
int scoreEntity2 = CreationUtils.getEntityComparisonScores(expEntity2.getID());
|
| 163 |
naveen |
577 |
|
|
|
578 |
context.put("expEntity1", expEntity1);
|
|
|
579 |
context.put("expEntity2", expEntity2);
|
|
|
580 |
context.put("mergedSlides", mergedSlides);
|
|
|
581 |
context.put("mergedComparisonScores", mergedComparisonScores);
|
|
|
582 |
context.put("scoreEntity1", scoreEntity1);
|
|
|
583 |
context.put("scoreEntity2", scoreEntity2);
|
|
|
584 |
|
|
|
585 |
template = Velocity.getTemplate(templateFile);
|
|
|
586 |
exportFileName = Utils.EXPORT_DIFF_PATH + entityID1 + "_" + entityID2 +
|
|
|
587 |
".html";
|
|
|
588 |
|
|
|
589 |
File exportFile = new File(exportFileName);
|
|
|
590 |
if(!exportFile.exists()) {
|
|
|
591 |
exportFile.createNewFile();
|
|
|
592 |
}
|
|
|
593 |
|
|
|
594 |
BufferedWriter writer = new BufferedWriter(
|
|
|
595 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
596 |
|
|
|
597 |
template.merge(context, writer);
|
|
|
598 |
|
|
|
599 |
writer.flush();
|
|
|
600 |
writer.close();
|
|
|
601 |
Utils.info("Export Complete!");
|
|
|
602 |
}
|
| 451 |
rajveer |
603 |
|
| 638 |
rajveer |
604 |
public static void getProductSummaryHtml(long catalogId, long itemId, String templateFile) {
|
| 451 |
rajveer |
605 |
CatalogServiceClient catalogServiceClient = null;
|
|
|
606 |
Client client = null;
|
|
|
607 |
String htmlString = "";
|
|
|
608 |
|
|
|
609 |
try {
|
| 512 |
rajveer |
610 |
double rating_all = 0.0;
|
| 451 |
rajveer |
611 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
612 |
client = catalogServiceClient.getClient();
|
| 638 |
rajveer |
613 |
List<Item> items = client.getItemsByCatalogId(catalogId);
|
| 451 |
rajveer |
614 |
|
| 638 |
rajveer |
615 |
|
|
|
616 |
List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>();
|
| 897 |
rajveer |
617 |
Date todate = new Date();
|
| 638 |
rajveer |
618 |
|
|
|
619 |
for(Item item: items){
|
| 897 |
rajveer |
620 |
if(item.getItemStatus() != status.ACTIVE || todate.getTime() < item.getStartDate()){
|
|
|
621 |
continue;
|
|
|
622 |
}
|
| 638 |
rajveer |
623 |
Map<String, String> itemDetail = new HashMap<String, String>();
|
|
|
624 |
double sellingPrice = item.getSellingPrice();
|
|
|
625 |
double mrp = item.getMrp();
|
|
|
626 |
double saving = Math.round((mrp-sellingPrice)/mrp*100);
|
| 806 |
rajveer |
627 |
itemDetail.put("ITEM_ID", ((int)item.getId())+"");
|
|
|
628 |
itemDetail.put("CATALOG_ID", ((int)item.getCatalogItemId())+"");
|
| 638 |
rajveer |
629 |
itemDetail.put("SP", ((int)item.getSellingPrice())+"");
|
|
|
630 |
itemDetail.put("MRP", ((int)item.getMrp())+"");
|
|
|
631 |
itemDetail.put("SAVING", ((int)saving)+"");
|
|
|
632 |
itemDetail.put("COLOR", item.getColor());
|
|
|
633 |
itemDetails.add(itemDetail);
|
|
|
634 |
}
|
|
|
635 |
|
| 451 |
rajveer |
636 |
// For an entity
|
|
|
637 |
EntityContainer entContainer = Catalog.getInstance().getEntityContainer();
|
| 638 |
rajveer |
638 |
ExpandedEntity expEntity = entContainer.getExpandedEntity(catalogId);
|
| 451 |
rajveer |
639 |
|
| 514 |
rajveer |
640 |
String title = expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber();
|
| 451 |
rajveer |
641 |
String categoryName = expEntity.getCategory().getLabel();
|
| 457 |
rajveer |
642 |
String tagline = "";
|
| 580 |
rajveer |
643 |
String warranty = "";
|
| 457 |
rajveer |
644 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
645 |
for(Feature feature: features){
|
|
|
646 |
if(feature.getFeatureDefinitionID() == 120084){
|
|
|
647 |
PrimitiveDataObject dataObject= (PrimitiveDataObject)feature.getBullets().get(0).getDataObject();
|
|
|
648 |
tagline = dataObject.getValue();
|
|
|
649 |
}
|
| 580 |
rajveer |
650 |
if(feature.getFeatureDefinitionID() == 120125){
|
|
|
651 |
ExpandedFeature expFeature = new ExpandedFeature(feature);
|
|
|
652 |
ExpandedBullet expBullet =expFeature.getExpandedBullets().get(0);
|
|
|
653 |
if(expBullet != null){
|
|
|
654 |
warranty = expBullet.getValue() + " "+ expBullet.getUnit().getShortForm();
|
|
|
655 |
}
|
|
|
656 |
}
|
| 457 |
rajveer |
657 |
}
|
| 451 |
rajveer |
658 |
|
|
|
659 |
|
|
|
660 |
|
|
|
661 |
|
|
|
662 |
long categoryId = expEntity.getCategory().getID();
|
|
|
663 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
664 |
params.put("TITLE", title);
|
| 516 |
rajveer |
665 |
params.put("CATEGORY_ID", ((int)categoryId)+"");
|
| 451 |
rajveer |
666 |
params.put("CATEGORY_NAME", categoryName);
|
| 993 |
vikas |
667 |
params.put("CATEGORY_URL", categoryName.replaceAll(" ", "-").toLowerCase() + "/" + categoryId);
|
| 638 |
rajveer |
668 |
/*
|
| 516 |
rajveer |
669 |
params.put("SELLING_PRICE", ((int)sellingPrice)+"");
|
|
|
670 |
params.put("MRP", ((int)mrp)+"");
|
|
|
671 |
params.put("SAVING", ((int)saving)+"");
|
| 638 |
rajveer |
672 |
params.put("ITEM_ID", ((int)itemId)+"");
|
|
|
673 |
*/
|
|
|
674 |
|
|
|
675 |
|
| 516 |
rajveer |
676 |
params.put("RATING_ALL", ((int)rating_all)+"");
|
| 638 |
rajveer |
677 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
| 451 |
rajveer |
678 |
params.put("TAGLINE", tagline);
|
| 580 |
rajveer |
679 |
params.put("WARRANTY", warranty);
|
|
|
680 |
|
| 451 |
rajveer |
681 |
VelocityContext context = new VelocityContext();
|
| 512 |
rajveer |
682 |
|
| 638 |
rajveer |
683 |
context.put("itemDetails", itemDetails);
|
|
|
684 |
|
| 451 |
rajveer |
685 |
context.put("params", params);
|
|
|
686 |
|
| 638 |
rajveer |
687 |
String exportFileName = Utils.EXPORT_ENTITIES_PATH + catalogId + File.separator + "ProductDetail.html";
|
| 451 |
rajveer |
688 |
|
|
|
689 |
File exportFile = new File(exportFileName);
|
|
|
690 |
if(!exportFile.exists()) {
|
|
|
691 |
exportFile.createNewFile();
|
|
|
692 |
}
|
|
|
693 |
|
|
|
694 |
BufferedWriter writer = new BufferedWriter(
|
|
|
695 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
696 |
|
|
|
697 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
698 |
template.merge(context, writer);
|
|
|
699 |
|
|
|
700 |
writer.flush();
|
|
|
701 |
writer.close();
|
|
|
702 |
Utils.info("Export Complete!");
|
|
|
703 |
|
|
|
704 |
|
|
|
705 |
} catch (Exception e) {
|
|
|
706 |
e.printStackTrace();
|
|
|
707 |
}
|
|
|
708 |
|
|
|
709 |
//return htmlString;
|
|
|
710 |
}
|
|
|
711 |
|
| 638 |
rajveer |
712 |
private static void getEntitySnippetHtml(long catalogId, long itemId, String templateFile) {
|
|
|
713 |
CatalogServiceClient catalogServiceClient = null;
|
|
|
714 |
Client client = null;
|
|
|
715 |
|
|
|
716 |
|
| 457 |
rajveer |
717 |
EntityContainer entContainer = Catalog.getInstance().getEntityContainer();
|
|
|
718 |
ExpandedEntity expEntity;
|
|
|
719 |
try {
|
| 638 |
rajveer |
720 |
|
|
|
721 |
expEntity = entContainer.getExpandedEntity(catalogId);
|
| 514 |
rajveer |
722 |
String title = expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber();
|
| 975 |
vikas |
723 |
String url = "/" + expEntity.getCategory().getParentCategory().getLabel().toLowerCase().replace(' ', '-') + "/"
|
|
|
724 |
+ expEntity.getBrand().toLowerCase().replace(' ', '-')
|
|
|
725 |
+ "-" + expEntity.getModelName().toLowerCase().replace(' ', '-')
|
|
|
726 |
+ "-" + expEntity.getModelNumber().toLowerCase().replace(' ', '-')
|
|
|
727 |
+ "-" + catalogId;
|
|
|
728 |
url = url.replaceAll("--", "-");
|
| 638 |
rajveer |
729 |
|
| 457 |
rajveer |
730 |
String tinySnippet = "";
|
|
|
731 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
732 |
for(Feature feature: features){
|
|
|
733 |
if(feature.getFeatureDefinitionID() == 120089){
|
|
|
734 |
PrimitiveDataObject dataObject= (PrimitiveDataObject)feature.getBullets().get(0).getDataObject();
|
|
|
735 |
tinySnippet = dataObject.getValue();
|
|
|
736 |
}
|
|
|
737 |
}
|
|
|
738 |
|
| 638 |
rajveer |
739 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
740 |
client = catalogServiceClient.getClient();
|
|
|
741 |
|
|
|
742 |
List<Item> items = client.getItemsByCatalogId(catalogId);
|
|
|
743 |
List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>();
|
|
|
744 |
|
|
|
745 |
Item minPriceItem = null;
|
|
|
746 |
for(Item item: items){
|
|
|
747 |
Map<String, String> itemDetail = new HashMap<String, String>();
|
|
|
748 |
if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
|
|
|
749 |
minPriceItem = item;
|
|
|
750 |
}
|
|
|
751 |
double sellingPrice = item.getSellingPrice();
|
|
|
752 |
double mrp = item.getMrp();
|
|
|
753 |
double saving = Math.round((mrp-sellingPrice)/mrp*100);
|
|
|
754 |
itemDetail.put("ITEM_ID", ((int)item.getId())+"");
|
|
|
755 |
itemDetail.put("SP", ((int)item.getSellingPrice())+"");
|
|
|
756 |
itemDetail.put("MRP", ((int)item.getMrp())+"");
|
|
|
757 |
itemDetail.put("SAVING", ((int)saving)+"");
|
|
|
758 |
itemDetail.put("COLOR", item.getColor());
|
|
|
759 |
itemDetails.add(itemDetail);
|
|
|
760 |
}
|
|
|
761 |
|
| 457 |
rajveer |
762 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
763 |
params.put("TITLE", title);
|
| 975 |
vikas |
764 |
params.put("URL", url);
|
| 638 |
rajveer |
765 |
params.put("SELLING_PRICE", ((int)minPriceItem.getSellingPrice())+"");
|
|
|
766 |
params.put("MRP", ((int)minPriceItem.getMrp())+"");
|
|
|
767 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
768 |
params.put("ITEM_ID", minPriceItem.getId()+"");
|
| 457 |
rajveer |
769 |
params.put("TINY_SNIPPET", tinySnippet);
|
| 638 |
rajveer |
770 |
|
| 457 |
rajveer |
771 |
VelocityContext context = new VelocityContext();
|
| 638 |
rajveer |
772 |
context.put("itemDetails", itemDetails);
|
| 457 |
rajveer |
773 |
context.put("params", params);
|
| 638 |
rajveer |
774 |
|
|
|
775 |
String exportFileName = Utils.EXPORT_ENTITIES_PATH + catalogId + File.separator + "WidgetSnippet.html";
|
| 457 |
rajveer |
776 |
File exportFile = new File(exportFileName);
|
|
|
777 |
if(!exportFile.exists()) {
|
|
|
778 |
exportFile.createNewFile();
|
|
|
779 |
}
|
|
|
780 |
|
|
|
781 |
BufferedWriter writer = new BufferedWriter(
|
|
|
782 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
783 |
|
|
|
784 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
785 |
template.merge(context, writer);
|
|
|
786 |
|
|
|
787 |
writer.flush();
|
|
|
788 |
writer.close();
|
|
|
789 |
Utils.info("Export Complete!");
|
|
|
790 |
|
|
|
791 |
|
|
|
792 |
} catch (Exception e) {
|
|
|
793 |
// TODO Auto-generated catch block
|
|
|
794 |
e.printStackTrace();
|
|
|
795 |
}
|
|
|
796 |
}
|
| 638 |
rajveer |
797 |
private static void getEntityHomeSnippetHtml(long catalogId, long itemId, String templateFile) {
|
| 512 |
rajveer |
798 |
EntityContainer entContainer = Catalog.getInstance().getEntityContainer();
|
|
|
799 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
800 |
CatalogServiceClient catalogServiceClient = null;
|
|
|
801 |
Client client = null;
|
|
|
802 |
|
|
|
803 |
ExpandedEntity expEntity;
|
|
|
804 |
try {
|
| 638 |
rajveer |
805 |
expEntity = entContainer.getExpandedEntity(catalogId);
|
| 514 |
rajveer |
806 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
|
| 975 |
vikas |
807 |
String url = "/" + expEntity.getCategory().getParentCategory().getLabel().toLowerCase().replace(' ', '-') + "/"
|
|
|
808 |
+ expEntity.getBrand().toLowerCase().replace(' ', '-')
|
|
|
809 |
+ "-" + expEntity.getModelName().toLowerCase().replace(' ', '-')
|
|
|
810 |
+ "-" + expEntity.getModelNumber().toLowerCase().replace(' ', '-')
|
|
|
811 |
+ "-" + catalogId;
|
|
|
812 |
url = url.replaceAll("--", "-");
|
| 512 |
rajveer |
813 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
814 |
client = catalogServiceClient.getClient();
|
| 638 |
rajveer |
815 |
|
| 512 |
rajveer |
816 |
String tinySnippet = "";
|
|
|
817 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
818 |
for(Feature feature: features){
|
|
|
819 |
if(feature.getFeatureDefinitionID() == 120081){
|
|
|
820 |
List<Bullet> bullets = feature.getBullets();
|
|
|
821 |
int count = 1;
|
|
|
822 |
for(Bullet bullet: bullets){
|
|
|
823 |
PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
|
|
|
824 |
tinySnippet = dataObject.getValue();
|
|
|
825 |
params.put("SNIPPET_"+count++, tinySnippet);
|
|
|
826 |
System.out.println("Tiny Snippets is " + dataObject.getValue());
|
|
|
827 |
}
|
|
|
828 |
}
|
|
|
829 |
}
|
|
|
830 |
|
|
|
831 |
|
| 516 |
rajveer |
832 |
|
| 638 |
rajveer |
833 |
List<Item> items = client.getItemsByCatalogId(catalogId);
|
|
|
834 |
List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>();
|
|
|
835 |
|
| 897 |
rajveer |
836 |
Item minPriceItem = null;
|
|
|
837 |
Date todate = new Date();
|
|
|
838 |
|
| 638 |
rajveer |
839 |
for(Item item: items){
|
| 897 |
rajveer |
840 |
if(item.getItemStatus() != status.ACTIVE || todate.getTime() < item.getStartDate()){
|
|
|
841 |
continue;
|
|
|
842 |
}
|
| 638 |
rajveer |
843 |
Map<String, String> itemDetail = new HashMap<String, String>();
|
|
|
844 |
if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
|
|
|
845 |
minPriceItem = item;
|
|
|
846 |
}
|
|
|
847 |
double sellingPrice = item.getSellingPrice();
|
|
|
848 |
double mrp = item.getMrp();
|
|
|
849 |
double saving = Math.round((mrp-sellingPrice)/mrp*100);
|
|
|
850 |
itemDetail.put("ITEM_ID", ((int)item.getId())+"");
|
|
|
851 |
itemDetail.put("SP", ((int)item.getSellingPrice())+"");
|
|
|
852 |
itemDetail.put("MRP", ((int)item.getMrp())+"");
|
|
|
853 |
itemDetail.put("SAVING", ((int)saving)+"");
|
|
|
854 |
itemDetail.put("COLOR", item.getColor());
|
|
|
855 |
itemDetails.add(itemDetail);
|
|
|
856 |
}
|
|
|
857 |
|
| 512 |
rajveer |
858 |
params.put("TITLE", title);
|
| 975 |
vikas |
859 |
params.put("URL", url);
|
| 638 |
rajveer |
860 |
params.put("SELLING_PRICE", ((int)minPriceItem.getSellingPrice())+"");
|
|
|
861 |
params.put("MRP", ((int)minPriceItem.getMrp())+"");
|
|
|
862 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
863 |
params.put("ITEM_ID", minPriceItem.getId()+"");
|
| 512 |
rajveer |
864 |
|
|
|
865 |
VelocityContext context = new VelocityContext();
|
| 638 |
rajveer |
866 |
context.put("itemDetails", itemDetails);
|
| 512 |
rajveer |
867 |
context.put("params", params);
|
|
|
868 |
//htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
869 |
|
| 638 |
rajveer |
870 |
String exportFileName = Utils.EXPORT_ENTITIES_PATH + catalogId + File.separator + "HomeSnippet.html";
|
| 512 |
rajveer |
871 |
File exportFile = new File(exportFileName);
|
|
|
872 |
if(!exportFile.exists()) {
|
|
|
873 |
exportFile.createNewFile();
|
|
|
874 |
}
|
|
|
875 |
|
|
|
876 |
BufferedWriter writer = new BufferedWriter(
|
|
|
877 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
878 |
|
|
|
879 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
880 |
template.merge(context, writer);
|
|
|
881 |
|
|
|
882 |
writer.flush();
|
|
|
883 |
writer.close();
|
|
|
884 |
Utils.info("Export Complete!");
|
|
|
885 |
|
|
|
886 |
|
|
|
887 |
} catch (Exception e) {
|
|
|
888 |
// TODO Auto-generated catch block
|
|
|
889 |
e.printStackTrace();
|
|
|
890 |
}
|
|
|
891 |
}
|
| 457 |
rajveer |
892 |
|
| 638 |
rajveer |
893 |
private static void getEntityCategorySnippetHtml(long catalogId, long itemId, String templateFile) {
|
| 532 |
rajveer |
894 |
EntityContainer entContainer = Catalog.getInstance().getEntityContainer();
|
|
|
895 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
896 |
CatalogServiceClient catalogServiceClient = null;
|
|
|
897 |
Client client = null;
|
|
|
898 |
|
|
|
899 |
|
|
|
900 |
ExpandedEntity expEntity;
|
|
|
901 |
try {
|
| 638 |
rajveer |
902 |
expEntity = entContainer.getExpandedEntity(catalogId);
|
| 532 |
rajveer |
903 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
|
|
|
904 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
905 |
client = catalogServiceClient.getClient();
|
| 975 |
vikas |
906 |
String url = "/" + expEntity.getCategory().getParentCategory().getLabel().toLowerCase().replace(' ', '-') + "/"
|
|
|
907 |
+ expEntity.getBrand().toLowerCase().replace(' ', '-')
|
|
|
908 |
+ "-" + expEntity.getModelName().toLowerCase().replace(' ', '-')
|
|
|
909 |
+ "-" + expEntity.getModelNumber().toLowerCase().replace(' ', '-')
|
|
|
910 |
+ "-" + catalogId;
|
|
|
911 |
url = url.replaceAll("--", "-");
|
| 532 |
rajveer |
912 |
String tinySnippet = "";
|
|
|
913 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
914 |
for(Feature feature: features){
|
|
|
915 |
if(feature.getFeatureDefinitionID() == 120081){
|
|
|
916 |
List<Bullet> bullets = feature.getBullets();
|
|
|
917 |
int count = 1;
|
|
|
918 |
for(Bullet bullet: bullets){
|
|
|
919 |
PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
|
|
|
920 |
tinySnippet = dataObject.getValue();
|
|
|
921 |
params.put("SNIPPET_"+count++, tinySnippet);
|
|
|
922 |
System.out.println("Tiny Snippets is " + dataObject.getValue());
|
|
|
923 |
}
|
|
|
924 |
}
|
|
|
925 |
}
|
|
|
926 |
|
|
|
927 |
|
| 638 |
rajveer |
928 |
List<Item> items = client.getItemsByCatalogId(catalogId);
|
|
|
929 |
List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>();
|
| 532 |
rajveer |
930 |
|
| 897 |
rajveer |
931 |
|
|
|
932 |
Item minPriceItem = null;
|
|
|
933 |
Date todate = new Date();
|
| 638 |
rajveer |
934 |
for(Item item: items){
|
| 897 |
rajveer |
935 |
if(item.getItemStatus() != status.ACTIVE || todate.getTime() < item.getStartDate()){
|
|
|
936 |
continue;
|
|
|
937 |
}
|
| 638 |
rajveer |
938 |
Map<String, String> itemDetail = new HashMap<String, String>();
|
|
|
939 |
if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
|
|
|
940 |
minPriceItem = item;
|
|
|
941 |
}
|
|
|
942 |
double sellingPrice = item.getSellingPrice();
|
|
|
943 |
double mrp = item.getMrp();
|
|
|
944 |
double saving = Math.round((mrp-sellingPrice)/mrp*100);
|
|
|
945 |
itemDetail.put("ITEM_ID", ((int)item.getId())+"");
|
|
|
946 |
itemDetail.put("SP", ((int)item.getSellingPrice())+"");
|
|
|
947 |
itemDetail.put("MRP", ((int)item.getMrp())+"");
|
|
|
948 |
itemDetail.put("SAVING", ((int)saving)+"");
|
|
|
949 |
itemDetail.put("COLOR", item.getColor());
|
|
|
950 |
itemDetails.add(itemDetail);
|
|
|
951 |
}
|
|
|
952 |
|
| 532 |
rajveer |
953 |
params.put("TITLE", title);
|
| 975 |
vikas |
954 |
params.put("URL", url);
|
| 638 |
rajveer |
955 |
params.put("SELLING_PRICE", ((int)minPriceItem.getSellingPrice())+"");
|
|
|
956 |
params.put("MRP", ((int)minPriceItem.getMrp())+"");
|
|
|
957 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
958 |
params.put("ITEM_ID", minPriceItem.getId()+"");
|
| 532 |
rajveer |
959 |
|
|
|
960 |
VelocityContext context = new VelocityContext();
|
| 638 |
rajveer |
961 |
context.put("itemDetails", itemDetails);
|
| 532 |
rajveer |
962 |
context.put("params", params);
|
|
|
963 |
//htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
964 |
|
| 638 |
rajveer |
965 |
String exportFileName = Utils.EXPORT_ENTITIES_PATH + catalogId + File.separator + "CategorySnippet.html";
|
| 532 |
rajveer |
966 |
File exportFile = new File(exportFileName);
|
|
|
967 |
if(!exportFile.exists()) {
|
|
|
968 |
exportFile.createNewFile();
|
|
|
969 |
}
|
|
|
970 |
|
|
|
971 |
BufferedWriter writer = new BufferedWriter(
|
|
|
972 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
973 |
|
|
|
974 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
975 |
template.merge(context, writer);
|
|
|
976 |
|
|
|
977 |
writer.flush();
|
|
|
978 |
writer.close();
|
|
|
979 |
Utils.info("Export Complete!");
|
|
|
980 |
|
|
|
981 |
|
|
|
982 |
} catch (Exception e) {
|
|
|
983 |
// TODO Auto-generated catch block
|
|
|
984 |
e.printStackTrace();
|
|
|
985 |
}
|
|
|
986 |
}
|
|
|
987 |
|
| 975 |
vikas |
988 |
private static void getEntityTitleSnippetHtml(long catalogId) {
|
|
|
989 |
EntityContainer entContainer = Catalog.getInstance().getEntityContainer();
|
|
|
990 |
|
|
|
991 |
ExpandedEntity expEntity;
|
|
|
992 |
try {
|
|
|
993 |
expEntity = entContainer.getExpandedEntity(catalogId);
|
|
|
994 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " "
|
| 979 |
vikas |
995 |
+ expEntity.getModelNumber();
|
|
|
996 |
if(expEntity.getCategory().getParentCategory().getID() == 10001) {
|
|
|
997 |
title += " | " + expEntity.getBrand() + " Mobile Phones";
|
|
|
998 |
}
|
|
|
999 |
if(expEntity.getCategory().getParentCategory().getID() == 10011) {
|
|
|
1000 |
title += " " + expEntity.getCategory().getLabel()
|
|
|
1001 |
+ " | " + expEntity.getBrand() + " Mobile Phone Accessories";
|
|
|
1002 |
}
|
|
|
1003 |
title += " | Saholic.com";
|
| 975 |
vikas |
1004 |
|
| 988 |
vikas |
1005 |
String exportFileName = Utils.EXPORT_ENTITIES_PATH + catalogId + File.separator + "TitleSnippet.html";
|
| 975 |
vikas |
1006 |
File exportFile = new File(exportFileName);
|
|
|
1007 |
if(!exportFile.exists()) {
|
|
|
1008 |
exportFile.createNewFile();
|
|
|
1009 |
}
|
|
|
1010 |
|
|
|
1011 |
BufferedWriter writer = new BufferedWriter(
|
|
|
1012 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
1013 |
|
|
|
1014 |
writer.write(title);
|
|
|
1015 |
|
|
|
1016 |
writer.flush();
|
|
|
1017 |
writer.close();
|
|
|
1018 |
} catch (Exception e) {
|
|
|
1019 |
// TODO Auto-generated catch block
|
|
|
1020 |
e.printStackTrace();
|
|
|
1021 |
}
|
|
|
1022 |
}
|
|
|
1023 |
|
| 532 |
rajveer |
1024 |
|
| 638 |
rajveer |
1025 |
private static void getEntitySearchSnippetHtml(long catalogId, long itemId, String templateFile) {
|
| 516 |
rajveer |
1026 |
EntityContainer entContainer = Catalog.getInstance().getEntityContainer();
|
|
|
1027 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
1028 |
CatalogServiceClient catalogServiceClient = null;
|
|
|
1029 |
Client client = null;
|
|
|
1030 |
|
|
|
1031 |
|
|
|
1032 |
|
|
|
1033 |
ExpandedEntity expEntity;
|
|
|
1034 |
try {
|
| 638 |
rajveer |
1035 |
expEntity = entContainer.getExpandedEntity(catalogId);
|
| 516 |
rajveer |
1036 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
|
| 975 |
vikas |
1037 |
String url = "/" + expEntity.getCategory().getParentCategory().getLabel().toLowerCase().replace(' ', '-') + "/"
|
|
|
1038 |
+ expEntity.getBrand().toLowerCase().replace(' ', '-')
|
|
|
1039 |
+ "-" + expEntity.getModelName().toLowerCase().replace(' ', '-')
|
|
|
1040 |
+ "-" + expEntity.getModelNumber().toLowerCase().replace(' ', '-')
|
|
|
1041 |
+ "-" + catalogId;
|
|
|
1042 |
url = url.replaceAll("--", "-");
|
| 516 |
rajveer |
1043 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
1044 |
client = catalogServiceClient.getClient();
|
| 638 |
rajveer |
1045 |
//Item item = client.getItem(itemId);
|
| 516 |
rajveer |
1046 |
String tinySnippet = "";
|
|
|
1047 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
1048 |
for(Feature feature: features){
|
|
|
1049 |
if(feature.getFeatureDefinitionID() == 120081){
|
|
|
1050 |
List<Bullet> bullets = feature.getBullets();
|
|
|
1051 |
int count = 1;
|
|
|
1052 |
for(Bullet bullet: bullets){
|
|
|
1053 |
PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
|
|
|
1054 |
tinySnippet = dataObject.getValue();
|
|
|
1055 |
params.put("SNIPPET_"+count++, tinySnippet);
|
|
|
1056 |
System.out.println("Tiny Snippets is " + dataObject.getValue());
|
|
|
1057 |
}
|
|
|
1058 |
}
|
|
|
1059 |
}
|
|
|
1060 |
|
|
|
1061 |
|
| 638 |
rajveer |
1062 |
List<Item> items = client.getItemsByCatalogId(catalogId);
|
|
|
1063 |
List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>();
|
| 516 |
rajveer |
1064 |
|
| 897 |
rajveer |
1065 |
Item minPriceItem = null;
|
|
|
1066 |
Date todate = new Date();
|
| 638 |
rajveer |
1067 |
for(Item item: items){
|
| 897 |
rajveer |
1068 |
if(item.getItemStatus() != status.ACTIVE || todate.getTime() < item.getStartDate()){
|
|
|
1069 |
continue;
|
|
|
1070 |
}
|
| 638 |
rajveer |
1071 |
Map<String, String> itemDetail = new HashMap<String, String>();
|
|
|
1072 |
if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
|
|
|
1073 |
minPriceItem = item;
|
|
|
1074 |
}
|
|
|
1075 |
double sellingPrice = item.getSellingPrice();
|
|
|
1076 |
double mrp = item.getMrp();
|
|
|
1077 |
double saving = Math.round((mrp-sellingPrice)/mrp*100);
|
|
|
1078 |
itemDetail.put("ITEM_ID", ((int)item.getId())+"");
|
|
|
1079 |
itemDetail.put("SP", ((int)item.getSellingPrice())+"");
|
|
|
1080 |
itemDetail.put("MRP", ((int)item.getMrp())+"");
|
|
|
1081 |
itemDetail.put("SAVING", ((int)saving)+"");
|
|
|
1082 |
itemDetail.put("COLOR", item.getColor());
|
|
|
1083 |
itemDetails.add(itemDetail);
|
|
|
1084 |
}
|
|
|
1085 |
|
| 516 |
rajveer |
1086 |
params.put("TITLE", title);
|
| 975 |
vikas |
1087 |
params.put("URL", url);
|
| 638 |
rajveer |
1088 |
params.put("SELLING_PRICE", ((int)minPriceItem.getSellingPrice())+"");
|
|
|
1089 |
params.put("MRP", ((int)minPriceItem.getMrp())+"");
|
|
|
1090 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
1091 |
params.put("ITEM_ID", minPriceItem.getId()+"");
|
| 516 |
rajveer |
1092 |
|
|
|
1093 |
|
|
|
1094 |
VelocityContext context = new VelocityContext();
|
| 638 |
rajveer |
1095 |
context.put("itemDetails", itemDetails);
|
| 516 |
rajveer |
1096 |
context.put("params", params);
|
|
|
1097 |
//htmlString = getHtmlFromVelocity(templateFile, context);
|
|
|
1098 |
|
| 638 |
rajveer |
1099 |
String exportFileName = Utils.EXPORT_ENTITIES_PATH + catalogId + File.separator + "SearchSnippet.html";
|
| 516 |
rajveer |
1100 |
File exportFile = new File(exportFileName);
|
|
|
1101 |
if(!exportFile.exists()) {
|
|
|
1102 |
exportFile.createNewFile();
|
|
|
1103 |
}
|
|
|
1104 |
|
|
|
1105 |
BufferedWriter writer = new BufferedWriter(
|
|
|
1106 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
1107 |
|
|
|
1108 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
1109 |
template.merge(context, writer);
|
|
|
1110 |
|
|
|
1111 |
writer.flush();
|
|
|
1112 |
writer.close();
|
|
|
1113 |
Utils.info("Export Complete!");
|
|
|
1114 |
|
|
|
1115 |
|
|
|
1116 |
} catch (Exception e) {
|
|
|
1117 |
// TODO Auto-generated catch block
|
|
|
1118 |
e.printStackTrace();
|
|
|
1119 |
}
|
|
|
1120 |
}
|
|
|
1121 |
|
|
|
1122 |
|
| 451 |
rajveer |
1123 |
public String getHtmlFromVelocity(String templateFile, VelocityContext context){
|
|
|
1124 |
try {
|
|
|
1125 |
Velocity.init("velocity/velocity.properties");
|
|
|
1126 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
1127 |
if(template != null) {
|
|
|
1128 |
StringWriter writer = new StringWriter();
|
|
|
1129 |
template.merge(context, writer);
|
|
|
1130 |
writer.flush();
|
|
|
1131 |
writer.close();
|
|
|
1132 |
return writer.toString();
|
|
|
1133 |
}
|
|
|
1134 |
|
|
|
1135 |
} catch (ResourceNotFoundException e) {
|
|
|
1136 |
// TODO Auto-generated catch block
|
|
|
1137 |
e.printStackTrace();
|
|
|
1138 |
} catch (ParseErrorException e) {
|
|
|
1139 |
// TODO Auto-generated catch block
|
|
|
1140 |
e.printStackTrace();
|
|
|
1141 |
} catch (MethodInvocationException e) {
|
|
|
1142 |
// TODO Auto-generated catch block
|
|
|
1143 |
e.printStackTrace();
|
|
|
1144 |
} catch (IOException e) {
|
|
|
1145 |
// TODO Auto-generated catch block
|
|
|
1146 |
e.printStackTrace();
|
|
|
1147 |
} catch (Exception e) {
|
|
|
1148 |
// TODO Auto-generated catch block
|
|
|
1149 |
e.printStackTrace();
|
|
|
1150 |
}
|
|
|
1151 |
|
|
|
1152 |
return null;
|
|
|
1153 |
}
|
|
|
1154 |
|
|
|
1155 |
|
| 22 |
naveen |
1156 |
}
|