| 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.util.Utils;
|
|
|
14 |
|
|
|
15 |
import java.io.BufferedWriter;
|
|
|
16 |
import java.io.File;
|
|
|
17 |
import java.io.FileInputStream;
|
|
|
18 |
import java.io.FileOutputStream;
|
|
|
19 |
import java.io.IOException;
|
|
|
20 |
import java.io.InputStream;
|
|
|
21 |
import java.io.OutputStream;
|
|
|
22 |
import java.io.OutputStreamWriter;
|
|
|
23 |
import java.io.StringWriter;
|
| 2227 |
rajveer |
24 |
import java.net.URLEncoder;
|
| 2171 |
rajveer |
25 |
import java.text.DecimalFormat;
|
|
|
26 |
import java.util.HashMap;
|
|
|
27 |
import java.util.List;
|
|
|
28 |
import java.util.Map;
|
|
|
29 |
|
|
|
30 |
import org.apache.velocity.Template;
|
|
|
31 |
import org.apache.velocity.VelocityContext;
|
|
|
32 |
import org.apache.velocity.app.Velocity;
|
|
|
33 |
import org.apache.velocity.exception.MethodInvocationException;
|
|
|
34 |
import org.apache.velocity.exception.ParseErrorException;
|
|
|
35 |
import org.apache.velocity.exception.ResourceNotFoundException;
|
| 2305 |
vikas |
36 |
import org.json.JSONObject;
|
| 2171 |
rajveer |
37 |
|
|
|
38 |
/**
|
|
|
39 |
* utility class to generated all html stuff from java objects
|
|
|
40 |
* Driver class to merge Java data objects with VTL script.
|
|
|
41 |
*
|
|
|
42 |
* @author rajveer
|
|
|
43 |
*
|
|
|
44 |
*/
|
|
|
45 |
public class NewVUI {
|
|
|
46 |
String contentVersion;
|
|
|
47 |
|
|
|
48 |
public NewVUI(Long contentVersion) throws Exception {
|
| 2367 |
rajveer |
49 |
this.contentVersion = contentVersion.toString();
|
| 2171 |
rajveer |
50 |
}
|
|
|
51 |
|
|
|
52 |
/**
|
|
|
53 |
* Generates content for the specified entity embedding links to the
|
|
|
54 |
* specified domain name.
|
|
|
55 |
*
|
|
|
56 |
* The method updates the member variable problems in any of the following
|
|
|
57 |
* four cases:
|
|
|
58 |
* <ol>
|
|
|
59 |
* <li>The entity is not ready.
|
|
|
60 |
* <li>The category has not been updated yet. (Set to -1).
|
|
|
61 |
* <li>There are no items in the catalog corresponding to this entity.
|
|
|
62 |
* <li>There are no active or content-complete items in the catalog
|
|
|
63 |
* corresponding to this entity.
|
|
|
64 |
* <li>Neither the items have been updated nor the content has been updated.
|
|
|
65 |
* </ol>
|
|
|
66 |
*
|
|
|
67 |
* @param entity
|
|
|
68 |
* - Entity for which the content has to be generated.
|
|
|
69 |
* @param domain
|
|
|
70 |
* - The domain name to be used to serve static content.
|
|
|
71 |
* @param exportPath
|
|
|
72 |
* - Local file system path where content has to be generated.
|
|
|
73 |
* @return -True if content is generated successfully, False otherwise.
|
|
|
74 |
* @throws Exception
|
|
|
75 |
*/
|
| 2367 |
rajveer |
76 |
public boolean generateHtmlForOneEntity(Entity entity, String exportPath) throws Exception{
|
| 2171 |
rajveer |
77 |
String mediaPath = Utils.EXPORT_MEDIA_PATH + entity.getID();
|
|
|
78 |
|
| 2367 |
rajveer |
79 |
deleteOldResources(mediaPath, exportPath + entity.getID());
|
| 2171 |
rajveer |
80 |
|
|
|
81 |
ExpandedEntity expEntity = new ExpandedEntity(entity);
|
|
|
82 |
|
|
|
83 |
long catalogId = expEntity.getID();
|
|
|
84 |
String templateFile;
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
//Create new directory
|
|
|
88 |
File exportDir = new File(exportPath + catalogId);
|
|
|
89 |
if(!exportDir.exists()) {
|
|
|
90 |
exportDir.mkdir();
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
templateFile= Utils.VTL_SRC_PATH + "product_summary.vm";
|
| 2367 |
rajveer |
94 |
getProductSummaryHtml(expEntity, templateFile, exportPath);
|
| 2171 |
rajveer |
95 |
|
|
|
96 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_widget.vm";
|
| 2367 |
rajveer |
97 |
getEntityWidgetSnippetHtml(expEntity, templateFile, exportPath);
|
| 2171 |
rajveer |
98 |
|
|
|
99 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_homepage.vm";
|
| 2367 |
rajveer |
100 |
getEntityHomeSnippetHtml(expEntity, templateFile, exportPath);
|
| 2171 |
rajveer |
101 |
|
|
|
102 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_searchpage.vm";
|
| 2367 |
rajveer |
103 |
getEntitySearchSnippetHtml(expEntity, templateFile, exportPath);
|
| 2171 |
rajveer |
104 |
|
|
|
105 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_categorypage.vm";
|
| 2367 |
rajveer |
106 |
getEntityCategorySnippetHtml(expEntity, templateFile, exportPath);
|
| 2171 |
rajveer |
107 |
|
|
|
108 |
templateFile= Utils.VTL_SRC_PATH + "slideguide_img_video.vm";
|
| 2367 |
rajveer |
109 |
getEntitySlideGuideHtml(expEntity, templateFile, exportPath);
|
| 2205 |
rajveer |
110 |
|
| 2171 |
rajveer |
111 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_phones_i_own.vm";
|
| 2367 |
rajveer |
112 |
getEntityPhonesIOwnSnippetHtml(expEntity, templateFile, exportPath);
|
| 2171 |
rajveer |
113 |
|
|
|
114 |
if(expEntity.getCategory().getParentCategory().getID() == Utils.MOBILE_PHONES_CATAGOEY){
|
|
|
115 |
|
|
|
116 |
templateFile= Utils.VTL_SRC_PATH + "slideguide_for_comparison.vm";
|
| 2367 |
rajveer |
117 |
getEntitySnippetForComparison(expEntity, templateFile, exportPath);
|
| 2171 |
rajveer |
118 |
|
|
|
119 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_comparisonpage.vm";
|
| 2367 |
rajveer |
120 |
getEntityCompareSnippetHtml(expEntity, templateFile, exportPath);
|
| 2205 |
rajveer |
121 |
|
| 2171 |
rajveer |
122 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_comparisonpage_summary.vm";
|
| 2367 |
rajveer |
123 |
getEntityCompareSummarySnippetHtml(expEntity, templateFile, exportPath);
|
| 2205 |
rajveer |
124 |
|
| 2171 |
rajveer |
125 |
getSlidenamesSnippet(expEntity, exportPath);
|
|
|
126 |
}
|
|
|
127 |
|
| 2305 |
vikas |
128 |
getProductPropertiesSnippet(expEntity, exportPath);
|
| 2171 |
rajveer |
129 |
|
|
|
130 |
generateImages(expEntity.getID(), getImagePrefix(expEntity));
|
|
|
131 |
|
|
|
132 |
return true;
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
public boolean deleteDir(File dir) {
|
|
|
136 |
if (dir.isDirectory()) {
|
|
|
137 |
String[] children = dir.list();
|
|
|
138 |
for (int i=0; i<children.length; i++) {
|
|
|
139 |
boolean success = deleteDir(new File(dir, children[i]));
|
|
|
140 |
if (!success) {
|
|
|
141 |
return false;
|
|
|
142 |
}
|
|
|
143 |
}
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
// The directory is now empty so delete it
|
|
|
147 |
return dir.delete();
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
private void deleteOldResources(String mediaPath, String contentPath) {
|
|
|
151 |
File f = new File(contentPath);
|
|
|
152 |
if(f.exists()){
|
|
|
153 |
deleteDir(f);
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
f = new File(mediaPath);
|
|
|
157 |
if(f.exists()){
|
|
|
158 |
deleteDir(f);
|
|
|
159 |
}
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
private void generateImages(long catalogId, String imagePrefix) throws IOException {
|
|
|
163 |
String globalImageDirPath = Utils.CONTENT_DB_PATH + "media" + File.separator;
|
|
|
164 |
String globalDefaultImagePath = globalImageDirPath + "default.jpg";
|
|
|
165 |
|
|
|
166 |
String imageDirPath = globalImageDirPath + catalogId + File.separator;
|
|
|
167 |
String defaultImagePath = imageDirPath + "default.jpg";
|
|
|
168 |
|
|
|
169 |
/*
|
|
|
170 |
* Create the directory for this entity if it didn't exist.
|
|
|
171 |
*/
|
|
|
172 |
File f = new File(globalImageDirPath + catalogId);
|
|
|
173 |
if (!f.exists()) {
|
|
|
174 |
f.mkdir();
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
/*
|
|
|
178 |
* If the default image is not present for this entity, copy the global
|
|
|
179 |
* default image.
|
|
|
180 |
* TODO: This part will be moved to the Jython Script
|
|
|
181 |
*/
|
|
|
182 |
File f3 = new File(defaultImagePath);
|
|
|
183 |
if (!f3.exists()) {
|
|
|
184 |
copyFile(globalDefaultImagePath, defaultImagePath);
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
String exportPath = Utils.EXPORT_MEDIA_PATH + catalogId;
|
|
|
188 |
/*
|
|
|
189 |
* Copying the generated content from db/media to export/media. This
|
|
|
190 |
* will also insert a timestamp tag in the file names.
|
|
|
191 |
*/
|
|
|
192 |
File sourceFile = new File(globalImageDirPath + catalogId);
|
|
|
193 |
File destinationFile = new File(exportPath);
|
| 2198 |
rajveer |
194 |
copyDirectory(sourceFile, destinationFile, imagePrefix);
|
| 2171 |
rajveer |
195 |
|
|
|
196 |
/*
|
|
|
197 |
* Copy the thumbnail and the icon files. This is required so that we can display the
|
|
|
198 |
* thumbnail on the cart page and icon on the facebook.
|
|
|
199 |
*/
|
| 2198 |
rajveer |
200 |
copyFile(imageDirPath + "thumbnail.jpg", exportPath + File.separator + "thumbnail.jpg");
|
|
|
201 |
copyFile(imageDirPath + "icon.jpg", exportPath + File.separator + "icon.jpg");
|
| 2171 |
rajveer |
202 |
}
|
|
|
203 |
|
|
|
204 |
/**
|
|
|
205 |
* Copies the contents of the input file into the output file. Creates the
|
|
|
206 |
* output file if it doesn't exist already.
|
|
|
207 |
*
|
|
|
208 |
* @param inputFile
|
|
|
209 |
* File to be copied.
|
|
|
210 |
* @param outputFile
|
|
|
211 |
* File to be created.
|
|
|
212 |
* @throws IOException
|
|
|
213 |
*/
|
|
|
214 |
private void copyFile(String inputFile, String outputFile) throws IOException {
|
|
|
215 |
File sourceFile = new File(inputFile);
|
|
|
216 |
File destinationFile = new File(outputFile);
|
| 2206 |
rajveer |
217 |
|
| 2171 |
rajveer |
218 |
if (!destinationFile.exists())
|
|
|
219 |
destinationFile.createNewFile();
|
|
|
220 |
|
|
|
221 |
InputStream in = new FileInputStream(sourceFile);
|
| 2305 |
vikas |
222 |
OutputStream out = new FileOutputStream(destinationFile);
|
| 2171 |
rajveer |
223 |
// Copy the bits from instream to outstream
|
|
|
224 |
byte[] buf = new byte[1024];
|
|
|
225 |
int len;
|
|
|
226 |
while ((len = in.read(buf)) > 0) {
|
|
|
227 |
out.write(buf, 0, len);
|
|
|
228 |
}
|
|
|
229 |
in.close();
|
|
|
230 |
out.close();
|
|
|
231 |
}
|
|
|
232 |
|
|
|
233 |
// If targetLocation does not exist, it will be created.
|
|
|
234 |
public void copyDirectory(File sourceLocation , File targetLocation, String imagePrefix) throws IOException {
|
|
|
235 |
|
|
|
236 |
if (sourceLocation.isDirectory()) {
|
|
|
237 |
if (!targetLocation.exists()) {
|
|
|
238 |
targetLocation.mkdir();
|
|
|
239 |
}
|
|
|
240 |
|
|
|
241 |
String[] children = sourceLocation.list();
|
|
|
242 |
for (int i=0; i<children.length; i++) {
|
|
|
243 |
copyDirectory(new File(sourceLocation, children[i]), new File(targetLocation, children[i]), imagePrefix);
|
|
|
244 |
}
|
|
|
245 |
} else {
|
|
|
246 |
InputStream in = new FileInputStream(sourceLocation);
|
|
|
247 |
|
|
|
248 |
String fileName = targetLocation.getName().split("\\.")[0];
|
|
|
249 |
String fileExt = targetLocation.getName().split("\\.")[1];
|
|
|
250 |
String newFileName = targetLocation.getParent() + File.separator + imagePrefix + "-" + fileName + "-" + this.contentVersion + "." + fileExt;
|
|
|
251 |
|
|
|
252 |
|
|
|
253 |
//String fileName = targetLocation
|
|
|
254 |
OutputStream out = new FileOutputStream(newFileName);
|
|
|
255 |
|
|
|
256 |
// Copy the bits from instream to outstream
|
|
|
257 |
byte[] buf = new byte[1024];
|
|
|
258 |
int len;
|
|
|
259 |
while ((len = in.read(buf)) > 0) {
|
|
|
260 |
out.write(buf, 0, len);
|
|
|
261 |
}
|
|
|
262 |
in.close();
|
|
|
263 |
out.close();
|
|
|
264 |
}
|
|
|
265 |
}
|
|
|
266 |
|
| 2305 |
vikas |
267 |
private void getProductPropertiesSnippet(ExpandedEntity expEntity, String exportPath) {
|
|
|
268 |
long catalogId = expEntity.getID();
|
|
|
269 |
try {
|
|
|
270 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
|
|
271 |
} catch (Exception e) {
|
|
|
272 |
e.printStackTrace();
|
|
|
273 |
}
|
|
|
274 |
|
|
|
275 |
String metaDescription = "";
|
|
|
276 |
String metaKeywords = "";
|
|
|
277 |
String entityUrl = getEntityURL(expEntity);
|
|
|
278 |
String title = "";
|
|
|
279 |
|
|
|
280 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
281 |
for(Feature feature: features){
|
|
|
282 |
if(feature.getFeatureDefinitionID() == 120132){
|
|
|
283 |
PrimitiveDataObject dataObject= (PrimitiveDataObject)feature.getBullets().get(0).getDataObject();
|
|
|
284 |
title = dataObject.getValue();
|
|
|
285 |
}
|
|
|
286 |
if(feature.getFeatureDefinitionID() == 120133){
|
|
|
287 |
PrimitiveDataObject dataObject= (PrimitiveDataObject)feature.getBullets().get(0).getDataObject();
|
|
|
288 |
metaDescription = dataObject.getValue();
|
|
|
289 |
}
|
|
|
290 |
if(feature.getFeatureDefinitionID() == 120134){
|
|
|
291 |
PrimitiveDataObject dataObject= (PrimitiveDataObject)feature.getBullets().get(0).getDataObject();
|
|
|
292 |
metaKeywords = dataObject.getValue();
|
|
|
293 |
}
|
|
|
294 |
}
|
| 2171 |
rajveer |
295 |
|
| 2305 |
vikas |
296 |
try {
|
| 2171 |
rajveer |
297 |
|
| 2305 |
vikas |
298 |
JSONObject props = new JSONObject();
|
|
|
299 |
props.put("metaDescription", metaDescription);
|
|
|
300 |
props.put("metaKeywords", metaKeywords);
|
|
|
301 |
props.put("entityUrl", entityUrl);
|
|
|
302 |
props.put("title", title);
|
| 2171 |
rajveer |
303 |
|
| 2305 |
vikas |
304 |
String exportFileName = exportPath + catalogId + File.separator
|
| 2367 |
rajveer |
305 |
+ "ProductPropertiesSnippet.vm";
|
| 2305 |
vikas |
306 |
File exportFile = new File(exportFileName);
|
|
|
307 |
if (!exportFile.exists()) {
|
|
|
308 |
exportFile.createNewFile();
|
|
|
309 |
}
|
| 2171 |
rajveer |
310 |
|
| 2305 |
vikas |
311 |
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
|
|
|
312 |
new FileOutputStream(exportFile)));
|
|
|
313 |
|
|
|
314 |
writer.write(props.toString());
|
|
|
315 |
|
|
|
316 |
writer.flush();
|
|
|
317 |
writer.close();
|
|
|
318 |
} catch (Exception e) {
|
|
|
319 |
e.printStackTrace();
|
|
|
320 |
}
|
| 2171 |
rajveer |
321 |
}
|
| 2305 |
vikas |
322 |
|
|
|
323 |
private void getSlidenamesSnippet(ExpandedEntity expEntity, String exportPath) throws ResourceNotFoundException, ParseErrorException, Exception{
|
| 2171 |
rajveer |
324 |
long catalogId = expEntity.getID();
|
|
|
325 |
|
|
|
326 |
StringBuilder slideNames = new StringBuilder();
|
|
|
327 |
|
|
|
328 |
slideNames.append(expEntity.getBrand() + " " + expEntity.getModelNumber() + " " + expEntity.getModelName() + "\n");
|
|
|
329 |
|
|
|
330 |
Map<Long, Double> slideScores = CreationUtils.getSlideComparisonScores(catalogId);
|
|
|
331 |
|
|
|
332 |
for(ExpandedSlide expSlide: expEntity.getExpandedSlides()){
|
|
|
333 |
if(expSlide.getSlideDefinitionID() == 130054){
|
|
|
334 |
continue;
|
|
|
335 |
}
|
|
|
336 |
slideNames.append(expSlide.getSlideDefinition().getLabel() + "!!!");
|
|
|
337 |
|
|
|
338 |
String bucketName = "None";
|
|
|
339 |
if(Catalog.getInstance().getDefinitionsContainer().getComparisonBucketName(expEntity.getCategoryID(), expSlide.getSlideDefinitionID()) != null){
|
|
|
340 |
bucketName = Catalog.getInstance().getDefinitionsContainer().getComparisonBucketName(expEntity.getCategoryID(), expSlide.getSlideDefinitionID());
|
|
|
341 |
}
|
|
|
342 |
slideNames.append(bucketName + "!!!");
|
|
|
343 |
|
|
|
344 |
double score = 0;
|
|
|
345 |
if(slideScores.get(expSlide.getSlideDefinitionID())!=null){
|
|
|
346 |
score = slideScores.get(expSlide.getSlideDefinitionID());
|
|
|
347 |
}
|
|
|
348 |
|
|
|
349 |
DecimalFormat oneDForm = new DecimalFormat("#.#");
|
|
|
350 |
score = Double.valueOf(oneDForm.format(score));
|
|
|
351 |
|
|
|
352 |
slideNames.append(score + "\n");
|
|
|
353 |
}
|
|
|
354 |
|
| 2367 |
rajveer |
355 |
String exportFileName = exportPath + catalogId + File.separator + "SlideNamesSnippet.vm";
|
| 2171 |
rajveer |
356 |
File exportFile = new File(exportFileName);
|
|
|
357 |
if(!exportFile.exists()) {
|
|
|
358 |
exportFile.createNewFile();
|
|
|
359 |
}
|
|
|
360 |
|
|
|
361 |
BufferedWriter writer = new BufferedWriter(
|
|
|
362 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
363 |
|
|
|
364 |
writer.write(slideNames.toString());
|
|
|
365 |
writer.flush();
|
|
|
366 |
writer.close();
|
|
|
367 |
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
|
| 2367 |
rajveer |
371 |
private void getEntitySnippetForComparison(ExpandedEntity expEntity, String templateFile,String exportPath) throws Exception {
|
| 2171 |
rajveer |
372 |
long catalogId = expEntity.getID();
|
|
|
373 |
VelocityContext context = new VelocityContext();
|
|
|
374 |
|
|
|
375 |
context.put("imagePrefix", getImagePrefix(expEntity));
|
|
|
376 |
context.put("expentity", expEntity);
|
|
|
377 |
context.put("contentVersion", this.contentVersion);
|
|
|
378 |
|
|
|
379 |
String exportFileName = null;
|
|
|
380 |
|
|
|
381 |
Template template = Velocity.getTemplate(templateFile);
|
| 2367 |
rajveer |
382 |
exportFileName = exportPath + catalogId + File.separator + "ComparisonSnippet.vm";
|
| 2171 |
rajveer |
383 |
|
|
|
384 |
File exportFile = new File(exportFileName);
|
|
|
385 |
if(!exportFile.exists()) {
|
|
|
386 |
exportFile.createNewFile();
|
|
|
387 |
}
|
|
|
388 |
|
|
|
389 |
BufferedWriter writer = new BufferedWriter(
|
|
|
390 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
391 |
|
|
|
392 |
//Template template = Velocity.getTemplate(templateFile);
|
|
|
393 |
template.merge(context, writer);
|
|
|
394 |
|
|
|
395 |
writer.flush();
|
|
|
396 |
writer.close();
|
|
|
397 |
Utils.info("Export Complete!");
|
|
|
398 |
|
|
|
399 |
}
|
|
|
400 |
|
| 2367 |
rajveer |
401 |
private void getEntitySlideGuideHtml(ExpandedEntity expEntity, String templateFile, String exportPath) throws Exception {
|
| 2171 |
rajveer |
402 |
long catalogId = expEntity.getID();
|
|
|
403 |
VelocityContext context = new VelocityContext();
|
|
|
404 |
|
|
|
405 |
context.put("imagePrefix", getImagePrefix(expEntity));
|
|
|
406 |
context.put("expentity", expEntity);
|
|
|
407 |
context.put("contentVersion", this.contentVersion);
|
|
|
408 |
context.put("defs", Catalog.getInstance().getDefinitionsContainer());
|
| 2319 |
rajveer |
409 |
context.put("helpdocs", CreationUtils.getHelpdocs());
|
|
|
410 |
|
| 2171 |
rajveer |
411 |
String exportFileName = null;
|
|
|
412 |
|
|
|
413 |
Template template = Velocity.getTemplate(templateFile);
|
| 2367 |
rajveer |
414 |
exportFileName = exportPath + catalogId + File.separator + "SlideGuide.vm";
|
| 2171 |
rajveer |
415 |
|
|
|
416 |
File exportFile = new File(exportFileName);
|
|
|
417 |
if(!exportFile.exists()) {
|
|
|
418 |
exportFile.createNewFile();
|
|
|
419 |
}
|
|
|
420 |
|
|
|
421 |
BufferedWriter writer = new BufferedWriter(
|
|
|
422 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
423 |
|
|
|
424 |
//Template template = Velocity.getTemplate(templateFile);
|
|
|
425 |
template.merge(context, writer);
|
|
|
426 |
|
|
|
427 |
writer.flush();
|
|
|
428 |
writer.close();
|
|
|
429 |
Utils.info("Export Complete!");
|
|
|
430 |
|
|
|
431 |
}
|
|
|
432 |
|
| 2367 |
rajveer |
433 |
public void getProductSummaryHtml(ExpandedEntity expEntity, String templateFile, String exportPath) {
|
| 2171 |
rajveer |
434 |
long catalogId = expEntity.getID();
|
|
|
435 |
try {
|
|
|
436 |
String title = expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber();
|
| 2314 |
vikas |
437 |
String brandName = expEntity.getBrand().trim();
|
| 2305 |
vikas |
438 |
String productName = expEntity.getModelName() + " " + expEntity.getModelNumber();
|
| 2171 |
rajveer |
439 |
String categoryName = expEntity.getCategory().getLabel();
|
|
|
440 |
String tagline = "";
|
|
|
441 |
String warranty = "";
|
|
|
442 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
443 |
for(Feature feature: features){
|
|
|
444 |
if(feature.getFeatureDefinitionID() == 120084){
|
|
|
445 |
PrimitiveDataObject dataObject= (PrimitiveDataObject)feature.getBullets().get(0).getDataObject();
|
|
|
446 |
tagline = dataObject.getValue();
|
|
|
447 |
}
|
|
|
448 |
if(feature.getFeatureDefinitionID() == 120125){
|
|
|
449 |
ExpandedFeature expFeature = new ExpandedFeature(feature);
|
|
|
450 |
ExpandedBullet expBullet =expFeature.getExpandedBullets().get(0);
|
|
|
451 |
if(expBullet != null){
|
|
|
452 |
warranty = expBullet.getValue() + " "+ expBullet.getUnit().getShortForm();
|
|
|
453 |
}
|
|
|
454 |
}
|
|
|
455 |
}
|
|
|
456 |
|
|
|
457 |
long categoryId = expEntity.getCategory().getID();
|
|
|
458 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
459 |
params.put("TITLE", title);
|
| 2305 |
vikas |
460 |
params.put("BRAND_NAME", brandName);
|
|
|
461 |
params.put("PRODUCT_NAME", productName);
|
| 2171 |
rajveer |
462 |
params.put("CATEGORY_ID", ((int)categoryId)+"");
|
|
|
463 |
params.put("CATEGORY_NAME", categoryName);
|
|
|
464 |
params.put("CATEGORY_URL", categoryName.replaceAll(" ", "-").toLowerCase() + "/" + categoryId);
|
| 2367 |
rajveer |
465 |
params.put("PRODUCT_URL", URLEncoder.encode(this.getEntityURL(expEntity), "UTF-8"));
|
| 2227 |
rajveer |
466 |
if(expEntity.getCategory().getParentCategory().getID() == Utils.MOBILE_PHONES_CATAGOEY){
|
|
|
467 |
params.put("IS_MOBILE", "TRUE" );
|
|
|
468 |
}else{
|
|
|
469 |
params.put("IS_MOBILE", "FALSE" );
|
|
|
470 |
}
|
| 2171 |
rajveer |
471 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
472 |
params.put("TAGLINE", tagline);
|
|
|
473 |
params.put("WARRANTY", warranty);
|
|
|
474 |
|
|
|
475 |
VelocityContext context = new VelocityContext();
|
|
|
476 |
context.put("params", params);
|
|
|
477 |
|
| 2367 |
rajveer |
478 |
String exportFileName = exportPath + catalogId + File.separator + "ProductDetail.vm";
|
| 2171 |
rajveer |
479 |
|
|
|
480 |
File exportFile = new File(exportFileName);
|
|
|
481 |
if(!exportFile.exists()) {
|
|
|
482 |
exportFile.createNewFile();
|
|
|
483 |
}
|
|
|
484 |
|
|
|
485 |
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
486 |
|
|
|
487 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
488 |
template.merge(context, writer);
|
|
|
489 |
|
|
|
490 |
writer.flush();
|
|
|
491 |
writer.close();
|
|
|
492 |
Utils.info("Export Complete!");
|
|
|
493 |
|
|
|
494 |
} catch (Exception e) {
|
|
|
495 |
e.printStackTrace();
|
|
|
496 |
}
|
|
|
497 |
}
|
|
|
498 |
|
|
|
499 |
private String getEntityURL(ExpandedEntity expEntity){
|
|
|
500 |
String url = "/" + expEntity.getCategory().getParentCategory().getLabel().toLowerCase().replace(' ', '-') + "/";
|
| 2367 |
rajveer |
501 |
String productUrl = ((expEntity.getBrand() != null) ? expEntity.getBrand().trim() + " " : "").toLowerCase().replace(' ', '-')
|
|
|
502 |
+ "-" + ((expEntity.getModelName() != null) ? expEntity.getModelName().trim() + " " : "").toLowerCase().replace(' ', '-')
|
|
|
503 |
+ "-" + (( expEntity.getModelNumber() != null ) ? expEntity.getModelNumber().trim() + " " : "" ).toLowerCase().replace(' ', '-')
|
| 2171 |
rajveer |
504 |
+ "-" + expEntity.getID();
|
|
|
505 |
productUrl = productUrl.replaceAll("/", "-");
|
|
|
506 |
url = url + productUrl;
|
| 2305 |
vikas |
507 |
url = url.replaceAll("-+", "-");
|
| 2171 |
rajveer |
508 |
return url;
|
|
|
509 |
}
|
|
|
510 |
|
|
|
511 |
private String getImagePrefix(ExpandedEntity expEntity){
|
| 2367 |
rajveer |
512 |
String imagePrefix = ((expEntity.getBrand() != null) ? expEntity.getBrand().trim() + " " : "").toLowerCase().replace(' ', '-')
|
|
|
513 |
+ "-" + ((expEntity.getModelName() != null) ? expEntity.getModelName().trim() + " " : "").toLowerCase().replace(' ', '-')
|
|
|
514 |
+ "-" + (( expEntity.getModelNumber() != null ) ? expEntity.getModelNumber().trim() + " " : "" ).toLowerCase().replace(' ', '-');
|
| 2171 |
rajveer |
515 |
imagePrefix = imagePrefix.replaceAll("/", "-");
|
| 2367 |
rajveer |
516 |
imagePrefix = imagePrefix.replaceAll("-+", "-");
|
| 2171 |
rajveer |
517 |
return imagePrefix;
|
|
|
518 |
}
|
|
|
519 |
|
| 2367 |
rajveer |
520 |
private void getEntityWidgetSnippetHtml(ExpandedEntity expEntity, String templateFile, String exportPath) {
|
| 2171 |
rajveer |
521 |
long catalogId = expEntity.getID();
|
|
|
522 |
try {
|
|
|
523 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
|
|
524 |
String title = expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber();
|
| 2197 |
rajveer |
525 |
String prodName = title;
|
|
|
526 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
|
|
527 |
prodName = expEntity.getBrand() + " " + expEntity.getModelName();
|
|
|
528 |
}
|
| 2171 |
rajveer |
529 |
String imagePrefix = getImagePrefix(expEntity);
|
|
|
530 |
String url = getEntityURL(expEntity);
|
|
|
531 |
|
|
|
532 |
String tinySnippet = "";
|
|
|
533 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
534 |
for(Feature feature: features){
|
|
|
535 |
if(feature.getFeatureDefinitionID() == 120089){
|
|
|
536 |
PrimitiveDataObject dataObject= (PrimitiveDataObject)feature.getBullets().get(0).getDataObject();
|
|
|
537 |
tinySnippet = dataObject.getValue();
|
|
|
538 |
}
|
|
|
539 |
}
|
|
|
540 |
|
|
|
541 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
542 |
params.put("TITLE", title);
|
| 2197 |
rajveer |
543 |
params.put("PROD_NAME", prodName);
|
| 2171 |
rajveer |
544 |
params.put("URL", url);
|
|
|
545 |
params.put("IMAGE_PREFIX", imagePrefix);
|
|
|
546 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
547 |
params.put("TINY_SNIPPET", tinySnippet);
|
|
|
548 |
params.put("contentVersion", contentVersion);
|
|
|
549 |
VelocityContext context = new VelocityContext();
|
| 2367 |
rajveer |
550 |
|
| 2171 |
rajveer |
551 |
context.put("params", params);
|
| 2367 |
rajveer |
552 |
|
|
|
553 |
|
|
|
554 |
String exportFileName = exportPath + catalogId + File.separator + "WidgetSnippet.vm";
|
| 2171 |
rajveer |
555 |
File exportFile = new File(exportFileName);
|
|
|
556 |
if(!exportFile.exists()) {
|
|
|
557 |
exportFile.createNewFile();
|
|
|
558 |
}
|
|
|
559 |
|
|
|
560 |
BufferedWriter writer = new BufferedWriter(
|
|
|
561 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
562 |
|
|
|
563 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
564 |
template.merge(context, writer);
|
|
|
565 |
|
|
|
566 |
writer.flush();
|
|
|
567 |
writer.close();
|
|
|
568 |
Utils.info("Export Complete!");
|
|
|
569 |
|
|
|
570 |
|
|
|
571 |
} catch (Exception e) {
|
|
|
572 |
e.printStackTrace();
|
|
|
573 |
}
|
|
|
574 |
}
|
|
|
575 |
|
|
|
576 |
|
| 2367 |
rajveer |
577 |
private void getEntityHomeSnippetHtml(ExpandedEntity expEntity, String templateFile, String exportPath) {
|
| 2171 |
rajveer |
578 |
long catalogId = expEntity.getID();
|
|
|
579 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
580 |
try {
|
|
|
581 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
|
|
582 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
|
| 2197 |
rajveer |
583 |
String prodName = title;
|
|
|
584 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
|
|
585 |
prodName = expEntity.getBrand() + " " + expEntity.getModelName();
|
|
|
586 |
}
|
| 2171 |
rajveer |
587 |
String url = getEntityURL(expEntity);
|
|
|
588 |
String imagePrefix = getImagePrefix(expEntity);
|
|
|
589 |
String tinySnippet = "";
|
|
|
590 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
591 |
for(Feature feature: features){
|
|
|
592 |
if(feature.getFeatureDefinitionID() == 120081){
|
|
|
593 |
List<Bullet> bullets = feature.getBullets();
|
|
|
594 |
int count = 1;
|
|
|
595 |
for(Bullet bullet: bullets){
|
|
|
596 |
PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
|
|
|
597 |
tinySnippet = dataObject.getValue();
|
|
|
598 |
params.put("SNIPPET_"+count++, tinySnippet);
|
|
|
599 |
System.out.println("Tiny Snippets is " + dataObject.getValue());
|
|
|
600 |
}
|
|
|
601 |
}
|
|
|
602 |
}
|
|
|
603 |
|
|
|
604 |
params.put("TITLE", title);
|
| 2197 |
rajveer |
605 |
params.put("PROD_NAME", prodName);
|
| 2171 |
rajveer |
606 |
params.put("URL", url);
|
|
|
607 |
params.put("IMAGE_PREFIX", imagePrefix);
|
|
|
608 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
609 |
params.put("contentVersion", contentVersion);
|
|
|
610 |
VelocityContext context = new VelocityContext();
|
|
|
611 |
context.put("params", params);
|
|
|
612 |
|
| 2367 |
rajveer |
613 |
String exportFileName = exportPath + catalogId + File.separator + "HomeSnippet.vm";
|
| 2171 |
rajveer |
614 |
File exportFile = new File(exportFileName);
|
|
|
615 |
if(!exportFile.exists()) {
|
|
|
616 |
exportFile.createNewFile();
|
|
|
617 |
}
|
|
|
618 |
|
|
|
619 |
BufferedWriter writer = new BufferedWriter(
|
|
|
620 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
621 |
|
|
|
622 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
623 |
template.merge(context, writer);
|
|
|
624 |
|
|
|
625 |
writer.flush();
|
|
|
626 |
writer.close();
|
|
|
627 |
Utils.info("Export Complete!");
|
|
|
628 |
|
|
|
629 |
} catch (Exception e) {
|
|
|
630 |
e.printStackTrace();
|
|
|
631 |
}
|
|
|
632 |
}
|
|
|
633 |
|
| 2367 |
rajveer |
634 |
private void getEntityCategorySnippetHtml(ExpandedEntity expEntity, String templateFile, String exportPath) {
|
| 2171 |
rajveer |
635 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
636 |
long catalogId = expEntity.getID();
|
|
|
637 |
|
|
|
638 |
try {
|
|
|
639 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
|
|
640 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
|
| 2197 |
rajveer |
641 |
String prodName = title;
|
|
|
642 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
|
|
643 |
prodName = expEntity.getBrand() + " " + expEntity.getModelName();
|
|
|
644 |
}
|
| 2171 |
rajveer |
645 |
String url = getEntityURL(expEntity);
|
|
|
646 |
String imagePrefix = getImagePrefix(expEntity);
|
|
|
647 |
|
|
|
648 |
String tinySnippet = "";
|
|
|
649 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
650 |
for(Feature feature: features){
|
|
|
651 |
if(feature.getFeatureDefinitionID() == 120081){
|
|
|
652 |
List<Bullet> bullets = feature.getBullets();
|
|
|
653 |
int count = 1;
|
|
|
654 |
for(Bullet bullet: bullets){
|
|
|
655 |
PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
|
|
|
656 |
tinySnippet = dataObject.getValue();
|
|
|
657 |
params.put("SNIPPET_"+count++, tinySnippet);
|
|
|
658 |
System.out.println("Tiny Snippets is " + dataObject.getValue());
|
|
|
659 |
}
|
|
|
660 |
}
|
|
|
661 |
}
|
|
|
662 |
params.put("TITLE", title);
|
| 2197 |
rajveer |
663 |
params.put("PROD_NAME", prodName);
|
| 2171 |
rajveer |
664 |
params.put("URL", url);
|
|
|
665 |
params.put("IMAGE_PREFIX", imagePrefix);
|
|
|
666 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
667 |
params.put("contentVersion", contentVersion);
|
|
|
668 |
|
|
|
669 |
VelocityContext context = new VelocityContext();
|
|
|
670 |
context.put("params", params);
|
|
|
671 |
|
| 2367 |
rajveer |
672 |
String exportFileName = exportPath + catalogId + File.separator + "CategorySnippet.vm";
|
| 2171 |
rajveer |
673 |
File exportFile = new File(exportFileName);
|
|
|
674 |
if(!exportFile.exists()) {
|
|
|
675 |
exportFile.createNewFile();
|
|
|
676 |
}
|
|
|
677 |
|
|
|
678 |
BufferedWriter writer = new BufferedWriter(
|
|
|
679 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
680 |
|
|
|
681 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
682 |
template.merge(context, writer);
|
|
|
683 |
|
|
|
684 |
writer.flush();
|
|
|
685 |
writer.close();
|
|
|
686 |
Utils.info("Export Complete!");
|
|
|
687 |
|
|
|
688 |
|
|
|
689 |
} catch (Exception e) {
|
|
|
690 |
e.printStackTrace();
|
|
|
691 |
}
|
|
|
692 |
}
|
|
|
693 |
|
| 2367 |
rajveer |
694 |
private void getEntitySearchSnippetHtml(ExpandedEntity expEntity, String templateFile, String exportPath) {
|
| 2171 |
rajveer |
695 |
long catalogId = expEntity.getID();
|
|
|
696 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
697 |
try {
|
|
|
698 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
|
|
699 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
|
| 2197 |
rajveer |
700 |
String prodName = title;
|
|
|
701 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
|
|
702 |
prodName = expEntity.getBrand() + " " + expEntity.getModelName();
|
|
|
703 |
}
|
| 2171 |
rajveer |
704 |
|
|
|
705 |
String url = getEntityURL(expEntity);
|
|
|
706 |
String imagePrefix = getImagePrefix(expEntity);
|
|
|
707 |
|
|
|
708 |
String tinySnippet = "";
|
|
|
709 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
710 |
for(Feature feature: features){
|
|
|
711 |
if(feature.getFeatureDefinitionID() == 120081){
|
|
|
712 |
List<Bullet> bullets = feature.getBullets();
|
|
|
713 |
int count = 1;
|
|
|
714 |
for(Bullet bullet: bullets){
|
|
|
715 |
PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
|
|
|
716 |
tinySnippet = dataObject.getValue();
|
|
|
717 |
params.put("SNIPPET_"+count++, tinySnippet);
|
|
|
718 |
System.out.println("Tiny Snippets is " + dataObject.getValue());
|
|
|
719 |
}
|
|
|
720 |
}
|
|
|
721 |
}
|
|
|
722 |
|
|
|
723 |
|
|
|
724 |
params.put("TITLE", title);
|
| 2197 |
rajveer |
725 |
params.put("PROD_NAME", prodName);
|
| 2171 |
rajveer |
726 |
params.put("URL", url);
|
|
|
727 |
params.put("IMAGE_PREFIX", imagePrefix);
|
|
|
728 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
729 |
params.put("contentVersion", contentVersion);
|
|
|
730 |
VelocityContext context = new VelocityContext();
|
|
|
731 |
context.put("params", params);
|
| 2367 |
rajveer |
732 |
String exportFileName = exportPath + catalogId + File.separator + "SearchSnippet.vm";
|
| 2171 |
rajveer |
733 |
File exportFile = new File(exportFileName);
|
|
|
734 |
if(!exportFile.exists()) {
|
|
|
735 |
exportFile.createNewFile();
|
|
|
736 |
}
|
|
|
737 |
|
|
|
738 |
BufferedWriter writer = new BufferedWriter(
|
|
|
739 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
740 |
|
|
|
741 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
742 |
template.merge(context, writer);
|
|
|
743 |
|
|
|
744 |
writer.flush();
|
|
|
745 |
writer.close();
|
|
|
746 |
Utils.info("Export Complete!");
|
|
|
747 |
|
|
|
748 |
|
|
|
749 |
} catch (Exception e) {
|
|
|
750 |
e.printStackTrace();
|
|
|
751 |
}
|
|
|
752 |
}
|
|
|
753 |
|
|
|
754 |
|
| 2367 |
rajveer |
755 |
private void getEntityCompareSnippetHtml(ExpandedEntity expEntity, String templateFile, String exportPath) {
|
| 2171 |
rajveer |
756 |
long catalogId = expEntity.getID();
|
|
|
757 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
758 |
|
|
|
759 |
try {
|
|
|
760 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
|
|
761 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
|
| 2197 |
rajveer |
762 |
String prodName = title;
|
|
|
763 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
|
|
764 |
prodName = expEntity.getBrand() + " " + expEntity.getModelName();
|
|
|
765 |
}
|
| 2171 |
rajveer |
766 |
String url = getEntityURL(expEntity);
|
|
|
767 |
String imagePrefix = getImagePrefix(expEntity);
|
|
|
768 |
|
|
|
769 |
String tinySnippet = "";
|
|
|
770 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
771 |
for(Feature feature: features){
|
|
|
772 |
if(feature.getFeatureDefinitionID() == 120081){
|
|
|
773 |
List<Bullet> bullets = feature.getBullets();
|
|
|
774 |
int count = 1;
|
|
|
775 |
for(Bullet bullet: bullets){
|
|
|
776 |
PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
|
|
|
777 |
tinySnippet = dataObject.getValue();
|
|
|
778 |
params.put("SNIPPET_"+count++, tinySnippet);
|
|
|
779 |
System.out.println("Tiny Snippets is " + dataObject.getValue());
|
|
|
780 |
}
|
|
|
781 |
}
|
|
|
782 |
}
|
|
|
783 |
|
|
|
784 |
|
|
|
785 |
params.put("TITLE", title);
|
| 2197 |
rajveer |
786 |
params.put("PROD_NAME", prodName);
|
| 2171 |
rajveer |
787 |
params.put("URL", url);
|
|
|
788 |
params.put("IMAGE_PREFIX", imagePrefix);
|
|
|
789 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
790 |
params.put("contentVersion", contentVersion);
|
|
|
791 |
|
|
|
792 |
VelocityContext context = new VelocityContext();
|
|
|
793 |
context.put("params", params);
|
|
|
794 |
|
| 2367 |
rajveer |
795 |
String exportFileName = exportPath + catalogId + File.separator + "CompareProductSnippet.vm";
|
| 2171 |
rajveer |
796 |
File exportFile = new File(exportFileName);
|
|
|
797 |
if(!exportFile.exists()) {
|
|
|
798 |
exportFile.createNewFile();
|
|
|
799 |
}
|
|
|
800 |
|
|
|
801 |
BufferedWriter writer = new BufferedWriter(
|
|
|
802 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
803 |
|
|
|
804 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
805 |
template.merge(context, writer);
|
|
|
806 |
|
|
|
807 |
writer.flush();
|
|
|
808 |
writer.close();
|
|
|
809 |
Utils.info("Export Complete!");
|
|
|
810 |
|
|
|
811 |
|
|
|
812 |
} catch (Exception e) {
|
|
|
813 |
e.printStackTrace();
|
|
|
814 |
}
|
|
|
815 |
}
|
|
|
816 |
|
|
|
817 |
|
| 2367 |
rajveer |
818 |
private void getEntityCompareSummarySnippetHtml(ExpandedEntity expEntity, String templateFile, String exportPath) {
|
| 2171 |
rajveer |
819 |
long catalogId = expEntity.getID();
|
|
|
820 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
821 |
try {
|
|
|
822 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
|
|
823 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
|
| 2197 |
rajveer |
824 |
String prodName = title;
|
|
|
825 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
|
|
826 |
prodName = expEntity.getBrand() + " " + expEntity.getModelName();
|
|
|
827 |
}
|
| 2171 |
rajveer |
828 |
String url = getEntityURL(expEntity);
|
|
|
829 |
String imagePrefix = getImagePrefix(expEntity);
|
|
|
830 |
|
|
|
831 |
String tinySnippet = "";
|
|
|
832 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
833 |
for(Feature feature: features){
|
|
|
834 |
if(feature.getFeatureDefinitionID() == 120081){
|
|
|
835 |
List<Bullet> bullets = feature.getBullets();
|
|
|
836 |
int count = 1;
|
|
|
837 |
for(Bullet bullet: bullets){
|
|
|
838 |
PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
|
|
|
839 |
tinySnippet = dataObject.getValue();
|
|
|
840 |
params.put("SNIPPET_"+count++, tinySnippet);
|
|
|
841 |
System.out.println("Tiny Snippets is " + dataObject.getValue());
|
|
|
842 |
}
|
|
|
843 |
}
|
|
|
844 |
}
|
|
|
845 |
|
|
|
846 |
|
|
|
847 |
params.put("TITLE", title);
|
| 2197 |
rajveer |
848 |
params.put("PROD_NAME", prodName);
|
| 2171 |
rajveer |
849 |
params.put("URL", url);
|
|
|
850 |
params.put("IMAGE_PREFIX", imagePrefix);
|
|
|
851 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
852 |
params.put("contentVersion", contentVersion);
|
|
|
853 |
|
|
|
854 |
VelocityContext context = new VelocityContext();
|
|
|
855 |
context.put("params", params);
|
|
|
856 |
|
| 2367 |
rajveer |
857 |
String exportFileName = exportPath + catalogId + File.separator + "CompareProductSummarySnippet.vm";
|
| 2171 |
rajveer |
858 |
File exportFile = new File(exportFileName);
|
|
|
859 |
if(!exportFile.exists()) {
|
|
|
860 |
exportFile.createNewFile();
|
|
|
861 |
}
|
|
|
862 |
|
|
|
863 |
BufferedWriter writer = new BufferedWriter(
|
|
|
864 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
865 |
|
|
|
866 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
867 |
template.merge(context, writer);
|
|
|
868 |
|
|
|
869 |
writer.flush();
|
|
|
870 |
writer.close();
|
|
|
871 |
Utils.info("Export Complete!");
|
|
|
872 |
|
|
|
873 |
|
|
|
874 |
} catch (Exception e) {
|
|
|
875 |
e.printStackTrace();
|
|
|
876 |
}
|
|
|
877 |
}
|
|
|
878 |
|
| 2367 |
rajveer |
879 |
private void getEntityPhonesIOwnSnippetHtml(ExpandedEntity expEntity, String templateFile, String exportPath) {
|
| 2171 |
rajveer |
880 |
long catalogId = expEntity.getID();
|
|
|
881 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
882 |
|
|
|
883 |
try {
|
|
|
884 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
|
|
885 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
|
| 2197 |
rajveer |
886 |
String prodName = title;
|
|
|
887 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
|
|
888 |
prodName = expEntity.getBrand() + " " + expEntity.getModelName();
|
|
|
889 |
}
|
| 2171 |
rajveer |
890 |
String url = getEntityURL(expEntity);
|
| 2197 |
rajveer |
891 |
|
| 2171 |
rajveer |
892 |
String imagePrefix = getImagePrefix(expEntity);
|
|
|
893 |
|
|
|
894 |
String tinySnippet = "";
|
|
|
895 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
896 |
for(Feature feature: features){
|
|
|
897 |
if(feature.getFeatureDefinitionID() == 120081){
|
|
|
898 |
List<Bullet> bullets = feature.getBullets();
|
|
|
899 |
int count = 1;
|
|
|
900 |
for(Bullet bullet: bullets){
|
|
|
901 |
PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
|
|
|
902 |
tinySnippet = dataObject.getValue();
|
|
|
903 |
params.put("SNIPPET_"+count++, tinySnippet);
|
|
|
904 |
System.out.println("Tiny Snippets is " + dataObject.getValue());
|
|
|
905 |
}
|
|
|
906 |
}
|
|
|
907 |
}
|
|
|
908 |
|
|
|
909 |
params.put("TITLE", title);
|
| 2197 |
rajveer |
910 |
params.put("PROD_NAME", prodName);
|
| 2171 |
rajveer |
911 |
params.put("URL", url);
|
|
|
912 |
params.put("IMAGE_PREFIX", imagePrefix);
|
|
|
913 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
914 |
params.put("contentVersion", contentVersion);
|
|
|
915 |
|
|
|
916 |
VelocityContext context = new VelocityContext();
|
|
|
917 |
context.put("params", params);
|
|
|
918 |
|
| 2367 |
rajveer |
919 |
String exportFileName = exportPath + catalogId + File.separator + "PhonesIOwnSnippet.vm";
|
| 2171 |
rajveer |
920 |
File exportFile = new File(exportFileName);
|
|
|
921 |
if(!exportFile.exists()) {
|
|
|
922 |
exportFile.createNewFile();
|
|
|
923 |
}
|
|
|
924 |
|
|
|
925 |
BufferedWriter writer = new BufferedWriter(
|
|
|
926 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
927 |
|
|
|
928 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
929 |
template.merge(context, writer);
|
|
|
930 |
|
|
|
931 |
writer.flush();
|
|
|
932 |
writer.close();
|
|
|
933 |
Utils.info("Export Complete!");
|
|
|
934 |
|
|
|
935 |
|
|
|
936 |
} catch (Exception e) {
|
|
|
937 |
e.printStackTrace();
|
|
|
938 |
}
|
|
|
939 |
}
|
|
|
940 |
|
|
|
941 |
public String getHtmlFromVelocity(String templateFile, VelocityContext context){
|
|
|
942 |
try {
|
|
|
943 |
Velocity.init("velocity/velocity.properties");
|
|
|
944 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
945 |
if(template != null) {
|
|
|
946 |
StringWriter writer = new StringWriter();
|
|
|
947 |
template.merge(context, writer);
|
|
|
948 |
writer.flush();
|
|
|
949 |
writer.close();
|
|
|
950 |
return writer.toString();
|
|
|
951 |
}
|
|
|
952 |
|
|
|
953 |
} catch (ResourceNotFoundException e) {
|
|
|
954 |
e.printStackTrace();
|
|
|
955 |
} catch (ParseErrorException e) {
|
|
|
956 |
e.printStackTrace();
|
|
|
957 |
} catch (MethodInvocationException e) {
|
|
|
958 |
e.printStackTrace();
|
|
|
959 |
} catch (IOException e) {
|
|
|
960 |
e.printStackTrace();
|
|
|
961 |
} catch (Exception e) {
|
|
|
962 |
e.printStackTrace();
|
|
|
963 |
}
|
|
|
964 |
|
|
|
965 |
return null;
|
|
|
966 |
}
|
|
|
967 |
|
|
|
968 |
|
|
|
969 |
}
|
|
|
970 |
|