| 536 |
rajveer |
1 |
package in.shop2020.serving.services;
|
|
|
2 |
|
|
|
3 |
import java.util.Map;
|
|
|
4 |
|
|
|
5 |
import org.apache.juli.logging.Log;
|
|
|
6 |
import org.apache.juli.logging.LogFactory;
|
|
|
7 |
|
|
|
8 |
import in.shop2020.metamodel.definitions.Catalog;
|
|
|
9 |
import in.shop2020.metamodel.definitions.Category;
|
|
|
10 |
import in.shop2020.utils.Logger;
|
|
|
11 |
|
|
|
12 |
public class CategoryManager {
|
|
|
13 |
|
|
|
14 |
private static CategoryManager categoryManager;
|
|
|
15 |
|
|
|
16 |
private Map<Long, Category> categories;
|
|
|
17 |
|
|
|
18 |
private static Log log = LogFactory.getLog(CategoryManager.class);
|
|
|
19 |
|
|
|
20 |
static{
|
|
|
21 |
synchronized(CategoryManager.class){
|
|
|
22 |
categoryManager = new CategoryManager();
|
|
|
23 |
}
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
private CategoryManager(){
|
|
|
27 |
log.info("Initializing category manager");
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
try {
|
|
|
31 |
categories = Catalog.getInstance().getDefinitionsContainer().getCategories();
|
|
|
32 |
} catch (Exception e) {
|
|
|
33 |
log.error("Unable to load categories from CMS.");
|
|
|
34 |
categories = null;
|
|
|
35 |
e.printStackTrace();
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
Logger.log("Initialized category manager", this);
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
public static CategoryManager getCategoryManager(){
|
|
|
42 |
return categoryManager;
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
public Map<Long, Category> getCategories(){
|
|
|
46 |
return this.categories;
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
public String getCategoryLabel(long categoryId){
|
|
|
50 |
Category category = this.categories.get(categoryId);
|
|
|
51 |
if(category == null){
|
|
|
52 |
return null;
|
|
|
53 |
}
|
|
|
54 |
return category.getLabel();
|
|
|
55 |
}
|
|
|
56 |
}
|