summaryrefslogtreecommitdiffstats
path: root/dmaap-dsa
diff options
context:
space:
mode:
authorCongcong Peng <peng.congcong@zte.com.cn>2018-02-27 16:37:17 +0800
committerCongcong Peng <peng.congcong@zte.com.cn>2018-02-27 16:37:17 +0800
commit18d79592085657e5d91daee17c09775e80fc671b (patch)
treee117e19fbadbd3c330e5eb887b5208d857da0470 /dmaap-dsa
parent160f012debe361e2827aeec06cd78d5ebb43906f (diff)
change version
Issue-ID: HOLMES-115 Change-Id: I74c2ce4f9186a80c2ffab79a10086690ca98da06 Signed-off-by: Congcong Peng <peng.congcong@zte.com.cn>
Diffstat (limited to 'dmaap-dsa')
-rw-r--r--dmaap-dsa/pom.xml63
-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, 92 insertions, 70 deletions
diff --git a/dmaap-dsa/pom.xml b/dmaap-dsa/pom.xml
index 9c981ea..fdd2462 100644
--- a/dmaap-dsa/pom.xml
+++ b/dmaap-dsa/pom.xml
@@ -29,13 +29,6 @@
<packaging>jar</packaging>
<dependencies>
-
- <!--<dependency>-->
- <!--<groupId>com.alibaba</groupId>-->
- <!--<artifactId>fastjson</artifactId>-->
- <!--<version>1.1.23</version>-->
- <!--</dependency>-->
-
<dependency>
<groupId>org.onap.msb.java-sdk</groupId>
<artifactId>msb-java-sdk</artifactId>
@@ -78,17 +71,45 @@
<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>
+ <groupId>net.sf.json-lib</groupId>
+ <artifactId>json-lib</artifactId>
+ <version>2.4</version>
+ <classifier>jdk15</classifier>
+ <exclusions>
+ <exclusion>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils</artifactId>
+ </exclusion>
</exclusions>
</dependency>
<dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.2.2</version>
+ </dependency>
+ <dependency>
+ <groupId>com.alibaba</groupId>
+ <artifactId>fastjson</artifactId>
+ <version>1.1.23</version>
+ </dependency>
+
+ <dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
@@ -186,12 +207,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 f19402c..be30153 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,95 +15,96 @@
*/
package org.onap.holmes.dsa.dmaappolling;
-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 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
@Service
public class DMaaPResponseUtil {
public VesAlarm convertJsonToVesAlarm(String responseJson) throws IOException {
- ObjectMapper mapper = new ObjectMapper();
- JsonNode jsonNode = mapper.readTree(responseJson);
- VesAlarm vesAlarm = new VesAlarm();
+ JSONObject jsonNode = JSON.parseObject(responseJson);
- JsonNode eventJson = jsonNode.get("event");
+ VesAlarm vesAlarm = new VesAlarm();
- JsonNode commonEventHeaderJson = eventJson.get("commonEventHeader");
+ JSONObject eventJson = JSON.parseObject(jsonNode.get("event") +"");
+ JSONObject commonEventHeaderJson = JSON.parseObject(eventJson.get("commonEventHeader") +"");
convertCommonEventHeaderJsonToEvent(commonEventHeaderJson, vesAlarm);
- JsonNode faultFieldsJson = eventJson.get("faultFields");
+ JSONObject faultFieldsJson = JSON.parseObject(eventJson.get("faultFields") +"");
convertFaultFieldsJsonToEvent(faultFieldsJson, vesAlarm);
return vesAlarm;
}
- private void convertCommonEventHeaderJsonToEvent(JsonNode commonEventHeaderJson,
+ private void convertCommonEventHeaderJsonToEvent(JSONObject commonEventHeaderJson,
VesAlarm vesAlarm) {
- vesAlarm.setDomain(commonEventHeaderJson.get("domain").asText());
- vesAlarm.setEventId(commonEventHeaderJson.get("eventId").asText());
- vesAlarm.setEventName(commonEventHeaderJson.get("eventName").asText());
+ vesAlarm.setDomain((String) commonEventHeaderJson.get("domain"));
+ vesAlarm.setEventId((String) commonEventHeaderJson.get("eventId"));
+ vesAlarm.setEventName((String) commonEventHeaderJson.get("eventName"));
vesAlarm.setAlarmIsCleared(vesAlarm.getEventName().endsWith("Cleared") ? 1 : 0);
vesAlarm.setEventType(getTextElementByNode(commonEventHeaderJson, "eventType"));
vesAlarm.setInternalHeaderFields(
getTextElementByNode(commonEventHeaderJson, "internalHeaderFields"));
- vesAlarm.setLastEpochMicrosec(commonEventHeaderJson.get("lastEpochMicrosec").asLong());
+ vesAlarm.setLastEpochMicrosec(commonEventHeaderJson.getLong("lastEpochMicrosec"));
vesAlarm.setNfcNamingCode(getTextElementByNode(commonEventHeaderJson, "nfcNamingCode"));
vesAlarm.setNfNamingCode(getTextElementByNode(commonEventHeaderJson, "nfNamingCode"));
- vesAlarm.setPriority(commonEventHeaderJson.get("priority").asText());
+ vesAlarm.setPriority((String) commonEventHeaderJson.get("priority"));
vesAlarm.setReportingEntityId(
getTextElementByNode(commonEventHeaderJson, "reportingEntityId"));
- vesAlarm.setReportingEntityName(commonEventHeaderJson.get("reportingEntityName").asText());
- vesAlarm.setSequence(commonEventHeaderJson.get("sequence").asInt());
+ vesAlarm.setReportingEntityName( (String) commonEventHeaderJson.get("reportingEntityName"));
+ vesAlarm.setSequence((Integer) commonEventHeaderJson.get("sequence"));
vesAlarm.setSourceId(getTextElementByNode(commonEventHeaderJson, "sourceId"));
- vesAlarm.setSourceName(commonEventHeaderJson.get("sourceName").asText());
- vesAlarm.setStartEpochMicrosec(commonEventHeaderJson.get("startEpochMicrosec").asLong());
- vesAlarm.setVersion(commonEventHeaderJson.get("version").asLong());
+ vesAlarm.setSourceName( (String) commonEventHeaderJson.get("sourceName"));
+ vesAlarm.setStartEpochMicrosec(commonEventHeaderJson.getLong("startEpochMicrosec"));
+ vesAlarm.setVersion(commonEventHeaderJson.getLong("version"));
}
- private void convertFaultFieldsJsonToEvent(JsonNode faultFieldsJson, VesAlarm vesAlarm) {
+ private void convertFaultFieldsJsonToEvent(JSONObject faultFieldsJson, VesAlarm vesAlarm) {
vesAlarm.setAlarmAdditionalInformation(getListElementByNode(faultFieldsJson, "alarmAdditionalInformation"));
- vesAlarm.setAlarmCondition(faultFieldsJson.get("alarmCondition").asText());
+ vesAlarm.setAlarmCondition(faultFieldsJson.getString("alarmCondition"));
vesAlarm.setAlarmInterfaceA(getTextElementByNode(faultFieldsJson, "alarmInterfaceA"));
vesAlarm.setEventCategory(getTextElementByNode(faultFieldsJson,"eventCategory"));
- 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());
+ 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"));
}
- private String getTextElementByNode(JsonNode jsonNode,String name){
- if(jsonNode.has(name)){
- return jsonNode.get(name).asText();
+ private String getTextElementByNode(JSONObject jsonNode,String name){
+ if(jsonNode.get(name) != null){
+ return jsonNode.getString(name);
}
return null;
}
- private Long getLongElementByNode(JsonNode jsonNode, String name) {
- if(jsonNode.has(name)){
- return jsonNode.get(name).asLong();
+ private Long getLongElementByNode(JSONObject jsonNode, String name) {
+ if(jsonNode.get(name) != null){
+ return jsonNode.getLong(name);
}
return null;
}
- private List<AlarmAdditionalField> getListElementByNode(JsonNode jsonNode, String name){
+ private List<AlarmAdditionalField> getListElementByNode(JSONObject jsonNode, String name){
List<AlarmAdditionalField> alarms = new ArrayList<AlarmAdditionalField>();
- 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);
- }
- });
+ 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);
+ }
}
}
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 87be654..26fba51 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(IOException.class);
+ thrown.expect(JSONException.class);
dMaaPResponseUtil.convertJsonToVesAlarm(json);
}