Subversion Repositories SmartDukaan

Rev

Rev 5101 | Rev 5196 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2320 rajveer 1
/**
2
 * 
3
 */
4
package in.shop2020.serving.controllers;
5
 
2436 rajveer 6
import java.io.File;
7
import java.io.IOException;
8
import java.util.HashMap;
9
import java.util.Map;
10
 
11
import org.apache.log4j.Logger;
12
import org.json.JSONException;
13
import org.json.JSONObject;
14
 
15
import in.shop2020.serving.services.SolrSearchService;
2320 rajveer 16
import in.shop2020.serving.utils.FileUtils;
17
import in.shop2020.serving.utils.Utils;
18
 
19
 
20
/**
21
 * 
22
 * @author Rajveer
23
 *
24
 */
25
@SuppressWarnings("serial")
26
public class GlossaryController extends BaseController {
3561 rajveer 27
	private static Logger logger = Logger.getLogger(GlossaryController.class);
2436 rajveer 28
 
2320 rajveer 29
	private String id;
5101 varun.gupt 30
	private String title;
31
	private String definition;
32
 
2320 rajveer 33
	public GlossaryController(){
34
		super();
35
	}
36
 
37
	public String show() {
5101 varun.gupt 38
		if(id == null)	{
39
			definition = "";
40
		} else	{
41
			try	{
42
				definition = FileUtils.read(Utils.EXPORT_ENTITIES_PATH + "../../../ROOT/helpdocs/" + id);
43
 
44
				String startTitleTagOpener = ">";
5192 varun.gupt 45
				String startTitleTagCloser = "</h1>";
5101 varun.gupt 46
				int titleBeginIndex = 1 + definition.indexOf(startTitleTagOpener);
47
				int titleEndIndex = definition.indexOf(startTitleTagCloser);
48
 
49
				title = definition.substring(titleBeginIndex, titleEndIndex);
50
 
51
			} catch (Exception e)	{
52
				logger.error("Unable to read helpdocs file for term " + id, e);
53
			}
54
		}
2320 rajveer 55
		return "show";
56
    }
57
 
58
	public String index() {
59
		return "show";
60
    }
61
 
62
	public String getId(){
63
		return this.id;
64
	}
65
 
66
	public void setId(String id){
67
		this.id = id;
68
	}
69
 
5101 varun.gupt 70
	public String getTitle()	{
71
		return title;
72
	}
73
 
2320 rajveer 74
	public String getDefinition(){
75
		return definition;
76
	}
77
 
2436 rajveer 78
    public Map<String, String> getItems(){
79
    	Map<String, String> snippets = new HashMap<String, String>();
80
    	if(id==null){
81
    		return snippets;
82
    	}
3561 rajveer 83
    	SolrSearchService search = new SolrSearchService(id, null, null, 0, 20, null, null, Utils.MOBILE_PHONES_CATEGORY, null, sourceId);
2436 rajveer 84
    	long[] items = search.getResultEntityIDs();
85
    	if(items != null){
86
    		for(long item: items){
87
    			try{
88
    	    	    JSONObject productPropertiesInJson = new JSONObject(FileUtils.read(Utils.EXPORT_ENTITIES_PATH + item + File.separator + "ProductPropertiesSnippet.html"));
89
    	    	    String entityUrl = productPropertiesInJson.getString("entityUrl");
90
    	    	    String entityName = productPropertiesInJson.getString("name");
91
    	    	    snippets.put(entityName, entityUrl);
92
    			}catch(IOException ioex){
93
    				logger.error("Unable to read json file to get product name and product urls.", ioex);
94
    			} catch (JSONException jsonex) {
95
    				logger.error("Unable to parse json file.", jsonex);
96
				}
97
			}
98
    	}
99
    	return snippets;
100
    }
101
 
2320 rajveer 102
	public String getGlossary(){
103
		String glossary = "";
104
		try{
105
			glossary = FileUtils.read(Utils.EXPORT_ENTITIES_PATH + "../../../ROOT/helpdocs/" + "glossary");
106
		}catch (Exception e) {
2436 rajveer 107
			logger.error("Unable to read glossary file", e);
2320 rajveer 108
		}
109
		return glossary;
110
	}
111
}