From 160f012debe361e2827aeec06cd78d5ebb43906f Mon Sep 17 00:00:00 2001 From: Congcong Peng Date: Tue, 27 Feb 2018 11:23:35 +0800 Subject: revert Issue-ID: HOLMES-115 Change-Id: I19a64c38461869f16224ed63809f9cdee7fca0f1 Signed-off-by: Congcong Peng --- dmaap-dsa/pom.xml | 38 ++++----- .../holmes/dsa/dmaappolling/DMaaPResponseUtil.java | 95 +++++++++++----------- .../dsa/dmaappolling/DMaaPResponseUtilTest.java | 4 +- 3 files changed, 68 insertions(+), 69 deletions(-) (limited to 'dmaap-dsa') 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 @@ - - com.alibaba - fastjson - 1.1.23 - + + + + + org.onap.msb.java-sdk @@ -78,14 +78,14 @@ log4j-over-slf4j org.slf4j - - com.fasterxml.jackson.core - jackson-databind - - - com.fasterxml.jackson.core - jackson-core - + + + + + + + + @@ -186,12 +186,12 @@ com.google.guava guava 19.0 - - - com.fasterxml.jackson.core - jackson-core - - + + + + + + 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 getListElementByNode(JSONObject jsonNode, String name){ + private List getListElementByNode(JsonNode jsonNode, String name){ List alarms = new ArrayList(); - 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); } -- cgit 1.2.3-korg