| Line 18... |
Line 18... |
| 18 |
import java.io.FileOutputStream;
|
18 |
import java.io.FileOutputStream;
|
| 19 |
import java.io.IOException;
|
19 |
import java.io.IOException;
|
| 20 |
import java.io.InputStream;
|
20 |
import java.io.InputStream;
|
| 21 |
import java.io.OutputStream;
|
21 |
import java.io.OutputStream;
|
| 22 |
import java.io.OutputStreamWriter;
|
22 |
import java.io.OutputStreamWriter;
|
| 23 |
import java.io.StringWriter;
|
- |
|
| 24 |
import java.net.URLEncoder;
|
23 |
import java.net.URLEncoder;
|
| 25 |
import java.text.DecimalFormat;
|
24 |
import java.text.DecimalFormat;
|
| - |
|
25 |
import java.util.ArrayList;
|
| 26 |
import java.util.HashMap;
|
26 |
import java.util.HashMap;
|
| 27 |
import java.util.List;
|
27 |
import java.util.List;
|
| 28 |
import java.util.Map;
|
28 |
import java.util.Map;
|
| - |
|
29 |
import java.util.Properties;
|
| 29 |
|
30 |
|
| 30 |
import org.apache.velocity.Template;
|
31 |
import org.apache.velocity.Template;
|
| 31 |
import org.apache.velocity.VelocityContext;
|
32 |
import org.apache.velocity.VelocityContext;
|
| 32 |
import org.apache.velocity.app.Velocity;
|
33 |
import org.apache.velocity.app.Velocity;
|
| 33 |
import org.apache.velocity.exception.MethodInvocationException;
|
- |
|
| 34 |
import org.apache.velocity.exception.ParseErrorException;
|
34 |
import org.apache.velocity.exception.ParseErrorException;
|
| 35 |
import org.apache.velocity.exception.ResourceNotFoundException;
|
35 |
import org.apache.velocity.exception.ResourceNotFoundException;
|
| 36 |
import org.json.JSONObject;
|
36 |
import org.json.JSONObject;
|
| 37 |
|
37 |
|
| 38 |
/**
|
38 |
/**
|
| 39 |
* utility class to generated all html stuff from java objects
|
39 |
* Utility class to merge Java data objects with VTL scripts.
|
| 40 |
* Driver class to merge Java data objects with VTL script.
|
40 |
* Also generates images and other required stuff for rendering content
|
| 41 |
*
|
41 |
*
|
| 42 |
* @author rajveer
|
42 |
* @author rajveer
|
| 43 |
*
|
43 |
*
|
| 44 |
*/
|
44 |
*/
|
| 45 |
public class NewVUI {
|
45 |
public class NewVUI {
|
| Line 48... |
Line 48... |
| 48 |
public NewVUI(Long contentVersion) throws Exception {
|
48 |
public NewVUI(Long contentVersion) throws Exception {
|
| 49 |
this.contentVersion = contentVersion.toString();
|
49 |
this.contentVersion = contentVersion.toString();
|
| 50 |
}
|
50 |
}
|
| 51 |
|
51 |
|
| 52 |
/**
|
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.
|
53 |
* Utility method to delete a directory.
|
| 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
|
54 |
* @param dir
|
| 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
|
55 |
* @return
|
| 75 |
*/
|
56 |
*/
|
| 76 |
public boolean generateHtmlForOneEntity(Entity entity, String exportPath) throws Exception{
|
- |
|
| 77 |
String mediaPath = Utils.EXPORT_MEDIA_PATH + entity.getID();
|
- |
|
| 78 |
|
- |
|
| 79 |
deleteOldResources(mediaPath, exportPath + entity.getID());
|
- |
|
| 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";
|
- |
|
| 94 |
getProductSummaryHtml(expEntity, templateFile, exportPath);
|
- |
|
| 95 |
|
- |
|
| 96 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_widget.vm";
|
- |
|
| 97 |
getEntityWidgetSnippetHtml(expEntity, templateFile, exportPath);
|
- |
|
| 98 |
|
- |
|
| 99 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_homepage.vm";
|
- |
|
| 100 |
getEntityHomeSnippetHtml(expEntity, templateFile, exportPath);
|
- |
|
| 101 |
|
- |
|
| 102 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_searchpage.vm";
|
- |
|
| 103 |
getEntitySearchSnippetHtml(expEntity, templateFile, exportPath);
|
- |
|
| 104 |
|
- |
|
| 105 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_categorypage.vm";
|
- |
|
| 106 |
getEntityCategorySnippetHtml(expEntity, templateFile, exportPath);
|
- |
|
| 107 |
|
- |
|
| 108 |
templateFile= Utils.VTL_SRC_PATH + "slideguide_img_video.vm";
|
- |
|
| 109 |
getEntitySlideGuideHtml(expEntity, templateFile, exportPath);
|
- |
|
| 110 |
|
- |
|
| 111 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_phones_i_own.vm";
|
- |
|
| 112 |
getEntityPhonesIOwnSnippetHtml(expEntity, templateFile, exportPath);
|
- |
|
| 113 |
|
- |
|
| 114 |
if(expEntity.getCategory().getParentCategory().getID() == Utils.MOBILE_PHONES_CATAGOEY){
|
- |
|
| 115 |
|
- |
|
| 116 |
templateFile= Utils.VTL_SRC_PATH + "slideguide_for_comparison.vm";
|
- |
|
| 117 |
getEntitySnippetForComparison(expEntity, templateFile, exportPath);
|
- |
|
| 118 |
|
- |
|
| 119 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_comparisonpage.vm";
|
- |
|
| 120 |
getEntityCompareSnippetHtml(expEntity, templateFile, exportPath);
|
- |
|
| 121 |
|
- |
|
| 122 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_comparisonpage_summary.vm";
|
- |
|
| 123 |
getEntityCompareSummarySnippetHtml(expEntity, templateFile, exportPath);
|
- |
|
| 124 |
|
- |
|
| 125 |
getSlidenamesSnippet(expEntity, exportPath);
|
- |
|
| 126 |
}
|
- |
|
| 127 |
|
- |
|
| 128 |
getProductPropertiesSnippet(expEntity, exportPath);
|
- |
|
| 129 |
|
- |
|
| 130 |
generateImages(expEntity.getID(), getImagePrefix(expEntity));
|
- |
|
| 131 |
|
- |
|
| 132 |
return true;
|
- |
|
| 133 |
}
|
- |
|
| 134 |
|
- |
|
| 135 |
public boolean deleteDir(File dir) {
|
57 |
private boolean deleteDir(File dir) {
|
| 136 |
if (dir.isDirectory()) {
|
58 |
if (dir.isDirectory()) {
|
| 137 |
String[] children = dir.list();
|
59 |
String[] children = dir.list();
|
| 138 |
for (int i=0; i<children.length; i++) {
|
60 |
for (int i=0; i<children.length; i++) {
|
| 139 |
boolean success = deleteDir(new File(dir, children[i]));
|
61 |
boolean success = deleteDir(new File(dir, children[i]));
|
| 140 |
if (!success) {
|
62 |
if (!success) {
|
| 141 |
return false;
|
63 |
return false;
|
| 142 |
}
|
64 |
}
|
| 143 |
}
|
65 |
}
|
| 144 |
}
|
66 |
}
|
| 145 |
|
- |
|
| 146 |
// The directory is now empty so delete it
|
67 |
// The directory is now empty so delete it
|
| 147 |
return dir.delete();
|
68 |
return dir.delete();
|
| 148 |
}
|
69 |
}
|
| 149 |
|
70 |
|
| - |
|
71 |
/**
|
| - |
|
72 |
* Delete old resources of the entity for which content needs to be regenerated
|
| - |
|
73 |
* @param mediaPath
|
| - |
|
74 |
* @param contentPath
|
| - |
|
75 |
*/
|
| 150 |
private void deleteOldResources(String mediaPath, String contentPath) {
|
76 |
private void deleteOldResources(String mediaPath, String contentPath) {
|
| 151 |
File f = new File(contentPath);
|
77 |
File f = new File(contentPath);
|
| 152 |
if(f.exists()){
|
78 |
if(f.exists()){
|
| 153 |
deleteDir(f);
|
79 |
deleteDir(f);
|
| 154 |
}
|
80 |
}
|
| Line 157... |
Line 83... |
| 157 |
if(f.exists()){
|
83 |
if(f.exists()){
|
| 158 |
deleteDir(f);
|
84 |
deleteDir(f);
|
| 159 |
}
|
85 |
}
|
| 160 |
}
|
86 |
}
|
| 161 |
|
87 |
|
| - |
|
88 |
/**
|
| - |
|
89 |
* It Actually copies the images from some given directory to export directory.
|
| - |
|
90 |
* It also attaches the imagePrefix at the end of image name.
|
| - |
|
91 |
* @param catalogId
|
| - |
|
92 |
* @param imagePrefix
|
| - |
|
93 |
* @throws IOException
|
| - |
|
94 |
*/
|
| 162 |
private void generateImages(long catalogId, String imagePrefix) throws IOException {
|
95 |
private void generateImages(long catalogId, String imagePrefix) throws IOException {
|
| 163 |
String globalImageDirPath = Utils.CONTENT_DB_PATH + "media" + File.separator;
|
96 |
String globalImageDirPath = Utils.CONTENT_DB_PATH + "media" + File.separator;
|
| 164 |
String globalDefaultImagePath = globalImageDirPath + "default.jpg";
|
97 |
String globalDefaultImagePath = globalImageDirPath + "default.jpg";
|
| 165 |
|
98 |
|
| 166 |
String imageDirPath = globalImageDirPath + catalogId + File.separator;
|
99 |
String imageDirPath = globalImageDirPath + catalogId + File.separator;
|
| Line 228... |
Line 161... |
| 228 |
}
|
161 |
}
|
| 229 |
in.close();
|
162 |
in.close();
|
| 230 |
out.close();
|
163 |
out.close();
|
| 231 |
}
|
164 |
}
|
| 232 |
|
165 |
|
| - |
|
166 |
|
| - |
|
167 |
/**
|
| - |
|
168 |
* Copy the images from one directory to other. It also renames files while copying.
|
| 233 |
// If targetLocation does not exist, it will be created.
|
169 |
* If targetLocation does not exist, it will be created.
|
| - |
|
170 |
* @param sourceLocation
|
| - |
|
171 |
* @param targetLocation
|
| - |
|
172 |
* @param imagePrefix
|
| - |
|
173 |
* @throws IOException
|
| - |
|
174 |
*/
|
| 234 |
public void copyDirectory(File sourceLocation , File targetLocation, String imagePrefix) throws IOException {
|
175 |
public void copyDirectory(File sourceLocation , File targetLocation, String imagePrefix) throws IOException {
|
| 235 |
|
176 |
|
| 236 |
if (sourceLocation.isDirectory()) {
|
177 |
if (sourceLocation.isDirectory()) {
|
| 237 |
if (!targetLocation.exists()) {
|
178 |
if (!targetLocation.exists()) {
|
| 238 |
targetLocation.mkdir();
|
179 |
targetLocation.mkdir();
|
| Line 262... |
Line 203... |
| 262 |
in.close();
|
203 |
in.close();
|
| 263 |
out.close();
|
204 |
out.close();
|
| 264 |
}
|
205 |
}
|
| 265 |
}
|
206 |
}
|
| 266 |
|
207 |
|
| - |
|
208 |
/**
|
| - |
|
209 |
* Get the commonly used product properties and store them in a file.
|
| - |
|
210 |
* @param expEntity
|
| - |
|
211 |
* @param exportPath
|
| - |
|
212 |
*/
|
| 267 |
private void getProductPropertiesSnippet(ExpandedEntity expEntity, String exportPath) {
|
213 |
private void getProductPropertiesSnippet(ExpandedEntity expEntity, String exportPath) {
|
| 268 |
long catalogId = expEntity.getID();
|
214 |
long catalogId = expEntity.getID();
|
| 269 |
try {
|
215 |
try {
|
| 270 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
216 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
| 271 |
} catch (Exception e) {
|
217 |
} catch (Exception e) {
|
| Line 292... |
Line 238... |
| 292 |
metaKeywords = dataObject.getValue();
|
238 |
metaKeywords = dataObject.getValue();
|
| 293 |
}
|
239 |
}
|
| 294 |
}
|
240 |
}
|
| 295 |
|
241 |
|
| 296 |
try {
|
242 |
try {
|
| 297 |
|
- |
|
| 298 |
JSONObject props = new JSONObject();
|
243 |
JSONObject props = new JSONObject();
|
| 299 |
props.put("metaDescription", metaDescription);
|
244 |
props.put("metaDescription", metaDescription);
|
| 300 |
props.put("metaKeywords", metaKeywords);
|
245 |
props.put("metaKeywords", metaKeywords);
|
| 301 |
props.put("entityUrl", entityUrl);
|
246 |
props.put("entityUrl", entityUrl);
|
| 302 |
props.put("title", title);
|
247 |
props.put("title", title);
|
| - |
|
248 |
props.put("name", getProductName(expEntity));
|
| 303 |
|
249 |
|
| 304 |
String exportFileName = exportPath + catalogId + File.separator
|
250 |
String exportFileName = exportPath + catalogId + File.separator
|
| 305 |
+ "ProductPropertiesSnippet.vm";
|
251 |
+ "ProductPropertiesSnippet.vm";
|
| 306 |
File exportFile = new File(exportFileName);
|
252 |
File exportFile = new File(exportFileName);
|
| 307 |
if (!exportFile.exists()) {
|
253 |
if (!exportFile.exists()) {
|
| 308 |
exportFile.createNewFile();
|
254 |
exportFile.createNewFile();
|
| Line 318... |
Line 264... |
| 318 |
} catch (Exception e) {
|
264 |
} catch (Exception e) {
|
| 319 |
e.printStackTrace();
|
265 |
e.printStackTrace();
|
| 320 |
}
|
266 |
}
|
| 321 |
}
|
267 |
}
|
| 322 |
|
268 |
|
| - |
|
269 |
/**
|
| - |
|
270 |
* Get slide names and write them in a file. This file will be used in comparison.
|
| - |
|
271 |
* @param expEntity
|
| - |
|
272 |
* @param exportPath
|
| - |
|
273 |
* @throws Exception
|
| - |
|
274 |
*/
|
| 323 |
private void getSlidenamesSnippet(ExpandedEntity expEntity, String exportPath) throws ResourceNotFoundException, ParseErrorException, Exception{
|
275 |
private void getSlidenamesSnippet(ExpandedEntity expEntity, String exportPath) throws Exception{
|
| 324 |
long catalogId = expEntity.getID();
|
276 |
long catalogId = expEntity.getID();
|
| 325 |
|
277 |
|
| 326 |
StringBuilder slideNames = new StringBuilder();
|
278 |
StringBuilder slideNames = new StringBuilder();
|
| 327 |
|
279 |
//TODO Investigate why brand + model number is used ?
|
| 328 |
slideNames.append(expEntity.getBrand() + " " + expEntity.getModelNumber() + " " + expEntity.getModelName() + "\n");
|
280 |
slideNames.append(expEntity.getBrand() + " " + expEntity.getModelNumber() + " " + expEntity.getModelName() + "\n");
|
| 329 |
|
281 |
|
| 330 |
Map<Long, Double> slideScores = CreationUtils.getSlideComparisonScores(catalogId);
|
282 |
Map<Long, Double> slideScores = CreationUtils.getSlideComparisonScores(catalogId);
|
| 331 |
|
283 |
|
| 332 |
for(ExpandedSlide expSlide: expEntity.getExpandedSlides()){
|
284 |
for(ExpandedSlide expSlide: expEntity.getExpandedSlides()){
|
| Line 364... |
Line 316... |
| 364 |
writer.write(slideNames.toString());
|
316 |
writer.write(slideNames.toString());
|
| 365 |
writer.flush();
|
317 |
writer.flush();
|
| 366 |
writer.close();
|
318 |
writer.close();
|
| 367 |
|
319 |
|
| 368 |
}
|
320 |
}
|
| 369 |
|
- |
|
| 370 |
|
- |
|
| 371 |
private void getEntitySnippetForComparison(ExpandedEntity expEntity, String templateFile,String exportPath) throws Exception {
|
- |
|
| 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);
|
- |
|
| 382 |
exportFileName = exportPath + catalogId + File.separator + "ComparisonSnippet.vm";
|
- |
|
| 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 |
|
- |
|
| 401 |
private void getEntitySlideGuideHtml(ExpandedEntity expEntity, String templateFile, String exportPath) throws Exception {
|
- |
|
| 402 |
long catalogId = expEntity.getID();
|
- |
|
| 403 |
VelocityContext context = new VelocityContext();
|
- |
|
| 404 |
|
321 |
|
| 405 |
context.put("imagePrefix", getImagePrefix(expEntity));
|
- |
|
| 406 |
context.put("expentity", expEntity);
|
- |
|
| 407 |
context.put("contentVersion", this.contentVersion);
|
- |
|
| 408 |
context.put("defs", Catalog.getInstance().getDefinitionsContainer());
|
- |
|
| 409 |
context.put("helpdocs", CreationUtils.getHelpdocs());
|
- |
|
| 410 |
|
322 |
/**
|
| 411 |
String exportFileName = null;
|
- |
|
| 412 |
|
- |
|
| 413 |
Template template = Velocity.getTemplate(templateFile);
|
323 |
* Get the name of the product from entity. It considers null values also
|
| 414 |
exportFileName = exportPath + catalogId + File.separator + "SlideGuide.vm";
|
- |
|
| 415 |
|
- |
|
| 416 |
File exportFile = new File(exportFileName);
|
- |
|
| 417 |
if(!exportFile.exists()) {
|
324 |
* @param expEntity
|
| 418 |
exportFile.createNewFile();
|
- |
|
| 419 |
}
|
325 |
* @return
|
| 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 |
|
326 |
*/
|
| 427 |
writer.flush();
|
- |
|
| 428 |
writer.close();
|
- |
|
| 429 |
Utils.info("Export Complete!");
|
- |
|
| 430 |
|
- |
|
| 431 |
}
|
- |
|
| 432 |
|
- |
|
| 433 |
public void getProductSummaryHtml(ExpandedEntity expEntity, String templateFile, String exportPath) {
|
327 |
private String getProductName(ExpandedEntity expEntity){
|
| 434 |
long catalogId = expEntity.getID();
|
328 |
//FIXME Use stringbuilder
|
| 435 |
try {
|
- |
|
| 436 |
String title = expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber();
|
329 |
String productName = ((expEntity.getBrand() != null) ? expEntity.getBrand().trim() + " " : "")
|
| 437 |
String brandName = expEntity.getBrand().trim();
|
330 |
+ ((expEntity.getModelName() != null) ? expEntity.getModelName().trim() + " " : "")
|
| 438 |
String productName = expEntity.getModelName() + " " + expEntity.getModelNumber();
|
331 |
+ (( expEntity.getModelNumber() != null ) ? expEntity.getModelNumber().trim() : "" );
|
| 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);
|
- |
|
| 460 |
params.put("BRAND_NAME", brandName);
|
- |
|
| 461 |
params.put("PRODUCT_NAME", productName);
|
- |
|
| 462 |
params.put("CATEGORY_ID", ((int)categoryId)+"");
|
- |
|
| 463 |
params.put("CATEGORY_NAME", categoryName);
|
- |
|
| 464 |
params.put("CATEGORY_URL", categoryName.replaceAll(" ", "-").toLowerCase() + "/" + categoryId);
|
- |
|
| 465 |
params.put("PRODUCT_URL", URLEncoder.encode("http://www.", "UTF-8") + "${domain}" + URLEncoder.encode(this.getEntityURL(expEntity), "UTF-8"));
|
- |
|
| 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 |
}
|
- |
|
| 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 |
|
- |
|
| 478 |
String exportFileName = exportPath + catalogId + File.separator + "ProductDetail.vm";
|
- |
|
| 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();
|
332 |
return productName;
|
| 496 |
}
|
- |
|
| 497 |
}
|
333 |
}
|
| 498 |
|
334 |
|
| - |
|
335 |
/**
|
| - |
|
336 |
* Get url of the entity.
|
| - |
|
337 |
* @param expEntity
|
| - |
|
338 |
* @return
|
| - |
|
339 |
*/
|
| 499 |
private String getEntityURL(ExpandedEntity expEntity){
|
340 |
private String getEntityURL(ExpandedEntity expEntity){
|
| 500 |
String url = "/" + expEntity.getCategory().getParentCategory().getLabel().toLowerCase().replace(' ', '-') + "/";
|
341 |
String url = "/" + expEntity.getCategory().getParentCategory().getLabel().toLowerCase().replace(' ', '-') + "/";
|
| 501 |
String productUrl = ((expEntity.getBrand() != null) ? expEntity.getBrand().trim() + " " : "").toLowerCase().replace(' ', '-')
|
342 |
String productName = getProductName(expEntity);
|
| 502 |
+ "-" + ((expEntity.getModelName() != null) ? expEntity.getModelName().trim() + " " : "").toLowerCase().replace(' ', '-')
|
- |
|
| 503 |
+ "-" + (( expEntity.getModelNumber() != null ) ? expEntity.getModelNumber().trim() + " " : "" ).toLowerCase().replace(' ', '-')
|
- |
|
| 504 |
+ "-" + expEntity.getID();
|
343 |
String productUrl = productName.toLowerCase().replace(' ', '-') + "-" + expEntity.getID();
|
| 505 |
productUrl = productUrl.replaceAll("/", "-");
|
344 |
productUrl = productUrl.replaceAll("/", "-");
|
| 506 |
url = url + productUrl;
|
345 |
url = url + productUrl;
|
| 507 |
url = url.replaceAll("-+", "-");
|
346 |
url = url.replaceAll("-+", "-");
|
| 508 |
return url;
|
347 |
return url;
|
| 509 |
}
|
348 |
}
|
| 510 |
|
349 |
|
| - |
|
350 |
/**
|
| - |
|
351 |
* get image prefix
|
| - |
|
352 |
* @param expEntity
|
| - |
|
353 |
* @return
|
| - |
|
354 |
*/
|
| 511 |
private String getImagePrefix(ExpandedEntity expEntity){
|
355 |
private String getImagePrefix(ExpandedEntity expEntity){
|
| 512 |
String imagePrefix = ((expEntity.getBrand() != null) ? expEntity.getBrand().trim() + " " : "").toLowerCase().replace(' ', '-')
|
356 |
String productName = getProductName(expEntity);
|
| 513 |
+ "-" + ((expEntity.getModelName() != null) ? expEntity.getModelName().trim() + " " : "").toLowerCase().replace(' ', '-')
|
357 |
String imagePrefix = productName.toLowerCase().replace(' ', '-');
|
| 514 |
+ "-" + (( expEntity.getModelNumber() != null ) ? expEntity.getModelNumber().trim() + " " : "" ).toLowerCase().replace(' ', '-');
|
- |
|
| 515 |
imagePrefix = imagePrefix.replaceAll("/", "-");
|
358 |
imagePrefix = imagePrefix.replaceAll("/", "-");
|
| 516 |
imagePrefix = imagePrefix.replaceAll("-+", "-");
|
359 |
imagePrefix = imagePrefix.replaceAll("-+", "-");
|
| 517 |
return imagePrefix;
|
360 |
return imagePrefix;
|
| 518 |
}
|
361 |
}
|
| 519 |
|
362 |
|
| 520 |
private void getEntityWidgetSnippetHtml(ExpandedEntity expEntity, String templateFile, String exportPath) {
|
- |
|
| 521 |
long catalogId = expEntity.getID();
|
- |
|
| 522 |
try {
|
- |
|
| 523 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
- |
|
| 524 |
String title = expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber();
|
- |
|
| 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 |
}
|
- |
|
| 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);
|
- |
|
| 543 |
params.put("PROD_NAME", prodName);
|
- |
|
| 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();
|
- |
|
| 550 |
|
- |
|
| 551 |
context.put("params", params);
|
- |
|
| 552 |
|
- |
|
| 553 |
|
- |
|
| 554 |
String exportFileName = exportPath + catalogId + File.separator + "WidgetSnippet.vm";
|
- |
|
| 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 |
|
363 |
|
| 570 |
|
364 |
/**
|
| 571 |
} catch (Exception e) {
|
365 |
* Get the required parameters for generating velocity content.
|
| 572 |
e.printStackTrace();
|
366 |
* @param expEntity
|
| 573 |
}
|
367 |
* @return
|
| 574 |
}
|
368 |
* @throws Exception
|
| 575 |
|
- |
|
| 576 |
|
369 |
*/
|
| 577 |
private void getEntityHomeSnippetHtml(ExpandedEntity expEntity, String templateFile, String exportPath) {
|
370 |
private Map<String, String> getEntityParameters(ExpandedEntity expEntity) throws Exception{
|
| 578 |
long catalogId = expEntity.getID();
|
- |
|
| 579 |
Map<String,String> params = new HashMap<String, String>();
|
371 |
Map<String,String> params = new HashMap<String, String>();
|
| 580 |
try {
|
372 |
String title = getProductName(expEntity);
|
| 581 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
373 |
String brandName = expEntity.getBrand().trim();
|
| 582 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
|
374 |
String productName = ((expEntity.getModelName() != null) ? expEntity.getModelName().trim() + " " : "")
|
| - |
|
375 |
+ ((expEntity.getModelNumber() != null) ? expEntity.getModelNumber().trim() : "");
|
| - |
|
376 |
|
| 583 |
String prodName = title;
|
377 |
String prodName = title;
|
| 584 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
378 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
| 585 |
prodName = expEntity.getBrand() + " " + expEntity.getModelName();
|
379 |
prodName = expEntity.getBrand().trim() + " " + ((expEntity.getModelName() != null) ? expEntity.getModelName().trim() : "");
|
| 586 |
}
|
380 |
}
|
| 587 |
String url = getEntityURL(expEntity);
|
381 |
String categoryName = expEntity.getCategory().getLabel();
|
| 588 |
String imagePrefix = getImagePrefix(expEntity);
|
382 |
String tagline = "";
|
| - |
|
383 |
String warranty = "";
|
| 589 |
String tinySnippet = "";
|
384 |
String tinySnippet = "";
|
| 590 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
385 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
| 591 |
for(Feature feature: features){
|
386 |
for(Feature feature: features){
|
| 592 |
if(feature.getFeatureDefinitionID() == 120081){
|
387 |
if(feature.getFeatureDefinitionID() == 120084){
|
| 593 |
List<Bullet> bullets = feature.getBullets();
|
388 |
PrimitiveDataObject dataObject= (PrimitiveDataObject)feature.getBullets().get(0).getDataObject();
|
| 594 |
int count = 1;
|
389 |
tagline = dataObject.getValue();
|
| - |
|
390 |
}
|
| 595 |
for(Bullet bullet: bullets){
|
391 |
if(feature.getFeatureDefinitionID() == 120125){
|
| 596 |
PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
|
392 |
ExpandedFeature expFeature = new ExpandedFeature(feature);
|
| 597 |
tinySnippet = dataObject.getValue();
|
393 |
ExpandedBullet expBullet =expFeature.getExpandedBullets().get(0);
|
| 598 |
params.put("SNIPPET_"+count++, tinySnippet);
|
394 |
if(expBullet != null){
|
| 599 |
System.out.println("Tiny Snippets is " + dataObject.getValue());
|
395 |
warranty = expBullet.getValue() + " "+ expBullet.getUnit().getShortForm();
|
| 600 |
}
|
- |
|
| 601 |
}
|
396 |
}
|
| 602 |
}
|
397 |
}
|
| 603 |
|
- |
|
| 604 |
params.put("TITLE", title);
|
398 |
if(feature.getFeatureDefinitionID() == 120089){
|
| 605 |
params.put("PROD_NAME", prodName);
|
399 |
PrimitiveDataObject dataObject= (PrimitiveDataObject)feature.getBullets().get(0).getDataObject();
|
| 606 |
params.put("URL", url);
|
- |
|
| 607 |
params.put("IMAGE_PREFIX", imagePrefix);
|
400 |
tinySnippet = dataObject.getValue();
|
| - |
|
401 |
}
|
| 608 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
402 |
if(feature.getFeatureDefinitionID() == 120081){
|
| 609 |
params.put("contentVersion", contentVersion);
|
403 |
List<Bullet> bullets = feature.getBullets();
|
| 610 |
VelocityContext context = new VelocityContext();
|
404 |
int count = 1;
|
| 611 |
context.put("params", params);
|
405 |
for(Bullet bullet: bullets){
|
| 612 |
|
- |
|
| 613 |
String exportFileName = exportPath + catalogId + File.separator + "HomeSnippet.vm";
|
406 |
PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
|
| 614 |
File exportFile = new File(exportFileName);
|
407 |
params.put("SNIPPET_"+count++, dataObject.getValue());
|
| 615 |
if(!exportFile.exists()) {
|
- |
|
| 616 |
exportFile.createNewFile();
|
408 |
}
|
| 617 |
}
|
409 |
}
|
| 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 |
}
|
410 |
}
|
| 632 |
}
|
- |
|
| 633 |
|
- |
|
| 634 |
private void getEntityCategorySnippetHtml(ExpandedEntity expEntity, String templateFile, String exportPath) {
|
- |
|
| 635 |
Map<String,String> params = new HashMap<String, String>();
|
- |
|
| 636 |
long catalogId = expEntity.getID();
|
- |
|
| 637 |
|
411 |
|
| 638 |
try {
|
- |
|
| 639 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
- |
|
| 640 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
|
- |
|
| 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 |
}
|
- |
|
| 645 |
String url = getEntityURL(expEntity);
|
- |
|
| 646 |
String imagePrefix = getImagePrefix(expEntity);
|
- |
|
| 647 |
|
412 |
|
| 648 |
String tinySnippet = "";
|
- |
|
| 649 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
413 |
long categoryId = expEntity.getCategory().getID();
|
| 650 |
for(Feature feature: features){
|
414 |
params.put("PROD_NAME", prodName);
|
| 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);
|
415 |
params.put("URL", getEntityURL(expEntity));
|
| 658 |
System.out.println("Tiny Snippets is " + dataObject.getValue());
|
- |
|
| 659 |
}
|
- |
|
| 660 |
}
|
- |
|
| 661 |
}
|
- |
|
| 662 |
params.put("TITLE", title);
|
416 |
params.put("TITLE", title);
|
| 663 |
params.put("PROD_NAME", prodName);
|
417 |
params.put("BRAND_NAME", brandName);
|
| 664 |
params.put("URL", url);
|
- |
|
| 665 |
params.put("IMAGE_PREFIX", imagePrefix);
|
418 |
params.put("PRODUCT_NAME", productName);
|
| 666 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
419 |
params.put("CATEGORY_ID", ((int)categoryId)+"");
|
| 667 |
params.put("contentVersion", contentVersion);
|
420 |
params.put("CATEGORY_NAME", categoryName);
|
| 668 |
|
- |
|
| 669 |
VelocityContext context = new VelocityContext();
|
421 |
params.put("CATEGORY_URL", categoryName.replaceAll(" ", "-").toLowerCase() + "/" + categoryId);
|
| 670 |
context.put("params", params);
|
- |
|
| 671 |
|
- |
|
| 672 |
String exportFileName = exportPath + catalogId + File.separator + "CategorySnippet.vm";
|
422 |
params.put("PRODUCT_URL", URLEncoder.encode("http://www.", "UTF-8") + "${domain}" + URLEncoder.encode(this.getEntityURL(expEntity), "UTF-8"));
|
| 673 |
File exportFile = new File(exportFileName);
|
423 |
if(expEntity.getCategory().getParentCategory().getID() == Utils.MOBILE_PHONES_CATAGOEY){
|
| 674 |
if(!exportFile.exists()) {
|
- |
|
| 675 |
exportFile.createNewFile();
|
424 |
params.put("IS_MOBILE", "TRUE" );
|
| 676 |
}
|
425 |
}else{
|
| 677 |
|
- |
|
| 678 |
BufferedWriter writer = new BufferedWriter(
|
426 |
params.put("IS_MOBILE", "FALSE" );
|
| 679 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
- |
|
| 680 |
|
427 |
}
|
| 681 |
Template template = Velocity.getTemplate(templateFile);
|
428 |
params.put("CATALOG_ID", expEntity.getID()+"");
|
| 682 |
template.merge(context, writer);
|
429 |
params.put("TAGLINE", tagline);
|
| 683 |
|
- |
|
| 684 |
writer.flush();
|
430 |
params.put("WARRANTY", warranty);
|
| 685 |
writer.close();
|
431 |
params.put("TINY_SNIPPET", tinySnippet);
|
| - |
|
432 |
params.put("IMAGE_PREFIX", getImagePrefix(expEntity));
|
| 686 |
Utils.info("Export Complete!");
|
433 |
params.put("contentVersion", contentVersion);
|
| 687 |
|
434 |
|
| 688 |
|
- |
|
| 689 |
} catch (Exception e) {
|
- |
|
| 690 |
e.printStackTrace();
|
435 |
return params;
|
| 691 |
}
|
- |
|
| 692 |
}
|
436 |
}
|
| - |
|
437 |
|
| 693 |
|
438 |
|
| - |
|
439 |
/**
|
| - |
|
440 |
* Generates content for the specified entity embedding links to the
|
| - |
|
441 |
* specified domain name.
|
| - |
|
442 |
*
|
| - |
|
443 |
* The method updates the member variable problems in any of the following
|
| - |
|
444 |
* four cases:
|
| - |
|
445 |
* <ol>
|
| - |
|
446 |
* <li>The entity is not ready.
|
| - |
|
447 |
* <li>The category has not been updated yet. (Set to -1).
|
| - |
|
448 |
* <li>There are no items in the catalog corresponding to this entity.
|
| - |
|
449 |
* <li>There are no active or content-complete items in the catalog
|
| - |
|
450 |
* corresponding to this entity.
|
| - |
|
451 |
* <li>Neither the items have been updated nor the content has been updated.
|
| - |
|
452 |
* </ol>
|
| - |
|
453 |
*
|
| - |
|
454 |
* @param entity
|
| - |
|
455 |
* - Entity for which the content has to be generated.
|
| - |
|
456 |
* @param domain
|
| - |
|
457 |
* - The domain name to be used to serve static content.
|
| - |
|
458 |
* @param exportPath
|
| - |
|
459 |
* - Local file system path where content has to be generated.
|
| - |
|
460 |
* @return -True if content is generated successfully, False otherwise.
|
| - |
|
461 |
* @throws Exception
|
| - |
|
462 |
*/
|
| 694 |
private void getEntitySearchSnippetHtml(ExpandedEntity expEntity, String templateFile, String exportPath) {
|
463 |
public void generateContentForOneEntity(Entity entity, String exportPath) throws Exception{
|
| - |
|
464 |
String mediaPath = Utils.EXPORT_MEDIA_PATH + entity.getID();
|
| - |
|
465 |
deleteOldResources(mediaPath, exportPath + entity.getID()); //Remove old resources. ie images and html content
|
| - |
|
466 |
ExpandedEntity expEntity = new ExpandedEntity(entity);
|
| 695 |
long catalogId = expEntity.getID();
|
467 |
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();
|
- |
|
| 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 |
}
|
- |
|
| 704 |
|
468 |
|
| 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){
|
469 |
//Create new directory
|
| 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);
|
- |
|
| 725 |
params.put("PROD_NAME", prodName);
|
- |
|
| 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);
|
- |
|
| 732 |
String exportFileName = exportPath + catalogId + File.separator + "SearchSnippet.vm";
|
- |
|
| 733 |
File exportFile = new File(exportFileName);
|
470 |
File exportDir = new File(exportPath + catalogId);
|
| 734 |
if(!exportFile.exists()) {
|
471 |
if(!exportDir.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();
|
472 |
exportDir.mkdir();
|
| 746 |
Utils.info("Export Complete!");
|
- |
|
| 747 |
|
- |
|
| 748 |
|
- |
|
| 749 |
} catch (Exception e) {
|
- |
|
| 750 |
e.printStackTrace();
|
- |
|
| 751 |
}
|
473 |
}
|
| 752 |
}
|
474 |
|
| 753 |
|
- |
|
| - |
|
475 |
VelocityContext context = new VelocityContext();
|
| 754 |
|
476 |
|
| - |
|
477 |
context.put("imagePrefix", getImagePrefix(expEntity));
|
| - |
|
478 |
context.put("expentity", expEntity);
|
| - |
|
479 |
context.put("contentVersion", this.contentVersion);
|
| 755 |
private void getEntityCompareSnippetHtml(ExpandedEntity expEntity, String templateFile, String exportPath) {
|
480 |
context.put("defs", Catalog.getInstance().getDefinitionsContainer());
|
| 756 |
long catalogId = expEntity.getID();
|
481 |
context.put("helpdocs", CreationUtils.getHelpdocs());
|
| 757 |
Map<String,String> params = new HashMap<String, String>();
|
482 |
context.put("params", getEntityParameters(expEntity));
|
| 758 |
|
483 |
|
| 759 |
try {
|
- |
|
| 760 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
484 |
List<String> filenames = new ArrayList<String>();
|
| 761 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
|
- |
|
| 762 |
String prodName = title;
|
485 |
filenames.add("ProductDetail");
|
| 763 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
- |
|
| 764 |
prodName = expEntity.getBrand() + " " + expEntity.getModelName();
|
- |
|
| 765 |
}
|
- |
|
| 766 |
String url = getEntityURL(expEntity);
|
- |
|
| 767 |
String imagePrefix = getImagePrefix(expEntity);
|
- |
|
| 768 |
|
- |
|
| 769 |
String tinySnippet = "";
|
486 |
filenames.add("WidgetSnippet");
|
| 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);
|
487 |
filenames.add("HomeSnippet");
|
| 786 |
params.put("PROD_NAME", prodName);
|
- |
|
| 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);
|
488 |
filenames.add("SearchSnippet");
|
| 794 |
|
- |
|
| 795 |
String exportFileName = exportPath + catalogId + File.separator + "CompareProductSnippet.vm";
|
- |
|
| 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!");
|
489 |
filenames.add("CategorySnippet");
|
| 810 |
|
- |
|
| 811 |
|
- |
|
| 812 |
} catch (Exception e) {
|
- |
|
| 813 |
e.printStackTrace();
|
490 |
filenames.add("SlideGuide");
|
| 814 |
}
|
- |
|
| 815 |
}
|
- |
|
| 816 |
|
- |
|
| 817 |
|
- |
|
| 818 |
private void getEntityCompareSummarySnippetHtml(ExpandedEntity expEntity, String templateFile, String exportPath) {
|
- |
|
| 819 |
long catalogId = expEntity.getID();
|
491 |
filenames.add("PhonesIOwnSnippet");
|
| 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();
|
492 |
if(expEntity.getCategory().getParentCategory().getID() == Utils.MOBILE_PHONES_CATAGOEY){
|
| 824 |
String prodName = title;
|
493 |
filenames.add("CompareProductSnippet");
|
| 825 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
- |
|
| 826 |
prodName = expEntity.getBrand() + " " + expEntity.getModelName();
|
- |
|
| 827 |
}
|
- |
|
| 828 |
String url = getEntityURL(expEntity);
|
- |
|
| 829 |
String imagePrefix = getImagePrefix(expEntity);
|
- |
|
| 830 |
|
- |
|
| 831 |
String tinySnippet = "";
|
494 |
filenames.add("ComparisonSnippet");
|
| 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);
|
- |
|
| 848 |
params.put("PROD_NAME", prodName);
|
- |
|
| 849 |
params.put("URL", url);
|
- |
|
| 850 |
params.put("IMAGE_PREFIX", imagePrefix);
|
495 |
filenames.add("CompareProductSummarySnippet");
|
| 851 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
- |
|
| 852 |
params.put("contentVersion", contentVersion);
|
- |
|
| 853 |
|
- |
|
| 854 |
VelocityContext context = new VelocityContext();
|
- |
|
| 855 |
context.put("params", params);
|
- |
|
| 856 |
|
- |
|
| 857 |
String exportFileName = exportPath + catalogId + File.separator + "CompareProductSummarySnippet.vm";
|
- |
|
| 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);
|
496 |
// This method wont use any velocity file, So calling directly
|
| 867 |
template.merge(context, writer);
|
497 |
getSlidenamesSnippet(expEntity, exportPath);
|
| 868 |
|
- |
|
| 869 |
writer.flush();
|
- |
|
| 870 |
writer.close();
|
- |
|
| 871 |
Utils.info("Export Complete!");
|
- |
|
| 872 |
|
- |
|
| 873 |
|
- |
|
| 874 |
} catch (Exception e) {
|
- |
|
| 875 |
e.printStackTrace();
|
- |
|
| 876 |
}
|
- |
|
| 877 |
}
|
498 |
}
|
| 878 |
|
499 |
|
| 879 |
private void getEntityPhonesIOwnSnippetHtml(ExpandedEntity expEntity, String templateFile, String exportPath) {
|
- |
|
| 880 |
long catalogId = expEntity.getID();
|
- |
|
| 881 |
Map<String,String> params = new HashMap<String, String>();
|
- |
|
| 882 |
|
500 |
|
| - |
|
501 |
// This method wont use any velocity file, So calling directly
|
| - |
|
502 |
getProductPropertiesSnippet(expEntity, exportPath);
|
| - |
|
503 |
|
| - |
|
504 |
applyVelocityTemplate(filenames,exportPath,context,catalogId);
|
| - |
|
505 |
|
| - |
|
506 |
generateImages(expEntity.getID(), getImagePrefix(expEntity));
|
| - |
|
507 |
}
|
| - |
|
508 |
|
| - |
|
509 |
/**
|
| - |
|
510 |
* Get list of files and apply velocity templates on them
|
| - |
|
511 |
* @param filenames
|
| - |
|
512 |
* @param exportPath
|
| - |
|
513 |
* @param context
|
| - |
|
514 |
* @param catalogId
|
| - |
|
515 |
*/
|
| - |
|
516 |
private void applyVelocityTemplate(List<String> filenames, String exportPath, VelocityContext context, long catalogId){
|
| 883 |
try {
|
517 |
try {
|
| 884 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
- |
|
| 885 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
|
- |
|
| 886 |
String prodName = title;
|
518 |
Properties p = new Properties();
|
| 887 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
- |
|
| 888 |
prodName = expEntity.getBrand() + " " + expEntity.getModelName();
|
- |
|
| 889 |
}
|
- |
|
| 890 |
String url = getEntityURL(expEntity);
|
519 |
p.setProperty("resource.loader", "file");
|
| 891 |
|
- |
|
| 892 |
String imagePrefix = getImagePrefix(expEntity);
|
- |
|
| 893 |
|
- |
|
| 894 |
String tinySnippet = "";
|
- |
|
| 895 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
520 |
p.setProperty("file.resource.loader.class","org.apache.velocity.runtime.resource.loader.FileResourceLoader");
|
| 896 |
for(Feature feature: features){
|
- |
|
| 897 |
if(feature.getFeatureDefinitionID() == 120081){
|
- |
|
| 898 |
List<Bullet> bullets = feature.getBullets();
|
521 |
p.setProperty( "file.resource.loader.path", Utils.VTL_SRC_PATH);
|
| 899 |
int count = 1;
|
522 |
Velocity.init(p);
|
| 900 |
for(Bullet bullet: bullets){
|
523 |
for(String filename: filenames){
|
| 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);
|
- |
|
| 910 |
params.put("PROD_NAME", prodName);
|
- |
|
| 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();
|
524 |
Template template = Velocity.getTemplate(filename + ".vm");
|
| 917 |
context.put("params", params);
|
- |
|
| 918 |
|
- |
|
| 919 |
String exportFileName = exportPath + catalogId + File.separator + "PhonesIOwnSnippet.vm";
|
525 |
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(exportPath + catalogId + File.separator +filename+".vm")));
|
| 920 |
File exportFile = new File(exportFileName);
|
526 |
template.merge(context, writer);
|
| 921 |
if(!exportFile.exists()) {
|
527 |
writer.flush();
|
| 922 |
exportFile.createNewFile();
|
528 |
writer.close();
|
| 923 |
}
|
529 |
}
|
| 924 |
|
- |
|
| 925 |
BufferedWriter writer = new BufferedWriter(
|
530 |
}catch (ResourceNotFoundException e) {
|
| 926 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
531 |
// TODO Auto-generated catch block
|
| 927 |
|
532 |
e.printStackTrace();
|
| 928 |
Template template = Velocity.getTemplate(templateFile);
|
533 |
} catch (IOException e) {
|
| 929 |
template.merge(context, writer);
|
534 |
// TODO Auto-generated catch block
|
| 930 |
|
- |
|
| 931 |
writer.flush();
|
535 |
e.printStackTrace();
|
| 932 |
writer.close();
|
536 |
} catch (ParseErrorException e) {
|
| 933 |
Utils.info("Export Complete!");
|
537 |
// TODO Auto-generated catch block
|
| 934 |
|
- |
|
| 935 |
|
538 |
e.printStackTrace();
|
| 936 |
} catch (Exception e) {
|
539 |
} catch (Exception e) {
|
| - |
|
540 |
// TODO Auto-generated catch block
|
| 937 |
e.printStackTrace();
|
541 |
e.printStackTrace();
|
| 938 |
}
|
542 |
}
|
| 939 |
}
|
543 |
}
|
| 940 |
|
544 |
|
| 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 |
|
545 |
|
| 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 |
}
|
546 |
}
|
| 970 |
|
547 |
|