Fixed the CLM Issues
[holmes/common.git] / holmes-actions / src / main / java / org / onap / holmes / common / api / stat / Alarm.java
1 /**\r
2  * Copyright 2017-2020 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.google.gson.Gson;\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     public boolean containNode(int linkId, int index) {\r
82        return linkIdNodeIdxMap.containsKey(linkId) && linkIdNodeIdxMap.get(linkId) == index;\r
83     }\r
84 \r
85     @Override\r
86     public byte getDataType() {\r
87         return APLUS_EVENT;\r
88     }\r
89 \r
90     @Override\r
91     public String toString() {\r
92 \r
93         return new Gson().toJson(this);\r
94     }\r
95 \r
96     @Override\r
97     public int hashCode() {\r
98         return this.getAlarmKey().hashCode();\r
99     }\r
100 \r
101     @Override\r
102     public boolean equals(Object arg0) {\r
103         if (arg0 == null || !(arg0 instanceof Alarm)) {\r
104             return false;\r
105         }\r
106         return this.alarmKey.equals(((Alarm) arg0).getAlarmKey());\r
107     }\r
108 \r
109     @Override\r
110     public Object clone() throws CloneNotSupportedException {\r
111         super.clone();\r
112 \r
113         Alarm alarm = new Alarm();\r
114 \r
115         alarm.setEventType(this.getEventType());\r
116 \r
117         alarm.setAid(this.getAid());\r
118         alarm.setId(this.getId());\r
119         alarm.setAlarmKey(this.getAlarmKey());\r
120 \r
121         alarm.setNetwork(this.getNetwork());\r
122         alarm.setEquipType(this.getEquipType());\r
123         alarm.setNeType(this.getNeType());\r
124         alarm.setPosition1(this.getPosition1());\r
125         alarm.setSubPosition1(this.getSubPosition1());\r
126         alarm.setPosition2(this.getPosition2());\r
127         alarm.setSubPosition2(this.getSubPosition2());\r
128         alarm.setRegion(this.getRegion());\r
129         alarm.setSite(this.getSite());\r
130 \r
131         alarm.setSeverity(this.getSeverity());\r
132         alarm.setAlarmType(this.getAlarmType());\r
133         alarm.setSystemType(this.getSystemType());\r
134         alarm.setSpecificProblem(this.getSpecificProblem());\r
135         alarm.setAdditionalText(this.getAdditionalText());\r
136         alarm.setProbableCause(this.getProbableCause());\r
137 \r
138         alarm.setRaisedTime(this.getRaisedTime());\r
139         alarm.setRaisedServerTime(this.getRaisedServerTime());\r
140         alarm.setClearedTime(this.getClearedTime());\r
141 \r
142         return alarm;\r
143     }\r
144 \r
145     @Override\r
146     public String getObjectId() {\r
147         return String.valueOf(id);\r
148     }\r
149 \r
150     public void addLinkIds(int linkId) {\r
151         linkIds.add(linkId);\r
152     }\r
153 \r
154 \r
155     public boolean containsPriority(String ruleId) {\r
156         return priorityMap.keySet().contains(ruleId);\r
157     }\r
158 \r
159     public int getPriority(String ruleId) {\r
160         Integer priority = this.priorityMap.get(ruleId);\r
161         if (priority == null) {\r
162             priority = 0;\r
163         }\r
164         return priority;\r
165     }\r
166 \r
167     public int getRootAlarmType(String ruleId) {\r
168         Integer rootAlarmTypeVar = this.rootAlarmTypeMap.get(ruleId);\r
169         return (rootAlarmTypeVar == null) ? -1 : rootAlarmTypeVar;\r
170     }\r
171 \r
172 }\r