| Line 1... |
Line 1... |
| 1 |
package in.shop2020.ui.util;
|
1 |
package in.shop2020.ui.util;
|
| 2 |
|
2 |
|
| 3 |
import in.shop2020.metamodel.core.Bullet;
|
3 |
import in.shop2020.metamodel.core.Bullet;
|
| 4 |
import in.shop2020.metamodel.core.Entity;
|
4 |
import in.shop2020.metamodel.core.Entity;
|
| 5 |
import in.shop2020.metamodel.core.Feature;
|
5 |
import in.shop2020.metamodel.core.Feature;
|
| - |
|
6 |
import in.shop2020.metamodel.core.Media;
|
| 6 |
import in.shop2020.metamodel.core.PrimitiveDataObject;
|
7 |
import in.shop2020.metamodel.core.PrimitiveDataObject;
|
| 7 |
import in.shop2020.metamodel.definitions.Catalog;
|
8 |
import in.shop2020.metamodel.definitions.Catalog;
|
| 8 |
import in.shop2020.metamodel.util.CreationUtils;
|
9 |
import in.shop2020.metamodel.util.CreationUtils;
|
| 9 |
import in.shop2020.metamodel.util.ExpandedBullet;
|
10 |
import in.shop2020.metamodel.util.ExpandedBullet;
|
| 10 |
import in.shop2020.metamodel.util.ExpandedEntity;
|
11 |
import in.shop2020.metamodel.util.ExpandedEntity;
|
| 11 |
import in.shop2020.metamodel.util.ExpandedFeature;
|
12 |
import in.shop2020.metamodel.util.ExpandedFeature;
|
| 12 |
import in.shop2020.metamodel.util.ExpandedSlide;
|
13 |
import in.shop2020.metamodel.util.ExpandedSlide;
|
| - |
|
14 |
import in.shop2020.util.EntityUtils;
|
| 13 |
import in.shop2020.util.Utils;
|
15 |
import in.shop2020.util.Utils;
|
| 14 |
|
16 |
|
| 15 |
import java.io.BufferedWriter;
|
17 |
import java.io.BufferedWriter;
|
| 16 |
import java.io.File;
|
18 |
import java.io.File;
|
| 17 |
import java.io.FileInputStream;
|
19 |
import java.io.FileInputStream;
|
| Line 83... |
Line 85... |
| 83 |
if(f.exists()){
|
85 |
if(f.exists()){
|
| 84 |
deleteDir(f);
|
86 |
deleteDir(f);
|
| 85 |
}
|
87 |
}
|
| 86 |
}
|
88 |
}
|
| 87 |
|
89 |
|
| - |
|
90 |
|
| - |
|
91 |
private void copyDocuments(ExpandedEntity expEntity) throws IOException {
|
| - |
|
92 |
long catalogId = expEntity.getID();
|
| - |
|
93 |
String sourceDirectory = Utils.CONTENT_DB_PATH + "media" + File.separator + catalogId;
|
| - |
|
94 |
String destinationDirectory = Utils.EXPORT_PATH + "documents" + File.separator + catalogId;
|
| - |
|
95 |
|
| - |
|
96 |
/*
|
| - |
|
97 |
* Create the directory for this entity if it didn't exist.
|
| - |
|
98 |
*/
|
| - |
|
99 |
File destFile = new File(destinationDirectory);
|
| - |
|
100 |
if (!destFile.exists()) {
|
| - |
|
101 |
destFile.mkdir();
|
| - |
|
102 |
}
|
| - |
|
103 |
|
| - |
|
104 |
ExpandedSlide expSlide = expEntity.getExpandedSlide(Utils.AFTER_SALES_SLIDE_DEFINITION_ID);
|
| - |
|
105 |
Map<String, Media> medias = expSlide.getFreeformContent().getMedias();
|
| - |
|
106 |
List<String> documentLabels = expSlide.getFreeformContent().getDocumentLabels();
|
| - |
|
107 |
if(!(documentLabels == null || documentLabels.isEmpty())){
|
| - |
|
108 |
for(String documentLabel: documentLabels){
|
| - |
|
109 |
Media document = medias.get(documentLabel);
|
| - |
|
110 |
String fileName = document.getFileName();
|
| - |
|
111 |
copyFile(sourceDirectory + File.separator + fileName, destinationDirectory + File.separator + fileName);
|
| - |
|
112 |
}
|
| - |
|
113 |
}
|
| - |
|
114 |
}
|
| - |
|
115 |
|
| - |
|
116 |
|
| 88 |
/**
|
117 |
/**
|
| 89 |
* It Actually copies the images from some given directory to export directory.
|
118 |
* It Actually copies the images from some given directory to export directory.
|
| 90 |
* It also attaches the imagePrefix at the end of image name.
|
119 |
* It also attaches the imagePrefix at the end of image name.
|
| 91 |
* @param catalogId
|
120 |
* @param catalogId
|
| 92 |
* @param imagePrefix
|
121 |
* @param imagePrefix
|
| Line 218... |
Line 247... |
| 218 |
e.printStackTrace();
|
247 |
e.printStackTrace();
|
| 219 |
}
|
248 |
}
|
| 220 |
|
249 |
|
| 221 |
String metaDescription = "";
|
250 |
String metaDescription = "";
|
| 222 |
String metaKeywords = "";
|
251 |
String metaKeywords = "";
|
| 223 |
String entityUrl = getEntityURL(expEntity);
|
252 |
String entityUrl = EntityUtils.getEntityURL(expEntity);
|
| 224 |
String title = "";
|
253 |
String title = "";
|
| 225 |
|
254 |
|
| 226 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
255 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
| 227 |
for(Feature feature: features){
|
256 |
for(Feature feature: features){
|
| 228 |
if(feature.getFeatureDefinitionID() == 120132){
|
257 |
if(feature.getFeatureDefinitionID() == 120132){
|
| Line 243... |
Line 272... |
| 243 |
JSONObject props = new JSONObject();
|
272 |
JSONObject props = new JSONObject();
|
| 244 |
props.put("metaDescription", metaDescription);
|
273 |
props.put("metaDescription", metaDescription);
|
| 245 |
props.put("metaKeywords", metaKeywords);
|
274 |
props.put("metaKeywords", metaKeywords);
|
| 246 |
props.put("entityUrl", entityUrl);
|
275 |
props.put("entityUrl", entityUrl);
|
| 247 |
props.put("title", title);
|
276 |
props.put("title", title);
|
| 248 |
props.put("name", getProductName(expEntity));
|
277 |
props.put("name", EntityUtils.getProductName(expEntity));
|
| 249 |
if(expEntity.getCategory().getParentCategory().getID() != Utils.MOBILE_ACCESSORIES_CATEGORY){
|
278 |
if(expEntity.getCategory().getParentCategory().getID() != Utils.MOBILE_ACCESSORIES_CATEGORY){
|
| 250 |
props.put("displayAccessories", "TRUE");
|
279 |
props.put("displayAccessories", "TRUE");
|
| 251 |
}else{
|
280 |
}else{
|
| 252 |
props.put("displayAccessories", "FALSE" );
|
281 |
props.put("displayAccessories", "FALSE" );
|
| 253 |
}
|
282 |
}
|
| Line 419... |
Line 448... |
| 419 |
writer.flush();
|
448 |
writer.flush();
|
| 420 |
writer.close();
|
449 |
writer.close();
|
| 421 |
|
450 |
|
| 422 |
}
|
451 |
}
|
| 423 |
|
452 |
|
| 424 |
/**
|
- |
|
| 425 |
* Get the name of the product from entity. It considers null values also
|
- |
|
| 426 |
* @param expEntity
|
- |
|
| 427 |
* @return
|
- |
|
| 428 |
*/
|
- |
|
| 429 |
public static String getProductName(ExpandedEntity expEntity){
|
- |
|
| 430 |
//FIXME Use stringbuilder
|
- |
|
| 431 |
String productName = ((expEntity.getBrand() != null) ? expEntity.getBrand().trim() + " " : "")
|
- |
|
| 432 |
+ ((expEntity.getModelName() != null) ? expEntity.getModelName().trim() + " " : "")
|
- |
|
| 433 |
+ (( expEntity.getModelNumber() != null ) ? expEntity.getModelNumber().trim() : "" );
|
- |
|
| 434 |
return productName;
|
- |
|
| 435 |
}
|
- |
|
| 436 |
|
- |
|
| 437 |
/**
|
- |
|
| 438 |
* Get url of the entity.
|
- |
|
| 439 |
* @param expEntity
|
- |
|
| 440 |
* @return
|
- |
|
| 441 |
*/
|
- |
|
| 442 |
private String getEntityURL(ExpandedEntity expEntity){
|
- |
|
| 443 |
String url = "/" + expEntity.getCategory().getParentCategory().getLabel().toLowerCase().replace(' ', '-') + "/";
|
- |
|
| 444 |
if(expEntity.getCategory().getParentCategory().getID() == Utils.ROOT_CATAGOEY){
|
- |
|
| 445 |
url = "/" + expEntity.getCategory().getLabel().toLowerCase().replace(' ', '-') + "/";
|
- |
|
| 446 |
}
|
- |
|
| 447 |
|
- |
|
| 448 |
String productName = getProductName(expEntity);
|
- |
|
| 449 |
String productUrl = productName.toLowerCase().replace(' ', '-') + "-" + expEntity.getID();
|
- |
|
| 450 |
productUrl = productUrl.replaceAll("/", "-");
|
- |
|
| 451 |
url = url + productUrl;
|
- |
|
| 452 |
url = url.replaceAll("-+", "-");
|
- |
|
| 453 |
return url;
|
- |
|
| 454 |
}
|
- |
|
| 455 |
|
- |
|
| 456 |
/**
|
- |
|
| 457 |
* get image prefix
|
- |
|
| 458 |
* @param expEntity
|
- |
|
| 459 |
* @return
|
- |
|
| 460 |
*/
|
- |
|
| 461 |
private String getImagePrefix(ExpandedEntity expEntity){
|
- |
|
| 462 |
String productName = getProductName(expEntity);
|
- |
|
| 463 |
String imagePrefix = productName.toLowerCase().replace(' ', '-');
|
- |
|
| 464 |
imagePrefix = imagePrefix.replaceAll("/", "-");
|
- |
|
| 465 |
imagePrefix = imagePrefix.replaceAll("-+", "-");
|
- |
|
| 466 |
return imagePrefix;
|
- |
|
| 467 |
}
|
- |
|
| 468 |
|
453 |
|
| 469 |
|
454 |
|
| 470 |
/**
|
455 |
/**
|
| 471 |
* Get the required parameters for generating velocity content.
|
456 |
* Get the required parameters for generating velocity content.
|
| 472 |
* @param expEntity
|
457 |
* @param expEntity
|
| 473 |
* @return
|
458 |
* @return
|
| 474 |
* @throws Exception
|
459 |
* @throws Exception
|
| 475 |
*/
|
460 |
*/
|
| 476 |
private Map<String, String> getEntityParameters(ExpandedEntity expEntity) throws Exception{
|
461 |
private Map<String, String> getEntityParameters(ExpandedEntity expEntity) throws Exception{
|
| 477 |
Map<String,String> params = new HashMap<String, String>();
|
462 |
Map<String,String> params = new HashMap<String, String>();
|
| 478 |
String title = getProductName(expEntity);
|
463 |
String title = EntityUtils.getProductName(expEntity);
|
| 479 |
String brandName = expEntity.getBrand().trim();
|
464 |
String brandName = expEntity.getBrand().trim();
|
| 480 |
String productName = ((expEntity.getModelName() != null) ? expEntity.getModelName().trim() + " " : "")
|
465 |
String productName = ((expEntity.getModelName() != null) ? expEntity.getModelName().trim() + " " : "")
|
| 481 |
+ ((expEntity.getModelNumber() != null) ? expEntity.getModelNumber().trim() : "");
|
466 |
+ ((expEntity.getModelNumber() != null) ? expEntity.getModelNumber().trim() : "");
|
| 482 |
|
467 |
|
| 483 |
String prodName = title;
|
468 |
String prodName = title;
|
| Line 516... |
Line 501... |
| 516 |
}
|
501 |
}
|
| 517 |
|
502 |
|
| 518 |
|
503 |
|
| 519 |
long categoryId = expEntity.getCategory().getID();
|
504 |
long categoryId = expEntity.getCategory().getID();
|
| 520 |
params.put("PROD_NAME", prodName);
|
505 |
params.put("PROD_NAME", prodName);
|
| 521 |
params.put("URL", getEntityURL(expEntity));
|
506 |
params.put("URL", EntityUtils.getEntityURL(expEntity));
|
| 522 |
params.put("TITLE", title);
|
507 |
params.put("TITLE", title);
|
| 523 |
params.put("BRAND_NAME", brandName);
|
508 |
params.put("BRAND_NAME", brandName);
|
| 524 |
params.put("PRODUCT_NAME", productName);
|
509 |
params.put("PRODUCT_NAME", productName);
|
| 525 |
params.put("CATEGORY_ID", ((int)categoryId)+"");
|
510 |
params.put("CATEGORY_ID", ((int)categoryId)+"");
|
| 526 |
params.put("CATEGORY_NAME", categoryName);
|
511 |
params.put("CATEGORY_NAME", categoryName);
|
| 527 |
params.put("CATEGORY_URL", categoryName.replaceAll(" ", "-").toLowerCase() + "/" + categoryId);
|
512 |
params.put("CATEGORY_URL", categoryName.replaceAll(" ", "-").toLowerCase() + "/" + categoryId);
|
| 528 |
params.put("PRODUCT_URL", URLEncoder.encode("http://www.", "UTF-8") + "${domain}" + URLEncoder.encode(this.getEntityURL(expEntity), "UTF-8"));
|
513 |
params.put("PRODUCT_URL", URLEncoder.encode("http://www.", "UTF-8") + "${domain}" + URLEncoder.encode(EntityUtils.getEntityURL(expEntity), "UTF-8"));
|
| 529 |
if(expEntity.getCategory().getParentCategory().getID() != Utils.MOBILE_ACCESSORIES_CATEGORY){
|
514 |
if(expEntity.getCategory().getParentCategory().getID() != Utils.MOBILE_ACCESSORIES_CATEGORY){
|
| 530 |
params.put("IS_MOBILE", "TRUE" );
|
515 |
params.put("IS_MOBILE", "TRUE" );
|
| 531 |
}else{
|
516 |
}else{
|
| 532 |
params.put("IS_MOBILE", "FALSE" );
|
517 |
params.put("IS_MOBILE", "FALSE" );
|
| 533 |
}
|
518 |
}
|
| 534 |
params.put("CATALOG_ID", expEntity.getID()+"");
|
519 |
params.put("CATALOG_ID", expEntity.getID()+"");
|
| 535 |
params.put("TAGLINE", tagline);
|
520 |
params.put("TAGLINE", tagline);
|
| 536 |
params.put("WARRANTY", warranty);
|
521 |
params.put("WARRANTY", warranty);
|
| 537 |
params.put("TINY_SNIPPET", tinySnippet);
|
522 |
params.put("TINY_SNIPPET", tinySnippet);
|
| 538 |
params.put("IMAGE_PREFIX", getImagePrefix(expEntity));
|
523 |
params.put("IMAGE_PREFIX", EntityUtils.getImagePrefix(expEntity));
|
| 539 |
params.put("contentVersion", contentVersion);
|
524 |
params.put("contentVersion", contentVersion);
|
| 540 |
|
525 |
|
| 541 |
return params;
|
526 |
return params;
|
| 542 |
}
|
527 |
}
|
| 543 |
|
528 |
|
| Line 578... |
Line 563... |
| 578 |
exportDir.mkdir();
|
563 |
exportDir.mkdir();
|
| 579 |
}
|
564 |
}
|
| 580 |
|
565 |
|
| 581 |
VelocityContext context = new VelocityContext();
|
566 |
VelocityContext context = new VelocityContext();
|
| 582 |
|
567 |
|
| 583 |
context.put("imagePrefix", getImagePrefix(expEntity));
|
568 |
context.put("imagePrefix", EntityUtils.getImagePrefix(expEntity));
|
| 584 |
context.put("expentity", expEntity);
|
569 |
context.put("expentity", expEntity);
|
| 585 |
context.put("contentVersion", this.contentVersion);
|
570 |
context.put("contentVersion", this.contentVersion);
|
| 586 |
context.put("defs", Catalog.getInstance().getDefinitionsContainer());
|
571 |
context.put("defs", Catalog.getInstance().getDefinitionsContainer());
|
| 587 |
context.put("helpdocs", CreationUtils.getHelpdocs());
|
572 |
context.put("helpdocs", CreationUtils.getHelpdocs());
|
| 588 |
context.put("params", getEntityParameters(expEntity));
|
573 |
context.put("params", getEntityParameters(expEntity));
|
| Line 593... |
Line 578... |
| 593 |
filenames.add("HomeSnippet");
|
578 |
filenames.add("HomeSnippet");
|
| 594 |
filenames.add("SearchSnippet");
|
579 |
filenames.add("SearchSnippet");
|
| 595 |
filenames.add("CategorySnippet");
|
580 |
filenames.add("CategorySnippet");
|
| 596 |
filenames.add("SlideGuide");
|
581 |
filenames.add("SlideGuide");
|
| 597 |
filenames.add("MyResearchSnippet");
|
582 |
filenames.add("MyResearchSnippet");
|
| 598 |
|
583 |
filenames.add("AfterSales");
|
| 599 |
if(expEntity.getCategory().getParentCategory().getID() != Utils.MOBILE_ACCESSORIES_CATEGORY){
|
584 |
if(expEntity.getCategory().getParentCategory().getID() != Utils.MOBILE_ACCESSORIES_CATEGORY){
|
| 600 |
filenames.add("PhonesIOwnSnippet");
|
585 |
filenames.add("PhonesIOwnSnippet");
|
| 601 |
filenames.add("CompareProductSnippet");
|
586 |
filenames.add("CompareProductSnippet");
|
| 602 |
filenames.add("ComparisonSnippet");
|
587 |
filenames.add("ComparisonSnippet");
|
| 603 |
filenames.add("CompareProductSummarySnippet");
|
588 |
filenames.add("CompareProductSummarySnippet");
|
| Line 611... |
Line 596... |
| 611 |
// This method wont use any velocity file, So calling directly
|
596 |
// This method wont use any velocity file, So calling directly
|
| 612 |
getProductPropertiesSnippet(expEntity, exportPath);
|
597 |
getProductPropertiesSnippet(expEntity, exportPath);
|
| 613 |
|
598 |
|
| 614 |
applyVelocityTemplate(filenames,exportPath,context,catalogId);
|
599 |
applyVelocityTemplate(filenames,exportPath,context,catalogId);
|
| 615 |
|
600 |
|
| 616 |
generateImages(expEntity.getID(), getImagePrefix(expEntity));
|
601 |
generateImages(expEntity.getID(), EntityUtils.getImagePrefix(expEntity));
|
| - |
|
602 |
|
| - |
|
603 |
copyDocuments(expEntity);
|
| - |
|
604 |
|
| 617 |
}
|
605 |
}
|
| 618 |
|
606 |
|
| 619 |
/**
|
607 |
/**
|
| 620 |
* Get list of files and apply velocity templates on them
|
608 |
* Get list of files and apply velocity templates on them
|
| 621 |
* @param filenames
|
609 |
* @param filenames
|