migrate model-impl from drools-applications
[policy/models.git] / models-interactions / model-impl / events / src / main / java / org / onap / policy / controlloop / ControlLoopOperation.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * controlloop
4  * ================================================================================
5  * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2019 Nordix Foundation.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.controlloop;
23
24 import java.io.Serializable;
25 import java.time.Instant;
26
27 public class ControlLoopOperation implements Serializable {
28
29     private static final long serialVersionUID = 8662706581293017099L;
30
31     private String actor;
32     private String operation;
33     private String target;
34     private Instant start = Instant.now();
35     private Instant end;
36     private String subRequestId;
37     private String outcome;
38     private String message;
39
40     public ControlLoopOperation() {
41
42     }
43
44     /**
45      * Construct an instance from an existing instance.
46      * 
47      * @param op the existing instance
48      */
49     public ControlLoopOperation(ControlLoopOperation op) {
50         if (op == null) {
51             return;
52         }
53
54         this.actor = op.actor;
55         this.operation = op.operation;
56         this.target = op.target;
57         this.start = op.start;
58         this.end = op.end;
59         this.subRequestId = op.subRequestId;
60         this.outcome = op.outcome;
61         this.message = op.message;
62     }
63
64     public String toMessage() {
65         return "actor=" + actor + ",operation=" + operation + ",target=" + target + ",subRequestId=" + subRequestId;
66     }
67
68     public String toHistory() {
69         return "actor=" + actor + ",operation=" + operation + ",target=" + target + ",start=" + start + ",end=" + end
70                 + ",subRequestId=" + subRequestId + ",outcome=" + outcome + ",message=" + message;
71     }
72
73     public String getActor() {
74         return actor;
75     }
76
77     public void setActor(String actor) {
78         this.actor = actor;
79     }
80
81     public String getOperation() {
82         return operation;
83     }
84
85     public void setOperation(String operation) {
86         this.operation = operation;
87     }
88
89     public String getTarget() {
90         return target;
91     }
92
93     public void setTarget(String target) {
94         this.target = target;
95     }
96
97     public Instant getStart() {
98         return start;
99     }
100
101     public void setStart(Instant start) {
102         this.start = start;
103     }
104
105     public Instant getEnd() {
106         return end;
107     }
108
109     public void setEnd(Instant end) {
110         this.end = end;
111     }
112
113     public String getSubRequestId() {
114         return subRequestId;
115     }
116
117     public void setSubRequestId(String subRequestId) {
118         this.subRequestId = subRequestId;
119     }
120
121     public String getOutcome() {
122         return outcome;
123     }
124
125     public void setOutcome(String outcome) {
126         this.outcome = outcome;
127     }
128
129     public String getMessage() {
130         return message;
131     }
132
133     public void setMessage(String message) {
134         this.message = message;
135     }
136
137     @Override
138     public String toString() {
139         return "ControlLoopOperation [actor=" + actor + ", operation=" + operation + ", target=" + target + ", start="
140                 + start + ", end=" + end + ", subRequestId=" + subRequestId + ", outcome=" + outcome + ", message="
141                 + message + "]";
142     }
143
144     @Override
145     public int hashCode() {
146         final int prime = 31;
147         int result = 1;
148         result = prime * result + ((actor == null) ? 0 : actor.hashCode());
149         result = prime * result + ((end == null) ? 0 : end.hashCode());
150         result = prime * result + ((message == null) ? 0 : message.hashCode());
151         result = prime * result + ((operation == null) ? 0 : operation.hashCode());
152         result = prime * result + ((outcome == null) ? 0 : outcome.hashCode());
153         result = prime * result + ((start == null) ? 0 : start.hashCode());
154         result = prime * result + ((subRequestId == null) ? 0 : subRequestId.hashCode());
155         result = prime * result + ((target == null) ? 0 : target.hashCode());
156         return result;
157     }
158
159     @Override
160     public boolean equals(Object obj) {
161         if (this == obj) {
162             return true;
163         }
164         if (obj == null) {
165             return false;
166         }
167         if (getClass() != obj.getClass()) {
168             return false;
169         }
170         ControlLoopOperation other = (ControlLoopOperation) obj;
171         if (actor == null) {
172             if (other.actor != null) {
173                 return false;
174             }
175         } else if (!actor.equals(other.actor)) {
176             return false;
177         }
178         if (end == null) {
179             if (other.end != null) {
180                 return false;
181             }
182         } else if (!end.equals(other.end)) {
183             return false;
184         }
185         if (message == null) {
186             if (other.message != null) {
187                 return false;
188             }
189         } else if (!message.equals(other.message)) {
190             return false;
191         }
192         if (operation == null) {
193             if (other.operation != null) {
194                 return false;
195             }
196         } else if (!operation.equals(other.operation)) {
197             return false;
198         }
199         if (outcome == null) {
200             if (other.outcome != null) {
201                 return false;
202             }
203         } else if (!outcome.equals(other.outcome)) {
204             return false;
205         }
206         if (start == null) {
207             if (other.start != null) {
208                 return false;
209             }
210         } else if (!start.equals(other.start)) {
211             return false;
212         }
213         if (subRequestId == null) {
214             if (other.subRequestId != null) {
215                 return false;
216             }
217         } else if (!subRequestId.equals(other.subRequestId)) {
218             return false;
219         }
220         if (target == null) {
221             if (other.target != null) {
222                 return false;
223             }
224         } else if (!target.equals(other.target)) {
225             return false;
226         }
227         return true;
228     }
229
230 }