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