61426799092a3b2f742b9adea3b20bb228d3b642
[vid.git] / vid-app-common / src / main / java / org / onap / vid / model / JobAuditStatus.java
1 package org.onap.vid.model;
2
3 import org.apache.commons.lang3.builder.EqualsBuilder;
4 import org.apache.commons.lang3.builder.HashCodeBuilder;
5 import org.hibernate.annotations.Type;
6 import org.onap.vid.job.Job.JobStatus;
7 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
8
9 import javax.persistence.*;
10 import java.util.Date;
11 import java.util.UUID;
12
13 @Entity
14 @Table(name = "vid_job_audit_status")
15 public class JobAuditStatus extends VidBaseEntity {
16
17     static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(JobAuditStatus.class);
18
19     public JobAuditStatus(){}
20
21     public JobAuditStatus(UUID jobId, String jobStatus, SourceStatus source){
22         this.jobId = jobId;
23         this.jobStatus = jobStatus;
24         this.source = source;
25     }
26
27     public JobAuditStatus(UUID jobId, String jobStatus, SourceStatus source, Date date){
28         this(jobId, jobStatus, source);
29         this.created = date;
30     }
31
32     public JobAuditStatus(UUID jobId, String jobStatus, SourceStatus source, UUID requestId, String additionalInfo) {
33         this(jobId, jobStatus, source);
34         this.requestId = requestId;
35         this.additionalInfo = additionalInfo;
36     }
37
38     public JobAuditStatus(UUID jobId, String jobStatus, SourceStatus source, UUID requestId, String additionalInfo, Date date){
39         this(jobId, jobStatus, source, requestId, additionalInfo);
40         this.created = date;
41     }
42
43     @Override
44     public boolean equals(Object o) {
45         if (this == o) return true;
46
47         if (o == null || getClass() != o.getClass()) return false;
48
49         JobAuditStatus that = (JobAuditStatus) o;
50
51         return new EqualsBuilder()
52                 .append(jobId, that.jobId)
53                 .append(jobStatus, that.jobStatus)
54                 .append(source, that.source)
55                 .append(requestId, that.requestId)
56                 .append(additionalInfo, that.additionalInfo)
57                 .isEquals();
58     }
59
60     @Override
61     public int hashCode() {
62         return new HashCodeBuilder(17, 37)
63                 .append(jobId)
64                 .append(jobStatus)
65                 .append(source)
66                 .append(requestId)
67                 .append(additionalInfo)
68                 .toHashCode();
69     }
70
71     public enum SourceStatus {
72         MSO,
73         VID
74     }
75
76     private UUID jobId;
77     private String jobStatus;
78     private SourceStatus source;
79     private UUID requestId;
80     private String additionalInfo;
81
82     @Id
83     @GeneratedValue(strategy = GenerationType.IDENTITY)
84     @Override
85     @Column(name = "ID", columnDefinition = "INT(11)")
86     public Long getId() {
87         return this.id;
88     }
89
90     @Column(name = "JOB_ID", columnDefinition = "CHAR(36)")
91     @Type(type="org.hibernate.type.UUIDCharType")
92     public UUID getJobId() {
93         return jobId;
94     }
95
96     public void setJobId(UUID jobId) {
97         this.jobId = jobId;
98     }
99
100
101     @Column(name = "JOB_STATUS")
102     public String getJobStatus() {
103         return jobStatus;
104     }
105
106     public void setJobStatus(String jobStatus) {
107         this.jobStatus = jobStatus;
108     }
109
110
111     @Enumerated(EnumType.STRING)
112     @Column(name = "SOURCE")
113     public SourceStatus getSource() {
114         return source;
115     }
116
117     public void setSource(SourceStatus source) {
118         this.source = source;
119     }
120
121     @Column(name = "REQUEST_ID", columnDefinition = "CHAR(36)")
122     @Type(type="org.hibernate.type.UUIDCharType")
123     public UUID getRequestId() {
124         return requestId;
125     }
126
127     public void setRequestId(UUID requestId) {
128         this.requestId = requestId;
129     }
130
131     @Column(name = "ADDITIONAL_INFO")
132     public String getAdditionalInfo() {
133         return additionalInfo;
134     }
135
136     public void setAdditionalInfo(String additionalInfo) {
137         this.additionalInfo = additionalInfo;
138     }
139
140     @Transient
141     public Boolean isFinal(){
142         try {
143             if (getSource() == SourceStatus.VID) {
144                 return JobStatus.valueOf(getJobStatus()).isFinal();
145             }
146         }
147         catch (IllegalArgumentException e){
148             logger.error("JobStatus: " + getJobStatus() + " from vid isn't a value of JobStatus enum" + e.getMessage());
149             return false;
150         }
151         return false;
152     }
153
154     @Transient
155     public Date getCreatedDate() {
156         return getCreated();
157     }
158
159 }