| 2171 |
rajveer |
1 |
package in.shop2020.ui.util;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.metamodel.core.Bullet;
|
|
|
4 |
import in.shop2020.metamodel.core.Entity;
|
|
|
5 |
import in.shop2020.metamodel.core.EntityState;
|
|
|
6 |
import in.shop2020.metamodel.core.EntityStatus;
|
|
|
7 |
import in.shop2020.metamodel.core.Feature;
|
|
|
8 |
import in.shop2020.metamodel.core.PrimitiveDataObject;
|
|
|
9 |
import in.shop2020.metamodel.definitions.CMPBucketDefinition;
|
|
|
10 |
import in.shop2020.metamodel.definitions.Catalog;
|
|
|
11 |
import in.shop2020.metamodel.definitions.DefinitionsContainer;
|
|
|
12 |
|
|
|
13 |
import in.shop2020.metamodel.definitions.SlideDefinition;
|
|
|
14 |
import in.shop2020.metamodel.util.CreationUtils;
|
|
|
15 |
import in.shop2020.metamodel.util.ExpandedBullet;
|
|
|
16 |
import in.shop2020.metamodel.util.ExpandedEntity;
|
|
|
17 |
import in.shop2020.metamodel.util.ExpandedFeature;
|
|
|
18 |
import in.shop2020.metamodel.util.ExpandedSlide;
|
|
|
19 |
import in.shop2020.model.v1.catalog.InventoryService.Client;
|
|
|
20 |
import in.shop2020.model.v1.catalog.Item;
|
|
|
21 |
import in.shop2020.model.v1.catalog.status;
|
|
|
22 |
import in.shop2020.thrift.clients.CatalogServiceClient;
|
|
|
23 |
import in.shop2020.util.Utils;
|
|
|
24 |
|
|
|
25 |
import java.awt.Graphics2D;
|
|
|
26 |
import java.awt.geom.AffineTransform;
|
|
|
27 |
import java.awt.image.BufferedImage;
|
|
|
28 |
import java.io.BufferedReader;
|
|
|
29 |
import java.io.BufferedWriter;
|
|
|
30 |
import java.io.DataInputStream;
|
|
|
31 |
import java.io.DataOutputStream;
|
|
|
32 |
import java.io.File;
|
|
|
33 |
import java.io.FileInputStream;
|
|
|
34 |
import java.io.FileNotFoundException;
|
|
|
35 |
import java.io.FileOutputStream;
|
|
|
36 |
import java.io.FileReader;
|
|
|
37 |
import java.io.FileWriter;
|
|
|
38 |
import java.io.IOException;
|
|
|
39 |
import java.io.InputStream;
|
|
|
40 |
import java.io.InputStreamReader;
|
|
|
41 |
import java.io.OutputStream;
|
|
|
42 |
import java.io.OutputStreamWriter;
|
|
|
43 |
import java.io.StringWriter;
|
| 2227 |
rajveer |
44 |
import java.net.URLEncoder;
|
| 2171 |
rajveer |
45 |
import java.text.DecimalFormat;
|
|
|
46 |
import java.util.ArrayList;
|
|
|
47 |
import java.util.Collection;
|
|
|
48 |
import java.util.Date;
|
|
|
49 |
import java.util.HashMap;
|
|
|
50 |
import java.util.LinkedHashMap;
|
|
|
51 |
import java.util.List;
|
|
|
52 |
import java.util.Map;
|
|
|
53 |
|
|
|
54 |
import javax.imageio.ImageIO;
|
|
|
55 |
|
|
|
56 |
import org.apache.commons.lang.StringUtils;
|
|
|
57 |
import org.apache.velocity.Template;
|
|
|
58 |
import org.apache.velocity.VelocityContext;
|
|
|
59 |
import org.apache.velocity.app.Velocity;
|
|
|
60 |
import org.apache.velocity.exception.MethodInvocationException;
|
|
|
61 |
import org.apache.velocity.exception.ParseErrorException;
|
|
|
62 |
import org.apache.velocity.exception.ResourceNotFoundException;
|
|
|
63 |
|
|
|
64 |
/**
|
|
|
65 |
* utility class to generated all html stuff from java objects
|
|
|
66 |
* Driver class to merge Java data objects with VTL script.
|
|
|
67 |
*
|
|
|
68 |
* @author rajveer
|
|
|
69 |
*
|
|
|
70 |
*/
|
|
|
71 |
public class NewVUI {
|
|
|
72 |
CatalogServiceClient catalogServiceClient = null;
|
|
|
73 |
Client client = null;
|
|
|
74 |
String lastContentVersion;
|
|
|
75 |
String contentVersion;
|
|
|
76 |
|
|
|
77 |
StringBuffer problems = new StringBuffer();
|
|
|
78 |
|
|
|
79 |
public NewVUI(Long contentVersion) throws Exception {
|
|
|
80 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
81 |
client = catalogServiceClient.getClient();
|
|
|
82 |
this.lastContentVersion = contentVersion.toString();
|
|
|
83 |
this.contentVersion = (new Date()).getTime() +"" ;
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
/**
|
|
|
88 |
* Usage: VUI [entities | entity] [Entity ID] {Template file name}
|
|
|
89 |
*
|
|
|
90 |
* @param args
|
|
|
91 |
*/
|
|
|
92 |
public static void main(String[] args) throws Exception {
|
|
|
93 |
|
|
|
94 |
String[] commands = new String[] {"entity", "entities", "entitiesall"};
|
|
|
95 |
String[] datatypes = new String[] {"Entity ID"};
|
|
|
96 |
|
|
|
97 |
String usage = "Usage: VUI ["+ StringUtils.join(commands, "|") +"] ["+ StringUtils.join(datatypes, "|") + "] ";
|
|
|
98 |
|
|
|
99 |
if(args.length < 1) {
|
|
|
100 |
System.out.println(usage);
|
|
|
101 |
System.exit(-1);
|
|
|
102 |
}
|
|
|
103 |
String inputCommand = args[0];
|
|
|
104 |
String inputID = null;
|
|
|
105 |
if(args.length == 2){
|
|
|
106 |
inputID = args[1];
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
Long lastGenerationTime = CreationUtils.getLastContentGenerationTime();
|
|
|
110 |
if(lastGenerationTime==null){
|
|
|
111 |
lastGenerationTime = new Long(0);
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
//If non incremental content needs to be generated
|
|
|
115 |
if(inputCommand.equals("entitiesall") || inputCommand.equals("entity")) {
|
|
|
116 |
lastGenerationTime = new Long(0);
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
NewVUI vui = new NewVUI(lastGenerationTime);
|
|
|
120 |
|
|
|
121 |
long catalogId = 0;
|
|
|
122 |
if(inputCommand.equals("entity")) {
|
|
|
123 |
try {
|
|
|
124 |
catalogId = Long.parseLong(inputID);
|
|
|
125 |
// vui.generateHtmlForOneEntity(CreationUtils.getEntity(catalogId), "saholic.com", Utils.EXPORT_ENTITIES_PATH_SAHOLIC);
|
|
|
126 |
// vui.generateHtmlForOneEntity(CreationUtils.getEntity(catalogId), "shop2020.in", Utils.EXPORT_ENTITIES_PATH_SHOP2020);
|
|
|
127 |
// vui.generateHtmlForOneEntity(CreationUtils.getEntity(catalogId), "localhost:8090", Utils.EXPORT_ENTITIES_PATH_LOCALHOST);
|
|
|
128 |
}
|
|
|
129 |
catch (NumberFormatException nfe) {
|
|
|
130 |
System.out.println("Invalid ID - " + inputID);
|
|
|
131 |
System.exit(-1);
|
|
|
132 |
}
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
if(inputCommand.equals("entities") || inputCommand.equals("entitiesall")) {
|
|
|
136 |
vui.generateHtmlForAllEntities("saholic.com", Utils.EXPORT_ENTITIES_PATH_SAHOLIC);
|
|
|
137 |
vui.generateHtmlForAllEntities("shop2020.in", Utils.EXPORT_ENTITIES_PATH_SHOP2020);
|
|
|
138 |
vui.generateHtmlForAllEntities("localhost:8090", Utils.EXPORT_ENTITIES_PATH_LOCALHOST);
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
|
|
|
142 |
Velocity.init("src/main/java/in/shop2020/ui/util/velocity.properties");
|
|
|
143 |
|
|
|
144 |
CreationUtils.storeLastContentGenerationTime((new Date()).getTime());
|
|
|
145 |
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
/**
|
|
|
149 |
* Generates content for the specified entity embedding links to the
|
|
|
150 |
* specified domain name.
|
|
|
151 |
*
|
|
|
152 |
* The method updates the member variable problems in any of the following
|
|
|
153 |
* four cases:
|
|
|
154 |
* <ol>
|
|
|
155 |
* <li>The entity is not ready.
|
|
|
156 |
* <li>The category has not been updated yet. (Set to -1).
|
|
|
157 |
* <li>There are no items in the catalog corresponding to this entity.
|
|
|
158 |
* <li>There are no active or content-complete items in the catalog
|
|
|
159 |
* corresponding to this entity.
|
|
|
160 |
* <li>Neither the items have been updated nor the content has been updated.
|
|
|
161 |
* </ol>
|
|
|
162 |
*
|
|
|
163 |
* @param entity
|
|
|
164 |
* - Entity for which the content has to be generated.
|
|
|
165 |
* @param domain
|
|
|
166 |
* - The domain name to be used to serve static content.
|
|
|
167 |
* @param exportPath
|
|
|
168 |
* - Local file system path where content has to be generated.
|
|
|
169 |
* @return -True if content is generated successfully, False otherwise.
|
|
|
170 |
* @throws Exception
|
|
|
171 |
*/
|
|
|
172 |
public boolean generateHtmlForOneEntity(Entity entity, String domain, String exportPath, List<Item> items) throws Exception{
|
|
|
173 |
String mediaPath = Utils.EXPORT_MEDIA_PATH + entity.getID();
|
|
|
174 |
|
|
|
175 |
deleteOldResources(mediaPath, exportPath + entity.getID());
|
|
|
176 |
|
|
|
177 |
ExpandedEntity expEntity = new ExpandedEntity(entity);
|
|
|
178 |
|
|
|
179 |
long catalogId = expEntity.getID();
|
|
|
180 |
String templateFile;
|
|
|
181 |
|
|
|
182 |
|
|
|
183 |
//Create new directory
|
|
|
184 |
File exportDir = new File(exportPath + catalogId);
|
|
|
185 |
if(!exportDir.exists()) {
|
|
|
186 |
exportDir.mkdir();
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
/*
|
|
|
190 |
* To delete
|
|
|
191 |
*/
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
// This URL is used to ensure that images such as icon and thumbnail for
|
|
|
195 |
// a particular entity are always downloaded from the same location.
|
|
|
196 |
String staticurl = "http://static" + entity.getID()%3 + "." + domain;
|
|
|
197 |
|
|
|
198 |
templateFile= Utils.VTL_SRC_PATH + "product_summary.vm";
|
| 2227 |
rajveer |
199 |
getProductSummaryHtml(expEntity, items, templateFile, exportPath, domain);
|
| 2171 |
rajveer |
200 |
|
|
|
201 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_widget.vm";
|
|
|
202 |
getEntityWidgetSnippetHtml(expEntity, items, templateFile, staticurl, exportPath);
|
|
|
203 |
|
|
|
204 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_homepage.vm";
|
|
|
205 |
getEntityHomeSnippetHtml(expEntity, items, templateFile, staticurl, exportPath);
|
|
|
206 |
|
|
|
207 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_searchpage.vm";
|
|
|
208 |
getEntitySearchSnippetHtml(expEntity, items, templateFile, staticurl, exportPath);
|
|
|
209 |
|
|
|
210 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_categorypage.vm";
|
|
|
211 |
getEntityCategorySnippetHtml(expEntity, items, templateFile, staticurl, exportPath);
|
|
|
212 |
|
|
|
213 |
templateFile= Utils.VTL_SRC_PATH + "slideguide_img_video.vm";
|
|
|
214 |
getEntitySlideGuideHtml(expEntity, templateFile, domain, exportPath);
|
| 2205 |
rajveer |
215 |
|
|
|
216 |
|
| 2171 |
rajveer |
217 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_phones_i_own.vm";
|
|
|
218 |
getEntityPhonesIOwnSnippetHtml(expEntity, items, templateFile, staticurl, exportPath);
|
|
|
219 |
|
|
|
220 |
if(expEntity.getCategory().getParentCategory().getID() == Utils.MOBILE_PHONES_CATAGOEY){
|
|
|
221 |
|
|
|
222 |
templateFile= Utils.VTL_SRC_PATH + "slideguide_for_comparison.vm";
|
|
|
223 |
getEntitySnippetForComparison(expEntity, templateFile, domain, exportPath);
|
|
|
224 |
|
|
|
225 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_comparisonpage.vm";
|
|
|
226 |
getEntityCompareSnippetHtml(expEntity, items, templateFile, staticurl, exportPath);
|
| 2205 |
rajveer |
227 |
|
| 2171 |
rajveer |
228 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_comparisonpage_summary.vm";
|
|
|
229 |
getEntityCompareSummarySnippetHtml(expEntity, items, templateFile, staticurl, exportPath);
|
| 2205 |
rajveer |
230 |
|
| 2171 |
rajveer |
231 |
getSlidenamesSnippet(expEntity, exportPath);
|
|
|
232 |
}
|
|
|
233 |
|
|
|
234 |
getEntityTitleSnippetHtml(expEntity, exportPath);
|
|
|
235 |
|
|
|
236 |
getEntityMetaDescriptionSnippetHtml(expEntity, exportPath);
|
|
|
237 |
|
|
|
238 |
getEntityMetaKeywordSnippetHtml(expEntity, exportPath);
|
|
|
239 |
|
|
|
240 |
generateImages(expEntity.getID(), getImagePrefix(expEntity));
|
|
|
241 |
|
|
|
242 |
return true;
|
|
|
243 |
}
|
|
|
244 |
|
|
|
245 |
private boolean generateHtmlForAllEntities(String domain, String exportPath) throws Exception{
|
|
|
246 |
Map<Long, Entity> entities = CreationUtils.getEntities();
|
|
|
247 |
for(Entity entity: entities.values()){
|
|
|
248 |
// generateHtmlForOneEntity(entity, domain, exportPath);
|
|
|
249 |
}
|
|
|
250 |
System.out.println(problems);
|
|
|
251 |
return true;
|
|
|
252 |
}
|
|
|
253 |
|
|
|
254 |
|
|
|
255 |
|
|
|
256 |
public boolean deleteDir(File dir) {
|
|
|
257 |
if (dir.isDirectory()) {
|
|
|
258 |
String[] children = dir.list();
|
|
|
259 |
for (int i=0; i<children.length; i++) {
|
|
|
260 |
boolean success = deleteDir(new File(dir, children[i]));
|
|
|
261 |
if (!success) {
|
|
|
262 |
return false;
|
|
|
263 |
}
|
|
|
264 |
}
|
|
|
265 |
}
|
|
|
266 |
|
|
|
267 |
// The directory is now empty so delete it
|
|
|
268 |
return dir.delete();
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
private void deleteOldResources(String mediaPath, String contentPath) {
|
|
|
272 |
File f = new File(contentPath);
|
|
|
273 |
if(f.exists()){
|
|
|
274 |
deleteDir(f);
|
|
|
275 |
}
|
|
|
276 |
|
|
|
277 |
f = new File(mediaPath);
|
|
|
278 |
if(f.exists()){
|
|
|
279 |
deleteDir(f);
|
|
|
280 |
}
|
|
|
281 |
}
|
|
|
282 |
|
|
|
283 |
private void generateImages(long catalogId, String imagePrefix) throws IOException {
|
|
|
284 |
String globalImageDirPath = Utils.CONTENT_DB_PATH + "media" + File.separator;
|
|
|
285 |
String globalDefaultImagePath = globalImageDirPath + "default.jpg";
|
|
|
286 |
|
|
|
287 |
String imageDirPath = globalImageDirPath + catalogId + File.separator;
|
|
|
288 |
String defaultImagePath = imageDirPath + "default.jpg";
|
|
|
289 |
|
|
|
290 |
/*
|
|
|
291 |
* Create the directory for this entity if it didn't exist.
|
|
|
292 |
*/
|
|
|
293 |
File f = new File(globalImageDirPath + catalogId);
|
|
|
294 |
if (!f.exists()) {
|
|
|
295 |
f.mkdir();
|
|
|
296 |
}
|
|
|
297 |
|
|
|
298 |
/*
|
|
|
299 |
* If the default image is not present for this entity, copy the global
|
|
|
300 |
* default image.
|
|
|
301 |
* TODO: This part will be moved to the Jython Script
|
|
|
302 |
*/
|
|
|
303 |
File f3 = new File(defaultImagePath);
|
|
|
304 |
if (!f3.exists()) {
|
|
|
305 |
copyFile(globalDefaultImagePath, defaultImagePath);
|
|
|
306 |
}
|
|
|
307 |
|
|
|
308 |
String exportPath = Utils.EXPORT_MEDIA_PATH + catalogId;
|
|
|
309 |
/*
|
|
|
310 |
* Copying the generated content from db/media to export/media. This
|
|
|
311 |
* will also insert a timestamp tag in the file names.
|
|
|
312 |
*/
|
|
|
313 |
File sourceFile = new File(globalImageDirPath + catalogId);
|
|
|
314 |
File destinationFile = new File(exportPath);
|
| 2198 |
rajveer |
315 |
copyDirectory(sourceFile, destinationFile, imagePrefix);
|
| 2171 |
rajveer |
316 |
|
|
|
317 |
/*
|
|
|
318 |
* Copy the thumbnail and the icon files. This is required so that we can display the
|
|
|
319 |
* thumbnail on the cart page and icon on the facebook.
|
|
|
320 |
*/
|
| 2198 |
rajveer |
321 |
copyFile(imageDirPath + "thumbnail.jpg", exportPath + File.separator + "thumbnail.jpg");
|
|
|
322 |
copyFile(imageDirPath + "icon.jpg", exportPath + File.separator + "icon.jpg");
|
| 2171 |
rajveer |
323 |
}
|
|
|
324 |
|
|
|
325 |
/**
|
|
|
326 |
* Copies the contents of the input file into the output file. Creates the
|
|
|
327 |
* output file if it doesn't exist already.
|
|
|
328 |
*
|
|
|
329 |
* @param inputFile
|
|
|
330 |
* File to be copied.
|
|
|
331 |
* @param outputFile
|
|
|
332 |
* File to be created.
|
|
|
333 |
* @throws IOException
|
|
|
334 |
*/
|
|
|
335 |
private void copyFile(String inputFile, String outputFile) throws IOException {
|
|
|
336 |
File sourceFile = new File(inputFile);
|
|
|
337 |
File destinationFile = new File(outputFile);
|
| 2206 |
rajveer |
338 |
|
| 2171 |
rajveer |
339 |
if (!destinationFile.exists())
|
|
|
340 |
destinationFile.createNewFile();
|
|
|
341 |
|
|
|
342 |
InputStream in = new FileInputStream(sourceFile);
|
|
|
343 |
OutputStream out = new FileOutputStream(destinationFile);
|
|
|
344 |
// Copy the bits from instream to outstream
|
|
|
345 |
byte[] buf = new byte[1024];
|
|
|
346 |
int len;
|
|
|
347 |
while ((len = in.read(buf)) > 0) {
|
|
|
348 |
out.write(buf, 0, len);
|
|
|
349 |
}
|
|
|
350 |
in.close();
|
|
|
351 |
out.close();
|
|
|
352 |
}
|
|
|
353 |
|
|
|
354 |
// If targetLocation does not exist, it will be created.
|
|
|
355 |
public void copyDirectory(File sourceLocation , File targetLocation, String imagePrefix) throws IOException {
|
|
|
356 |
|
|
|
357 |
if (sourceLocation.isDirectory()) {
|
|
|
358 |
if (!targetLocation.exists()) {
|
|
|
359 |
targetLocation.mkdir();
|
|
|
360 |
}
|
|
|
361 |
|
|
|
362 |
String[] children = sourceLocation.list();
|
|
|
363 |
for (int i=0; i<children.length; i++) {
|
|
|
364 |
copyDirectory(new File(sourceLocation, children[i]), new File(targetLocation, children[i]), imagePrefix);
|
|
|
365 |
}
|
|
|
366 |
} else {
|
|
|
367 |
InputStream in = new FileInputStream(sourceLocation);
|
|
|
368 |
|
|
|
369 |
String fileName = targetLocation.getName().split("\\.")[0];
|
|
|
370 |
String fileExt = targetLocation.getName().split("\\.")[1];
|
|
|
371 |
String newFileName = targetLocation.getParent() + File.separator + imagePrefix + "-" + fileName + "-" + this.contentVersion + "." + fileExt;
|
|
|
372 |
|
|
|
373 |
|
|
|
374 |
//String fileName = targetLocation
|
|
|
375 |
OutputStream out = new FileOutputStream(newFileName);
|
|
|
376 |
|
|
|
377 |
// Copy the bits from instream to outstream
|
|
|
378 |
byte[] buf = new byte[1024];
|
|
|
379 |
int len;
|
|
|
380 |
while ((len = in.read(buf)) > 0) {
|
|
|
381 |
out.write(buf, 0, len);
|
|
|
382 |
}
|
|
|
383 |
in.close();
|
|
|
384 |
out.close();
|
|
|
385 |
}
|
|
|
386 |
}
|
|
|
387 |
|
|
|
388 |
|
|
|
389 |
private void getEntityMetaDescriptionSnippetHtml(ExpandedEntity expEntity, String exportPath) {
|
|
|
390 |
long catalogId = expEntity.getID();
|
|
|
391 |
try {
|
|
|
392 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
|
|
393 |
String description = "Best Price " + expEntity.getBrand() + " " + expEntity.getModelName()
|
|
|
394 |
+ " " + expEntity.getModelNumber() + " ";
|
|
|
395 |
|
|
|
396 |
if(expEntity.getCategory().getParentCategory().getID() == 10011) {
|
|
|
397 |
description += expEntity.getCategory().getLabel() + " in India.";
|
|
|
398 |
}
|
|
|
399 |
else {
|
|
|
400 |
description += ".";
|
|
|
401 |
}
|
|
|
402 |
description += " Experience n' buy online. FREE Next Day delivery."
|
|
|
403 |
+ " Original product - Full manufacturer warranty. Comprehensive reviews.";
|
|
|
404 |
|
|
|
405 |
description = description.replaceAll("--", "-");
|
|
|
406 |
String exportFileName = exportPath + catalogId + File.separator + "MetaDescriptionSnippet.html";
|
|
|
407 |
File exportFile = new File(exportFileName);
|
|
|
408 |
if(!exportFile.exists()) {
|
|
|
409 |
exportFile.createNewFile();
|
|
|
410 |
}
|
|
|
411 |
|
|
|
412 |
BufferedWriter writer = new BufferedWriter(
|
|
|
413 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
414 |
|
|
|
415 |
writer.write(description);
|
|
|
416 |
|
|
|
417 |
writer.flush();
|
|
|
418 |
writer.close();
|
|
|
419 |
} catch (Exception e) {
|
|
|
420 |
e.printStackTrace();
|
|
|
421 |
}
|
|
|
422 |
}
|
|
|
423 |
|
|
|
424 |
private void getEntityMetaKeywordSnippetHtml(ExpandedEntity expEntity, String exportPath) {
|
|
|
425 |
long catalogId = expEntity.getID();
|
|
|
426 |
try {
|
|
|
427 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
| 2197 |
rajveer |
428 |
String keywords;
|
|
|
429 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
|
|
430 |
keywords = expEntity.getBrand() + " " + expEntity.getModelName() + ", ";
|
|
|
431 |
if (expEntity.getCategory().getParentCategory().getID() == 10001) {
|
|
|
432 |
keywords += expEntity.getBrand() + " mobile phones, ";
|
|
|
433 |
}
|
|
|
434 |
if (expEntity.getCategory().getParentCategory().getID() == 10011) {
|
|
|
435 |
keywords += "phone accessories, ";
|
|
|
436 |
}
|
|
|
437 |
keywords += expEntity.getBrand() + " " + expEntity.getModelName() + " Price, ";
|
|
|
438 |
keywords += expEntity.getBrand() + " " + expEntity.getModelName() + " India, ";
|
|
|
439 |
if (expEntity.getCategory().getParentCategory().getID() == 10001) {
|
|
|
440 |
keywords += expEntity.getBrand() + " " + expEntity.getModelName() + " Review, ";
|
|
|
441 |
}
|
|
|
442 |
}
|
|
|
443 |
else {
|
|
|
444 |
keywords = expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber() + ", ";
|
|
|
445 |
if(expEntity.getCategory().getParentCategory().getID() == 10001) {
|
|
|
446 |
keywords += expEntity.getBrand() + " mobile phones, ";
|
|
|
447 |
}
|
|
|
448 |
if(expEntity.getCategory().getParentCategory().getID() == 10011) {
|
|
|
449 |
keywords += "phone accessories, ";
|
|
|
450 |
}
|
|
|
451 |
keywords += expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber() + " Price, ";
|
|
|
452 |
keywords += expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber() + " India, ";
|
|
|
453 |
if(expEntity.getCategory().getParentCategory().getID() == 10001) {
|
|
|
454 |
keywords += expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber() + " Review, ";
|
|
|
455 |
}
|
| 2171 |
rajveer |
456 |
}
|
|
|
457 |
|
| 2197 |
rajveer |
458 |
|
| 2171 |
rajveer |
459 |
String exportFileName = exportPath + catalogId + File.separator + "MetaKeywordsSnippet.html";
|
|
|
460 |
File exportFile = new File(exportFileName);
|
|
|
461 |
if(!exportFile.exists()) {
|
|
|
462 |
exportFile.createNewFile();
|
|
|
463 |
}
|
|
|
464 |
|
|
|
465 |
BufferedWriter writer = new BufferedWriter(
|
|
|
466 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
467 |
|
|
|
468 |
writer.write(keywords);
|
|
|
469 |
|
|
|
470 |
writer.flush();
|
|
|
471 |
writer.close();
|
|
|
472 |
} catch (Exception e) {
|
|
|
473 |
e.printStackTrace();
|
|
|
474 |
}
|
|
|
475 |
}
|
|
|
476 |
|
|
|
477 |
|
|
|
478 |
private void getSlidenamesSnippet(ExpandedEntity expEntity, String exportPath) throws ResourceNotFoundException, ParseErrorException, Exception{
|
|
|
479 |
long catalogId = expEntity.getID();
|
|
|
480 |
|
|
|
481 |
StringBuilder slideNames = new StringBuilder();
|
|
|
482 |
|
|
|
483 |
slideNames.append(expEntity.getBrand() + " " + expEntity.getModelNumber() + " " + expEntity.getModelName() + "\n");
|
|
|
484 |
|
|
|
485 |
Map<Long, Double> slideScores = CreationUtils.getSlideComparisonScores(catalogId);
|
|
|
486 |
|
|
|
487 |
for(ExpandedSlide expSlide: expEntity.getExpandedSlides()){
|
|
|
488 |
if(expSlide.getSlideDefinitionID() == 130054){
|
|
|
489 |
continue;
|
|
|
490 |
}
|
|
|
491 |
slideNames.append(expSlide.getSlideDefinition().getLabel() + "!!!");
|
|
|
492 |
|
|
|
493 |
String bucketName = "None";
|
|
|
494 |
if(Catalog.getInstance().getDefinitionsContainer().getComparisonBucketName(expEntity.getCategoryID(), expSlide.getSlideDefinitionID()) != null){
|
|
|
495 |
bucketName = Catalog.getInstance().getDefinitionsContainer().getComparisonBucketName(expEntity.getCategoryID(), expSlide.getSlideDefinitionID());
|
|
|
496 |
}
|
|
|
497 |
slideNames.append(bucketName + "!!!");
|
|
|
498 |
|
|
|
499 |
double score = 0;
|
|
|
500 |
if(slideScores.get(expSlide.getSlideDefinitionID())!=null){
|
|
|
501 |
score = slideScores.get(expSlide.getSlideDefinitionID());
|
|
|
502 |
}
|
|
|
503 |
|
|
|
504 |
DecimalFormat oneDForm = new DecimalFormat("#.#");
|
|
|
505 |
score = Double.valueOf(oneDForm.format(score));
|
|
|
506 |
|
|
|
507 |
slideNames.append(score + "\n");
|
|
|
508 |
}
|
|
|
509 |
|
|
|
510 |
String exportFileName = exportPath + catalogId + File.separator + "SlideNamesSnippet.html";
|
|
|
511 |
File exportFile = new File(exportFileName);
|
|
|
512 |
if(!exportFile.exists()) {
|
|
|
513 |
exportFile.createNewFile();
|
|
|
514 |
}
|
|
|
515 |
|
|
|
516 |
BufferedWriter writer = new BufferedWriter(
|
|
|
517 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
518 |
|
|
|
519 |
writer.write(slideNames.toString());
|
|
|
520 |
writer.flush();
|
|
|
521 |
writer.close();
|
|
|
522 |
|
|
|
523 |
}
|
|
|
524 |
|
|
|
525 |
|
|
|
526 |
private void getEntitySnippetForComparison(ExpandedEntity expEntity, String templateFile, String domain, String exportPath) throws Exception {
|
|
|
527 |
long catalogId = expEntity.getID();
|
|
|
528 |
VelocityContext context = new VelocityContext();
|
|
|
529 |
|
|
|
530 |
context.put("imagePrefix", getImagePrefix(expEntity));
|
|
|
531 |
context.put("expentity", expEntity);
|
|
|
532 |
context.put("domain", domain);
|
|
|
533 |
context.put("contentVersion", this.contentVersion);
|
|
|
534 |
|
|
|
535 |
String exportFileName = null;
|
|
|
536 |
|
|
|
537 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
538 |
exportFileName = exportPath + catalogId + File.separator + "ComparisonSnippet.html";
|
|
|
539 |
|
|
|
540 |
File exportFile = new File(exportFileName);
|
|
|
541 |
if(!exportFile.exists()) {
|
|
|
542 |
exportFile.createNewFile();
|
|
|
543 |
}
|
|
|
544 |
|
|
|
545 |
BufferedWriter writer = new BufferedWriter(
|
|
|
546 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
547 |
|
|
|
548 |
//Template template = Velocity.getTemplate(templateFile);
|
|
|
549 |
template.merge(context, writer);
|
|
|
550 |
|
|
|
551 |
writer.flush();
|
|
|
552 |
writer.close();
|
|
|
553 |
Utils.info("Export Complete!");
|
|
|
554 |
|
|
|
555 |
}
|
|
|
556 |
|
|
|
557 |
private void getEntitySlideGuideHtml(ExpandedEntity expEntity, String templateFile, String domain, String exportPath) throws Exception {
|
|
|
558 |
long catalogId = expEntity.getID();
|
|
|
559 |
VelocityContext context = new VelocityContext();
|
|
|
560 |
|
|
|
561 |
context.put("imagePrefix", getImagePrefix(expEntity));
|
|
|
562 |
context.put("expentity", expEntity);
|
|
|
563 |
context.put("domain", domain);
|
|
|
564 |
context.put("contentVersion", this.contentVersion);
|
|
|
565 |
context.put("defs", Catalog.getInstance().getDefinitionsContainer());
|
|
|
566 |
|
|
|
567 |
String exportFileName = null;
|
|
|
568 |
|
|
|
569 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
570 |
exportFileName = exportPath + catalogId + File.separator + "SlideGuide.html";
|
|
|
571 |
|
|
|
572 |
File exportFile = new File(exportFileName);
|
|
|
573 |
if(!exportFile.exists()) {
|
|
|
574 |
exportFile.createNewFile();
|
|
|
575 |
}
|
|
|
576 |
|
|
|
577 |
BufferedWriter writer = new BufferedWriter(
|
|
|
578 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
579 |
|
|
|
580 |
//Template template = Velocity.getTemplate(templateFile);
|
|
|
581 |
template.merge(context, writer);
|
|
|
582 |
|
|
|
583 |
writer.flush();
|
|
|
584 |
writer.close();
|
|
|
585 |
Utils.info("Export Complete!");
|
|
|
586 |
|
|
|
587 |
}
|
|
|
588 |
|
| 2227 |
rajveer |
589 |
public void getProductSummaryHtml(ExpandedEntity expEntity, List<Item> items, String templateFile, String exportPath, String domain) {
|
| 2171 |
rajveer |
590 |
long catalogId = expEntity.getID();
|
|
|
591 |
try {
|
|
|
592 |
List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>();
|
|
|
593 |
for(Item item: items){
|
|
|
594 |
Map<String, String> itemDetail = new HashMap<String, String>();
|
|
|
595 |
double sellingPrice = item.getSellingPrice();
|
|
|
596 |
double mrp = item.getMrp();
|
|
|
597 |
boolean showmrp = true;
|
|
|
598 |
if (mrp <= sellingPrice) {
|
|
|
599 |
showmrp = false;
|
|
|
600 |
}
|
|
|
601 |
|
|
|
602 |
double saving = Math.round((mrp-sellingPrice)/mrp*100);
|
|
|
603 |
itemDetail.put("ITEM_ID", ((int)item.getId())+"");
|
|
|
604 |
itemDetail.put("CATALOG_ID", ((int)item.getCatalogItemId())+"");
|
|
|
605 |
itemDetail.put("SP", ((int)item.getSellingPrice())+"");
|
|
|
606 |
itemDetail.put("MRP", ((int)item.getMrp())+"");
|
|
|
607 |
itemDetail.put("SAVING", ((int)saving)+"");
|
|
|
608 |
itemDetail.put("COLOR", item.getColor());
|
|
|
609 |
itemDetail.put("SHOWMRP", showmrp +"");
|
|
|
610 |
itemDetail.put("IS_SELECTED", item.isDefaultForEntity() ? "SELECTED" : "");
|
|
|
611 |
itemDetails.add(itemDetail);
|
|
|
612 |
}
|
|
|
613 |
|
|
|
614 |
String title = expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber();
|
|
|
615 |
String categoryName = expEntity.getCategory().getLabel();
|
|
|
616 |
String tagline = "";
|
|
|
617 |
String warranty = "";
|
|
|
618 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
619 |
for(Feature feature: features){
|
|
|
620 |
if(feature.getFeatureDefinitionID() == 120084){
|
|
|
621 |
PrimitiveDataObject dataObject= (PrimitiveDataObject)feature.getBullets().get(0).getDataObject();
|
|
|
622 |
tagline = dataObject.getValue();
|
|
|
623 |
}
|
|
|
624 |
if(feature.getFeatureDefinitionID() == 120125){
|
|
|
625 |
ExpandedFeature expFeature = new ExpandedFeature(feature);
|
|
|
626 |
ExpandedBullet expBullet =expFeature.getExpandedBullets().get(0);
|
|
|
627 |
if(expBullet != null){
|
|
|
628 |
warranty = expBullet.getValue() + " "+ expBullet.getUnit().getShortForm();
|
|
|
629 |
}
|
|
|
630 |
}
|
|
|
631 |
}
|
|
|
632 |
|
|
|
633 |
|
|
|
634 |
|
|
|
635 |
long categoryId = expEntity.getCategory().getID();
|
|
|
636 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
637 |
params.put("TITLE", title);
|
|
|
638 |
params.put("CATEGORY_ID", ((int)categoryId)+"");
|
|
|
639 |
params.put("CATEGORY_NAME", categoryName);
|
|
|
640 |
params.put("CATEGORY_URL", categoryName.replaceAll(" ", "-").toLowerCase() + "/" + categoryId);
|
| 2227 |
rajveer |
641 |
params.put("PRODUCT_URL", URLEncoder.encode("http://www."+ domain + this.getEntityURL(expEntity), "UTF-8"));
|
|
|
642 |
if(expEntity.getCategory().getParentCategory().getID() == Utils.MOBILE_PHONES_CATAGOEY){
|
|
|
643 |
params.put("IS_MOBILE", "TRUE" );
|
|
|
644 |
}else{
|
|
|
645 |
params.put("IS_MOBILE", "FALSE" );
|
|
|
646 |
}
|
| 2171 |
rajveer |
647 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
648 |
params.put("TAGLINE", tagline);
|
|
|
649 |
params.put("WARRANTY", warranty);
|
|
|
650 |
|
|
|
651 |
VelocityContext context = new VelocityContext();
|
|
|
652 |
|
|
|
653 |
context.put("itemDetails", itemDetails);
|
|
|
654 |
|
|
|
655 |
context.put("params", params);
|
|
|
656 |
|
|
|
657 |
String exportFileName = exportPath + catalogId + File.separator + "ProductDetail.html";
|
|
|
658 |
|
|
|
659 |
File exportFile = new File(exportFileName);
|
|
|
660 |
if(!exportFile.exists()) {
|
|
|
661 |
exportFile.createNewFile();
|
|
|
662 |
}
|
|
|
663 |
|
|
|
664 |
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
665 |
|
|
|
666 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
667 |
template.merge(context, writer);
|
|
|
668 |
|
|
|
669 |
writer.flush();
|
|
|
670 |
writer.close();
|
|
|
671 |
Utils.info("Export Complete!");
|
|
|
672 |
|
|
|
673 |
} catch (Exception e) {
|
|
|
674 |
e.printStackTrace();
|
|
|
675 |
}
|
|
|
676 |
}
|
|
|
677 |
|
|
|
678 |
private String getEntityURL(ExpandedEntity expEntity){
|
|
|
679 |
String url = "/" + expEntity.getCategory().getParentCategory().getLabel().toLowerCase().replace(' ', '-') + "/";
|
|
|
680 |
String productUrl = expEntity.getBrand().toLowerCase().replace(' ', '-')
|
|
|
681 |
+ "-" + expEntity.getModelName().toLowerCase().replace(' ', '-')
|
|
|
682 |
+ "-" + expEntity.getModelNumber().toLowerCase().replace(' ', '-')
|
|
|
683 |
+ "-" + expEntity.getID();
|
|
|
684 |
productUrl = productUrl.replaceAll("/", "-");
|
|
|
685 |
url = url + productUrl;
|
|
|
686 |
url = url.replaceAll("--", "-");
|
|
|
687 |
return url;
|
|
|
688 |
}
|
|
|
689 |
|
|
|
690 |
private String getImagePrefix(ExpandedEntity expEntity){
|
|
|
691 |
String imagePrefix = expEntity.getBrand().toLowerCase().replace(' ', '-')
|
|
|
692 |
+ "-" + expEntity.getModelName().toLowerCase().replace(' ', '-')
|
|
|
693 |
+ "-" + expEntity.getModelNumber().toLowerCase().replace(' ', '-');
|
|
|
694 |
imagePrefix = imagePrefix.replaceAll("/", "-");
|
|
|
695 |
imagePrefix = imagePrefix.replaceAll("--", "-");
|
|
|
696 |
return imagePrefix;
|
|
|
697 |
}
|
|
|
698 |
|
|
|
699 |
private void getEntityWidgetSnippetHtml(ExpandedEntity expEntity, List<Item> items, String templateFile, String staticurl, String exportPath) {
|
|
|
700 |
long catalogId = expEntity.getID();
|
|
|
701 |
try {
|
|
|
702 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
|
|
703 |
String title = expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber();
|
| 2197 |
rajveer |
704 |
String prodName = title;
|
|
|
705 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
|
|
706 |
prodName = expEntity.getBrand() + " " + expEntity.getModelName();
|
|
|
707 |
}
|
| 2171 |
rajveer |
708 |
String imagePrefix = getImagePrefix(expEntity);
|
|
|
709 |
String url = getEntityURL(expEntity);
|
|
|
710 |
|
|
|
711 |
String tinySnippet = "";
|
|
|
712 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
713 |
for(Feature feature: features){
|
|
|
714 |
if(feature.getFeatureDefinitionID() == 120089){
|
|
|
715 |
PrimitiveDataObject dataObject= (PrimitiveDataObject)feature.getBullets().get(0).getDataObject();
|
|
|
716 |
tinySnippet = dataObject.getValue();
|
|
|
717 |
}
|
|
|
718 |
}
|
|
|
719 |
|
|
|
720 |
List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>();
|
|
|
721 |
|
|
|
722 |
Item minPriceItem = null;
|
|
|
723 |
for(Item item: items){
|
|
|
724 |
Map<String, String> itemDetail = new HashMap<String, String>();
|
|
|
725 |
if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
|
|
|
726 |
minPriceItem = item;
|
|
|
727 |
}
|
|
|
728 |
double sellingPrice = item.getSellingPrice();
|
|
|
729 |
double mrp = item.getMrp();
|
|
|
730 |
double saving = Math.round((mrp-sellingPrice)/mrp*100);
|
|
|
731 |
itemDetail.put("ITEM_ID", ((int)item.getId())+"");
|
|
|
732 |
itemDetail.put("SP", ((int)item.getSellingPrice())+"");
|
|
|
733 |
itemDetail.put("MRP", ((int)item.getMrp())+"");
|
|
|
734 |
itemDetail.put("SAVING", ((int)saving)+"");
|
|
|
735 |
itemDetail.put("COLOR", item.getColor());
|
|
|
736 |
itemDetails.add(itemDetail);
|
|
|
737 |
}
|
|
|
738 |
|
|
|
739 |
boolean showmrp = true;
|
|
|
740 |
if (minPriceItem.getMrp() <= minPriceItem.getSellingPrice()) {
|
|
|
741 |
showmrp = false;
|
|
|
742 |
}
|
|
|
743 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
744 |
params.put("TITLE", title);
|
| 2197 |
rajveer |
745 |
params.put("PROD_NAME", prodName);
|
| 2171 |
rajveer |
746 |
params.put("URL", url);
|
|
|
747 |
params.put("IMAGE_PREFIX", imagePrefix);
|
|
|
748 |
params.put("SELLING_PRICE", ((int)minPriceItem.getSellingPrice())+"");
|
|
|
749 |
params.put("MRP", ((int)minPriceItem.getMrp())+"");
|
|
|
750 |
params.put("SHOWMRP", showmrp +"");
|
|
|
751 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
752 |
params.put("ITEM_ID", minPriceItem.getId()+"");
|
|
|
753 |
params.put("TINY_SNIPPET", tinySnippet);
|
|
|
754 |
params.put("staticurl", staticurl);
|
|
|
755 |
params.put("contentVersion", contentVersion);
|
|
|
756 |
VelocityContext context = new VelocityContext();
|
|
|
757 |
context.put("itemDetails", itemDetails);
|
|
|
758 |
context.put("params", params);
|
|
|
759 |
|
|
|
760 |
String exportFileName = exportPath + catalogId + File.separator + "WidgetSnippet.html";
|
|
|
761 |
File exportFile = new File(exportFileName);
|
|
|
762 |
if(!exportFile.exists()) {
|
|
|
763 |
exportFile.createNewFile();
|
|
|
764 |
}
|
|
|
765 |
|
|
|
766 |
BufferedWriter writer = new BufferedWriter(
|
|
|
767 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
768 |
|
|
|
769 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
770 |
template.merge(context, writer);
|
|
|
771 |
|
|
|
772 |
writer.flush();
|
|
|
773 |
writer.close();
|
|
|
774 |
Utils.info("Export Complete!");
|
|
|
775 |
|
|
|
776 |
|
|
|
777 |
} catch (Exception e) {
|
|
|
778 |
e.printStackTrace();
|
|
|
779 |
}
|
|
|
780 |
}
|
|
|
781 |
|
|
|
782 |
|
|
|
783 |
private void getEntityHomeSnippetHtml(ExpandedEntity expEntity, List<Item> items, String templateFile, String staticurl, String exportPath) {
|
|
|
784 |
long catalogId = expEntity.getID();
|
|
|
785 |
|
|
|
786 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
787 |
|
|
|
788 |
try {
|
|
|
789 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
|
|
790 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
|
| 2197 |
rajveer |
791 |
String prodName = title;
|
|
|
792 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
|
|
793 |
prodName = expEntity.getBrand() + " " + expEntity.getModelName();
|
|
|
794 |
}
|
| 2171 |
rajveer |
795 |
String url = getEntityURL(expEntity);
|
|
|
796 |
String imagePrefix = getImagePrefix(expEntity);
|
|
|
797 |
|
|
|
798 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
799 |
client = catalogServiceClient.getClient();
|
|
|
800 |
|
|
|
801 |
String tinySnippet = "";
|
|
|
802 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
803 |
for(Feature feature: features){
|
|
|
804 |
if(feature.getFeatureDefinitionID() == 120081){
|
|
|
805 |
List<Bullet> bullets = feature.getBullets();
|
|
|
806 |
int count = 1;
|
|
|
807 |
for(Bullet bullet: bullets){
|
|
|
808 |
PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
|
|
|
809 |
tinySnippet = dataObject.getValue();
|
|
|
810 |
params.put("SNIPPET_"+count++, tinySnippet);
|
|
|
811 |
System.out.println("Tiny Snippets is " + dataObject.getValue());
|
|
|
812 |
}
|
|
|
813 |
}
|
|
|
814 |
}
|
|
|
815 |
|
|
|
816 |
|
|
|
817 |
|
|
|
818 |
List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>();
|
|
|
819 |
|
|
|
820 |
Item minPriceItem = null;
|
|
|
821 |
|
|
|
822 |
for(Item item: items){
|
|
|
823 |
Map<String, String> itemDetail = new HashMap<String, String>();
|
|
|
824 |
if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
|
|
|
825 |
minPriceItem = item;
|
|
|
826 |
}
|
|
|
827 |
double sellingPrice = item.getSellingPrice();
|
|
|
828 |
double mrp = item.getMrp();
|
|
|
829 |
double saving = Math.round((mrp-sellingPrice)/mrp*100);
|
|
|
830 |
itemDetail.put("ITEM_ID", ((int)item.getId())+"");
|
|
|
831 |
itemDetail.put("SP", ((int)item.getSellingPrice())+"");
|
|
|
832 |
itemDetail.put("MRP", ((int)item.getMrp())+"");
|
|
|
833 |
itemDetail.put("SAVING", ((int)saving)+"");
|
|
|
834 |
itemDetail.put("COLOR", item.getColor());
|
|
|
835 |
itemDetails.add(itemDetail);
|
|
|
836 |
}
|
|
|
837 |
boolean showmrp = true;
|
|
|
838 |
if (minPriceItem.getMrp() <= minPriceItem.getSellingPrice()) {
|
|
|
839 |
showmrp = false;
|
|
|
840 |
}
|
|
|
841 |
|
|
|
842 |
params.put("TITLE", title);
|
| 2197 |
rajveer |
843 |
params.put("PROD_NAME", prodName);
|
| 2171 |
rajveer |
844 |
params.put("URL", url);
|
|
|
845 |
params.put("IMAGE_PREFIX", imagePrefix);
|
|
|
846 |
params.put("SELLING_PRICE", ((int)minPriceItem.getSellingPrice())+"");
|
|
|
847 |
params.put("MRP", ((int)minPriceItem.getMrp())+"");
|
|
|
848 |
params.put("SHOWMRP", showmrp +"");
|
|
|
849 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
850 |
params.put("ITEM_ID", minPriceItem.getId()+"");
|
|
|
851 |
params.put("staticurl", staticurl);
|
|
|
852 |
params.put("contentVersion", contentVersion);
|
|
|
853 |
|
|
|
854 |
VelocityContext context = new VelocityContext();
|
|
|
855 |
context.put("itemDetails", itemDetails);
|
|
|
856 |
context.put("params", params);
|
|
|
857 |
|
|
|
858 |
|
|
|
859 |
String exportFileName = exportPath + catalogId + File.separator + "HomeSnippet.html";
|
|
|
860 |
File exportFile = new File(exportFileName);
|
|
|
861 |
if(!exportFile.exists()) {
|
|
|
862 |
exportFile.createNewFile();
|
|
|
863 |
}
|
|
|
864 |
|
|
|
865 |
BufferedWriter writer = new BufferedWriter(
|
|
|
866 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
867 |
|
|
|
868 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
869 |
template.merge(context, writer);
|
|
|
870 |
|
|
|
871 |
writer.flush();
|
|
|
872 |
writer.close();
|
|
|
873 |
Utils.info("Export Complete!");
|
|
|
874 |
|
|
|
875 |
} catch (Exception e) {
|
|
|
876 |
e.printStackTrace();
|
|
|
877 |
}
|
|
|
878 |
}
|
|
|
879 |
|
|
|
880 |
private void getEntityCategorySnippetHtml(ExpandedEntity expEntity, List<Item> items, String templateFile, String staticurl, String exportPath) {
|
|
|
881 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
882 |
long catalogId = expEntity.getID();
|
|
|
883 |
|
|
|
884 |
try {
|
|
|
885 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
|
|
886 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
|
| 2197 |
rajveer |
887 |
String prodName = title;
|
|
|
888 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
|
|
889 |
prodName = expEntity.getBrand() + " " + expEntity.getModelName();
|
|
|
890 |
}
|
| 2171 |
rajveer |
891 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
892 |
client = catalogServiceClient.getClient();
|
|
|
893 |
String url = getEntityURL(expEntity);
|
|
|
894 |
String imagePrefix = getImagePrefix(expEntity);
|
|
|
895 |
|
|
|
896 |
String tinySnippet = "";
|
|
|
897 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
898 |
for(Feature feature: features){
|
|
|
899 |
if(feature.getFeatureDefinitionID() == 120081){
|
|
|
900 |
List<Bullet> bullets = feature.getBullets();
|
|
|
901 |
int count = 1;
|
|
|
902 |
for(Bullet bullet: bullets){
|
|
|
903 |
PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
|
|
|
904 |
tinySnippet = dataObject.getValue();
|
|
|
905 |
params.put("SNIPPET_"+count++, tinySnippet);
|
|
|
906 |
System.out.println("Tiny Snippets is " + dataObject.getValue());
|
|
|
907 |
}
|
|
|
908 |
}
|
|
|
909 |
}
|
|
|
910 |
|
|
|
911 |
List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>();
|
|
|
912 |
|
|
|
913 |
Item minPriceItem = null;
|
|
|
914 |
for(Item item: items){
|
|
|
915 |
Map<String, String> itemDetail = new HashMap<String, String>();
|
|
|
916 |
if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
|
|
|
917 |
minPriceItem = item;
|
|
|
918 |
}
|
|
|
919 |
double sellingPrice = item.getSellingPrice();
|
|
|
920 |
double mrp = item.getMrp();
|
|
|
921 |
double saving = Math.round((mrp-sellingPrice)/mrp*100);
|
|
|
922 |
itemDetail.put("ITEM_ID", ((int)item.getId())+"");
|
|
|
923 |
itemDetail.put("SP", ((int)item.getSellingPrice())+"");
|
|
|
924 |
itemDetail.put("MRP", ((int)item.getMrp())+"");
|
|
|
925 |
itemDetail.put("SAVING", ((int)saving)+"");
|
|
|
926 |
itemDetail.put("COLOR", item.getColor());
|
|
|
927 |
itemDetails.add(itemDetail);
|
|
|
928 |
}
|
|
|
929 |
|
|
|
930 |
boolean showmrp = true;
|
|
|
931 |
if (minPriceItem.getMrp() <= minPriceItem.getSellingPrice()) {
|
|
|
932 |
showmrp = false;
|
|
|
933 |
}
|
|
|
934 |
params.put("TITLE", title);
|
| 2197 |
rajveer |
935 |
params.put("PROD_NAME", prodName);
|
| 2171 |
rajveer |
936 |
params.put("URL", url);
|
|
|
937 |
params.put("IMAGE_PREFIX", imagePrefix);
|
|
|
938 |
params.put("SELLING_PRICE", ((int)minPriceItem.getSellingPrice())+"");
|
|
|
939 |
params.put("MRP", ((int)minPriceItem.getMrp())+"");
|
|
|
940 |
params.put("SHOWMRP", showmrp +"");
|
|
|
941 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
942 |
params.put("ITEM_ID", minPriceItem.getId()+"");
|
|
|
943 |
params.put("staticurl", staticurl);
|
|
|
944 |
params.put("contentVersion", contentVersion);
|
|
|
945 |
|
|
|
946 |
VelocityContext context = new VelocityContext();
|
|
|
947 |
context.put("itemDetails", itemDetails);
|
|
|
948 |
context.put("params", params);
|
|
|
949 |
|
|
|
950 |
String exportFileName = exportPath + catalogId + File.separator + "CategorySnippet.html";
|
|
|
951 |
File exportFile = new File(exportFileName);
|
|
|
952 |
if(!exportFile.exists()) {
|
|
|
953 |
exportFile.createNewFile();
|
|
|
954 |
}
|
|
|
955 |
|
|
|
956 |
BufferedWriter writer = new BufferedWriter(
|
|
|
957 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
958 |
|
|
|
959 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
960 |
template.merge(context, writer);
|
|
|
961 |
|
|
|
962 |
writer.flush();
|
|
|
963 |
writer.close();
|
|
|
964 |
Utils.info("Export Complete!");
|
|
|
965 |
|
|
|
966 |
|
|
|
967 |
} catch (Exception e) {
|
|
|
968 |
e.printStackTrace();
|
|
|
969 |
}
|
|
|
970 |
}
|
|
|
971 |
|
|
|
972 |
private void getEntityTitleSnippetHtml(ExpandedEntity expEntity, String exportPath) {
|
|
|
973 |
long catalogId = expEntity.getID();
|
|
|
974 |
|
|
|
975 |
try {
|
|
|
976 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
| 2197 |
rajveer |
977 |
String title = expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber();
|
|
|
978 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
|
|
979 |
title = expEntity.getBrand() + " " + expEntity.getModelName();
|
|
|
980 |
}
|
| 2171 |
rajveer |
981 |
if(expEntity.getCategory().getParentCategory().getID() == 10001) {
|
|
|
982 |
title += " | " + expEntity.getBrand() + " Mobile Phones";
|
|
|
983 |
}
|
|
|
984 |
if(expEntity.getCategory().getParentCategory().getID() == 10011) {
|
|
|
985 |
title += " " + expEntity.getCategory().getLabel()
|
|
|
986 |
+ " | " + expEntity.getBrand() + " Mobile Phone Accessories";
|
|
|
987 |
}
|
|
|
988 |
title += " | Saholic.com";
|
|
|
989 |
|
|
|
990 |
String exportFileName = exportPath + catalogId + File.separator + "TitleSnippet.html";
|
|
|
991 |
File exportFile = new File(exportFileName);
|
|
|
992 |
if(!exportFile.exists()) {
|
|
|
993 |
exportFile.createNewFile();
|
|
|
994 |
}
|
|
|
995 |
|
|
|
996 |
BufferedWriter writer = new BufferedWriter(
|
|
|
997 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
998 |
|
|
|
999 |
writer.write(title);
|
|
|
1000 |
|
|
|
1001 |
writer.flush();
|
|
|
1002 |
writer.close();
|
|
|
1003 |
} catch (Exception e) {
|
|
|
1004 |
e.printStackTrace();
|
|
|
1005 |
}
|
|
|
1006 |
}
|
|
|
1007 |
|
|
|
1008 |
|
|
|
1009 |
private void getEntitySearchSnippetHtml(ExpandedEntity expEntity, List<Item> items, String templateFile, String staticurl, String exportPath) {
|
|
|
1010 |
long catalogId = expEntity.getID();
|
|
|
1011 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
1012 |
|
|
|
1013 |
try {
|
|
|
1014 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
|
|
1015 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
|
| 2197 |
rajveer |
1016 |
String prodName = title;
|
|
|
1017 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
|
|
1018 |
prodName = expEntity.getBrand() + " " + expEntity.getModelName();
|
|
|
1019 |
}
|
| 2171 |
rajveer |
1020 |
|
|
|
1021 |
String url = getEntityURL(expEntity);
|
|
|
1022 |
String imagePrefix = getImagePrefix(expEntity);
|
|
|
1023 |
|
|
|
1024 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
1025 |
client = catalogServiceClient.getClient();
|
|
|
1026 |
|
|
|
1027 |
String tinySnippet = "";
|
|
|
1028 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
1029 |
for(Feature feature: features){
|
|
|
1030 |
if(feature.getFeatureDefinitionID() == 120081){
|
|
|
1031 |
List<Bullet> bullets = feature.getBullets();
|
|
|
1032 |
int count = 1;
|
|
|
1033 |
for(Bullet bullet: bullets){
|
|
|
1034 |
PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
|
|
|
1035 |
tinySnippet = dataObject.getValue();
|
|
|
1036 |
params.put("SNIPPET_"+count++, tinySnippet);
|
|
|
1037 |
System.out.println("Tiny Snippets is " + dataObject.getValue());
|
|
|
1038 |
}
|
|
|
1039 |
}
|
|
|
1040 |
}
|
|
|
1041 |
|
|
|
1042 |
|
|
|
1043 |
List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>();
|
|
|
1044 |
|
|
|
1045 |
Item minPriceItem = null;
|
|
|
1046 |
for(Item item: items){
|
|
|
1047 |
Map<String, String> itemDetail = new HashMap<String, String>();
|
|
|
1048 |
if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
|
|
|
1049 |
minPriceItem = item;
|
|
|
1050 |
}
|
|
|
1051 |
double sellingPrice = item.getSellingPrice();
|
|
|
1052 |
double mrp = item.getMrp();
|
|
|
1053 |
double saving = Math.round((mrp-sellingPrice)/mrp*100);
|
|
|
1054 |
itemDetail.put("ITEM_ID", ((int)item.getId())+"");
|
|
|
1055 |
itemDetail.put("SP", ((int)item.getSellingPrice())+"");
|
|
|
1056 |
itemDetail.put("MRP", ((int)item.getMrp())+"");
|
|
|
1057 |
itemDetail.put("SAVING", ((int)saving)+"");
|
|
|
1058 |
itemDetail.put("COLOR", item.getColor());
|
|
|
1059 |
itemDetails.add(itemDetail);
|
|
|
1060 |
}
|
|
|
1061 |
|
|
|
1062 |
boolean showmrp = true;
|
|
|
1063 |
if (minPriceItem.getMrp() <= minPriceItem.getSellingPrice()) {
|
|
|
1064 |
showmrp = false;
|
|
|
1065 |
}
|
|
|
1066 |
params.put("TITLE", title);
|
| 2197 |
rajveer |
1067 |
params.put("PROD_NAME", prodName);
|
| 2171 |
rajveer |
1068 |
params.put("URL", url);
|
|
|
1069 |
params.put("IMAGE_PREFIX", imagePrefix);
|
|
|
1070 |
params.put("SELLING_PRICE", ((int)minPriceItem.getSellingPrice())+"");
|
|
|
1071 |
params.put("MRP", ((int)minPriceItem.getMrp())+"");
|
|
|
1072 |
params.put("SHOWMRP", showmrp +"");
|
|
|
1073 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
1074 |
params.put("ITEM_ID", minPriceItem.getId()+"");
|
|
|
1075 |
params.put("staticurl", staticurl);
|
|
|
1076 |
params.put("contentVersion", contentVersion);
|
|
|
1077 |
|
|
|
1078 |
VelocityContext context = new VelocityContext();
|
|
|
1079 |
context.put("itemDetails", itemDetails);
|
|
|
1080 |
context.put("params", params);
|
|
|
1081 |
|
|
|
1082 |
String exportFileName = exportPath + catalogId + File.separator + "SearchSnippet.html";
|
|
|
1083 |
File exportFile = new File(exportFileName);
|
|
|
1084 |
if(!exportFile.exists()) {
|
|
|
1085 |
exportFile.createNewFile();
|
|
|
1086 |
}
|
|
|
1087 |
|
|
|
1088 |
BufferedWriter writer = new BufferedWriter(
|
|
|
1089 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
1090 |
|
|
|
1091 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
1092 |
template.merge(context, writer);
|
|
|
1093 |
|
|
|
1094 |
writer.flush();
|
|
|
1095 |
writer.close();
|
|
|
1096 |
Utils.info("Export Complete!");
|
|
|
1097 |
|
|
|
1098 |
|
|
|
1099 |
} catch (Exception e) {
|
|
|
1100 |
e.printStackTrace();
|
|
|
1101 |
}
|
|
|
1102 |
}
|
|
|
1103 |
|
|
|
1104 |
|
|
|
1105 |
private void getEntityCompareSnippetHtml(ExpandedEntity expEntity, List<Item> items, String templateFile, String staticurl, String exportPath) {
|
|
|
1106 |
long catalogId = expEntity.getID();
|
|
|
1107 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
1108 |
|
|
|
1109 |
try {
|
|
|
1110 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
|
|
1111 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
|
| 2197 |
rajveer |
1112 |
String prodName = title;
|
|
|
1113 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
|
|
1114 |
prodName = expEntity.getBrand() + " " + expEntity.getModelName();
|
|
|
1115 |
}
|
| 2171 |
rajveer |
1116 |
String url = getEntityURL(expEntity);
|
|
|
1117 |
String imagePrefix = getImagePrefix(expEntity);
|
|
|
1118 |
|
|
|
1119 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
1120 |
client = catalogServiceClient.getClient();
|
|
|
1121 |
|
|
|
1122 |
String tinySnippet = "";
|
|
|
1123 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
1124 |
for(Feature feature: features){
|
|
|
1125 |
if(feature.getFeatureDefinitionID() == 120081){
|
|
|
1126 |
List<Bullet> bullets = feature.getBullets();
|
|
|
1127 |
int count = 1;
|
|
|
1128 |
for(Bullet bullet: bullets){
|
|
|
1129 |
PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
|
|
|
1130 |
tinySnippet = dataObject.getValue();
|
|
|
1131 |
params.put("SNIPPET_"+count++, tinySnippet);
|
|
|
1132 |
System.out.println("Tiny Snippets is " + dataObject.getValue());
|
|
|
1133 |
}
|
|
|
1134 |
}
|
|
|
1135 |
}
|
|
|
1136 |
|
|
|
1137 |
|
|
|
1138 |
List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>();
|
|
|
1139 |
|
|
|
1140 |
Item minPriceItem = null;
|
|
|
1141 |
for(Item item: items){
|
|
|
1142 |
Map<String, String> itemDetail = new HashMap<String, String>();
|
|
|
1143 |
if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
|
|
|
1144 |
minPriceItem = item;
|
|
|
1145 |
}
|
|
|
1146 |
double sellingPrice = item.getSellingPrice();
|
|
|
1147 |
double mrp = item.getMrp();
|
|
|
1148 |
double saving = Math.round((mrp-sellingPrice)/mrp*100);
|
|
|
1149 |
itemDetail.put("ITEM_ID", ((int)item.getId())+"");
|
|
|
1150 |
itemDetail.put("SP", ((int)item.getSellingPrice())+"");
|
|
|
1151 |
itemDetail.put("MRP", ((int)item.getMrp())+"");
|
|
|
1152 |
itemDetail.put("SAVING", ((int)saving)+"");
|
|
|
1153 |
itemDetail.put("COLOR", item.getColor());
|
|
|
1154 |
itemDetails.add(itemDetail);
|
|
|
1155 |
}
|
|
|
1156 |
|
|
|
1157 |
boolean showmrp = true;
|
|
|
1158 |
if (minPriceItem.getMrp() <= minPriceItem.getSellingPrice()) {
|
|
|
1159 |
showmrp = false;
|
|
|
1160 |
}
|
|
|
1161 |
params.put("TITLE", title);
|
| 2197 |
rajveer |
1162 |
params.put("PROD_NAME", prodName);
|
| 2171 |
rajveer |
1163 |
params.put("URL", url);
|
|
|
1164 |
params.put("IMAGE_PREFIX", imagePrefix);
|
|
|
1165 |
params.put("SELLING_PRICE", ((int)minPriceItem.getSellingPrice())+"");
|
|
|
1166 |
params.put("MRP", ((int)minPriceItem.getMrp())+"");
|
|
|
1167 |
params.put("SHOWMRP", showmrp +"");
|
|
|
1168 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
1169 |
params.put("ITEM_ID", minPriceItem.getId()+"");
|
|
|
1170 |
params.put("staticurl", staticurl);
|
|
|
1171 |
params.put("contentVersion", contentVersion);
|
|
|
1172 |
|
|
|
1173 |
VelocityContext context = new VelocityContext();
|
|
|
1174 |
context.put("itemDetails", itemDetails);
|
|
|
1175 |
context.put("params", params);
|
|
|
1176 |
|
|
|
1177 |
String exportFileName = exportPath + catalogId + File.separator + "CompareProductSnippet.html";
|
|
|
1178 |
File exportFile = new File(exportFileName);
|
|
|
1179 |
if(!exportFile.exists()) {
|
|
|
1180 |
exportFile.createNewFile();
|
|
|
1181 |
}
|
|
|
1182 |
|
|
|
1183 |
BufferedWriter writer = new BufferedWriter(
|
|
|
1184 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
1185 |
|
|
|
1186 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
1187 |
template.merge(context, writer);
|
|
|
1188 |
|
|
|
1189 |
writer.flush();
|
|
|
1190 |
writer.close();
|
|
|
1191 |
Utils.info("Export Complete!");
|
|
|
1192 |
|
|
|
1193 |
|
|
|
1194 |
} catch (Exception e) {
|
|
|
1195 |
e.printStackTrace();
|
|
|
1196 |
}
|
|
|
1197 |
}
|
|
|
1198 |
|
|
|
1199 |
|
|
|
1200 |
private void getEntityCompareSummarySnippetHtml(ExpandedEntity expEntity, List<Item> items, String templateFile, String staticurl, String exportPath) {
|
|
|
1201 |
long catalogId = expEntity.getID();
|
|
|
1202 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
1203 |
|
|
|
1204 |
try {
|
|
|
1205 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
|
|
1206 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
|
| 2197 |
rajveer |
1207 |
String prodName = title;
|
|
|
1208 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
|
|
1209 |
prodName = expEntity.getBrand() + " " + expEntity.getModelName();
|
|
|
1210 |
}
|
| 2171 |
rajveer |
1211 |
String url = getEntityURL(expEntity);
|
|
|
1212 |
String imagePrefix = getImagePrefix(expEntity);
|
|
|
1213 |
|
|
|
1214 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
1215 |
client = catalogServiceClient.getClient();
|
|
|
1216 |
|
|
|
1217 |
String tinySnippet = "";
|
|
|
1218 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
1219 |
for(Feature feature: features){
|
|
|
1220 |
if(feature.getFeatureDefinitionID() == 120081){
|
|
|
1221 |
List<Bullet> bullets = feature.getBullets();
|
|
|
1222 |
int count = 1;
|
|
|
1223 |
for(Bullet bullet: bullets){
|
|
|
1224 |
PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
|
|
|
1225 |
tinySnippet = dataObject.getValue();
|
|
|
1226 |
params.put("SNIPPET_"+count++, tinySnippet);
|
|
|
1227 |
System.out.println("Tiny Snippets is " + dataObject.getValue());
|
|
|
1228 |
}
|
|
|
1229 |
}
|
|
|
1230 |
}
|
|
|
1231 |
|
|
|
1232 |
|
|
|
1233 |
List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>();
|
|
|
1234 |
|
|
|
1235 |
Item minPriceItem = null;
|
|
|
1236 |
for(Item item: items){
|
|
|
1237 |
Map<String, String> itemDetail = new HashMap<String, String>();
|
|
|
1238 |
if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
|
|
|
1239 |
minPriceItem = item;
|
|
|
1240 |
}
|
|
|
1241 |
double sellingPrice = item.getSellingPrice();
|
|
|
1242 |
double mrp = item.getMrp();
|
|
|
1243 |
double saving = Math.round((mrp-sellingPrice)/mrp*100);
|
|
|
1244 |
itemDetail.put("ITEM_ID", ((int)item.getId())+"");
|
|
|
1245 |
itemDetail.put("SP", ((int)item.getSellingPrice())+"");
|
|
|
1246 |
itemDetail.put("MRP", ((int)item.getMrp())+"");
|
|
|
1247 |
itemDetail.put("SAVING", ((int)saving)+"");
|
|
|
1248 |
itemDetail.put("COLOR", item.getColor());
|
|
|
1249 |
itemDetails.add(itemDetail);
|
|
|
1250 |
}
|
|
|
1251 |
|
|
|
1252 |
boolean showmrp = true;
|
|
|
1253 |
if (minPriceItem.getMrp() <= minPriceItem.getSellingPrice()) {
|
|
|
1254 |
showmrp = false;
|
|
|
1255 |
}
|
|
|
1256 |
params.put("TITLE", title);
|
| 2197 |
rajveer |
1257 |
params.put("PROD_NAME", prodName);
|
| 2171 |
rajveer |
1258 |
params.put("URL", url);
|
|
|
1259 |
params.put("IMAGE_PREFIX", imagePrefix);
|
|
|
1260 |
params.put("SELLING_PRICE", ((int)minPriceItem.getSellingPrice())+"");
|
|
|
1261 |
params.put("MRP", ((int)minPriceItem.getMrp())+"");
|
|
|
1262 |
params.put("SHOWMRP", showmrp +"");
|
|
|
1263 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
1264 |
params.put("ITEM_ID", minPriceItem.getId()+"");
|
|
|
1265 |
params.put("staticurl", staticurl);
|
|
|
1266 |
params.put("contentVersion", contentVersion);
|
|
|
1267 |
|
|
|
1268 |
VelocityContext context = new VelocityContext();
|
|
|
1269 |
context.put("itemDetails", itemDetails);
|
|
|
1270 |
context.put("params", params);
|
|
|
1271 |
|
|
|
1272 |
String exportFileName = exportPath + catalogId + File.separator + "CompareProductSummarySnippet.html";
|
|
|
1273 |
File exportFile = new File(exportFileName);
|
|
|
1274 |
if(!exportFile.exists()) {
|
|
|
1275 |
exportFile.createNewFile();
|
|
|
1276 |
}
|
|
|
1277 |
|
|
|
1278 |
BufferedWriter writer = new BufferedWriter(
|
|
|
1279 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
1280 |
|
|
|
1281 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
1282 |
template.merge(context, writer);
|
|
|
1283 |
|
|
|
1284 |
writer.flush();
|
|
|
1285 |
writer.close();
|
|
|
1286 |
Utils.info("Export Complete!");
|
|
|
1287 |
|
|
|
1288 |
|
|
|
1289 |
} catch (Exception e) {
|
|
|
1290 |
e.printStackTrace();
|
|
|
1291 |
}
|
|
|
1292 |
}
|
|
|
1293 |
|
|
|
1294 |
private void getEntityPhonesIOwnSnippetHtml(ExpandedEntity expEntity, List<Item> items, String templateFile, String staticurl, String exportPath) {
|
|
|
1295 |
long catalogId = expEntity.getID();
|
|
|
1296 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
1297 |
|
|
|
1298 |
try {
|
|
|
1299 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
|
|
1300 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
|
| 2197 |
rajveer |
1301 |
String prodName = title;
|
|
|
1302 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
|
|
1303 |
prodName = expEntity.getBrand() + " " + expEntity.getModelName();
|
|
|
1304 |
}
|
| 2171 |
rajveer |
1305 |
String url = getEntityURL(expEntity);
|
| 2197 |
rajveer |
1306 |
|
| 2171 |
rajveer |
1307 |
String imagePrefix = getImagePrefix(expEntity);
|
|
|
1308 |
|
|
|
1309 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
1310 |
client = catalogServiceClient.getClient();
|
|
|
1311 |
|
|
|
1312 |
String tinySnippet = "";
|
|
|
1313 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
1314 |
for(Feature feature: features){
|
|
|
1315 |
if(feature.getFeatureDefinitionID() == 120081){
|
|
|
1316 |
List<Bullet> bullets = feature.getBullets();
|
|
|
1317 |
int count = 1;
|
|
|
1318 |
for(Bullet bullet: bullets){
|
|
|
1319 |
PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
|
|
|
1320 |
tinySnippet = dataObject.getValue();
|
|
|
1321 |
params.put("SNIPPET_"+count++, tinySnippet);
|
|
|
1322 |
System.out.println("Tiny Snippets is " + dataObject.getValue());
|
|
|
1323 |
}
|
|
|
1324 |
}
|
|
|
1325 |
}
|
|
|
1326 |
|
|
|
1327 |
|
|
|
1328 |
List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>();
|
|
|
1329 |
|
|
|
1330 |
Item minPriceItem = null;
|
|
|
1331 |
for(Item item: items){
|
|
|
1332 |
Map<String, String> itemDetail = new HashMap<String, String>();
|
|
|
1333 |
if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
|
|
|
1334 |
minPriceItem = item;
|
|
|
1335 |
}
|
|
|
1336 |
double sellingPrice = item.getSellingPrice();
|
|
|
1337 |
double mrp = item.getMrp();
|
|
|
1338 |
double saving = Math.round((mrp-sellingPrice)/mrp*100);
|
|
|
1339 |
itemDetail.put("ITEM_ID", ((int)item.getId())+"");
|
|
|
1340 |
itemDetail.put("SP", ((int)item.getSellingPrice())+"");
|
|
|
1341 |
itemDetail.put("MRP", ((int)item.getMrp())+"");
|
|
|
1342 |
itemDetail.put("SAVING", ((int)saving)+"");
|
|
|
1343 |
itemDetail.put("COLOR", item.getColor());
|
|
|
1344 |
itemDetails.add(itemDetail);
|
|
|
1345 |
}
|
|
|
1346 |
|
|
|
1347 |
boolean showmrp = true;
|
|
|
1348 |
if (minPriceItem.getMrp() <= minPriceItem.getSellingPrice()) {
|
|
|
1349 |
showmrp = false;
|
|
|
1350 |
}
|
|
|
1351 |
params.put("TITLE", title);
|
| 2197 |
rajveer |
1352 |
params.put("PROD_NAME", prodName);
|
| 2171 |
rajveer |
1353 |
params.put("URL", url);
|
|
|
1354 |
params.put("IMAGE_PREFIX", imagePrefix);
|
|
|
1355 |
params.put("SELLING_PRICE", ((int)minPriceItem.getSellingPrice())+"");
|
|
|
1356 |
params.put("MRP", ((int)minPriceItem.getMrp())+"");
|
|
|
1357 |
params.put("SHOWMRP", showmrp +"");
|
|
|
1358 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
1359 |
params.put("ITEM_ID", minPriceItem.getId()+"");
|
|
|
1360 |
params.put("staticurl", staticurl);
|
|
|
1361 |
params.put("contentVersion", contentVersion);
|
|
|
1362 |
|
|
|
1363 |
VelocityContext context = new VelocityContext();
|
|
|
1364 |
context.put("itemDetails", itemDetails);
|
|
|
1365 |
context.put("params", params);
|
|
|
1366 |
|
|
|
1367 |
String exportFileName = exportPath + catalogId + File.separator + "PhonesIOwnSnippet.html";
|
|
|
1368 |
File exportFile = new File(exportFileName);
|
|
|
1369 |
if(!exportFile.exists()) {
|
|
|
1370 |
exportFile.createNewFile();
|
|
|
1371 |
}
|
|
|
1372 |
|
|
|
1373 |
BufferedWriter writer = new BufferedWriter(
|
|
|
1374 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
1375 |
|
|
|
1376 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
1377 |
template.merge(context, writer);
|
|
|
1378 |
|
|
|
1379 |
writer.flush();
|
|
|
1380 |
writer.close();
|
|
|
1381 |
Utils.info("Export Complete!");
|
|
|
1382 |
|
|
|
1383 |
|
|
|
1384 |
} catch (Exception e) {
|
|
|
1385 |
e.printStackTrace();
|
|
|
1386 |
}
|
|
|
1387 |
}
|
|
|
1388 |
|
|
|
1389 |
public String getHtmlFromVelocity(String templateFile, VelocityContext context){
|
|
|
1390 |
try {
|
|
|
1391 |
Velocity.init("velocity/velocity.properties");
|
|
|
1392 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
1393 |
if(template != null) {
|
|
|
1394 |
StringWriter writer = new StringWriter();
|
|
|
1395 |
template.merge(context, writer);
|
|
|
1396 |
writer.flush();
|
|
|
1397 |
writer.close();
|
|
|
1398 |
return writer.toString();
|
|
|
1399 |
}
|
|
|
1400 |
|
|
|
1401 |
} catch (ResourceNotFoundException e) {
|
|
|
1402 |
e.printStackTrace();
|
|
|
1403 |
} catch (ParseErrorException e) {
|
|
|
1404 |
e.printStackTrace();
|
|
|
1405 |
} catch (MethodInvocationException e) {
|
|
|
1406 |
e.printStackTrace();
|
|
|
1407 |
} catch (IOException e) {
|
|
|
1408 |
e.printStackTrace();
|
|
|
1409 |
} catch (Exception e) {
|
|
|
1410 |
e.printStackTrace();
|
|
|
1411 |
}
|
|
|
1412 |
|
|
|
1413 |
return null;
|
|
|
1414 |
}
|
|
|
1415 |
|
|
|
1416 |
|
|
|
1417 |
}
|
|
|
1418 |
|