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