Sonar Critical Fix
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-common / src / main / java / org / openecomp / dcae / apod / analytics / cdap / common / persistance / tca / TCAAlertsAbatementEntity.java
1 /*\r
2  * ===============================LICENSE_START======================================\r
3  *  dcae-analytics\r
4  * ================================================================================\r
5  *    Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  *  Licensed under the Apache License, Version 2.0 (the "License");\r
8  *  you may not use this file except in compliance with the License.\r
9  *   You may obtain a copy of the License at\r
10  *\r
11  *          http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  *  Unless required by applicable law or agreed to in writing, software\r
14  *  distributed under the License is distributed on an "AS IS" BASIS,\r
15  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  *  See the License for the specific language governing permissions and\r
17  *  limitations under the License.\r
18  *  ============================LICENSE_END===========================================\r
19  */\r
20 \r
21 package org.openecomp.dcae.apod.analytics.cdap.common.persistance.tca;\r
22 \r
23 import com.google.common.base.Objects;\r
24 import org.apache.hadoop.io.Writable;\r
25 import org.apache.hadoop.io.WritableUtils;\r
26 \r
27 import java.io.DataInput;\r
28 import java.io.DataOutput;\r
29 import java.io.IOException;\r
30 import java.io.Serializable;\r
31 \r
32 /**\r
33  * TCA Alerts Abatement Entity is used to persist information to determine if abatement event need to sent to downstream\r
34  * systems\r
35  *\r
36  *  @author Rajiv Singla . Creation Date: 9/11/2017.\r
37  */\r
38 public class TCAAlertsAbatementEntity implements Writable, Serializable {\r
39 \r
40     private static final long serialVersionUID = 1L;\r
41 \r
42     private long creationTS;\r
43     private String requestId;\r
44     // Kept as string to avoid null checks\r
45     private String abatementSentTS;\r
46 \r
47     /**\r
48      * No Arg constructor required for Jackson Json Serialization / Deserialization\r
49      */\r
50     public TCAAlertsAbatementEntity() {\r
51         // required no arg constructor\r
52     }\r
53 \r
54     /**\r
55      * Creates TCA Alerts Abatement Entity to persist information to determine if abatement alerts need to be posted\r
56      *\r
57      * @param creationTS record creation time\r
58      * @param requestId request ID of generated alert\r
59      * @param abatementSentTS time when abatement was sent out for that alert if any\r
60      */\r
61     public TCAAlertsAbatementEntity(long creationTS, String requestId, String abatementSentTS) {\r
62         this.creationTS = creationTS;\r
63         this.requestId = requestId;\r
64         this.abatementSentTS = abatementSentTS;\r
65     }\r
66 \r
67     /**\r
68      * Timestamp when record was created\r
69      *\r
70      * @return timestamp when record was created\r
71      */\r
72     public long getCreationTS() {\r
73         return creationTS;\r
74     }\r
75 \r
76     /**\r
77      * Set value for timestamp when record was created\r
78      *\r
79      * @param creationTS new value for timestamp when record was created\r
80      */\r
81     public void setCreationTS(long creationTS) {\r
82         this.creationTS = creationTS;\r
83     }\r
84 \r
85     /**\r
86      * Request Id of ONSET alert which was sent\r
87      *\r
88      * @return request Id of ONSET alert which was sent\r
89      */\r
90     public String getRequestId() {\r
91         return requestId;\r
92     }\r
93 \r
94     /**\r
95      * Set Request Id of ONSET alert\r
96      *\r
97      * @param requestId set new value for ONSET alert request id\r
98      */\r
99     public void setRequestId(String requestId) {\r
100         this.requestId = requestId;\r
101     }\r
102 \r
103 \r
104     /**\r
105      * Get abatement Sent Timestamp\r
106      *\r
107      * @return get abatement alert sent timestamp\r
108      */\r
109     public String getAbatementSentTS() {\r
110         return abatementSentTS;\r
111     }\r
112 \r
113     /**\r
114      * Set timestamp when abatement alert is sent\r
115      *\r
116      * @param abatementSentTS sent new value for timestamp when abatement alert is sent\r
117      */\r
118     public void setAbatementSentTS(String abatementSentTS) {\r
119         this.abatementSentTS = abatementSentTS;\r
120     }\r
121 \r
122     /**\r
123      * Write entity to Table\r
124      *\r
125      * @param dataOutput data output\r
126      * @throws IOException io exception\r
127      */\r
128     @Override\r
129     public void write(DataOutput dataOutput) throws IOException {\r
130         WritableUtils.writeVLong(dataOutput, creationTS);\r
131         WritableUtils.writeString(dataOutput, requestId);\r
132         WritableUtils.writeString(dataOutput, abatementSentTS);\r
133     }\r
134 \r
135     /**\r
136      * Read entity from table\r
137      *\r
138      * @param dataInput data input\r
139      * @throws IOException io exception\r
140      */\r
141     @Override\r
142     public void readFields(DataInput dataInput) throws IOException {\r
143         creationTS = WritableUtils.readVLong(dataInput);\r
144         requestId = WritableUtils.readString(dataInput);\r
145         abatementSentTS = WritableUtils.readString(dataInput);\r
146     }\r
147 \r
148 \r
149     @Override\r
150     public String toString() {\r
151         return Objects.toStringHelper(this)\r
152                 .add("creationTS", creationTS)\r
153                 .add("requestId", requestId)\r
154                 .add("abatementSentTS", abatementSentTS)\r
155                 .toString();\r
156     }\r
157 }\r