| 20399 |
amit.gupta |
1 |
package com.hotspotstore.controllers;
|
|
|
2 |
|
| 20424 |
kshitij.so |
3 |
import java.util.ArrayList;
|
|
|
4 |
import java.util.HashMap;
|
|
|
5 |
import java.util.List;
|
|
|
6 |
import java.util.Map;
|
|
|
7 |
|
|
|
8 |
import org.apache.struts2.convention.annotation.Action;
|
| 20399 |
amit.gupta |
9 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
10 |
import org.apache.struts2.convention.annotation.Results;
|
| 20424 |
kshitij.so |
11 |
import org.json.JSONArray;
|
|
|
12 |
import org.json.JSONException;
|
|
|
13 |
import org.json.JSONObject;
|
| 20399 |
amit.gupta |
14 |
|
| 20424 |
kshitij.so |
15 |
import com.hotspotstore.model.Banner;
|
|
|
16 |
import com.hotspotstore.model.EntityShort;
|
|
|
17 |
import com.hotspotstore.model.Snippet;
|
|
|
18 |
import com.hotspotstore.storage.Mongo;
|
|
|
19 |
|
|
|
20 |
public class HomeController extends BaseController {
|
|
|
21 |
|
| 20399 |
amit.gupta |
22 |
private static final long serialVersionUID = 1L;
|
| 20424 |
kshitij.so |
23 |
private List<Banner> activeBanners;
|
|
|
24 |
private Map<String, List<EntityShort>> snippetMap = new HashMap<String, List<EntityShort>>();
|
| 20399 |
amit.gupta |
25 |
|
| 20424 |
kshitij.so |
26 |
public Map<String, List<EntityShort>> getSnippetMap() {
|
|
|
27 |
return snippetMap;
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
public void setSnippetMap(Map<String, List<EntityShort>> snippetMap) {
|
|
|
31 |
this.snippetMap = snippetMap;
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
public List<Banner> getActiveBanners() {
|
|
|
35 |
return activeBanners;
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
public void setActiveBanners(List<Banner> activeBanners) {
|
|
|
39 |
this.activeBanners = activeBanners;
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
@Action("/")
|
|
|
43 |
public String index() throws JSONException{
|
|
|
44 |
activeBanners = Mongo.getAllActiveBanners();
|
|
|
45 |
List<Snippet> snippets = Mongo.getSnippets();
|
|
|
46 |
for (Snippet s : snippets){
|
|
|
47 |
ArrayList<EntityShort> entityShortList = new ArrayList<EntityShort>();
|
|
|
48 |
for (Long entityId: s.getEntities()){
|
|
|
49 |
JSONObject entity;
|
|
|
50 |
try {
|
|
|
51 |
entity = Mongo.getEntityById(entityId);
|
|
|
52 |
} catch (Exception e) {
|
|
|
53 |
// TODO Auto-generated catch block
|
|
|
54 |
e.printStackTrace();
|
|
|
55 |
continue;
|
|
|
56 |
}
|
|
|
57 |
EntityShort entityShort = new EntityShort();
|
|
|
58 |
entityShort.setEntityId(entityId);
|
|
|
59 |
entityShort.setTitle(entity.getString("title"));
|
| 20594 |
amit.gupta |
60 |
entityShort.setThumbnail(entity.getString("defaultImageUrl"));
|
| 20424 |
kshitij.so |
61 |
entityShort.setUrl(entity.getString("url"));
|
|
|
62 |
JSONArray keySpecs = entity.getJSONArray("keySpecs");
|
|
|
63 |
ArrayList<String> specs = new ArrayList<String>();
|
|
|
64 |
for (int i = 0; i < keySpecs.length(); i++) {
|
|
|
65 |
specs.add(keySpecs.getString(i));
|
|
|
66 |
}
|
|
|
67 |
entityShort.setKeySpecs(specs);
|
|
|
68 |
entityShortList.add(entityShort);
|
|
|
69 |
}
|
|
|
70 |
snippetMap.put(s.getSnippet(), entityShortList);
|
|
|
71 |
}
|
| 20399 |
amit.gupta |
72 |
return "index";
|
|
|
73 |
}
|
|
|
74 |
}
|