| 3018 |
rajveer |
1 |
package in.shop2020.util;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.metamodel.util.ExpandedEntity;
|
|
|
4 |
|
|
|
5 |
public class EntityUtils {
|
|
|
6 |
/**
|
|
|
7 |
* Get the name of the product from entity. It considers null values also
|
|
|
8 |
* @param expEntity
|
|
|
9 |
* @return
|
|
|
10 |
*/
|
|
|
11 |
public static String getProductName(ExpandedEntity expEntity){
|
|
|
12 |
//FIXME Use stringbuilder
|
|
|
13 |
String productName = ((expEntity.getBrand() != null) ? expEntity.getBrand().trim() + " " : "")
|
|
|
14 |
+ ((expEntity.getModelName() != null) ? expEntity.getModelName().trim() + " " : "")
|
|
|
15 |
+ (( expEntity.getModelNumber() != null ) ? expEntity.getModelNumber().trim() : "" );
|
|
|
16 |
return productName;
|
|
|
17 |
}
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* Get url of the entity.
|
|
|
21 |
* @param expEntity
|
|
|
22 |
* @return
|
|
|
23 |
*/
|
|
|
24 |
public static String getEntityURL(ExpandedEntity expEntity){
|
|
|
25 |
String url = "/" + expEntity.getCategory().getParentCategory().getLabel().toLowerCase().replace(' ', '-') + "/";
|
|
|
26 |
if(expEntity.getCategory().getParentCategory().getID() == Utils.ROOT_CATAGOEY){
|
|
|
27 |
url = "/" + expEntity.getCategory().getLabel().toLowerCase().replace(' ', '-') + "/";
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
String productName = getProductName(expEntity);
|
|
|
31 |
String productUrl = productName.toLowerCase().replace(' ', '-') + "-" + expEntity.getID();
|
|
|
32 |
productUrl = productUrl.replaceAll("/", "-");
|
|
|
33 |
url = url + productUrl;
|
|
|
34 |
url = url.replaceAll("-+", "-");
|
|
|
35 |
return url;
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
* get image prefix
|
|
|
40 |
* @param expEntity
|
|
|
41 |
* @return
|
|
|
42 |
*/
|
|
|
43 |
public static String getImagePrefix(ExpandedEntity expEntity){
|
|
|
44 |
String productName = getProductName(expEntity);
|
|
|
45 |
String imagePrefix = productName.toLowerCase().replace(' ', '-');
|
|
|
46 |
imagePrefix = imagePrefix.replaceAll("/", "-");
|
|
|
47 |
imagePrefix = imagePrefix.replaceAll("-+", "-");
|
|
|
48 |
return imagePrefix;
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
}
|