| 2644 |
varun.gupt |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
| 2988 |
varun.gupt |
3 |
import in.shop2020.serving.utils.Utils;
|
|
|
4 |
import in.shop2020.utils.MyNotesGAEClient;
|
|
|
5 |
|
| 2718 |
varun.gupt |
6 |
import java.io.BufferedReader;
|
|
|
7 |
import java.io.File;
|
|
|
8 |
import java.io.FileInputStream;
|
|
|
9 |
import java.io.IOException;
|
|
|
10 |
import java.io.InputStreamReader;
|
|
|
11 |
import java.util.LinkedHashMap;
|
|
|
12 |
import java.util.Map;
|
| 2644 |
varun.gupt |
13 |
|
|
|
14 |
import org.apache.log4j.Logger;
|
|
|
15 |
import org.apache.struts2.convention.annotation.Action;
|
|
|
16 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
| 2988 |
varun.gupt |
17 |
import org.json.JSONObject;
|
| 2644 |
varun.gupt |
18 |
|
|
|
19 |
/**
|
|
|
20 |
*
|
|
|
21 |
* @author Varun Gupta
|
|
|
22 |
*
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
@SuppressWarnings("serial")
|
|
|
26 |
public class MyNotesController extends BaseController {
|
|
|
27 |
|
|
|
28 |
private String id;
|
|
|
29 |
|
|
|
30 |
private static Logger logger = Logger.getLogger(Class.class);
|
|
|
31 |
|
| 2731 |
varun.gupt |
32 |
private long entityId;
|
|
|
33 |
|
| 2718 |
varun.gupt |
34 |
private Map<String, String> slideNotes;
|
| 2644 |
varun.gupt |
35 |
|
|
|
36 |
public MyNotesController() {
|
|
|
37 |
super();
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
@Action(value="my-notes",interceptorRefs={@InterceptorRef("myDefault")})
|
|
|
41 |
public String show() {
|
| 2718 |
varun.gupt |
42 |
String responseContentType = null;
|
|
|
43 |
|
| 2866 |
varun.gupt |
44 |
try {
|
|
|
45 |
String[] idParts = this.id.split("-");
|
|
|
46 |
|
|
|
47 |
this.entityId = Long.parseLong(idParts[0]);
|
|
|
48 |
responseContentType = idParts[1];
|
|
|
49 |
|
|
|
50 |
this.slideNotes = getSlideNames(this.entityId);
|
|
|
51 |
|
|
|
52 |
if(userinfo.getUserId() != -1) {
|
|
|
53 |
|
| 2988 |
varun.gupt |
54 |
String gaeNotesJSON = MyNotesGAEClient.getNotes(userinfo.getUserId(), this.entityId);
|
|
|
55 |
JSONObject gaeNotes = new JSONObject(gaeNotesJSON);
|
|
|
56 |
|
|
|
57 |
for(String key: this.slideNotes.keySet()) {
|
|
|
58 |
String datastoreKey = key.replace(" ", "");
|
|
|
59 |
|
|
|
60 |
if(gaeNotes.has(datastoreKey)) {
|
|
|
61 |
this.slideNotes.put(key, gaeNotes.getString(datastoreKey));
|
|
|
62 |
}
|
| 2866 |
varun.gupt |
63 |
}
|
|
|
64 |
}
|
|
|
65 |
} catch (NumberFormatException e) {
|
|
|
66 |
logger.error("Number Format Exception. String: " + this.id);
|
|
|
67 |
} catch (Exception e) {
|
|
|
68 |
logger.error("Exception: " + e.getMessage());
|
| 2644 |
varun.gupt |
69 |
}
|
|
|
70 |
|
| 2718 |
varun.gupt |
71 |
return responseContentType.equals("json") ? "json" : "show";
|
| 2644 |
varun.gupt |
72 |
}
|
|
|
73 |
|
| 2672 |
varun.gupt |
74 |
// Handle POST /save-note/
|
| 2644 |
varun.gupt |
75 |
@Action(value="save-note",interceptorRefs={@InterceptorRef("createuser"),@InterceptorRef("myDefault")})
|
|
|
76 |
public String create() {
|
|
|
77 |
try {
|
| 2731 |
varun.gupt |
78 |
this.entityId = Long.parseLong(request.getParameter("entity"));
|
| 2718 |
varun.gupt |
79 |
String slide = request.getParameter("slide");
|
| 2644 |
varun.gupt |
80 |
String note = request.getParameter("note");
|
|
|
81 |
|
| 2988 |
varun.gupt |
82 |
MyNotesGAEClient.putNote(userinfo.getUserId(), this.entityId, slide, note);
|
| 2644 |
varun.gupt |
83 |
|
|
|
84 |
} catch (NumberFormatException e) {
|
|
|
85 |
logger.error("Number Format Exception: " + e.getMessage());
|
|
|
86 |
} catch (Exception e) {
|
|
|
87 |
logger.error("Exception: " + e.getMessage());
|
|
|
88 |
}
|
|
|
89 |
return "success";
|
|
|
90 |
}
|
|
|
91 |
|
| 2718 |
varun.gupt |
92 |
public Map<String, String> getSlideNotes() {
|
|
|
93 |
return this.slideNotes;
|
| 2644 |
varun.gupt |
94 |
}
|
|
|
95 |
|
| 2718 |
varun.gupt |
96 |
private Map<String, String> getSlideNames(long productId) {
|
|
|
97 |
Map<String, String> slides = new LinkedHashMap<String, String>();
|
|
|
98 |
|
|
|
99 |
File f = new File(Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "SlideNamesSnippet.html");
|
|
|
100 |
FileInputStream fis = null;
|
|
|
101 |
try {
|
|
|
102 |
fis = new FileInputStream(f);
|
|
|
103 |
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
|
|
|
104 |
|
|
|
105 |
String line = br.readLine(); // Ignoring first line, which contains Product name and not Slide Label
|
| 5048 |
amit.gupta |
106 |
br.readLine(); // Ignoring second line, which contains Product Title
|
| 2718 |
varun.gupt |
107 |
|
|
|
108 |
while((line = br.readLine()) != null){
|
|
|
109 |
|
|
|
110 |
String[] parts = line.split("!!!");
|
|
|
111 |
String slideName = parts[0];
|
|
|
112 |
|
|
|
113 |
if(!slides.containsKey(slideName)){
|
|
|
114 |
slides.put(slideName, null);
|
|
|
115 |
}
|
|
|
116 |
}
|
|
|
117 |
} catch (IOException e) {
|
| 2949 |
chandransh |
118 |
logger.error("Unable to get slide names", e);
|
| 2718 |
varun.gupt |
119 |
}
|
|
|
120 |
return slides;
|
|
|
121 |
}
|
| 2731 |
varun.gupt |
122 |
|
|
|
123 |
public long getEntityId() {
|
|
|
124 |
return this.entityId;
|
|
|
125 |
}
|
| 2718 |
varun.gupt |
126 |
|
| 2644 |
varun.gupt |
127 |
public String getId() {
|
|
|
128 |
return this.id;
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
/**
|
|
|
132 |
* @param id
|
|
|
133 |
*/
|
|
|
134 |
public void setId(String id) {
|
|
|
135 |
this.id = id;
|
|
|
136 |
}
|
|
|
137 |
}
|