Rev 3018 | Rev 9280 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.util;import java.util.Map;import in.shop2020.metamodel.core.FreeformContent;import in.shop2020.metamodel.core.Media;import in.shop2020.metamodel.util.ExpandedEntity;public class EntityUtils {/*** Get the name of the product from entity. It considers null values also* @param expEntity* @return*/public static String getProductName(ExpandedEntity expEntity){//FIXME Use stringbuilderString productName = ((expEntity.getBrand() != null) ? expEntity.getBrand().trim() + " " : "")+ ((expEntity.getModelName() != null) ? expEntity.getModelName().trim() + " " : "")+ (( expEntity.getModelNumber() != null ) ? expEntity.getModelNumber().trim() : "" );return productName;}/*** Get url of the entity.* @param expEntity* @return*/public static String getEntityURL(ExpandedEntity expEntity){String url = "/" + expEntity.getCategory().getParentCategory().getLabel().toLowerCase().replace(' ', '-') + "/";if(expEntity.getCategory().getParentCategory().getID() == Utils.ROOT_CATAGOEY){url = "/" + expEntity.getCategory().getLabel().toLowerCase().replace(' ', '-') + "/";}String productName = getProductName(expEntity);String productUrl = productName.toLowerCase().replace(' ', '-') + "-" + expEntity.getID();productUrl = productUrl.replaceAll("/", "-");url = url + productUrl;url = url.replaceAll("-+", "-");return url;}/*** Gets media prefix to be used for naming files** @param expEntity* @return*/public static String getMediaPrefix(ExpandedEntity expEntity){String productName = getProductName(expEntity);String mediaPrefix = productName.toLowerCase().replace(' ', '-');mediaPrefix = mediaPrefix.replaceAll("/", "-");mediaPrefix = mediaPrefix.replaceAll("-+", "-");return mediaPrefix;}/*** Returns the creation timestamp of the media with a given label* in summary slide.** @param expEntity* @return*/public static long getCreationTimeFromSummarySlide(ExpandedEntity expEntity, String label) {long defaultSuffix = 0;if (expEntity != null && expEntity.getSlide(Utils.SUMMARY_SLIDE_DEFINITION_ID) != null) {FreeformContent content = expEntity.getSlide(Utils.SUMMARY_SLIDE_DEFINITION_ID).getFreeformContent();if (content != null) {Map<String, Media> media = content.getMedias();if (media != null) {Media defaultImage = media.get(label);if (defaultImage != null) {defaultSuffix = defaultImage.getCreationTime().getTime();}}}}return defaultSuffix;}}