Containerization feature of SO
[so.git] / mso-api-handlers / mso-requests-db / src / main / java / org / onap / so / db / request / beans / OperationStatus.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.db.request.beans;
22
23 import java.io.Serializable;
24 import java.util.Date;
25
26 import javax.persistence.Column;
27 import javax.persistence.Entity;
28 import javax.persistence.Id;
29 import javax.persistence.IdClass;
30 import javax.persistence.PrePersist;
31 import javax.persistence.PreUpdate;
32 import javax.persistence.Table;
33 import javax.persistence.Temporal;
34 import javax.persistence.TemporalType;
35 import java.util.Objects;
36 import org.apache.commons.lang3.builder.ToStringBuilder;
37
38 /**
39  * The service operation status 
40  * <br>
41  * <p>
42  * </p>
43  * 
44  * @author
45  * @version     ONAP Amsterdam Release  2017-08-28
46  */
47
48 @IdClass(OperationStatusId.class)
49 @Entity
50 @Table(name = "operation_status")
51 public class OperationStatus implements Serializable{
52     
53     /**
54      * 
55      */
56     private static final long serialVersionUID = 1L;
57
58     @Id
59         @Column(name = "SERVICE_ID")
60     private String serviceId;
61     @Id
62         @Column(name = "OPERATION_ID", length=256)
63     private String operationId;
64     
65     @Column(name = "SERVICE_NAME", length=256)
66     private String serviceName;
67     
68     @Column(name = "OPERATION_TYPE", length=256)
69     private String operation;
70     
71     @Column(name = "USER_ID", length=256)
72     private String userId;
73     
74     @Column(name = "RESULT", length=256)
75     private String result;
76     
77     @Column(name = "OPERATION_CONTENT", length=256)
78     private String operationContent;
79     
80     @Column(name = "PROGRESS", length=256)
81     private String progress = "0";
82     
83     @Column(name = "REASON", length=256)
84     private String reason;
85
86     @Column(name = "OPERATE_AT", length=256, updatable=false)
87     @Temporal(TemporalType.TIMESTAMP)
88     private Date operateAt;
89     
90     @Column(name = "FINISHED_AT", length=256)
91     @Temporal(TemporalType.TIMESTAMP)
92     private Date finishedAt;
93
94     public OperationStatus() {
95         
96     }
97     
98     public OperationStatus(String serviceId, String operationId) {
99         this.serviceId = serviceId;
100         this.operationId = operationId;
101     }
102     
103     
104     public String getServiceId() {
105         return serviceId;
106     }
107
108     
109     public void setServiceId(String serviceId) {
110         this.serviceId = serviceId;
111     }
112
113     
114     public String getOperationId() {
115         return operationId;
116     }
117
118     
119     public void setOperationId(String operationId) {
120         this.operationId = operationId;
121     }
122
123     
124     public String getOperation() {
125         return operation;
126     }
127
128     
129     public void setOperation(String operation) {
130         this.operation = operation;
131     }
132
133     
134     public String getServiceName() {
135                 return serviceName;
136         }
137
138         public void setServiceName(String serviceName) {
139                 this.serviceName = serviceName;
140         }
141
142         public String getUserId() {
143         return userId;
144     }
145
146     
147     public void setUserId(String userId) {
148         this.userId = userId;
149     }
150
151     
152     public String getResult() {
153         return result;
154     }
155
156     
157     public void setResult(String result) {
158         this.result = result;
159     }
160
161     
162     public String getOperationContent() {
163         return operationContent;
164     }
165
166     
167     public void setOperationContent(String operationContent) {
168         this.operationContent = operationContent;
169     }
170
171     
172     public String getProgress() {
173         return progress;
174     }
175
176     
177     public void setProgress(String progress) {
178         this.progress = progress;
179     }
180
181     
182     public String getReason() {
183         return reason;
184     }
185
186     
187     public void setReason(String reason) {
188         this.reason = reason;
189     }
190
191     
192     public Date getOperateAt() {
193         return operateAt;
194     }
195     
196     public Date getFinishedAt() {
197         return finishedAt;
198     }
199
200     @PrePersist
201     protected void onCreate() {
202         this.finishedAt = this.operateAt = new Date();
203     }
204     
205     @PreUpdate
206     protected void onUpdate() {
207         this.finishedAt = new Date();
208     }
209
210         @Override
211         public boolean equals(final Object other) {
212                 if (this == other) {
213                         return true;
214                 }
215                 if (!(other instanceof OperationStatus)) {
216                         return false;
217                 }
218                 OperationStatus castOther = (OperationStatus) other;
219                 return Objects.equals(getServiceId(), castOther.getServiceId())
220                                 && Objects.equals(getOperationId(), castOther.getOperationId());
221         }
222
223         @Override
224         public int hashCode() {
225                 return Objects.hash(getServiceId(), getOperationId());
226         }
227
228         @Override
229         public String toString() {
230                 return new ToStringBuilder(this).append("serviceId", getServiceId()).append("operationId", getOperationId())
231                                 .append("operation", getOperation()).append("userId", getUserId()).append("result", getResult())
232                                 .append("operationContent", getOperationContent()).append("progress", getProgress())
233                                 .append("reason", getReason()).append("operateAt", getOperateAt()).append("finishedAt", getFinishedAt())
234                                 .toString();
235         }
236
237     
238
239 }