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