Rev 5075 | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.creation.controllers;import in.shop2020.metamodel.definitions.Catalog;import in.shop2020.metamodel.definitions.Category;import in.shop2020.metamodel.definitions.DefinitionsContainer;import in.shop2020.metamodel.util.CreationUtils;import in.shop2020.metamodel.util.ExpandedBullet;import in.shop2020.util.Utils;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import org.apache.commons.lang.StringUtils;import org.apache.struts2.convention.annotation.InterceptorRef;import org.apache.struts2.convention.annotation.InterceptorRefs;import org.apache.struts2.convention.annotation.Result;import org.apache.struts2.convention.annotation.Results;@InterceptorRefs({ @InterceptorRef("myDefault"), @InterceptorRef("login") })@Results({@Result(name = "success", type = "redirectAction", params = {"actionName", "synonym" }),@Result(name = "redirect", location = "${url}", type = "redirect") })public class SynonymController extends BaseController{/****/private static final long serialVersionUID = 1L;private DefinitionsContainer defs = Catalog.getInstance().getDefinitionsContainer();private boolean status = false;public boolean isStatus() {return status;}public void setStatus(boolean status) {this.status = status;}// Index pagepublic String index() {return "index";}// updatePagepublic String show() {String key = (String)this.reqparams.get("key")[0];String value = (String)this.reqparams.get("value")[0];String type = (String)this.reqparams.get("type")[0];this.setStatus(true);try{Map<String, Map<String, String>> synMap = CreationUtils.getSynonyms();if(synMap==null){synMap = new HashMap<String, Map<String,String>>();}Map<String,String> typeMap = synMap.get(type);if(typeMap==null){typeMap = new HashMap<String,String>();synMap.put(type, typeMap);}typeMap.put(key,value);CreationUtils.storeSynonyms(synMap);} catch(Exception e){e.printStackTrace();this.setStatus(false);}return "update";}/**** @return* @throws Exception*/public String getBrandString() throws Exception {List<String> brands = this.getBrands();return "\"" + StringUtils.join(brands, "\", \"") + "\"";}/**** @return* @throws Exception*/public List<String> getBrands() throws Exception {List<String> brands = new ArrayList<String>();List<ExpandedBullet> expBullets;expBullets = CreationUtils.getLearnedBullets(Utils.BRAND_FEATURE_DEFINITION_ID);if(expBullets!=null){for(ExpandedBullet expBullet : expBullets) {brands.add(expBullet.getValue());}}return brands;}public String getCategories() throws Exception {Map<String, String> cats = new HashMap<String, String>();List<Category> children = defs.getChildrenCategories(Catalog.getInstance().getRootCategory().getID());for(Category child : children) {cats.put(new Long(child.getID()).toString(), child.getLabel());}return "\"" + StringUtils.join(cats.values(), "\", \"") + "\"";}public Map<String, String>getLeafcategories() throws Exception {Map<String, String> cats = new HashMap<String, String>();List<Category> children = defs.getChildrenCategories(Catalog.getInstance().getRootCategory().getID());for(Category child : children) {if(child.getChildrenCategory() == null){cats.put(new Long(child.getID()).toString(), child.getLabel());}else{List<Category> grandChildren = defs.getChildrenCategories(child.getID());for(Category grandChild: grandChildren){if(grandChild.getChildrenCategory() == null){cats.put(new Long(grandChild.getID()).toString(), grandChild.getLabel());}}}}return cats;}public Map<String, Map<String, String>> getSynonymmap () throws Exception {return CreationUtils.getSynonyms();}}