Subversion Repositories SmartDukaan

Rev

Rev 2320 | Rev 3294 | 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 = "";
52
		try{
53
			definition = FileUtils.read(Utils.EXPORT_ENTITIES_PATH + "../../../ROOT/helpdocs/" + id);
54
		}catch (Exception e) {
2436 rajveer 55
			logger.error("Unable to read helpdocs file for term " + id, e);
2320 rajveer 56
		}
57
		return definition;
58
	}
59
 
2436 rajveer 60
    public Map<String, String> getItems(){
61
    	Map<String, String> snippets = new HashMap<String, String>();
62
    	if(id==null){
63
    		return snippets;
64
    	}
65
    	SolrSearchService search = new SolrSearchService(id, null, null, 0, 20, null, null, Utils.MOBILE_PHONES_CATEGORY, null);
66
    	long[] items = search.getResultEntityIDs();
67
    	if(items != null){
68
    		for(long item: items){
69
    			try{
70
    	    	    JSONObject productPropertiesInJson = new JSONObject(FileUtils.read(Utils.EXPORT_ENTITIES_PATH + item + File.separator + "ProductPropertiesSnippet.html"));
71
    	    	    String entityUrl = productPropertiesInJson.getString("entityUrl");
72
    	    	    String entityName = productPropertiesInJson.getString("name");
73
    	    	    snippets.put(entityName, entityUrl);
74
    			}catch(IOException ioex){
75
    				logger.error("Unable to read json file to get product name and product urls.", ioex);
76
    			} catch (JSONException jsonex) {
77
    				logger.error("Unable to parse json file.", jsonex);
78
				}
79
			}
80
    	}
81
    	return snippets;
82
    }
83
 
2320 rajveer 84
	public String getGlossary(){
85
		String glossary = "";
86
		try{
87
			glossary = FileUtils.read(Utils.EXPORT_ENTITIES_PATH + "../../../ROOT/helpdocs/" + "glossary");
88
		}catch (Exception e) {
2436 rajveer 89
			logger.error("Unable to read glossary file", e);
2320 rajveer 90
		}
91
		return glossary;
92
	}
93
}