Subversion Repositories SmartDukaan

Rev

Rev 9218 | Rev 19685 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
	}
9280 amit.gupta 42
 
43
	/**
44
	 * Get url of the entity without beginSlash. 
45
	 * @param expEntity
46
	 * @return
47
	 */
48
	public static String getEntityNoSlashURL(ExpandedEntity expEntity){
49
		String url = expEntity.getCategory().getParentCategory().getLabel().toLowerCase().replace(' ', '-') + "/";
50
		if(expEntity.getCategory().getParentCategory().getID() == Utils.ROOT_CATAGOEY){
51
			url = expEntity.getCategory().getLabel().toLowerCase().replace(' ', '-') + "/";
52
		}
53
 
54
		String productName = getProductName(expEntity);
55
		String productUrl = productName.toLowerCase().replace(' ', '-') + "-" + expEntity.getID();
56
		productUrl = productUrl.replaceAll("/", "-");
57
		url = url + productUrl;
58
		url = url.replaceAll("-+", "-");
59
		return url;
60
	}
3018 rajveer 61
 
62
	/**
3929 mandeep.dh 63
	 * Gets media prefix to be used for naming files
64
	 *
3018 rajveer 65
	 * @param expEntity
66
	 * @return
67
	 */
9218 amit.gupta 68
	public static String getMediaPrefix(Entity expEntity){
3018 rajveer 69
		String productName = getProductName(expEntity);
3929 mandeep.dh 70
		String mediaPrefix = productName.toLowerCase().replace(' ', '-');
71
		mediaPrefix = mediaPrefix.replaceAll("/", "-");
72
		mediaPrefix = mediaPrefix.replaceAll("-+", "-");
73
		return mediaPrefix;
3018 rajveer 74
	}
75
 
3929 mandeep.dh 76
	/**
77
	 * Returns the creation timestamp of the media with a given label
78
	 * in summary slide.
79
	 *
80
	 * @param expEntity
81
	 * @return
82
	 */
83
    public static long getCreationTimeFromSummarySlide(ExpandedEntity expEntity, String label) {
84
        long defaultSuffix = 0;
85
 
86
        if (expEntity != null && expEntity.getSlide(Utils.SUMMARY_SLIDE_DEFINITION_ID) != null) {
87
            FreeformContent content = expEntity.getSlide(Utils.SUMMARY_SLIDE_DEFINITION_ID).getFreeformContent();
88
            if (content != null) {
89
                Map<String, Media> media = content.getMedias();
90
                if (media != null) {
91
                    Media defaultImage = media.get(label);
92
                    if (defaultImage != null) {
93
                        defaultSuffix = defaultImage.getCreationTime().getTime();
94
                    }
95
                }
96
            }
97
        }
98
 
99
        return defaultSuffix;
100
    }
3018 rajveer 101
}