Subversion Repositories SmartDukaan

Rev

Rev 6998 | 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() {
5196 varun.gupt 59
		definition = "<h1>Glossary</h1>";
2320 rajveer 60
		return "show";
61
    }
62
 
63
	public String getId(){
64
		return this.id;
65
	}
66
 
67
	public void setId(String id){
68
		this.id = id;
69
	}
70
 
5101 varun.gupt 71
	public String getTitle()	{
72
		return title;
73
	}
74
 
2320 rajveer 75
	public String getDefinition(){
76
		return definition;
77
	}
78
 
2436 rajveer 79
    public Map<String, String> getItems(){
80
    	Map<String, String> snippets = new HashMap<String, String>();
81
    	if(id==null){
82
    		return snippets;
83
    	}
12110 amit.gupta 84
    	SolrSearchService search = new SolrSearchService(id + "&fq=F_50010:\"Mobile Phones\"", null, 0, 20, null, null, null, sourceId, userinfo.isPrivateDealUser());
2436 rajveer 85
    	long[] items = search.getResultEntityIDs();
86
    	if(items != null){
87
    		for(long item: items){
88
    			try{
89
    	    	    JSONObject productPropertiesInJson = new JSONObject(FileUtils.read(Utils.EXPORT_ENTITIES_PATH + item + File.separator + "ProductPropertiesSnippet.html"));
90
    	    	    String entityUrl = productPropertiesInJson.getString("entityUrl");
91
    	    	    String entityName = productPropertiesInJson.getString("name");
92
    	    	    snippets.put(entityName, entityUrl);
93
    			}catch(IOException ioex){
94
    				logger.error("Unable to read json file to get product name and product urls.", ioex);
95
    			} catch (JSONException jsonex) {
96
    				logger.error("Unable to parse json file.", jsonex);
97
				}
98
			}
99
    	}
100
    	return snippets;
101
    }
102
 
2320 rajveer 103
	public String getGlossary(){
104
		String glossary = "";
105
		try{
106
			glossary = FileUtils.read(Utils.EXPORT_ENTITIES_PATH + "../../../ROOT/helpdocs/" + "glossary");
107
		}catch (Exception e) {
2436 rajveer 108
			logger.error("Unable to read glossary file", e);
2320 rajveer 109
		}
110
		return glossary;
111
	}
112
}