Subversion Repositories SmartDukaan

Rev

Rev 5075 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5074 amit.gupta 1
package in.shop2020.creation.controllers;
2
 
3
import in.shop2020.metamodel.definitions.Catalog;
4
import in.shop2020.metamodel.definitions.Category;
5
import in.shop2020.metamodel.definitions.DefinitionsContainer;
6
import in.shop2020.metamodel.util.CreationUtils;
7
import in.shop2020.metamodel.util.ExpandedBullet;
8
import in.shop2020.util.Utils;
9
 
10
import java.util.ArrayList;
11
import java.util.HashMap;
12
import java.util.List;
13
import java.util.Map;
14
 
15
import org.apache.commons.lang.StringUtils;
16
import org.apache.struts2.convention.annotation.InterceptorRef;
17
import org.apache.struts2.convention.annotation.InterceptorRefs;
18
import org.apache.struts2.convention.annotation.Result;
19
import org.apache.struts2.convention.annotation.Results;
20
 
21
@InterceptorRefs({ @InterceptorRef("myDefault"), @InterceptorRef("login") })
22
@Results({
23
        @Result(name = "success", type = "redirectAction", params = {
24
                "actionName", "synonym" }),
25
        @Result(name = "redirect", location = "${url}", type = "redirect") })
26
public class SynonymController extends BaseController{
27
 
28
	/**
29
	 * 
30
	 */
31
	private static final long serialVersionUID = 1L;
32
	private DefinitionsContainer defs = Catalog.getInstance().getDefinitionsContainer();
33
	private boolean status = false; 
34
 
35
    public boolean isStatus() {
36
		return status;
37
	}
38
 
39
	public void setStatus(boolean status) {
40
		this.status = status;
41
	}
42
 
43
	// Index page
44
    public String index() {
45
        return "index";
46
    }
47
 
48
    // updatePage
49
    public String show() {
50
    	String key = (String)this.reqparams.get("key")[0];
51
    	String value = (String)this.reqparams.get("value")[0];
52
    	String type = (String)this.reqparams.get("type")[0];
53
    	this.setStatus(true);
54
    	try{
55
    		Map<String, Map<String, String>> synMap = CreationUtils.getSynonyms();
5075 amit.gupta 56
    		if(synMap==null){
57
    			synMap = new HashMap<String, Map<String,String>>();
58
    		}
5074 amit.gupta 59
    		Map<String,String> typeMap = synMap.get(type);
5075 amit.gupta 60
    		if(typeMap==null){
61
    			typeMap = new HashMap<String,String>();
5090 amit.gupta 62
    			synMap.put(type, typeMap);
5075 amit.gupta 63
    		}
5074 amit.gupta 64
    		typeMap.put(key,value);
65
    		CreationUtils.storeSynonyms(synMap);
66
    	} catch(Exception e){
67
    		e.printStackTrace();
68
    		this.setStatus(false);
69
    	}
70
    	return "update";
71
    }
72
	/**
73
	 * 
74
	 * @return
75
	 * @throws Exception
76
	 */
77
	public String getBrandString() throws Exception {
78
		List<String> brands = this.getBrands();
79
		return "\"" + StringUtils.join(brands, "\", \"") + "\"";
80
	}
81
 
82
	/**
83
	 * 
84
	 * @return
85
	 * @throws Exception
86
	 */
87
	public List<String> getBrands() throws Exception {
88
 
89
		List<String> brands = new ArrayList<String>();
90
 
91
		List<ExpandedBullet> expBullets;
92
 
93
		expBullets = CreationUtils.getLearnedBullets(Utils.BRAND_FEATURE_DEFINITION_ID);
94
		if(expBullets!=null){
95
			for(ExpandedBullet expBullet : expBullets) {
96
				brands.add(expBullet.getValue());
97
			}
98
		}
99
		return brands;
100
	}
101
 
102
	public String getCategories() throws Exception {
103
		Map<String, String> cats = new HashMap<String, String>();
104
 
105
		List<Category> children = defs.getChildrenCategories(Catalog.getInstance().getRootCategory().getID());
106
		for(Category child : children) {
107
			cats.put(new Long(child.getID()).toString(), child.getLabel());
108
		}
109
		return "\"" + StringUtils.join(cats.values(), "\", \"") + "\"";
110
	}
111
 
112
 
113
	public Map<String, String>getLeafcategories() throws Exception {
114
		Map<String, String> cats = new HashMap<String, String>();
115
		List<Category> children = defs.getChildrenCategories(Catalog.getInstance().getRootCategory().getID());
116
		for(Category child : children) {
117
			if(child.getChildrenCategory() == null){
118
				cats.put(new Long(child.getID()).toString(), child.getLabel());	
119
			}else{
120
				List<Category> grandChildren = defs.getChildrenCategories(child.getID());
121
				for(Category grandChild: grandChildren){
122
					if(grandChild.getChildrenCategory() == null){
123
						cats.put(new Long(grandChild.getID()).toString(), grandChild.getLabel());
124
					}
125
				}
126
			}
127
 
128
		}
129
 
130
		return cats;
131
	}
132
 
133
	public Map<String, Map<String, String>> getSynonymmap () throws Exception {
134
		return CreationUtils.getSynonyms();
135
	}
136
 
137
}