Rev 6998 | 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;private String title;private String definition;public GlossaryController(){super();}public String show() {if(id == null) {definition = "";} else {try {definition = FileUtils.read(Utils.EXPORT_ENTITIES_PATH + "../../../ROOT/helpdocs/" + id);String startTitleTagOpener = ">";String startTitleTagCloser = "</h1>";int titleBeginIndex = 1 + definition.indexOf(startTitleTagOpener);int titleEndIndex = definition.indexOf(startTitleTagCloser);title = definition.substring(titleBeginIndex, titleEndIndex);} catch (Exception e) {logger.error("Unable to read helpdocs file for term " + id, e);}}return "show";}public String index() {definition = "<h1>Glossary</h1>";return "show";}public String getId(){return this.id;}public void setId(String id){this.id = id;}public String getTitle() {return title;}public String getDefinition(){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 + "&fq=F_50010:\"Mobile Phones\"", null, 0, 20, null, null, null, sourceId, userinfo.isPrivateDealUser());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;}}