1 package org.onap.dcae.dmaapbc.dbcapp.controller;
5 import javax.servlet.http.HttpServletRequest;
6 import javax.servlet.http.HttpServletResponse;
8 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
9 import org.openecomp.portalsdk.core.util.SystemProperties;
11 import org.springframework.stereotype.Controller;
12 import org.springframework.web.bind.annotation.PathVariable;
13 import org.springframework.web.bind.annotation.RequestMapping;
14 import org.springframework.web.bind.annotation.RequestMethod;
15 import org.springframework.web.bind.annotation.ResponseBody;
18 * Message Router controller: serves Ajax requests made by Angular scripts on
19 * pages that show topics and clients.
23 public class MessageRouterController extends DbcappRestrictedBaseController {
25 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MessageRouterController.class);
27 private static final String TOPIC_PATH = "/mr_topic";
28 private static final String CLIENT_PATH = "/mr_client";
30 public MessageRouterController() {
34 * Answers a request for one page of message router topics. See
35 * {@link #getItemListForPageWrapper(HttpServletRequest, DmaapDataItem)}
39 * @return One page of MR topics
41 @RequestMapping(value = { TOPIC_PATH }, method = RequestMethod.GET, produces = "application/json")
43 public String getMRTopicsByPage(HttpServletRequest request) {
44 MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
45 logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, DataBusHomeController.APP_NAME);
46 String response = getItemListForPageWrapper(request, DmaapDataItem.MR_TOPIC);
47 MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
48 logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
53 * Answers a request for one page of message router clients. See
54 * {@link #getItemListForPageWrapper(HttpServletRequest, DmaapDataItem)}
58 * @return One page of MR clients
60 @RequestMapping(value = { CLIENT_PATH }, method = RequestMethod.GET, produces = "application/json")
62 public String getMRClientsByPage(HttpServletRequest request) {
63 MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
64 logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, DataBusHomeController.APP_NAME);
65 String response = getItemListForPageWrapper(request, DmaapDataItem.MR_CLIENT);
66 MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
67 logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
72 * Adds a topic with the specified information. Expects a JSON block in the
73 * request body - a Topic object.
77 * @return JSON success/failure response
79 @RequestMapping(value = { TOPIC_PATH }, method = RequestMethod.POST, produces = "application/json")
81 public String addTopic(HttpServletRequest request) {
82 MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
83 logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, DataBusHomeController.APP_NAME);
84 String response = addItem(request, DmaapDataItem.MR_TOPIC, HttpServletResponse.SC_CREATED);
85 MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
86 logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
91 * Adds a client with the specified information. Expects a JSON block in the
92 * request body - a MR_Client object.
96 * @return JSON success/failure response
98 @RequestMapping(value = { CLIENT_PATH }, method = RequestMethod.POST, produces = "application/json")
100 public String addMRClient(HttpServletRequest request) {
101 MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
102 logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, DataBusHomeController.APP_NAME);
103 String response = addItem(request, DmaapDataItem.MR_CLIENT, HttpServletResponse.SC_CREATED);
104 MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
105 logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
110 * Updates a topic with the specified information. Expects a JSON block in
111 * the request body - a Topic object.
113 * Writes a JSON object as an HTTP response; on success it has a "status"
114 * and possibly a "data" item; on failure, also has an "error" item.
117 * ID of the topic to update
120 * @return JSON success/failure response
122 @RequestMapping(value = { TOPIC_PATH + "/{id}" }, method = RequestMethod.PUT, produces = "application/json")
124 public String updateTopic(@PathVariable("id") long id, HttpServletRequest request) {
125 MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
126 logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, DataBusHomeController.APP_NAME);
127 String response = updateItem(request, DmaapDataItem.MR_TOPIC, Long.toString(id), null);
128 MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
129 logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
134 * Updates a client with the specified information. Expects a JSON block in
135 * the request body - a MR_Client object.
137 * Writes a JSON object as an HTTP response; on success it has a "status"
138 * and possibly a "data" item; on failure, also has an "error" item.
141 * ID of the client to update
144 * @return JSON success/failure response
146 @RequestMapping(value = { CLIENT_PATH + "/{id}" }, method = RequestMethod.PUT, produces = "application/json")
148 public String updateMRClient(@PathVariable("id") long id, HttpServletRequest request) {
149 MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
150 logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, DataBusHomeController.APP_NAME);
151 String response = updateItem(request, DmaapDataItem.MR_CLIENT, Long.toString(id), null);
152 MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
153 logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
158 * Deletes a topic with the FQTN ID specified as a path parameter.
160 * FQTN is a string of dot-separated names. Spring, in its infinite wisdom,
161 * truncates extensions on dotted path parameters; e.g., "foo.json" becomes
162 * "foo". Avoid truncation here with the extra ":.+" incantation at the end.
164 * Writes a JSON object as an HTTP response; on success it only has "status"
165 * item; on failure, also has an "error" item.
168 * Path parameter with object ID
171 * @return JSON success/failure response
173 @RequestMapping(value = { "/mr_topic/{id:.+}" }, method = RequestMethod.DELETE, produces = "application/json")
175 public String deleteTopic(@PathVariable("id") String id, HttpServletRequest request) {
176 MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
177 logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, DataBusHomeController.APP_NAME);
178 String response = deleteItem(request, DmaapDataItem.MR_TOPIC, id, 204);
179 MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
180 logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
185 * Deletes a client with the mrClientId specified as a path parameter.
187 * Writes a JSON object as an HTTP response; on success it only has "status"
188 * item; on failure, also has an "error" item.
191 * Path parameter with object ID
194 * @return JSON success/failure response
196 @RequestMapping(value = { "/mr_client/{id}" }, method = RequestMethod.DELETE, produces = "application/json")
198 public String deleteMRClient(@PathVariable("id") long id, HttpServletRequest request) {
199 MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
200 logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, DataBusHomeController.APP_NAME);
201 String response = deleteItem(request, DmaapDataItem.MR_CLIENT, Long.toString(id), null);
202 MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
203 logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());