ce2487ea9dca557cc17cef3e6ebee2e8d682a254
[so.git] / so-etsi-nfvo / so-etsi-nfvo-ns-lcm / so-etsi-nfvo-ns-lcm-database-service / src / main / java / org / onap / so / etsi / nfvo / ns / lcm / database / beans / NfvoJob.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.so.etsi.nfvo.ns.lcm.database.beans;
21
22 import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils.Utils.toIndentedString;
23 import java.time.LocalDateTime;
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.Objects;
27 import java.util.UUID;
28 import javax.persistence.CascadeType;
29 import javax.persistence.Column;
30 import javax.persistence.Entity;
31 import javax.persistence.EnumType;
32 import javax.persistence.Enumerated;
33 import javax.persistence.FetchType;
34 import javax.persistence.Id;
35 import javax.persistence.OneToMany;
36 import javax.persistence.Table;
37 import org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils.Utils;
38
39
40 @Entity
41 @Table(name = "JOB")
42 public class NfvoJob {
43
44     @Id
45     @Column(name = "JOB_ID")
46     private String jobId;
47
48     @Column(name = "JOB_TYPE")
49     private String jobType;
50
51     @Enumerated(EnumType.STRING)
52     @Column(name = "JOB_ACTION")
53     private JobAction jobAction;
54
55     @Column(name = "RESOURCE_ID")
56     private String resourceId;
57
58     @Column(name = "RESOURCE_NAME")
59     private String resourceName;
60
61     @Enumerated(EnumType.STRING)
62     @Column(name = "STATUS")
63     private JobStatusEnum status;
64
65     @Column(name = "START_TIME")
66     private LocalDateTime startTime;
67
68     @Column(name = "END_TIME")
69     private LocalDateTime endTime;
70
71     @Column(name = "PROGRESS")
72     private int progress;
73
74     @Column(name = "PROCESS_INSTANCE_ID")
75     private String processInstanceId;
76
77     @OneToMany(mappedBy = "nfvoJob", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
78     private List<NfvoJobStatus> nfvoJobStatuses = new ArrayList<>();
79
80     public NfvoJob() {
81         this.jobId = UUID.randomUUID().toString();
82     }
83
84     public void setJobId(final String jobId) {
85         this.jobId = jobId;
86     }
87
88     public String getJobId() {
89         return jobId;
90     }
91
92     public NfvoJob jobId(final String jobId) {
93         this.jobId = jobId;
94         return this;
95     }
96
97     public String getJobType() {
98         return jobType;
99     }
100
101     public void setJobType(final String jobType) {
102         this.jobType = jobType;
103     }
104
105     public NfvoJob jobType(final String jobType) {
106         this.jobType = jobType;
107         return this;
108     }
109
110     public JobAction getJobAction() {
111         return jobAction;
112     }
113
114     public void setJobAction(final JobAction jobAction) {
115         this.jobAction = jobAction;
116     }
117
118     public NfvoJob jobAction(final JobAction jobAction) {
119         this.jobAction = jobAction;
120         return this;
121     }
122
123     public String getResourceId() {
124         return resourceId;
125     }
126
127     public void setResourceId(final String resourceId) {
128         this.resourceId = resourceId;
129     }
130
131     public NfvoJob resourceId(final String resourceId) {
132         this.resourceId = resourceId;
133         return this;
134     }
135
136     public JobStatusEnum getStatus() {
137         return status;
138     }
139
140     public void setStatus(final JobStatusEnum status) {
141         this.status = status;
142     }
143
144     public NfvoJob status(final JobStatusEnum status) {
145         this.status = status;
146         return this;
147     }
148
149     public LocalDateTime getStartTime() {
150         return startTime;
151     }
152
153     public void setStartTime(final LocalDateTime startTime) {
154         this.startTime = startTime;
155     }
156
157     public NfvoJob startTime(final LocalDateTime startTime) {
158         this.startTime = startTime;
159         return this;
160     }
161
162     public LocalDateTime getEndTime() {
163         return endTime;
164     }
165
166     public void setEndTime(final LocalDateTime endTime) {
167         this.endTime = endTime;
168     }
169
170     public NfvoJob endTime(final LocalDateTime endTime) {
171         this.endTime = endTime;
172         return this;
173     }
174
175     public int getProgress() {
176         return progress;
177     }
178
179     public void setProgress(final int progress) {
180         this.progress = progress;
181     }
182
183     public NfvoJob progress(final int progress) {
184         this.progress = progress;
185         return this;
186     }
187
188     public String getProcessInstanceId() {
189         return processInstanceId;
190     }
191
192     public void setProcessInstanceId(final String processInstanceId) {
193         this.processInstanceId = processInstanceId;
194     }
195
196     public NfvoJob processInstanceId(final String processInstanceId) {
197         this.processInstanceId = processInstanceId;
198         return this;
199     }
200
201     public String getResourceName() {
202         return resourceName;
203     }
204
205     public void setResourceName(final String resourceName) {
206         this.resourceName = resourceName;
207     }
208
209     public NfvoJob resourceName(final String resourceName) {
210         this.resourceName = resourceName;
211         return this;
212     }
213
214     public List<NfvoJobStatus> getNfvoJobStatuses() {
215         return nfvoJobStatuses;
216     }
217
218     public void setJobStatuses(final List<NfvoJobStatus> nfvoJobStatuses) {
219         this.nfvoJobStatuses = nfvoJobStatuses;
220     }
221
222     public NfvoJob nfvoJobStatuses(final List<NfvoJobStatus> nfvoJobStatuses) {
223         this.nfvoJobStatuses = nfvoJobStatuses;
224         return this;
225     }
226
227     public NfvoJob nfvoJobStatus(final NfvoJobStatus nfvoJobStatus) {
228         nfvoJobStatus.setNfvoJob(this);
229         this.nfvoJobStatuses.add(nfvoJobStatus);
230         return this;
231     }
232
233     @Override
234     public int hashCode() {
235         return Objects.hash(jobId, processInstanceId, jobType, jobAction, startTime, endTime, status, progress,
236                 resourceId, resourceName, nfvoJobStatuses);
237     }
238
239     @Override
240     public boolean equals(final Object obj) {
241         if (this == obj)
242             return true;
243         if (obj == null || getClass() != obj.getClass())
244             return false;
245         if (obj instanceof NfvoJob) {
246             final NfvoJob other = (NfvoJob) obj;
247             return Objects.equals(jobId, other.jobId) && Objects.equals(processInstanceId, other.processInstanceId)
248                     && Objects.equals(jobType, other.jobType) && Objects.equals(jobAction, other.jobAction)
249                     && Objects.equals(progress, other.progress) && Objects.equals(status, other.status)
250                     && Objects.equals(startTime, other.startTime) && Objects.equals(endTime, other.endTime)
251                     && Objects.equals(resourceId, other.resourceId) && Objects.equals(resourceName, other.resourceName)
252                     && Utils.isEquals(nfvoJobStatuses, other.nfvoJobStatuses);
253         }
254         return false;
255     }
256
257     @Override
258     public String toString() {
259         final StringBuilder sb = new StringBuilder();
260         sb.append("class NfvoJob {\n");
261         sb.append("    jobId: ").append(toIndentedString(jobId)).append("\n");
262         sb.append("    processInstanceId: ").append(toIndentedString(processInstanceId)).append("\n");
263         sb.append("    jobType: ").append(toIndentedString(jobType)).append("\n");
264         sb.append("    jobAction: ").append(toIndentedString(jobAction)).append("\n");
265         sb.append("    progress: ").append(toIndentedString(progress)).append("\n");
266         sb.append("    status: ").append(toIndentedString(status)).append("\n");
267         sb.append("    startTime: ").append(toIndentedString(startTime)).append("\n");
268         sb.append("    endTime: ").append(toIndentedString(endTime)).append("\n");
269         sb.append("    resId: ").append(toIndentedString(resourceId)).append("\n");
270         sb.append("    resName: ").append(toIndentedString(resourceName)).append("\n");
271         sb.append("    nfvoJobStatuses: ").append(toIndentedString(nfvoJobStatuses)).append("\n");
272
273         sb.append("}");
274         return sb.toString();
275     }
276
277 }