Subversion Repositories SmartDukaan

Rev

Rev 5074 | Go to most recent revision | 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>();
62
    		}
5074 amit.gupta 63
    		typeMap.put(key,value);
64
    		CreationUtils.storeSynonyms(synMap);
65
    	} catch(Exception e){
66
    		e.printStackTrace();
67
    		this.setStatus(false);
68
    	}
69
    	return "update";
70
    }
71
	/**
72
	 * 
73
	 * @return
74
	 * @throws Exception
75
	 */
76
	public String getBrandString() throws Exception {
77
		List<String> brands = this.getBrands();
78
		return "\"" + StringUtils.join(brands, "\", \"") + "\"";
79
	}
80
 
81
	/**
82
	 * 
83
	 * @return
84
	 * @throws Exception
85
	 */
86
	public List<String> getBrands() throws Exception {
87
 
88
		List<String> brands = new ArrayList<String>();
89
 
90
		List<ExpandedBullet> expBullets;
91
 
92
		expBullets = CreationUtils.getLearnedBullets(Utils.BRAND_FEATURE_DEFINITION_ID);
93
		if(expBullets!=null){
94
			for(ExpandedBullet expBullet : expBullets) {
95
				brands.add(expBullet.getValue());
96
			}
97
		}
98
		return brands;
99
	}
100
 
101
	public String getCategories() throws Exception {
102
		Map<String, String> cats = new HashMap<String, String>();
103
 
104
		List<Category> children = defs.getChildrenCategories(Catalog.getInstance().getRootCategory().getID());
105
		for(Category child : children) {
106
			cats.put(new Long(child.getID()).toString(), child.getLabel());
107
		}
108
		return "\"" + StringUtils.join(cats.values(), "\", \"") + "\"";
109
	}
110
 
111
 
112
	public Map<String, String>getLeafcategories() throws Exception {
113
		Map<String, String> cats = new HashMap<String, String>();
114
		List<Category> children = defs.getChildrenCategories(Catalog.getInstance().getRootCategory().getID());
115
		for(Category child : children) {
116
			if(child.getChildrenCategory() == null){
117
				cats.put(new Long(child.getID()).toString(), child.getLabel());	
118
			}else{
119
				List<Category> grandChildren = defs.getChildrenCategories(child.getID());
120
				for(Category grandChild: grandChildren){
121
					if(grandChild.getChildrenCategory() == null){
122
						cats.put(new Long(grandChild.getID()).toString(), grandChild.getLabel());
123
					}
124
				}
125
			}
126
 
127
		}
128
 
129
		return cats;
130
	}
131
 
132
	public Map<String, Map<String, String>> getSynonymmap () throws Exception {
133
		return CreationUtils.getSynonyms();
134
	}
135
 
136
}