| 1778 |
rajveer |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.serving.utils.FileUtils;
|
|
|
4 |
import in.shop2020.serving.utils.Utils;
|
|
|
5 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
|
|
6 |
import in.shop2020.model.v1.user.UserContextService.Client;
|
|
|
7 |
|
|
|
8 |
import java.io.BufferedReader;
|
|
|
9 |
import java.io.File;
|
|
|
10 |
import java.io.FileInputStream;
|
|
|
11 |
import java.io.IOException;
|
|
|
12 |
import java.io.InputStreamReader;
|
|
|
13 |
import java.net.URLEncoder;
|
|
|
14 |
import java.util.ArrayList;
|
|
|
15 |
import java.util.HashMap;
|
|
|
16 |
import java.util.LinkedHashMap;
|
|
|
17 |
import java.util.List;
|
|
|
18 |
import java.util.Map;
|
|
|
19 |
import java.util.StringTokenizer;
|
|
|
20 |
|
|
|
21 |
import org.apache.log4j.Logger;
|
|
|
22 |
import org.apache.struts2.convention.annotation.Action;
|
|
|
23 |
import org.apache.struts2.convention.annotation.Actions;
|
|
|
24 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
25 |
import org.apache.velocity.VelocityContext;
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
*
|
|
|
29 |
* @author rajveer
|
|
|
30 |
*
|
|
|
31 |
*/
|
|
|
32 |
|
|
|
33 |
@Result(name = "show", location = "compare-show.vm")
|
|
|
34 |
public class CompareController extends BaseController {
|
|
|
35 |
|
|
|
36 |
private static final long serialVersionUID = 1L;
|
|
|
37 |
|
|
|
38 |
private static Logger log = Logger.getLogger(Class.class);
|
|
|
39 |
|
|
|
40 |
private List<String> productList;
|
|
|
41 |
private List<String> productNames;
|
|
|
42 |
private Map<String, String> snippets;
|
|
|
43 |
|
|
|
44 |
public CompareController() {
|
|
|
45 |
super();
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
@Actions({
|
|
|
49 |
@Action("/compare-mobile-phones"),
|
|
|
50 |
@Action("/compare")
|
|
|
51 |
})
|
|
|
52 |
|
|
|
53 |
public String index() throws SecurityException, IOException {
|
|
|
54 |
productList = new ArrayList<String>();
|
| 1821 |
rajveer |
55 |
if(request.getParameter("p1") != null){
|
|
|
56 |
this.productList.add(request.getParameter("p1"));
|
| 1778 |
rajveer |
57 |
}
|
| 1821 |
rajveer |
58 |
if(request.getParameter("p2") != null){
|
|
|
59 |
this.productList.add(request.getParameter("p2"));
|
| 1778 |
rajveer |
60 |
}
|
| 1821 |
rajveer |
61 |
if(request.getParameter("p3") != null){
|
|
|
62 |
this.productList.add(request.getParameter("p3"));
|
| 1778 |
rajveer |
63 |
}
|
| 1821 |
rajveer |
64 |
if(request.getParameter("p4") != null){
|
|
|
65 |
this.productList.add(request.getParameter("p4"));
|
| 1778 |
rajveer |
66 |
}
|
| 1821 |
rajveer |
67 |
if(request.getParameter("p5") != null){
|
|
|
68 |
this.productList.add(request.getParameter("p5"));
|
| 1778 |
rajveer |
69 |
}
|
|
|
70 |
|
|
|
71 |
readSlideNames();
|
|
|
72 |
|
|
|
73 |
return "show";
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
private void readSlideNames(){
|
|
|
77 |
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
public List<String> getSlideNames() {
|
|
|
81 |
List<String> slides = new ArrayList<String>();
|
|
|
82 |
productNames = new ArrayList<String>();
|
|
|
83 |
for (String productId : productList) {
|
|
|
84 |
File f = new File(Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "SlideNamesSnippet.html");
|
|
|
85 |
FileInputStream fis = null;
|
|
|
86 |
try {
|
|
|
87 |
fis = new FileInputStream(f);
|
|
|
88 |
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
|
|
|
89 |
String line;
|
|
|
90 |
boolean isProductName = true;;
|
|
|
91 |
while((line = br.readLine()) != null){
|
|
|
92 |
if(isProductName){
|
|
|
93 |
productNames.add(line);
|
|
|
94 |
isProductName = false;
|
|
|
95 |
continue;
|
|
|
96 |
}
|
|
|
97 |
if(!slides.contains(line)){
|
|
|
98 |
slides.add(line);
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
} catch (IOException e) {
|
|
|
102 |
e.printStackTrace();
|
|
|
103 |
}
|
|
|
104 |
}
|
|
|
105 |
log.info(productNames);
|
|
|
106 |
return slides;
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
public Map<String, String> getSnippets(){
|
|
|
111 |
if (productList != null) {
|
|
|
112 |
snippets = new HashMap<String, String>();
|
|
|
113 |
for (String productId : productList) {
|
|
|
114 |
try {
|
|
|
115 |
snippets.put(productId, FileUtils.read(Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "ComparisonSnippet.html"));
|
|
|
116 |
} catch (IOException e) {
|
|
|
117 |
log.error(e);
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
}
|
|
|
121 |
return snippets;
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
public Map<String, String> getProductSnippets(){
|
|
|
125 |
if (productList != null) {
|
|
|
126 |
snippets = new HashMap<String, String>();
|
|
|
127 |
for (String productId : productList) {
|
|
|
128 |
try {
|
|
|
129 |
snippets.put(productId, FileUtils.read(Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "CompareProductSnippet.html"));
|
|
|
130 |
} catch (IOException e) {
|
|
|
131 |
log.error(e);
|
|
|
132 |
}
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
}
|
|
|
136 |
return snippets;
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
public List<String> getProductNames(){
|
|
|
140 |
return this.productNames;
|
|
|
141 |
}
|
| 1821 |
rajveer |
142 |
}
|