Subversion Repositories SmartDukaan

Rev

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