Subversion Repositories SmartDukaan

Rev

Rev 20399 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 20399 Rev 20424
Line 1... Line 1...
1
package com.hotspotstore.controllers;
1
package com.hotspotstore.controllers;
2
 
2
 
-
 
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;
3
import org.apache.struts2.convention.annotation.Result;
9
import org.apache.struts2.convention.annotation.Result;
4
import org.apache.struts2.convention.annotation.Results;
10
import org.apache.struts2.convention.annotation.Results;
-
 
11
import org.json.JSONArray;
-
 
12
import org.json.JSONException;
-
 
13
import org.json.JSONObject;
-
 
14
 
-
 
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 {
5
 
21
 
6
class HomeController extends BaseController {
-
 
7
	
-
 
8
	private static final long serialVersionUID = 1L;
22
	private static final long serialVersionUID = 1L;
-
 
23
	private List<Banner> activeBanners;
-
 
24
	private Map<String, List<EntityShort>> snippetMap = new HashMap<String, List<EntityShort>>();
-
 
25
 
-
 
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
	}
9
 
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;
10
	
56
				}
-
 
57
				EntityShort entityShort = new EntityShort();
-
 
58
				entityShort.setEntityId(entityId);
-
 
59
				entityShort.setTitle(entity.getString("title"));
-
 
60
				entityShort.setThumbnail(entity.getString("iconImageUrl"));
-
 
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
				}
11
	public String index(){
67
				entityShort.setKeySpecs(specs);
-
 
68
				entityShortList.add(entityShort);
-
 
69
			}
-
 
70
			snippetMap.put(s.getSnippet(), entityShortList);
-
 
71
		}
12
		return "index";
72
		return "index";
13
	}
73
	}
14
}
74
}
15
75