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