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.Data;
45
46 /*
47  * The Entity class to persist a policy object Action Body
48  */
49 // @formatter:off
50 @Entity
51 @Table(name = "ActionBodyEntity")
52 @NamedQueries(
53     {
54         @NamedQuery(name = " ActionBodyEntity.findAll", query = "SELECT e FROM ActionBodyEntity e "),
55         @NamedQuery(name = "ActionBodyEntity.deleteAll", query = "DELETE FROM ActionBodyEntity WHERE 1=1")
56     }
57 )
58 @Data
59 //@foramtter:on
60
61 public class ActionBodyEntity implements Serializable {
62     private static final long serialVersionUID = 1L;
63
64     @Id
65     @GeneratedValue(strategy = GenerationType.AUTO)
66     @Column(name = "actionBodyId")
67     @JsonBackReference
68     private long actionBodyId;
69
70     @Column(name = "actionBodyName", nullable = false, length = 255)
71     private String actionBodyName = "";
72
73     @Version
74     @Column(name = "version")
75     private int version;
76
77     @Lob
78     @Column(name = "actionBody", nullable = false, columnDefinition = "TEXT")
79     private String actionBody = "NoBody";
80
81     @Column(name = "created_by", nullable = false, length = 255)
82     private String createdBy = "guest";
83
84     @Temporal(TemporalType.TIMESTAMP)
85     @Column(name = "created_date", updatable = false)
86     private Date createdDate;
87
88     @Column(name = "modified_by", nullable = false, length = 255)
89     private String modifiedBy = "guest";
90
91     @Temporal(TemporalType.TIMESTAMP)
92     @Column(name = "modified_date", nullable = false)
93     private Date modifiedDate;
94
95     @Column(name = "deleted", nullable = false)
96     private boolean deleted = false;
97
98     public ActionBodyEntity() {
99         // An empty constructor
100     }
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 }