Subversion Repositories SmartDukaan

Rev

Rev 2436 | Rev 3561 | 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 {
2436 rajveer 27
	private static Logger logger = Logger.getLogger(Class.class);
28
 
2320 rajveer 29
	private String id;
30
	public GlossaryController(){
31
		super();
32
	}
33
 
34
	public String show() {
35
		return "show";
36
    }
37
 
38
	public String index() {
39
		return "show";
40
    }
41
 
42
	public String getId(){
43
		return this.id;
44
	}
45
 
46
	public void setId(String id){
47
		this.id = id;
48
	}
49
 
50
	public String getDefinition(){
51
		String definition = "";
3294 rajveer 52
		if(id == null){
53
			return definition;
54
		}
2320 rajveer 55
		try{
56
			definition = FileUtils.read(Utils.EXPORT_ENTITIES_PATH + "../../../ROOT/helpdocs/" + id);
57
		}catch (Exception e) {
2436 rajveer 58
			logger.error("Unable to read helpdocs file for term " + id, e);
2320 rajveer 59
		}
60
		return definition;
61
	}
62
 
2436 rajveer 63
    public Map<String, String> getItems(){
64
    	Map<String, String> snippets = new HashMap<String, String>();
65
    	if(id==null){
66
    		return snippets;
67
    	}
68
    	SolrSearchService search = new SolrSearchService(id, null, null, 0, 20, null, null, Utils.MOBILE_PHONES_CATEGORY, null);
69
    	long[] items = search.getResultEntityIDs();
70
    	if(items != null){
71
    		for(long item: items){
72
    			try{
73
    	    	    JSONObject productPropertiesInJson = new JSONObject(FileUtils.read(Utils.EXPORT_ENTITIES_PATH + item + File.separator + "ProductPropertiesSnippet.html"));
74
    	    	    String entityUrl = productPropertiesInJson.getString("entityUrl");
75
    	    	    String entityName = productPropertiesInJson.getString("name");
76
    	    	    snippets.put(entityName, entityUrl);
77
    			}catch(IOException ioex){
78
    				logger.error("Unable to read json file to get product name and product urls.", ioex);
79
    			} catch (JSONException jsonex) {
80
    				logger.error("Unable to parse json file.", jsonex);
81
				}
82
			}
83
    	}
84
    	return snippets;
85
    }
86
 
2320 rajveer 87
	public String getGlossary(){
88
		String glossary = "";
89
		try{
90
			glossary = FileUtils.read(Utils.EXPORT_ENTITIES_PATH + "../../../ROOT/helpdocs/" + "glossary");
91
		}catch (Exception e) {
2436 rajveer 92
			logger.error("Unable to read glossary file", e);
2320 rajveer 93
		}
94
		return glossary;
95
	}
96
}