Fix Bugs Identified by Sonar
[holmes/common.git] / holmes-actions / src / main / java / org / onap / holmes / common / api / stat / VesAlarm.java
1 /*
2  * Copyright 2017 ZTE Corporation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.holmes.common.api.stat;
18
19 import java.io.Serializable;
20 import java.util.ArrayList;
21 import java.util.List;
22 import lombok.Getter;
23 import lombok.Setter;
24
25 @Getter
26 @Setter
27 public class VesAlarm implements Cloneable, Serializable{
28     private String domain;
29     private String eventId;
30     private String eventName;
31     private String eventType;
32     //Temporarily make it transient cuz no details of this field is provided and it is not used for now.
33     transient private Object internalHeaderFields;
34     private Long lastEpochMicrosec;
35     private String nfcNamingCode;
36     private String nfNamingCode;
37     private String priority;
38     private String reportingEntityId;
39     private String reportingEntityName;
40     private Integer sequence;
41     private String sourceId;
42     private String sourceName;
43     private Long startEpochMicrosec;
44     private Long version;
45
46     private List<AlarmAdditionalField> alarmAdditionalInformation;
47     private String alarmCondition;
48     private String alarmInterfaceA;
49     private String eventCategory;
50     private String eventSeverity;
51     private String eventSourceType;
52     private Long faultFieldsVersion;
53     private String specificProblem;
54     private String vfStatus;
55     private String parentId;
56     private int alarmIsCleared = 0;  //mark as 1 when alarm type is cleared, else mark as 0
57     private int rootFlag = 0;        // mark as 1 when alarm is a root alarm , else mark as 0
58
59     @Override
60     public int hashCode() {
61         return (this.getSourceId() + this.eventName.replace("Cleared", "")).hashCode();
62     }
63
64     @Override
65     public boolean equals(Object object) {
66         if (object == null || !(object instanceof VesAlarm)) {
67             return false;
68         }
69         return this.eventName.replace("Cleared", "")
70                 .equals(((VesAlarm) object).getEventName().replace("Cleared", ""))
71                 && this.getSourceId().equals(((VesAlarm) object).getSourceId());
72     }
73
74     @Override
75     public Object clone() throws CloneNotSupportedException {
76         VesAlarm vesAlarm = new VesAlarm();
77
78         vesAlarm.setDomain(this.domain);
79         vesAlarm.setEventId(this.getEventId());
80         vesAlarm.setEventName(this.getEventName());
81         vesAlarm.setEventType(this.getEventType());
82         vesAlarm.setInternalHeaderFields(this.getInternalHeaderFields());
83         vesAlarm.setLastEpochMicrosec(this.getLastEpochMicrosec());
84         vesAlarm.setNfcNamingCode(this.nfcNamingCode);
85         vesAlarm.setNfNamingCode(this.getNfNamingCode());
86         vesAlarm.setPriority(this.getPriority());
87         vesAlarm.setReportingEntityId(this.getReportingEntityId());
88         vesAlarm.setReportingEntityName(this.reportingEntityName);
89         vesAlarm.setSequence(this.getSequence());
90         vesAlarm.setSourceId(this.getSourceId());
91         vesAlarm.setSourceName(this.getSourceName());
92         vesAlarm.setStartEpochMicrosec(this.getStartEpochMicrosec());
93         vesAlarm.setVersion(this.getVersion());
94
95         if (alarmAdditionalInformation != null) {
96             List<AlarmAdditionalField> alarmAdditionalFields = new ArrayList<>();
97             alarmAdditionalInformation.forEach(alarmAdditionalField -> {
98                 AlarmAdditionalField alarmAdditionalField1 = new AlarmAdditionalField();
99                 alarmAdditionalField1.setName(alarmAdditionalField.getName());
100                 alarmAdditionalField1.setName(alarmAdditionalField.getValue());
101                 alarmAdditionalFields.add(alarmAdditionalField1);
102             });
103             vesAlarm.setAlarmAdditionalInformation(alarmAdditionalFields);
104         }
105
106         vesAlarm.setAlarmCondition(this.getAlarmCondition());
107         vesAlarm.setAlarmInterfaceA(this.getAlarmInterfaceA());
108         vesAlarm.setEventCategory(this.getEventCategory());
109         vesAlarm.setEventSeverity(this.getEventSeverity());
110         vesAlarm.setEventSourceType(this.getEventSourceType());
111         vesAlarm.setFaultFieldsVersion(this.getFaultFieldsVersion());
112         vesAlarm.setSpecificProblem(this.getSpecificProblem());
113         vesAlarm.setVfStatus(this.vfStatus);
114         vesAlarm.setAlarmIsCleared(this.alarmIsCleared);
115         vesAlarm.setRootFlag(this.rootFlag);
116
117         return vesAlarm;
118     }
119 }