aboutsummaryrefslogtreecommitdiffstats
path: root/dcae-analytics-dmaap/src/main/java
diff options
context:
space:
mode:
authoran4828 <nekrassov@att.com>2017-09-15 15:28:53 -0400
committeran4828 <nekrassov@att.com>2017-09-18 09:24:04 -0400
commit4edf0fa48892bf38d0e3838d125e9bf2324b38e0 (patch)
tree7216dae042828ec2cf38cb9300af1a32a17b3b91 /dcae-analytics-dmaap/src/main/java
parent82aaf956855507e5a72d5ef5b45e398430d04a7a (diff)
Add support for ABATED alerts within CDAP TCA
Change-Id: Iae560a2d0a47b30b41cd31206dc481a08e4930f7 Signed-off-by: an4828 <nekrassov@att.com> Issue-ID: DCAEGEN2-107 Signed-off-by: an4828 <nekrassov@att.com>
Diffstat (limited to 'dcae-analytics-dmaap/src/main/java')
-rw-r--r--dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/BaseDMaaPMRComponent.java38
1 files changed, 30 insertions, 8 deletions
diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/BaseDMaaPMRComponent.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/BaseDMaaPMRComponent.java
index 72f859c..58b1a1f 100644
--- a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/BaseDMaaPMRComponent.java
+++ b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/BaseDMaaPMRComponent.java
@@ -327,17 +327,24 @@ public abstract class BaseDMaaPMRComponent implements DMaaPMRComponent {
// If message string is not null or not empty parse json message array to List of string messages
if (messagesJsonString != null && !messagesJsonString.trim().isEmpty()
- && !"[]".equals(messagesJsonString.trim())) {
+ && !("[]").equals(messagesJsonString.trim())) {
try {
- final List messageList = objectMapper.readValue(messagesJsonString, List.class);
- for (Object message : messageList) {
- final String jsonMessageString = objectMapper.writeValueAsString(message);
- if (jsonMessageString.startsWith("\"") && jsonMessageString.endsWith("\"")) {
- final String jsonSubString = jsonMessageString.substring(1, jsonMessageString.length() - 1);
- messages.add(StringEscapeUtils.unescapeJson(jsonSubString));
+ // get root node
+ final JsonNode rootNode = objectMapper.readTree(messagesJsonString);
+ // iterate over root node and parse arrays messages
+ for (JsonNode jsonNode : rootNode) {
+ // if array parse it is array of messages
+ final String incomingMessageString = jsonNode.toString();
+ if (jsonNode.isArray()) {
+ final List messageList = objectMapper.readValue(incomingMessageString, List.class);
+ for (Object message : messageList) {
+ final String jsonMessageString = objectMapper.writeValueAsString(message);
+ addUnescapedJsonToMessage(messages, jsonMessageString);
+ }
} else {
- messages.add(StringEscapeUtils.unescapeJson(jsonMessageString));
+ // parse it as object
+ addUnescapedJsonToMessage(messages, incomingMessageString);
}
}
@@ -352,5 +359,20 @@ public abstract class BaseDMaaPMRComponent implements DMaaPMRComponent {
return messages;
}
+ /**
+ * Adds unescaped Json messages to given messages list
+ *
+ * @param messages message list in which unescaped messages will be added
+ * @param incomingMessageString incoming message string that may need to be escaped
+ */
+ private static void addUnescapedJsonToMessage(List<String> messages, String incomingMessageString) {
+ if (incomingMessageString.startsWith("\"") && incomingMessageString.endsWith("\"")) {
+ messages.add(StringEscapeUtils.unescapeJson(
+ incomingMessageString.substring(1, incomingMessageString.length() - 1)));
+ } else {
+ messages.add(StringEscapeUtils.unescapeJson(incomingMessageString));
+ }
+ }
+
}