Subversion Repositories SmartDukaan

Rev

Rev 3294 | Rev 5192 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/**
 * 
 */
package in.shop2020.serving.controllers;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
import org.json.JSONException;
import org.json.JSONObject;

import in.shop2020.serving.services.SolrSearchService;
import in.shop2020.serving.utils.FileUtils;
import in.shop2020.serving.utils.Utils;


/**
 * 
 * @author Rajveer
 *
 */
@SuppressWarnings("serial")
public class GlossaryController extends BaseController {
        private static Logger logger = Logger.getLogger(GlossaryController.class);
        
        private String id;
        public GlossaryController(){
                super();
        }

        public String show() {
                return "show";
    }

        public String index() {
                return "show";
    }
        
        public String getId(){
                return this.id;
        }
        
        public void setId(String id){
                this.id = id;
        }
        
        public String getDefinition(){
                String definition = "";
                if(id == null){
                        return definition;
                }
                try{
                        definition = FileUtils.read(Utils.EXPORT_ENTITIES_PATH + "../../../ROOT/helpdocs/" + id);
                }catch (Exception e) {
                        logger.error("Unable to read helpdocs file for term " + id, e);
                }
                return definition;
        }

    public Map<String, String> getItems(){
        Map<String, String> snippets = new HashMap<String, String>();
        if(id==null){
                return snippets;
        }
        SolrSearchService search = new SolrSearchService(id, null, null, 0, 20, null, null, Utils.MOBILE_PHONES_CATEGORY, null, sourceId);
        long[] items = search.getResultEntityIDs();
        if(items != null){
                for(long item: items){
                        try{
                    JSONObject productPropertiesInJson = new JSONObject(FileUtils.read(Utils.EXPORT_ENTITIES_PATH + item + File.separator + "ProductPropertiesSnippet.html"));
                    String entityUrl = productPropertiesInJson.getString("entityUrl");
                    String entityName = productPropertiesInJson.getString("name");
                    snippets.put(entityName, entityUrl);
                        }catch(IOException ioex){
                                logger.error("Unable to read json file to get product name and product urls.", ioex);
                        } catch (JSONException jsonex) {
                                logger.error("Unable to parse json file.", jsonex);
                                }
                        }
        }
        return snippets;
    }

        public String getGlossary(){
                String glossary = "";
                try{
                        glossary = FileUtils.read(Utils.EXPORT_ENTITIES_PATH + "../../../ROOT/helpdocs/" + "glossary");
                }catch (Exception e) {
                        logger.error("Unable to read glossary file", e);
                }
                return glossary;
        }
}