1 package org.onap.dcae.dmaapbc.dbcapp.controller;
3 import java.util.ArrayList;
7 import javax.servlet.http.HttpServletRequest;
8 import javax.servlet.http.HttpServletResponse;
10 import org.onap.dcae.dmaapbc.dbcapp.util.DbcappProperties;
11 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
12 import org.openecomp.portalsdk.core.util.SystemProperties;
14 import org.springframework.beans.factory.annotation.Autowired;
15 import org.springframework.stereotype.Controller;
16 import org.springframework.web.bind.annotation.PathVariable;
17 import org.springframework.web.bind.annotation.RequestMapping;
18 import org.springframework.web.bind.annotation.RequestMethod;
19 import org.springframework.web.bind.annotation.ResponseBody;
22 * Data Router controller: serves Ajax requests made by Angular scripts on pages
23 * that show feeds, publishers and subscribers.
27 public class DataRouterController extends DbcappRestrictedBaseController {
29 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(DataRouterController.class);
32 * Application properties - NOT available to constructor.
35 private DbcappProperties appProperties;
37 private static final String FEED_PATH = "/dr_feed";
38 private static final String PUB_PATH = "/dr_pub";
39 private static final String SUB_PATH = "/dr_sub";
41 public DataRouterController() {
45 * Answers a request for one page of data router feeds.
50 * {@link #getItemListForPageWrapper(HttpServletRequest, DmaapDataItem)}
52 @RequestMapping(value = { FEED_PATH }, method = RequestMethod.GET, produces = "application/json")
54 public String getDRFeedsByPage(HttpServletRequest request) {
55 MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
56 logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, DataBusHomeController.APP_NAME);
57 String response = getItemListForPageWrapper(request, DmaapDataItem.DR_FEED);
58 MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
59 logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
64 * Answers a request for one page of data router publishers.
69 * {@link #getItemListForPageWrapper(HttpServletRequest, DmaapDataItem)}
71 @RequestMapping(value = { PUB_PATH }, method = RequestMethod.GET, produces = "application/json")
73 public String getDRPubsByPage(HttpServletRequest request) {
74 MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
75 logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, DataBusHomeController.APP_NAME);
76 String response = getItemListForPageWrapper(request, DmaapDataItem.DR_PUB);
77 MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
78 logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
83 * Answers a request for one page of data router subscribers.
88 * {@link #getItemListForPageWrapper(HttpServletRequest, DmaapDataItem)}
90 @RequestMapping(value = { SUB_PATH }, method = RequestMethod.GET, produces = "application/json")
92 public String getDRSubsByPage(HttpServletRequest request) {
93 MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
94 logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, DataBusHomeController.APP_NAME);
95 String response = getItemListForPageWrapper(request, DmaapDataItem.DR_SUB);
96 MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
97 logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
102 * Adds a feed with the specified information. Expects a JSON block in the
103 * request body - a Feed object.
107 * @return a JSON object; on success it has a "status" and possibly a "data"
108 * item; on failure, also has an "error" item.
110 @RequestMapping(value = { FEED_PATH }, method = RequestMethod.POST, produces = "application/json")
112 public String addDRFeed(HttpServletRequest request) {
113 MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
114 logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, DataBusHomeController.APP_NAME);
115 String response = addItem(request, DmaapDataItem.DR_FEED, null);
116 MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
117 logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
122 * Adds a publisher with the specified information. Expects a JSON block in
123 * the request body - a DR_Pub object.
127 * @return a JSON object; on success it has a "status" and possibly a "data"
128 * item; on failure, also has an "error" item.
130 @RequestMapping(value = { PUB_PATH }, method = RequestMethod.POST, produces = "application/json")
132 public String addDRPub(HttpServletRequest request) {
133 MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
134 logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, DataBusHomeController.APP_NAME);
135 String response = addItem(request, DmaapDataItem.DR_PUB, HttpServletResponse.SC_CREATED);
136 MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
137 logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
142 * Adds a subscriber with the specified information. Expects a JSON block in
143 * the request body - a DR_Sub object.
147 * @return a JSON object; on success it has a "status" and possibly a "data"
148 * item; on failure, also has an "error" item.
150 @RequestMapping(value = { SUB_PATH }, method = RequestMethod.POST, produces = "application/json")
152 public String addDRSub(HttpServletRequest request) {
153 MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
154 logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, DataBusHomeController.APP_NAME);
155 String response = addItem(request, DmaapDataItem.DR_SUB, HttpServletResponse.SC_CREATED);
156 MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
157 logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
162 * Updates a feed with the specified information. Expects a JSON block in
163 * the request body - a Feed object.
166 * Path parameter with object ID
169 * @return a JSON object; on success it has a "status" and possibly a "data"
170 * item; on failure, also has an "error" item.
172 @RequestMapping(value = { FEED_PATH + "/{id}" }, method = RequestMethod.PUT, produces = "application/json")
174 public String updateFeed(@PathVariable("id") long id, HttpServletRequest request) {
175 MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
176 logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, DataBusHomeController.APP_NAME);
177 String response = updateItem(request, DmaapDataItem.DR_FEED, Long.toString(id), null);
178 MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
179 logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
184 * Updates a publisher with the specified information. Expects a JSON block
185 * in the request body - a DR_Pub object.
187 * The pubId may have a dot in it. Spring, in its infinite wisdom, truncates
188 * extensions on dotted path parameters; e.g., "foo.json" becomes "foo".
189 * Avoid truncation here with the extra ":.+" incantation at the end.
192 * Path parameter with object ID
195 * @return a JSON object; on success it has a "status" and possibly a "data"
196 * item; on failure, also has an "error" item.
198 @RequestMapping(value = { PUB_PATH + "/{id:.+}" }, method = RequestMethod.PUT, produces = "application/json")
200 public String updateDRPub(@PathVariable("id") String id, HttpServletRequest request) {
201 MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
202 logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, DataBusHomeController.APP_NAME);
203 String response = updateItem(request, DmaapDataItem.DR_PUB, id, null);
204 MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
205 logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
210 * Updates a subscriber with the specified information. Expects a JSON block
211 * in the request body - a DR_Sub object.
214 * Path parameter with object ID
217 * @return a JSON object; on success it has a "status" and possibly a "data"
218 * item; on failure, also has an "error" item.
220 @RequestMapping(value = { SUB_PATH + "/{id}" }, method = RequestMethod.PUT, produces = "application/json")
222 public String updateDRSub(@PathVariable("id") long id, HttpServletRequest request) {
223 MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
224 logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, DataBusHomeController.APP_NAME);
225 String response = updateItem(request, DmaapDataItem.DR_SUB, Long.toString(id), null);
226 MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
227 logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
232 * Deletes a feed with the ID specified as a path parameter. On successful
233 * delete the endpoint returns 204 (confusingly).
236 * Path parameter with object ID
239 * @return A JSON object as an HTTP response; on success it only has
240 * "status" item; on failure, also has an "error" item.
242 @RequestMapping(value = { FEED_PATH + "/{id}" }, method = RequestMethod.DELETE, produces = "application/json")
244 public String deleteDRFeed(@PathVariable("id") long id, HttpServletRequest request) {
245 MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
246 logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, DataBusHomeController.APP_NAME);
247 String response = deleteItem(request, DmaapDataItem.DR_FEED, Long.toString(id), 204);
248 MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
249 logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
254 * Deletes the publisher with the ID specified as a path parameter.
256 * The pubId may have a dot in it. Spring, in its infinite wisdom, truncates
257 * extensions on dotted path parameters; e.g., "foo.json" becomes "foo".
258 * Avoid truncation here with the extra ":.+" incantation at the end.
261 * Path parameter with object ID
264 * @return a JSON object; on success it only has "status" item; on failure,
265 * also has an "error" item.
267 @RequestMapping(value = { PUB_PATH + "/{id:.+}" }, method = RequestMethod.DELETE, produces = "application/json")
269 public String deleteDRPub(@PathVariable("id") String id, HttpServletRequest request) {
270 MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
271 logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, DataBusHomeController.APP_NAME);
272 String response = deleteItem(request, DmaapDataItem.DR_PUB, id, null);
273 MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
274 logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
279 * Deletes the subscriber with the ID specified as a path parameter.
282 * Path parameter with object ID
285 * @return A JSON object; on success it only has "status" item; on failure,
286 * also has an "error" item.
288 @RequestMapping(value = { SUB_PATH + "/{id}" }, method = RequestMethod.DELETE, produces = "application/json")
290 public String deleteDRSub(@PathVariable("id") long id, HttpServletRequest request) {
291 MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
292 logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, DataBusHomeController.APP_NAME);
293 String response = deleteItem(request, DmaapDataItem.DR_SUB, Long.toString(id), 204);
294 MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
295 logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
300 * Answers a request for data router feed classification labels, such as
301 * "Customer Proprietary", which are read from properties.
305 * @return List of string values
307 @RequestMapping(value = { FEED_PATH + "_pii_types" }, method = RequestMethod.GET, produces = "application/json")
309 public List<String> getDRFeedPiiType(HttpServletRequest request) {
310 MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
311 logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, DataBusHomeController.APP_NAME);
312 ArrayList<String> response = new ArrayList<>();
313 String[] propKeys = appProperties.getCsvListProperty(DbcappProperties.DMAAP_PII_TYPE_LIST);
314 for (String key : propKeys)
315 response.add(appProperties.getProperty(key));
316 MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, DataBusHomeController.logDateFormat.format(new Date()));
317 logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());