Merge "Add fix for SQL injection."
[policy/engine.git] / ONAP-REST / src / main / java / org / onap / policy / rest / jpa / ConfigurationDataEntity.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
21 package org.onap.policy.rest.jpa;
22 /*
23  */
24 import java.io.Serializable;
25 import java.util.Date;
26 import java.util.Objects;
27
28 import javax.persistence.Column;
29 import javax.persistence.Entity;
30 import javax.persistence.GeneratedValue;
31 import javax.persistence.GenerationType;
32 import javax.persistence.Id;
33 import javax.persistence.Lob;
34 import javax.persistence.NamedQueries;
35 import javax.persistence.NamedQuery;
36 import javax.persistence.PrePersist;
37 import javax.persistence.PreUpdate;
38 import javax.persistence.Table;
39 import javax.persistence.Temporal;
40 import javax.persistence.TemporalType;
41 import javax.persistence.Version;
42 /*
43  * The Entity class to persist a policy object configuration data
44  */
45
46
47 import com.fasterxml.jackson.annotation.JsonBackReference;
48
49 @Entity
50 @Table(name="ConfigurationDataEntity")
51 @NamedQueries({
52         @NamedQuery(name="ConfigurationDataEntity.findAll", query="SELECT e FROM ConfigurationDataEntity e "),
53         @NamedQuery(name="ConfigurationDataEntity.deleteAll", query="DELETE FROM ConfigurationDataEntity WHERE 1=1")
54 })
55
56 public class ConfigurationDataEntity implements Serializable {
57         private static final long serialVersionUID = 1L;
58
59         @Id
60         @GeneratedValue(strategy = GenerationType.AUTO)
61         @Column(name="configurationDataId")
62         @JsonBackReference
63         private long configurationDataId;
64         
65         @Column(name="configurationName", nullable=false, length=255)
66         private String configurationName = "";
67         
68         @Version 
69         @Column(name="version")
70         private int version;
71         
72         @Column(name="configType", nullable=false, length=255)
73         private String configType = "NoType";
74         
75         @Lob
76         @Column(name="configBody", nullable=false, columnDefinition="TEXT")
77         private String configBody = "NoBody";
78         
79         @Column(name="created_by", nullable=false, length=255)
80         private String createdBy = "guest";
81
82         @Temporal(TemporalType.TIMESTAMP)
83         @Column(name="created_date", updatable=false)
84         private Date createdDate;
85
86         @Column(name="description", nullable=false, length=2048)
87         private String description = "NoDescription";
88
89         @Column(name="modified_by", nullable=false, length=255)
90         private String modifiedBy = "guest";
91
92         @Temporal(TemporalType.TIMESTAMP)
93         @Column(name="modified_date", nullable=false)
94         private Date modifiedDate;
95         
96         @Column(name="deleted", nullable=false)
97         private boolean deleted = false;
98
99         public ConfigurationDataEntity() {
100         }
101
102         @PrePersist
103         public void     prePersist() {
104                 Date date = new Date();
105                 this.createdDate = date;
106                 this.modifiedDate = date;
107         }
108
109         @PreUpdate
110         public void preUpdate() {
111                 this.modifiedDate = new Date();
112         }
113         /**
114          * @return the configurationDataId
115          */
116         public long getConfigurationDataId() {
117                 return configurationDataId;
118         }
119         /**
120          * @param configurationDataId the configurationDataId to set
121          */
122         public void setConfigurationName(String configurationName) {
123                 this.configurationName = configurationName;
124         }
125         public String getConfigurationName(){
126                 return this.configurationName;
127         }
128         /**
129          * @return the configType
130          */
131         public String getConfigType() {
132                 return configType;
133         }
134         /**
135          * @param configType the configType to set
136          */
137         public void setConfigType(String configType) {
138                 this.configType = configType;
139         }
140         /**
141          * @return the configBody
142          */
143         public String getConfigBody() {
144                 return configBody;
145         }
146         /**
147          * @param configBody the configBody to set
148          */
149         public void setConfigBody(String configBody) {
150                 this.configBody = configBody;
151         }
152         /**
153          * @return the createdBy
154          */
155         public String getCreatedBy() {
156                 return createdBy;
157         }
158         /**
159          * @param createdBy the createdBy to set
160          */
161         public void setCreatedBy(String createdBy) {
162                 this.createdBy = createdBy;
163         }
164         /**
165          * @return the description
166          */
167         public String getDescription() {
168                 return description;
169         }
170         /**
171          * @param description the description to set
172          */
173         public void setDescription(String description) {
174                 this.description = description;
175         }
176         /**
177          * @return the modifiedBy
178          */
179         public String getModifiedBy() {
180                 return modifiedBy;
181         }
182         /**
183          * @param modifiedBy the modifiedBy to set
184          */
185         public void setModifiedBy(String modifiedBy) {
186                 this.modifiedBy = modifiedBy;
187         }
188         /**
189          * @return the modifiedDate
190          */
191         public Date getModifiedDate() {
192                 return modifiedDate;
193         }
194         /**
195          * @param modifiedDate the modifiedDate to set
196          */
197         public void setModifiedDate(Date modifiedDate) {
198                 this.modifiedDate = modifiedDate;
199         }
200         /**
201          * @return the version
202          */
203         public int getVersion() {
204                 return version;
205         }
206         /**
207          * @return the createdDate
208          */
209         public Date getCreatedDate() {
210                 return createdDate;
211         }
212
213         /**
214          * @return the deleted
215          */
216         public boolean isDeleted() {
217                 return deleted;
218         }
219
220         /**
221          * @param deleted the deleted to set
222          */
223         public void setDeleted(boolean deleted) {
224                 this.deleted = deleted;
225         }
226         
227         @Override
228         public int hashCode() {
229         return Objects.hash(configurationDataId, configurationName,     version, configType,
230                         configBody, createdBy, createdDate, description, modifiedBy, modifiedDate, deleted);
231         }
232
233         @Override
234         public boolean equals(Object obj) {
235                 if(obj == null){
236                         return false;
237                 }
238                 if(obj == this){
239                         return true;
240                 }
241                 if(!(obj instanceof ConfigurationDataEntity)){
242                         return false;
243                 }
244                 
245                 return (
246                                 configurationDataId == ((ConfigurationDataEntity) obj).configurationDataId &&   
247                                 configurationName.equals(((ConfigurationDataEntity) obj).configurationName) && 
248                                 version == ((ConfigurationDataEntity) obj).version &&
249                                 configType.equals(((ConfigurationDataEntity) obj).configType) &&
250                                 configBody.equals(((ConfigurationDataEntity) obj).configBody) &&
251                                 createdBy.equals(((ConfigurationDataEntity) obj).createdBy) &&
252                                 createdDate.equals(((ConfigurationDataEntity) obj).createdDate) &&
253                                 description.equals(((ConfigurationDataEntity) obj).description) &&
254                                 modifiedBy.equals(((ConfigurationDataEntity) obj).modifiedBy) &&
255                                 modifiedDate.equals(((ConfigurationDataEntity) obj).modifiedDate) &&
256                                 deleted == ((ConfigurationDataEntity) obj).deleted
257                                 );
258         }
259 }