summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCongcong Peng <peng.congcong@zte.com.cn>2018-02-27 11:23:35 +0800
committerCongcong Peng <peng.congcong@zte.com.cn>2018-02-27 11:23:35 +0800
commit160f012debe361e2827aeec06cd78d5ebb43906f (patch)
tree9cb5a8b50593a77e25557e95be1fbd4f78fe9c8b
parentbe988c78605a1e90e13829db6505d12cd26ea1b4 (diff)
revert
Issue-ID: HOLMES-115 Change-Id: I19a64c38461869f16224ed63809f9cdee7fca0f1 Signed-off-by: Congcong Peng <peng.congcong@zte.com.cn>
-rw-r--r--dmaap-dsa/pom.xml38
-rw-r--r--dmaap-dsa/src/main/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtil.java95
-rw-r--r--dmaap-dsa/src/test/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtilTest.java4
3 files changed, 68 insertions, 69 deletions
diff --git a/dmaap-dsa/pom.xml b/dmaap-dsa/pom.xml
index f0c7bd9..9c981ea 100644
--- a/dmaap-dsa/pom.xml
+++ b/dmaap-dsa/pom.xml
@@ -30,11 +30,11 @@
<dependencies>
- <dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>fastjson</artifactId>
- <version>1.1.23</version>
- </dependency>
+ <!--<dependency>-->
+ <!--<groupId>com.alibaba</groupId>-->
+ <!--<artifactId>fastjson</artifactId>-->
+ <!--<version>1.1.23</version>-->
+ <!--</dependency>-->
<dependency>
<groupId>org.onap.msb.java-sdk</groupId>
@@ -78,14 +78,14 @@
<artifactId>log4j-over-slf4j</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
- <exclusion>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- </exclusion>
- <exclusion>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-core</artifactId>
- </exclusion>
+ <!--<exclusion>-->
+ <!--<groupId>com.fasterxml.jackson.core</groupId>-->
+ <!--<artifactId>jackson-databind</artifactId>-->
+ <!--</exclusion>-->
+ <!--<exclusion>-->
+ <!--<groupId>com.fasterxml.jackson.core</groupId>-->
+ <!--<artifactId>jackson-core</artifactId>-->
+ <!--</exclusion>-->
</exclusions>
</dependency>
<dependency>
@@ -186,12 +186,12 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
- <exclusions>
- <exclusion>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-core</artifactId>
- </exclusion>
- </exclusions>
+ <!--<exclusions>-->
+ <!--<exclusion>-->
+ <!--<groupId>com.fasterxml.jackson.core</groupId>-->
+ <!--<artifactId>jackson-core</artifactId>-->
+ <!--</exclusion>-->
+ <!--</exclusions>-->
</dependency>
</dependencies>
diff --git a/dmaap-dsa/src/main/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtil.java b/dmaap-dsa/src/main/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtil.java
index be30153..f19402c 100644
--- a/dmaap-dsa/src/main/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtil.java
+++ b/dmaap-dsa/src/main/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtil.java
@@ -15,96 +15,95 @@
*/
package org.onap.holmes.dsa.dmaappolling;
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import org.jvnet.hk2.annotations.Service;
-import org.onap.holmes.common.api.stat.AlarmAdditionalField;
-import org.onap.holmes.common.api.stat.VesAlarm;
-
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import org.jvnet.hk2.annotations.Service;
+import org.onap.holmes.common.api.stat.AlarmAdditionalField;
+import org.onap.holmes.common.api.stat.VesAlarm;
@Service
public class DMaaPResponseUtil {
public VesAlarm convertJsonToVesAlarm(String responseJson) throws IOException {
- JSONObject jsonNode = JSON.parseObject(responseJson);
-
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode jsonNode = mapper.readTree(responseJson);
VesAlarm vesAlarm = new VesAlarm();
- JSONObject eventJson = JSON.parseObject(jsonNode.get("event") +"");
- JSONObject commonEventHeaderJson = JSON.parseObject(eventJson.get("commonEventHeader") +"");
+ JsonNode eventJson = jsonNode.get("event");
+
+ JsonNode commonEventHeaderJson = eventJson.get("commonEventHeader");
convertCommonEventHeaderJsonToEvent(commonEventHeaderJson, vesAlarm);
- JSONObject faultFieldsJson = JSON.parseObject(eventJson.get("faultFields") +"");
+ JsonNode faultFieldsJson = eventJson.get("faultFields");
convertFaultFieldsJsonToEvent(faultFieldsJson, vesAlarm);
return vesAlarm;
}
- private void convertCommonEventHeaderJsonToEvent(JSONObject commonEventHeaderJson,
+ private void convertCommonEventHeaderJsonToEvent(JsonNode commonEventHeaderJson,
VesAlarm vesAlarm) {
- vesAlarm.setDomain((String) commonEventHeaderJson.get("domain"));
- vesAlarm.setEventId((String) commonEventHeaderJson.get("eventId"));
- vesAlarm.setEventName((String) commonEventHeaderJson.get("eventName"));
+ vesAlarm.setDomain(commonEventHeaderJson.get("domain").asText());
+ vesAlarm.setEventId(commonEventHeaderJson.get("eventId").asText());
+ vesAlarm.setEventName(commonEventHeaderJson.get("eventName").asText());
vesAlarm.setAlarmIsCleared(vesAlarm.getEventName().endsWith("Cleared") ? 1 : 0);
vesAlarm.setEventType(getTextElementByNode(commonEventHeaderJson, "eventType"));
vesAlarm.setInternalHeaderFields(
getTextElementByNode(commonEventHeaderJson, "internalHeaderFields"));
- vesAlarm.setLastEpochMicrosec(commonEventHeaderJson.getLong("lastEpochMicrosec"));
+ vesAlarm.setLastEpochMicrosec(commonEventHeaderJson.get("lastEpochMicrosec").asLong());
vesAlarm.setNfcNamingCode(getTextElementByNode(commonEventHeaderJson, "nfcNamingCode"));
vesAlarm.setNfNamingCode(getTextElementByNode(commonEventHeaderJson, "nfNamingCode"));
- vesAlarm.setPriority((String) commonEventHeaderJson.get("priority"));
+ vesAlarm.setPriority(commonEventHeaderJson.get("priority").asText());
vesAlarm.setReportingEntityId(
getTextElementByNode(commonEventHeaderJson, "reportingEntityId"));
- vesAlarm.setReportingEntityName( (String) commonEventHeaderJson.get("reportingEntityName"));
- vesAlarm.setSequence((Integer) commonEventHeaderJson.get("sequence"));
+ vesAlarm.setReportingEntityName(commonEventHeaderJson.get("reportingEntityName").asText());
+ vesAlarm.setSequence(commonEventHeaderJson.get("sequence").asInt());
vesAlarm.setSourceId(getTextElementByNode(commonEventHeaderJson, "sourceId"));
- vesAlarm.setSourceName( (String) commonEventHeaderJson.get("sourceName"));
- vesAlarm.setStartEpochMicrosec(commonEventHeaderJson.getLong("startEpochMicrosec"));
- vesAlarm.setVersion(commonEventHeaderJson.getLong("version"));
+ vesAlarm.setSourceName(commonEventHeaderJson.get("sourceName").asText());
+ vesAlarm.setStartEpochMicrosec(commonEventHeaderJson.get("startEpochMicrosec").asLong());
+ vesAlarm.setVersion(commonEventHeaderJson.get("version").asLong());
}
- private void convertFaultFieldsJsonToEvent(JSONObject faultFieldsJson, VesAlarm vesAlarm) {
+ private void convertFaultFieldsJsonToEvent(JsonNode faultFieldsJson, VesAlarm vesAlarm) {
vesAlarm.setAlarmAdditionalInformation(getListElementByNode(faultFieldsJson, "alarmAdditionalInformation"));
- vesAlarm.setAlarmCondition(faultFieldsJson.getString("alarmCondition"));
+ vesAlarm.setAlarmCondition(faultFieldsJson.get("alarmCondition").asText());
vesAlarm.setAlarmInterfaceA(getTextElementByNode(faultFieldsJson, "alarmInterfaceA"));
vesAlarm.setEventCategory(getTextElementByNode(faultFieldsJson,"eventCategory"));
- vesAlarm.setEventSeverity(faultFieldsJson.getString("eventSeverity"));
- vesAlarm.setEventSourceType(faultFieldsJson.getString("eventSourceType"));
- vesAlarm.setFaultFieldsVersion(faultFieldsJson.getLong("faultFieldsVersion"));
- vesAlarm.setSpecificProblem(faultFieldsJson.getString("specificProblem"));
- vesAlarm.setVfStatus(faultFieldsJson.getString("vfStatus"));
+ vesAlarm.setEventSeverity(faultFieldsJson.get("eventSeverity").asText());
+ vesAlarm.setEventSourceType(faultFieldsJson.get("eventSourceType").asText());
+ vesAlarm.setFaultFieldsVersion(faultFieldsJson.get("faultFieldsVersion").asLong());
+ vesAlarm.setSpecificProblem(faultFieldsJson.get("specificProblem").asText());
+ vesAlarm.setVfStatus(faultFieldsJson.get("vfStatus").asText());
}
- private String getTextElementByNode(JSONObject jsonNode,String name){
- if(jsonNode.get(name) != null){
- return jsonNode.getString(name);
+ private String getTextElementByNode(JsonNode jsonNode,String name){
+ if(jsonNode.has(name)){
+ return jsonNode.get(name).asText();
}
return null;
}
- private Long getLongElementByNode(JSONObject jsonNode, String name) {
- if(jsonNode.get(name) != null){
- return jsonNode.getLong(name);
+ private Long getLongElementByNode(JsonNode jsonNode, String name) {
+ if(jsonNode.has(name)){
+ return jsonNode.get(name).asLong();
}
return null;
}
- private List<AlarmAdditionalField> getListElementByNode(JSONObject jsonNode, String name){
+ private List<AlarmAdditionalField> getListElementByNode(JsonNode jsonNode, String name){
List<AlarmAdditionalField> alarms = new ArrayList<AlarmAdditionalField>();
- if (jsonNode.get(name) != null) {
- JSONArray alarmAdditionalInformations = jsonNode.getJSONArray(name);
- for (int i = 0; i < alarmAdditionalInformations.size(); i++) {
- JSONObject jsonObject = alarmAdditionalInformations.getJSONObject(i);
- if (jsonObject.get("name") != null
- && jsonObject.get("value") != null) {
- AlarmAdditionalField field = new AlarmAdditionalField();
- field.setName(getTextElementByNode(jsonObject, "name"));
- field.setValue(getTextElementByNode(jsonObject, "value"));
- alarms.add(field);
- }
+ if (jsonNode.has(name)) {
+ JsonNode alarmAdditionalInformations = jsonNode.get(name);
+ if (alarmAdditionalInformations.isArray()) {
+ alarmAdditionalInformations.forEach(alarm -> {
+ if(alarm.has("name") && alarm.has("value")) {
+ AlarmAdditionalField field = new AlarmAdditionalField();
+ field.setName(getTextElementByNode(alarm, "name"));
+ field.setValue(getTextElementByNode(alarm, "value"));
+ alarms.add(field);
+ }
+ });
}
}
return alarms;
diff --git a/dmaap-dsa/src/test/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtilTest.java b/dmaap-dsa/src/test/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtilTest.java
index 26fba51..87be654 100644
--- a/dmaap-dsa/src/test/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtilTest.java
+++ b/dmaap-dsa/src/test/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtilTest.java
@@ -22,7 +22,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import com.alibaba.fastjson.JSONException;
+//import com.alibaba.fastjson.JSONException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -163,7 +163,7 @@ public class DMaaPResponseUtilTest {
@Test
public void testDMaaPResponseUtil_input_illegal() throws Exception {
String json = "***";
- thrown.expect(JSONException.class);
+ thrown.expect(IOException.class);
dMaaPResponseUtil.convertJsonToVesAlarm(json);
}