1
2
3
4
5
6
7
8
9
10
11
12
13
14 package uk.nhs.interoperability.client.samples.notification;
15
16 import java.io.IOException;
17 import java.text.SimpleDateFormat;
18 import java.util.Date;
19 import java.util.HashMap;
20
21 import javax.servlet.ServletException;
22 import javax.servlet.http.HttpServlet;
23 import javax.servlet.http.HttpServletRequest;
24 import javax.servlet.http.HttpServletResponse;
25 import javax.servlet.http.HttpSession;
26
27 import uk.nhs.interoperability.transform.TransformManager;
28 import uk.nhs.interoperability.util.Logger;
29
30
31
32
33
34
35
36 public class NotificationView extends HttpServlet {
37
38
39 private static final long serialVersionUID = 1L;
40
41
42
43
44
45
46 public NotificationView() {
47 super();
48
49 }
50
51
52
53
54
55
56
57
58
59
60 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
61 Logger.debug("this is doGet");
62 String notificationId= request.getParameter("notificationid");
63 HttpSession session = request.getSession(true);
64 session.removeAttribute("errorMessage");
65 session.removeAttribute("outcomeMessage");
66 session.removeAttribute("responseBody");
67
68 if (null == notificationId) {
69 session.setAttribute("outcomeMessage", "Notification List");
70 session.setAttribute("responseBody", createList());
71
72 } else {
73 Logger.debug("Notification ID:"+notificationId);
74 String htmlResponse = process(notificationId);
75 Logger.trace(htmlResponse);
76 if (htmlResponse.equals("NOTFOUND")){
77 session.setAttribute("errorMessage", htmlResponse);
78 } else {
79 session.setAttribute("outcomeMessage", "Notification Found");
80 session.setAttribute("responseBody", htmlResponse);
81 }
82 }
83
84 response.sendRedirect("./NotificationView.jsp");
85 Logger.trace("*** NotificationView: Ending");
86 }
87
88
89
90
91
92
93
94
95
96
97 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
98
99 Logger.debug("this is doPost");
100 String docId= request.getParameter("docid");
101 response.getWriter().write("DO POST. DOCID:"+docId);
102 }
103
104
105
106
107
108
109
110
111 protected String process(String notificationId) {
112 String notification = NotificationStore.getNotification(notificationId);
113 Logger.debug("Notification:"+notification);
114
115 if (null!=notification){
116 String htmlResponse = "";
117 try {
118 htmlResponse = TransformManager.doTransform("Notification_Renderer.xsl", notification);
119 } catch (Exception e) {
120 Logger.error("Notification Transformation Failed.",e);
121 }
122
123 Logger.trace(htmlResponse);
124 return htmlResponse;
125
126 } else {
127 Logger.trace("Notification not found");
128 return "NOTFOUND";
129 }
130 }
131
132
133
134
135
136
137 protected String createList() {
138
139 SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
140
141 String output = "";
142
143 HashMap<String, Date> notifications = NotificationStore.getMessageList();
144 if (!notifications.isEmpty()) {
145
146 output = output + "<ul>";
147 for (String key : notifications.keySet()) {
148 String url = "./notificationview?notificationid=" + key;
149 String date = formatter.format(notifications.get(key));
150 output = output + "<li><a href=\"" + url + "\">ID: " + key + " - Received: " + date + "</a></li>";
151 }
152 output = output + "</ul>";
153 } else {
154 output = output + "<p>No Notifications Received</p>";
155 }
156
157 return output;
158 }
159
160 }