From 2f92be933fc2ef3ccf1f44572a9be99058dd7ec0 Mon Sep 17 00:00:00 2001 From: Guangrong Fu Date: Fri, 26 Jan 2018 17:31:00 +0800 Subject: Fix IQ Findings Change-Id: I0ab0e2a9f5c3b7e3fa183ddbf7e4ecd2d4ed41ec Issue-ID: HOLMES-116 Signed-off-by: Guangrong Fu --- .../org/onap/holmes/common/api/stat/Alarm.java | 89 ++-------------------- .../holmes/common/dcae/DcaeConfigurationQuery.java | 4 - 2 files changed, 5 insertions(+), 88 deletions(-) (limited to 'holmes-actions/src/main/java') diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/stat/Alarm.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/stat/Alarm.java index be876e0..9822076 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/api/stat/Alarm.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/stat/Alarm.java @@ -16,21 +16,12 @@ package org.onap.holmes.common.api.stat; -import java.io.Serializable; -import java.io.StringReader; -import java.lang.reflect.Field; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; import lombok.Getter; import lombok.Setter; -import org.jdom.Attribute; -import org.jdom.Element; -import org.jdom.input.SAXBuilder; -import org.jdom.output.XMLOutputter; +import net.sf.json.JSONObject; + +import java.io.Serializable; +import java.util.*; @Getter @@ -83,47 +74,6 @@ public class Alarm implements AplusData, Cloneable, Serializable { private int linkType = -1; private int centerType; - public static Alarm valueOf(String xmlString) { - Element element; - try { - StringReader sb = new StringReader(xmlString); - element = new SAXBuilder().build(sb).getRootElement(); - sb.close(); - } catch (Exception e) { - throw new RuntimeException(e); - } - - Alarm alarm = new Alarm(); - @SuppressWarnings("unchecked") - List list = element.getAttributes(); - for (Attribute attr : list) { - String attrName = attr.getName(); - try { - Field field = Alarm.class.getDeclaredField(attrName); - if (!attrName.endsWith("Time")) { - String type = field.getType().getSimpleName(); - if ("byte".equals(type)) { - field.set(alarm, Byte.parseByte(attr.getValue())); - } else if ("long".equals(type)) { - field.set(alarm, Long.parseLong(attr.getValue())); - } else if ("String".equals(type)) { - field.set(alarm, attr.getValue()); - } else { - throw new RuntimeException("unknow attr type: " + type.toString()); - } - } else { - Date date = new Date(); - date.setTime(Long.parseLong(attr.getValue())); - field.set(alarm, date); - } - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - return alarm; - } - public void addLinkIdNodeIdx(int linkId, int index) { linkIdNodeIdxMap.put(linkId, index); } @@ -161,37 +111,8 @@ public class Alarm implements AplusData, Cloneable, Serializable { @Override public String toString() { - final String nullStr = ""; - - Element el = new Element("Alarm"); - el.setAttribute("id", String.valueOf(id)); - el.setAttribute("aid", String.valueOf(aid)); - el.setAttribute("alarmKey", String.valueOf(alarmKey)); - el.setAttribute("eventType", String.valueOf(eventType)); - el.setAttribute("region", region == null ? nullStr : region); - el.setAttribute("site", site == null ? nullStr : site); - el.setAttribute("network", network); - el.setAttribute("neType", neType); - el.setAttribute("equipType", equipType); - el.setAttribute("position1", position1); - el.setAttribute("subPosition1", subPosition1 == null ? nullStr : subPosition1); - el.setAttribute("position2", position2 == null ? nullStr : position2); - el.setAttribute("subPosition2", subPosition2 == null ? nullStr : subPosition2); - el.setAttribute("severity", String.valueOf(severity)); - el.setAttribute("alarmType", String.valueOf(alarmType)); - el.setAttribute("probableCause", String.valueOf(probableCause)); - el.setAttribute("specificProblem", specificProblem == null ? nullStr : specificProblem); - el.setAttribute("additionalText", additionalText == null ? nullStr : additionalText); - el.setAttribute("raisedTime", String.valueOf(raisedTime.getTime())); - el.setAttribute("raisedServerTime", String.valueOf(raisedServerTime.getTime())); - if (clearedTime != null) { - el.setAttribute("clearedTime", String.valueOf(clearedTime.getTime())); - } - if (clearedServerTime != null) { - el.setAttribute("clearedServerTime", String.valueOf(clearedServerTime.getTime())); - } - return new XMLOutputter().outputString(el); + return JSONObject.fromObject(this).toString(); } @Override diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dcae/DcaeConfigurationQuery.java b/holmes-actions/src/main/java/org/onap/holmes/common/dcae/DcaeConfigurationQuery.java index 597e879..4f8a0a5 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dcae/DcaeConfigurationQuery.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dcae/DcaeConfigurationQuery.java @@ -15,10 +15,6 @@ */ package org.onap.holmes.common.dcae; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.WebTarget; -import org.glassfish.jersey.client.ClientConfig; import org.onap.holmes.common.config.MicroServiceConfig; import org.onap.holmes.common.dcae.entity.DcaeConfigurations; import org.onap.holmes.common.dcae.utils.DcaeConfigurationParser; -- cgit 1.2.3-korg