| 3018 |
rajveer |
1 |
package in.shop2020.util;
|
|
|
2 |
|
| 9218 |
amit.gupta |
3 |
import in.shop2020.metamodel.core.Entity;
|
| 3929 |
mandeep.dh |
4 |
import in.shop2020.metamodel.core.FreeformContent;
|
|
|
5 |
import in.shop2020.metamodel.core.Media;
|
| 19685 |
kshitij.so |
6 |
import in.shop2020.metamodel.definitions.Category;
|
|
|
7 |
import in.shop2020.metamodel.definitions.DefinitionsContainer;
|
| 3018 |
rajveer |
8 |
import in.shop2020.metamodel.util.ExpandedEntity;
|
|
|
9 |
|
| 19685 |
kshitij.so |
10 |
import java.text.MessageFormat;
|
| 9218 |
amit.gupta |
11 |
import java.util.Map;
|
|
|
12 |
|
| 19685 |
kshitij.so |
13 |
import org.apache.commons.lang.StringUtils;
|
|
|
14 |
|
| 3018 |
rajveer |
15 |
public class EntityUtils {
|
|
|
16 |
/**
|
|
|
17 |
* Get the name of the product from entity. It considers null values also
|
|
|
18 |
* @param expEntity
|
|
|
19 |
* @return
|
|
|
20 |
*/
|
| 9218 |
amit.gupta |
21 |
public static String getProductName(Entity expEntity){
|
| 22388 |
amit.gupta |
22 |
StringBuilder sb = new StringBuilder();
|
|
|
23 |
sb.append((expEntity.getBrand()!= null) ? expEntity.getBrand() + " " : "")
|
|
|
24 |
.append(((expEntity.getModelName() != null) ? expEntity.getModelName() + " " : ""))
|
|
|
25 |
.append((( expEntity.getModelNumber()!= null ) ? expEntity.getModelNumber() : "" ));
|
|
|
26 |
return sb.toString();
|
| 3018 |
rajveer |
27 |
}
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Get url of the entity.
|
|
|
31 |
* @param expEntity
|
|
|
32 |
* @return
|
|
|
33 |
*/
|
|
|
34 |
public static String getEntityURL(ExpandedEntity expEntity){
|
|
|
35 |
String url = "/" + expEntity.getCategory().getParentCategory().getLabel().toLowerCase().replace(' ', '-') + "/";
|
|
|
36 |
if(expEntity.getCategory().getParentCategory().getID() == Utils.ROOT_CATAGOEY){
|
|
|
37 |
url = "/" + expEntity.getCategory().getLabel().toLowerCase().replace(' ', '-') + "/";
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
String productName = getProductName(expEntity);
|
|
|
41 |
String productUrl = productName.toLowerCase().replace(' ', '-') + "-" + expEntity.getID();
|
|
|
42 |
productUrl = productUrl.replaceAll("/", "-");
|
|
|
43 |
url = url + productUrl;
|
|
|
44 |
url = url.replaceAll("-+", "-");
|
|
|
45 |
return url;
|
|
|
46 |
}
|
| 9280 |
amit.gupta |
47 |
|
|
|
48 |
/**
|
|
|
49 |
* Get url of the entity without beginSlash.
|
|
|
50 |
* @param expEntity
|
|
|
51 |
* @return
|
|
|
52 |
*/
|
|
|
53 |
public static String getEntityNoSlashURL(ExpandedEntity expEntity){
|
|
|
54 |
String url = expEntity.getCategory().getParentCategory().getLabel().toLowerCase().replace(' ', '-') + "/";
|
|
|
55 |
if(expEntity.getCategory().getParentCategory().getID() == Utils.ROOT_CATAGOEY){
|
|
|
56 |
url = expEntity.getCategory().getLabel().toLowerCase().replace(' ', '-') + "/";
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
String productName = getProductName(expEntity);
|
|
|
60 |
String productUrl = productName.toLowerCase().replace(' ', '-') + "-" + expEntity.getID();
|
|
|
61 |
productUrl = productUrl.replaceAll("/", "-");
|
|
|
62 |
url = url + productUrl;
|
|
|
63 |
url = url.replaceAll("-+", "-");
|
|
|
64 |
return url;
|
|
|
65 |
}
|
| 3018 |
rajveer |
66 |
|
|
|
67 |
/**
|
| 3929 |
mandeep.dh |
68 |
* Gets media prefix to be used for naming files
|
|
|
69 |
*
|
| 3018 |
rajveer |
70 |
* @param expEntity
|
|
|
71 |
* @return
|
|
|
72 |
*/
|
| 9218 |
amit.gupta |
73 |
public static String getMediaPrefix(Entity expEntity){
|
| 3018 |
rajveer |
74 |
String productName = getProductName(expEntity);
|
| 3929 |
mandeep.dh |
75 |
String mediaPrefix = productName.toLowerCase().replace(' ', '-');
|
|
|
76 |
mediaPrefix = mediaPrefix.replaceAll("/", "-");
|
|
|
77 |
mediaPrefix = mediaPrefix.replaceAll("-+", "-");
|
|
|
78 |
return mediaPrefix;
|
| 3018 |
rajveer |
79 |
}
|
|
|
80 |
|
| 3929 |
mandeep.dh |
81 |
/**
|
|
|
82 |
* Returns the creation timestamp of the media with a given label
|
|
|
83 |
* in summary slide.
|
|
|
84 |
*
|
|
|
85 |
* @param expEntity
|
|
|
86 |
* @return
|
|
|
87 |
*/
|
|
|
88 |
public static long getCreationTimeFromSummarySlide(ExpandedEntity expEntity, String label) {
|
|
|
89 |
long defaultSuffix = 0;
|
|
|
90 |
|
|
|
91 |
if (expEntity != null && expEntity.getSlide(Utils.SUMMARY_SLIDE_DEFINITION_ID) != null) {
|
|
|
92 |
FreeformContent content = expEntity.getSlide(Utils.SUMMARY_SLIDE_DEFINITION_ID).getFreeformContent();
|
|
|
93 |
if (content != null) {
|
|
|
94 |
Map<String, Media> media = content.getMedias();
|
|
|
95 |
if (media != null) {
|
|
|
96 |
Media defaultImage = media.get(label);
|
|
|
97 |
if (defaultImage != null) {
|
|
|
98 |
defaultSuffix = defaultImage.getCreationTime().getTime();
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
return defaultSuffix;
|
|
|
105 |
}
|
| 19685 |
kshitij.so |
106 |
|
|
|
107 |
public static String getTitle(Entity entity){
|
|
|
108 |
String brand = entity.getBrand();
|
|
|
109 |
String modelName = entity.getModelName();
|
|
|
110 |
String modelNumber = entity.getModelNumber();
|
|
|
111 |
String titleString = "";
|
|
|
112 |
if(StringUtils.isEmpty(modelName)){
|
|
|
113 |
titleString = brand + " " + modelNumber + " Price in India | Specifications, Features and Reviews";
|
|
|
114 |
}else {
|
|
|
115 |
titleString = brand + " " + modelName + " " + modelNumber +" Price in India | Specifications, Features and Reviews";
|
|
|
116 |
}
|
|
|
117 |
return titleString;
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
public static String getMetaDescription(Entity entity, DefinitionsContainer defs){
|
|
|
121 |
Category cat = defs.getCategory(entity.getCategoryID());
|
|
|
122 |
Category parentCategory = cat.getParentCategory();
|
|
|
123 |
String categoryName = parentCategory.getLabel();
|
|
|
124 |
if (parentCategory.getID()== Utils.MOBILE_ACCESSORIES_CATEGORY){
|
|
|
125 |
categoryName = cat.getLabel();
|
|
|
126 |
}
|
|
|
127 |
String template = "Buy {0} {1} {2} at $minPriceItem.getSellingPrice(). All {3} are 100% Original and carry full Manufacturers Warranty since we procure directly from the Brand. Free Next Day Delivery.";
|
|
|
128 |
return MessageFormat.format(template, entity.getBrand(), entity.getModelName(), entity.getModelNumber(), categoryName.toLowerCase());
|
|
|
129 |
}
|
| 3018 |
rajveer |
130 |
}
|