bf9d10d7464cb2b720d234589a20e3bbc3029cc7
[clamp.git] / src / main / java / org / onap / clamp / loop / common / AuditEntity.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2020 AT&T Intellectual Property. All rights
6  *                             reserved.
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  */
23
24 package org.onap.clamp.loop.common;
25
26 import com.google.gson.annotations.Expose;
27
28 import java.time.Instant;
29 import java.time.temporal.ChronoUnit;
30
31 import javax.persistence.Column;
32 import javax.persistence.EntityListeners;
33 import javax.persistence.MappedSuperclass;
34
35 import org.springframework.data.annotation.CreatedBy;
36 import org.springframework.data.annotation.CreatedDate;
37 import org.springframework.data.annotation.LastModifiedBy;
38 import org.springframework.data.annotation.LastModifiedDate;
39 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
40
41 /**
42  * This class is the parent of the hibernate entities requiring to be audited.
43  *
44  */
45 @MappedSuperclass
46 @EntityListeners(AuditingEntityListener.class)
47 public class AuditEntity {
48
49     @Expose
50     @CreatedDate
51     @Column(name = "created_timestamp", nullable = false, updatable = false)
52     private Instant createdDate;
53
54     @Expose
55     @LastModifiedDate
56     @Column(name = "updated_timestamp", nullable = false)
57     private Instant updatedDate;
58
59     @Expose
60     @LastModifiedBy
61     @Column(name = "updated_by")
62     private String updatedBy;
63
64     @Expose
65     @CreatedBy
66     @Column(name = "created_by")
67     private String createdBy;
68
69     public Instant getCreatedDate() {
70         return createdDate;
71     }
72
73     /**
74      * createdDate setter.
75      * 
76      * @param createdDate The created Date object
77      */
78     public void setCreatedDate(Instant createdDate) {
79         if (createdDate != null) {
80             this.createdDate = createdDate.truncatedTo(ChronoUnit.SECONDS);
81         } else {
82             this.createdDate = null;
83         }
84     }
85
86     /**
87      * updatedDate getter.
88      * 
89      * @return the updatedDate
90      */
91     public Instant getUpdatedDate() {
92         return updatedDate;
93     }
94
95     /**
96      * updatedDate setter.
97      * 
98      * @param updatedDate updatedDate to set
99      */
100     public void setUpdatedDate(Instant updatedDate) {
101         if (updatedDate != null) {
102             this.updatedDate = updatedDate.truncatedTo(ChronoUnit.SECONDS);
103         } else {
104             this.updatedDate = null;
105         }
106     }
107
108     /**
109      * updatedBy getter.
110      * 
111      * @return the updatedBy
112      */
113     public String getUpdatedBy() {
114         return updatedBy;
115     }
116
117     /**
118      * updatedBy setter.
119      * 
120      * @param updatedBy the updatedBy
121      */
122     public void setUpdatedBy(String updatedBy) {
123         this.updatedBy = updatedBy;
124     }
125
126     /**
127      * createdBy getter.
128      * 
129      * @return the createdBy
130      */
131     public String getCreatedBy() {
132         return createdBy;
133     }
134
135     /**
136      * createdBy setter.
137      * 
138      * @param createdBy the createdBy to set
139      */
140     public void setCreatedBy(String createdBy) {
141         this.createdBy = createdBy;
142     }
143
144     /**
145      * Empty constructor.
146      */
147     public AuditEntity() {
148     }
149
150 }