JUnit/SONAR/Checkstyle in ONAP-REST
[policy/engine.git] / ONAP-REST / src / main / java / org / onap / policy / rest / jpa / ActionBodyEntity.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-REST
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2019 Nordix Foundation.
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 package org.onap.policy.rest.jpa;
23
24 import com.fasterxml.jackson.annotation.JsonBackReference;
25
26 import java.io.Serializable;
27 import java.util.Date;
28
29 import javax.persistence.Column;
30 import javax.persistence.Entity;
31 import javax.persistence.GeneratedValue;
32 import javax.persistence.GenerationType;
33 import javax.persistence.Id;
34 import javax.persistence.Lob;
35 import javax.persistence.NamedQueries;
36 import javax.persistence.NamedQuery;
37 import javax.persistence.PrePersist;
38 import javax.persistence.PreUpdate;
39 import javax.persistence.Table;
40 import javax.persistence.Temporal;
41 import javax.persistence.TemporalType;
42 import javax.persistence.Version;
43
44 import lombok.Getter;
45 import lombok.NoArgsConstructor;
46 import lombok.Setter;
47
48 /*
49  * The Entity class to persist a policy object Action Body
50  */
51 // @formatter:off
52 @Entity
53 @Table(name = "ActionBodyEntity")
54 @NamedQueries(
55     {
56         @NamedQuery(name = " ActionBodyEntity.findAll", query = "SELECT e FROM ActionBodyEntity e "),
57         @NamedQuery(name = "ActionBodyEntity.deleteAll", query = "DELETE FROM ActionBodyEntity WHERE 1=1")
58     }
59 )
60 @Getter
61 @Setter
62 @NoArgsConstructor
63 // @foramtter:on
64
65 public class ActionBodyEntity implements Serializable {
66     private static final long serialVersionUID = 1L;
67
68     @Id
69     @GeneratedValue(strategy = GenerationType.AUTO)
70     @Column(name = "actionBodyId")
71     @JsonBackReference
72     private long actionBodyId;
73
74     @Column(name = "actionBodyName", nullable = false, length = 255)
75     private String actionBodyName = "";
76
77     @Version
78     @Column(name = "version")
79     private int version;
80
81     @Lob
82     @Column(name = "actionBody", nullable = false, columnDefinition = "TEXT")
83     private String actionBody = "NoBody";
84
85     @Column(name = "created_by", nullable = false, length = 255)
86     private String createdBy = "guest";
87
88     @Temporal(TemporalType.TIMESTAMP)
89     @Column(name = "created_date", updatable = false)
90     private Date createdDate;
91
92     @Column(name = "modified_by", nullable = false, length = 255)
93     private String modifiedBy = "guest";
94
95     @Temporal(TemporalType.TIMESTAMP)
96     @Column(name = "modified_date", nullable = false)
97     private Date modifiedDate;
98
99     @Column(name = "deleted", nullable = false)
100     private boolean deleted = false;
101
102     /**
103      * Called before an instance is persisted.
104      */
105     @PrePersist
106     public void prePersist() {
107         Date date = new Date();
108         this.createdDate = date;
109         this.modifiedDate = date;
110     }
111
112     /**
113      * Called before an instance is updated.
114      */
115     @PreUpdate
116     public void preUpdate() {
117         this.modifiedDate = new Date();
118     }
119 }