| 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;
|
| 3018 |
rajveer |
6 |
import in.shop2020.metamodel.util.ExpandedEntity;
|
|
|
7 |
|
| 9218 |
amit.gupta |
8 |
import java.util.Map;
|
|
|
9 |
|
| 3018 |
rajveer |
10 |
public class EntityUtils {
|
|
|
11 |
/**
|
|
|
12 |
* Get the name of the product from entity. It considers null values also
|
|
|
13 |
* @param expEntity
|
|
|
14 |
* @return
|
|
|
15 |
*/
|
| 9218 |
amit.gupta |
16 |
public static String getProductName(Entity expEntity){
|
| 3018 |
rajveer |
17 |
//FIXME Use stringbuilder
|
|
|
18 |
String productName = ((expEntity.getBrand() != null) ? expEntity.getBrand().trim() + " " : "")
|
|
|
19 |
+ ((expEntity.getModelName() != null) ? expEntity.getModelName().trim() + " " : "")
|
|
|
20 |
+ (( expEntity.getModelNumber() != null ) ? expEntity.getModelNumber().trim() : "" );
|
|
|
21 |
return productName;
|
|
|
22 |
}
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* Get url of the entity.
|
|
|
26 |
* @param expEntity
|
|
|
27 |
* @return
|
|
|
28 |
*/
|
|
|
29 |
public static String getEntityURL(ExpandedEntity expEntity){
|
|
|
30 |
String url = "/" + expEntity.getCategory().getParentCategory().getLabel().toLowerCase().replace(' ', '-') + "/";
|
|
|
31 |
if(expEntity.getCategory().getParentCategory().getID() == Utils.ROOT_CATAGOEY){
|
|
|
32 |
url = "/" + expEntity.getCategory().getLabel().toLowerCase().replace(' ', '-') + "/";
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
String productName = getProductName(expEntity);
|
|
|
36 |
String productUrl = productName.toLowerCase().replace(' ', '-') + "-" + expEntity.getID();
|
|
|
37 |
productUrl = productUrl.replaceAll("/", "-");
|
|
|
38 |
url = url + productUrl;
|
|
|
39 |
url = url.replaceAll("-+", "-");
|
|
|
40 |
return url;
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
/**
|
| 3929 |
mandeep.dh |
44 |
* Gets media prefix to be used for naming files
|
|
|
45 |
*
|
| 3018 |
rajveer |
46 |
* @param expEntity
|
|
|
47 |
* @return
|
|
|
48 |
*/
|
| 9218 |
amit.gupta |
49 |
public static String getMediaPrefix(Entity expEntity){
|
| 3018 |
rajveer |
50 |
String productName = getProductName(expEntity);
|
| 3929 |
mandeep.dh |
51 |
String mediaPrefix = productName.toLowerCase().replace(' ', '-');
|
|
|
52 |
mediaPrefix = mediaPrefix.replaceAll("/", "-");
|
|
|
53 |
mediaPrefix = mediaPrefix.replaceAll("-+", "-");
|
|
|
54 |
return mediaPrefix;
|
| 3018 |
rajveer |
55 |
}
|
|
|
56 |
|
| 3929 |
mandeep.dh |
57 |
/**
|
|
|
58 |
* Returns the creation timestamp of the media with a given label
|
|
|
59 |
* in summary slide.
|
|
|
60 |
*
|
|
|
61 |
* @param expEntity
|
|
|
62 |
* @return
|
|
|
63 |
*/
|
|
|
64 |
public static long getCreationTimeFromSummarySlide(ExpandedEntity expEntity, String label) {
|
|
|
65 |
long defaultSuffix = 0;
|
|
|
66 |
|
|
|
67 |
if (expEntity != null && expEntity.getSlide(Utils.SUMMARY_SLIDE_DEFINITION_ID) != null) {
|
|
|
68 |
FreeformContent content = expEntity.getSlide(Utils.SUMMARY_SLIDE_DEFINITION_ID).getFreeformContent();
|
|
|
69 |
if (content != null) {
|
|
|
70 |
Map<String, Media> media = content.getMedias();
|
|
|
71 |
if (media != null) {
|
|
|
72 |
Media defaultImage = media.get(label);
|
|
|
73 |
if (defaultImage != null) {
|
|
|
74 |
defaultSuffix = defaultImage.getCreationTime().getTime();
|
|
|
75 |
}
|
|
|
76 |
}
|
|
|
77 |
}
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
return defaultSuffix;
|
|
|
81 |
}
|
| 3018 |
rajveer |
82 |
}
|