1c1c3f4fe3c876c2475362b134dc5a6d266f1b7d
[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  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.policy.rest.jpa;
21 /*
22  */
23 import java.io.Serializable;
24 import java.util.Date;
25 import java.util.Objects;
26
27 import javax.persistence.Column;
28 import javax.persistence.Entity;
29 import javax.persistence.GeneratedValue;
30 import javax.persistence.GenerationType;
31 import javax.persistence.Id;
32 import javax.persistence.Lob;
33 import javax.persistence.NamedQueries;
34 import javax.persistence.NamedQuery;
35 import javax.persistence.PrePersist;
36 import javax.persistence.PreUpdate;
37 import javax.persistence.Table;
38 import javax.persistence.Temporal;
39 import javax.persistence.TemporalType;
40 import javax.persistence.Version;
41 /*
42  * The Entity class to persist a policy object Action Body
43  */
44
45
46 import com.fasterxml.jackson.annotation.JsonBackReference;
47
48 @Entity
49 @Table(name="ActionBodyEntity")
50 @NamedQueries({
51         @NamedQuery(name=" ActionBodyEntity.findAll", query="SELECT e FROM ActionBodyEntity e "),
52         @NamedQuery(name="ActionBodyEntity.deleteAll", query="DELETE FROM ActionBodyEntity WHERE 1=1")
53 })
54
55 public class ActionBodyEntity implements Serializable {
56         private static final long serialVersionUID = 1L;
57
58         @Id
59         @GeneratedValue(strategy = GenerationType.AUTO)
60         @Column(name="actionBodyId")
61         @JsonBackReference
62         private long actionBodyId;
63         
64         @Column(name="actionBodyName", nullable=false, length=255)
65         private String actionBodyName = "";
66         
67         @Version 
68         @Column(name="version")
69         private int version;
70         
71         @Lob
72         @Column(name="actionBody", nullable=false, columnDefinition="TEXT")
73         private String actionBody = "NoBody";
74         
75         @Column(name="created_by", nullable=false, length=255)
76         private String createdBy = "guest";
77
78         @Temporal(TemporalType.TIMESTAMP)
79         @Column(name="created_date", updatable=false)
80         private Date createdDate;
81
82         @Column(name="modified_by", nullable=false, length=255)
83         private String modifiedBy = "guest";
84
85         @Temporal(TemporalType.TIMESTAMP)
86         @Column(name="modified_date", nullable=false)
87         private Date modifiedDate;
88         
89         @Column(name="deleted", nullable=false)
90         private boolean deleted = false;
91
92         public ActionBodyEntity() {
93         }
94
95         @PrePersist
96         public void     prePersist() {
97                 Date date = new Date();
98                 this.createdDate = date;
99                 this.modifiedDate = date;
100         }
101
102         @PreUpdate
103         public void preUpdate() {
104                 this.modifiedDate = new Date();
105         }
106         /**
107          * @return the configurationDataId
108          */
109         public long getActionBodyId() {
110                 return actionBodyId;
111         }
112         /**
113          * @param configurationDataId the configurationDataId to set
114          */
115         public void setActionBodyName(String name) {
116                 this.actionBodyName = name;
117         }
118         public String getActionBodyName(){
119                 return this.actionBodyName;
120         }
121         
122         /**
123          * @return the actionBody
124          */
125         public String getActionBody() {
126                 return actionBody;
127         }
128         /**
129          * @param configBody the configBody to set
130          */
131         public void setActionBody(String body) {
132                 this.actionBody = body;
133         }
134         /**
135          * @return the createdBy
136          */
137         public String getCreatedBy() {
138                 return createdBy;
139         }
140         /**
141          * @param createdBy the createdBy to set
142          */
143         public void setCreatedBy(String createdBy) {
144                 this.createdBy = createdBy;
145         }
146         
147         /**
148          * @return the modifiedBy
149          */
150         public String getModifiedBy() {
151                 return modifiedBy;
152         }
153         /**
154          * @param modifiedBy the modifiedBy to set
155          */
156         public void setModifiedBy(String modifiedBy) {
157                 this.modifiedBy = modifiedBy;
158         }
159         /**
160          * @return the modifiedDate
161          */
162         public Date getModifiedDate() {
163                 return modifiedDate;
164         }
165         /**
166          * @param modifiedDate the modifiedDate to set
167          */
168         public void setModifiedDate(Date modifiedDate) {
169                 this.modifiedDate = modifiedDate;
170         }
171         /**
172          * @return the version
173          */
174         public int getVersion() {
175                 return version;
176         }
177         /**
178          * @return the createdDate
179          */
180         public Date getCreatedDate() {
181                 return createdDate;
182         }
183
184         /**
185          * @return the deleted
186          */
187         public boolean isDeleted() {
188                 return deleted;
189         }
190
191         /**
192          * @param deleted the deleted to set
193          */
194         public void setDeleted(boolean deleted) {
195                 this.deleted = deleted;
196         }
197         
198         @Override
199         public int hashCode() {
200         return Objects.hash(actionBodyId, actionBodyName, version, actionBody,
201                         createdBy, createdDate, modifiedBy, modifiedDate, deleted);
202         }
203
204         @Override
205         public boolean equals(Object obj) {
206                 if(obj == null){
207                         return false;
208                 }
209                 if(obj == this){
210                         return true;
211                 }
212                 if(!(obj instanceof ActionBodyEntity)){
213                         return false;
214                 }
215
216                 return (
217                                 actionBodyId == ((ActionBodyEntity) obj).actionBodyId &&
218                                 actionBodyName.equals(((ActionBodyEntity) obj).actionBodyName) && 
219                                 version == ((ActionBodyEntity) obj).version && 
220                                 actionBody.equals(((ActionBodyEntity) obj).actionBody) && 
221                                 createdBy.equals(((ActionBodyEntity) obj).createdBy) && 
222                                 createdDate.equals(((ActionBodyEntity) obj).createdDate) && 
223                                 modifiedBy.equals(((ActionBodyEntity) obj).modifiedBy) &&
224                                 modifiedDate.equals(((ActionBodyEntity) obj).modifiedDate) &&
225                                 deleted == ((ActionBodyEntity) obj).deleted
226                                 );
227         }
228 }