Add template and tosca model entities and repositories
[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 @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     public void setCreatedDate(Instant createdDate) {
70         if (createdDate != null) {
71             this.createdDate = createdDate.truncatedTo(ChronoUnit.SECONDS);
72         } else {
73             this.createdDate = null;
74         }
75     }
76
77     public Instant getUpdatedDate() {
78         return updatedDate;
79     }
80
81     public void setUpdatedDate(Instant updatedDate) {
82         if (updatedDate != null) {
83             this.updatedDate = updatedDate.truncatedTo(ChronoUnit.SECONDS);
84         } else {
85             this.updatedDate = null;
86         }
87     }
88
89     public String getUpdatedBy() {
90         return updatedBy;
91     }
92
93     public void setUpdatedBy(String updatedBy) {
94         this.updatedBy = updatedBy;
95     }
96
97     public String getCreatedBy() {
98         return createdBy;
99     }
100
101     public void setCreatedBy(String createdBy) {
102         this.createdBy = createdBy;
103     }
104
105     public AuditEntity() {
106     }
107
108 }