Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

package in.shop2020.serving.services;

import java.util.Map;

import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;

import in.shop2020.metamodel.definitions.Catalog;
import in.shop2020.metamodel.definitions.Category;
import in.shop2020.utils.Logger;

public class CategoryManager {

        private static CategoryManager categoryManager;
        
        private Map<Long, Category> categories;
        
        private static Log log = LogFactory.getLog(CategoryManager.class);
        
        static{
                synchronized(CategoryManager.class){
                        categoryManager = new CategoryManager();
                }
        }
        
        private CategoryManager(){
                log.info("Initializing category manager");
                
                
                try {
                        categories =  Catalog.getInstance().getDefinitionsContainer().getCategories();
                } catch (Exception e) {
                        log.error("Unable to load categories from CMS.");
                        categories = null;
                        e.printStackTrace();
                }
                
                Logger.log("Initialized category manager", this);               
        }
        
        public static CategoryManager getCategoryManager(){
                return categoryManager;
        }
        
        public Map<Long, Category> getCategories(){
                return this.categories;         
        }
        
        public String getCategoryLabel(long categoryId){
                Category category = this.categories.get(categoryId);
                if(category == null){
                        return null;
                }
                return category.getLabel();
        }
}