Subversion Repositories SmartDukaan

Rev

Rev 1044 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1044 Rev 1971
Line 1... Line 1...
1
package in.shop2020.serving.services;
1
package in.shop2020.serving.services;
2
 
2
 
3
import java.io.Serializable;
3
import java.io.Serializable;
-
 
4
import java.util.ArrayList;
-
 
5
import java.util.HashMap;
-
 
6
import java.util.List;
4
import java.util.Map;
7
import java.util.Map;
5
 
8
 
6
import org.apache.log4j.Logger;
9
import org.apache.log4j.Logger;
7
 
10
 
8
import in.shop2020.serving.utils.Category;
11
import in.shop2020.model.v1.catalog.Category;
-
 
12
import in.shop2020.model.v1.catalog.InventoryService.Client;
9
import in.shop2020.serving.utils.Utils;
13
import in.shop2020.thrift.clients.CatalogServiceClient;
10
 
14
 
11
public class CategoryManager implements Serializable{
15
public class CategoryManager implements Serializable{
12
 
16
 
13
	private static final long serialVersionUID = 1L;
17
	private static final long serialVersionUID = 1L;
14
 
18
 
Line 25... Line 29...
25
	}
29
	}
26
	
30
	
27
	@SuppressWarnings("unchecked")
31
	@SuppressWarnings("unchecked")
28
	private CategoryManager(){
32
	private CategoryManager(){
29
		log.info("Initializing category manager");
33
		log.info("Initializing category manager");
30
		
-
 
-
 
34
		categories = new HashMap<Long, Category>();
31
		try {
35
		try {
-
 
36
		    CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
-
 
37
	        Client client = catalogServiceClient.getClient();
32
			categories = (Map<Long, Category>)Utils.getCategories();
38
	        List<Category> t_categories =  client.getAllCategories();
-
 
39
	        for(Category category: t_categories){
-
 
40
	            categories.put(category.getId(), category);
-
 
41
	        }
-
 
42
	        for(Category category: t_categories){
-
 
43
	            if(category.getParent_category_id() != 0){
-
 
44
	                if(category.getParent_category_id()!=0){
-
 
45
	                    List<Long> childCats = categories.get(category.getParent_category_id()).getChildren_category_ids();
-
 
46
	                    if(childCats==null){
-
 
47
	                        childCats = new ArrayList<Long>();
-
 
48
	                    }
-
 
49
	                    childCats.add(category.getId());
-
 
50
	                }
-
 
51
	             }
-
 
52
            }
33
		} catch (Exception e) {
53
		} catch (Exception e) {
34
			log.error("Unable to load categories from Catalog.");
54
			log.error("Unable to load categories from Catalog.");
35
			categories = null;
55
			categories = null;
36
			e.printStackTrace();
56
			e.printStackTrace();
37
		}
57
		}