Multiple Sonar Fixes
[holmes/common.git] / holmes-actions / src / main / java / org / onap / holmes / common / api / stat / Alarm.java
1 /**\r
2  * Copyright 2017 ZTE Corporation.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 package org.onap.holmes.common.api.stat;\r
18 \r
19 import com.alibaba.fastjson.JSONObject;\r
20 import lombok.Getter;\r
21 import lombok.Setter;\r
22 \r
23 import java.io.Serializable;\r
24 import java.util.*;\r
25 \r
26 \r
27 @Getter\r
28 @Setter\r
29 public class Alarm implements AplusData, Cloneable, Serializable {\r
30 \r
31     public static final byte EVENT_CLEARED_ALARM = 3;\r
32 \r
33     public static final byte EVENT_CHANGED = 2;\r
34 \r
35     public static final byte EVENT_CLEARED = 1;\r
36 \r
37     public static final byte EVENT_RAISED = 0;\r
38 \r
39     private static final long serialVersionUID = 4520003737132012000L;\r
40     private static final Date clearedServerTime = null;\r
41     private final Map<Integer, Integer> linkIdNodeIdxMap = new HashMap<>();\r
42     private byte eventType = EVENT_RAISED;\r
43     private long id = 0L;\r
44     private String alarmKey = "";\r
45     private String network = "";\r
46     private String neType = "";\r
47     private String equipType = "";\r
48     private String position1 = "";\r
49     private String subPosition1 = null;\r
50     private String position2 = null;\r
51     private String subPosition2 = null;\r
52     private byte severity = -1;\r
53     private byte alarmType = -1;\r
54     private long probableCause = -1;\r
55     private String specificProblem = null;\r
56     private String additionalText = null;\r
57     private Date raisedTime = new Date();\r
58     private Date raisedServerTime = new Date();\r
59     private Date clearedTime = null;\r
60     private String region = null;\r
61     private String site = null;\r
62     private String aid = null;\r
63     private short systemType = -1;\r
64     private boolean rootAlarmFlag = false;\r
65     private int linkId = -1;\r
66     private int nodeIdx = -1;\r
67     private Set<Integer> linkIds = new HashSet<>();\r
68     private HashMap<String, Integer> priorityMap = new HashMap<>();\r
69     private HashMap<String, Integer> rootAlarmTypeMap = new HashMap<>();\r
70     private int rootAlarmType = -1;\r
71     private boolean keyAlarmFlag = false;\r
72     private int keyAlarmType = -1;\r
73     private int networkLevel = -1;\r
74     private int linkType = -1;\r
75     private int centerType;\r
76 \r
77     public void addLinkIdNodeIdx(int linkId, int index) {\r
78         linkIdNodeIdxMap.put(linkId, index);\r
79     }\r
80 \r
81     /**\r
82      * Comparison of the location of different links: 999 the same link: the location of the node\r
83      * number less than otherIdIdx in the location of the number (in the otherIdIdx upstream):-1,\r
84      * the same link: the node position number is equal to the number of position in the otherIdIdx\r
85      * (in the same site otherIdIdx):0, the same link: the node location number is greater than the\r
86      * number of locations in otherIdIdx (otherIdIdx) with the site):1,\r
87      */\r
88     public int CompareLinkPosition(Map<Integer, Integer> otherIdIdx) {\r
89         Set<Integer> myIdSet = new HashSet<>();\r
90         myIdSet.addAll(this.linkIdNodeIdxMap.keySet());\r
91         myIdSet.retainAll(otherIdIdx.keySet());\r
92 \r
93         if (myIdSet.isEmpty()) {\r
94             return 999;\r
95         }\r
96 \r
97         for (int tempLinkId : myIdSet) {\r
98             return this.linkIdNodeIdxMap.get(tempLinkId) - otherIdIdx.get(tempLinkId);\r
99         }\r
100         return 999;\r
101     }\r
102 \r
103     public boolean containNode(int linkId, int index) {\r
104        return linkIdNodeIdxMap.containsKey(linkId) && linkIdNodeIdxMap.get(linkId) == index;\r
105     }\r
106 \r
107     @Override\r
108     public byte getDataType() {\r
109         return APLUS_EVENT;\r
110     }\r
111 \r
112     @Override\r
113     public String toString() {\r
114 \r
115         return JSONObject.toJSONString(this);\r
116     }\r
117 \r
118     @Override\r
119     public int hashCode() {\r
120         return this.getAlarmKey().hashCode();\r
121     }\r
122 \r
123     @Override\r
124     public boolean equals(Object arg0) {\r
125         if (arg0 == null || !(arg0 instanceof Alarm)) {\r
126             return false;\r
127         }\r
128         return this.alarmKey.equals(((Alarm) arg0).getAlarmKey());\r
129     }\r
130 \r
131     @Override\r
132     public Object clone() throws CloneNotSupportedException {\r
133         super.clone();\r
134 \r
135         Alarm alarm = new Alarm();\r
136 \r
137         alarm.setEventType(this.getEventType());\r
138 \r
139         alarm.setAid(this.getAid());\r
140         alarm.setId(this.getId());\r
141         alarm.setAlarmKey(this.getAlarmKey());\r
142 \r
143         alarm.setNetwork(this.getNetwork());\r
144         alarm.setEquipType(this.getEquipType());\r
145         alarm.setNeType(this.getNeType());\r
146         alarm.setPosition1(this.getPosition1());\r
147         alarm.setSubPosition1(this.getSubPosition1());\r
148         alarm.setPosition2(this.getPosition2());\r
149         alarm.setSubPosition2(this.getSubPosition2());\r
150         alarm.setRegion(this.getRegion());\r
151         alarm.setSite(this.getSite());\r
152 \r
153         alarm.setSeverity(this.getSeverity());\r
154         alarm.setAlarmType(this.getAlarmType());\r
155         alarm.setSystemType(this.getSystemType());\r
156         alarm.setSpecificProblem(this.getSpecificProblem());\r
157         alarm.setAdditionalText(this.getAdditionalText());\r
158         alarm.setProbableCause(this.getProbableCause());\r
159 \r
160         alarm.setRaisedTime(this.getRaisedTime());\r
161         alarm.setRaisedServerTime(this.getRaisedServerTime());\r
162         alarm.setClearedTime(this.getClearedTime());\r
163 \r
164         return alarm;\r
165     }\r
166 \r
167     @Override\r
168     public String getObjectId() {\r
169         return String.valueOf(id);\r
170     }\r
171 \r
172     public void addLinkIds(int linkId) {\r
173         linkIds.add(linkId);\r
174     }\r
175 \r
176 \r
177     public boolean containsPriority(String ruleId) {\r
178         return priorityMap.keySet().contains(ruleId);\r
179     }\r
180 \r
181     public int getPriority(String ruleId) {\r
182         Integer priority = this.priorityMap.get(ruleId);\r
183         if (priority == null) {\r
184             priority = 0;\r
185         }\r
186         return priority;\r
187     }\r
188 \r
189     public int getRootAlarmType(String ruleId) {\r
190         Integer rootAlarmTypeVar = this.rootAlarmTypeMap.get(ruleId);\r
191         return (rootAlarmTypeVar == null) ? -1 : rootAlarmTypeVar;\r
192     }\r
193 \r
194 }\r