Fix console issues
[policy/engine.git] / ONAP-REST / src / main / java / org / onap / policy / rest / jpa / PolicyEntity.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
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.JoinColumn;
33 import javax.persistence.Lob;
34 import javax.persistence.NamedQueries;
35 import javax.persistence.NamedQuery;
36 import javax.persistence.OneToOne;
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 com.fasterxml.jackson.annotation.JsonBackReference;
45 import com.fasterxml.jackson.annotation.JsonManagedReference;
46
47 /*
48  * The Entity class to persist a policy object and its configuration data
49  */
50
51 /**
52  *
53  */
54 @Entity
55 //Add a non-unique index and a constraint that says the combo of policyName and scopeId must be unique
56 @Table(name="PolicyEntity")
57
58 @NamedQueries({
59         @NamedQuery(name="PolicyEntity.findAll", query="SELECT e FROM PolicyEntity e "),
60         @NamedQuery(name="PolicyEntity.findAllByDeletedFlag", query="SELECT e FROM PolicyEntity e WHERE e.deleted = :deleted"),
61         @NamedQuery(name="PolicyEntity.FindById", query="SELECT e FROM PolicyEntity e WHERE e.policyId = :id"),
62         @NamedQuery(name="PolicyEntity.deleteAll", query="DELETE FROM PolicyEntity WHERE 1=1"),
63         @NamedQuery(name="PolicyEntity.findByNameAndScope", query="SELECT e FROM PolicyEntity e WHERE e.policyName = :name AND e.scope = :scope")
64 })
65
66 public class PolicyEntity implements Serializable {
67         private static final long serialVersionUID = 1L;
68
69         @Id
70         @GeneratedValue(strategy = GenerationType.AUTO)
71         @Column (name="policyId")
72         @JsonBackReference
73         private long policyId;
74
75         @Column(name="policyName", nullable=false, unique=false, length=255)
76         private String policyName;
77         
78         //The scope is the directory structure in dot notation.  For example: org.onap.myproject 
79         @Column(name="scope", nullable=false, unique=false, length=255)
80         private String scope;
81         
82         @Version 
83         @Column(name="version")
84         private int version;
85         
86         //not going to be used
87         @Column(name="policyVersion")
88         private int policyVersion = 0;
89         
90         @Lob
91         @Column(name="policyData", nullable=false, columnDefinition="TEXT")
92         private String policyData = "NoData";
93
94         @OneToOne(optional=true, orphanRemoval=true)
95         @JoinColumn(name="configurationDataId")
96         @JsonManagedReference
97         private ConfigurationDataEntity configurationDataEntity;
98         
99         @OneToOne(optional=true, orphanRemoval=true)
100         @JoinColumn(name="actionBodyId")
101         @JsonManagedReference
102         private ActionBodyEntity actionBodyEntity;
103         
104         @Column(name="created_by", nullable=false, length=255)
105         private String createdBy = "guest";
106
107         @Temporal(TemporalType.TIMESTAMP)
108         @Column(name="created_date", updatable=false)
109         private Date createdDate;
110
111         @Column(name="description", nullable=false, length=2048)
112         private String description = "NoDescription";
113
114         @Column(name="modified_by", nullable=false, length=255)
115         private String modifiedBy = "guest";
116
117         @Temporal(TemporalType.TIMESTAMP)
118         @Column(name="modified_date", nullable=false)
119         private Date modifiedDate;
120         
121         @Column(name="deleted", nullable=false)
122         private boolean deleted = false;
123
124         public PolicyEntity() {
125                 super();
126         }
127
128         @PrePersist
129         public void     prePersist() {
130                 Date date = new Date();
131                 this.createdDate = date;
132                 this.modifiedDate = date;
133         }
134
135         @PreUpdate
136         public void preUpdate() {
137                 this.modifiedDate = new Date();         
138         }
139
140         /**
141          * @return the policyId
142          */
143         public long getPolicyId() {
144                 return policyId;
145         }
146
147         /**
148          * @param policyId cannot be set
149          */
150
151         public String getPolicyName() {
152                 return policyName;
153         }
154
155         public void setPolicyName(String policyName) {
156                 this.policyName = policyName;
157         }
158
159         /**
160          * @return the policyData
161          */
162         public String getPolicyData() {
163                 return policyData;
164         }
165
166         /**
167          * @param policyData the policyData to set
168          */
169         public void setPolicyData(String policyData) {
170                 this.policyData = policyData;
171         }
172
173         /**
174          * @return the configurationDataEntity
175          */
176         public ConfigurationDataEntity getConfigurationData() {
177                 return configurationDataEntity;
178         }
179
180         /**
181          * @param configurationDataEntity the configurationDataEntity to set
182          */
183         public void setConfigurationData(ConfigurationDataEntity configurationDataEntity) {
184                 this.configurationDataEntity = configurationDataEntity;
185         }
186
187         /**
188          * @return the actionBodyEntity
189          */
190         public ActionBodyEntity getActionBodyEntity() {
191                 return actionBodyEntity;
192         }
193
194         /**
195          * @param actionBodyEntity the actionBodyEntity to set
196          */
197         public void setActionBodyEntity(ActionBodyEntity actionBodyEntity) {
198                 this.actionBodyEntity = actionBodyEntity;
199         }
200
201         /**
202          * @return the scope
203          */
204         public String getScope() {
205                 return scope;
206         }
207
208         /**
209          * @param scope the scope to set
210          */
211         public void setScope(String scope) {
212                 this.scope = scope;
213         }
214
215         /**
216          * @return the createdBy
217          */
218         public String getCreatedBy() {
219                 return createdBy;
220         }
221
222         /**
223          * @param createdBy the createdBy to set
224          */
225         public void setCreatedBy(String createdBy) {
226                 this.createdBy = createdBy;
227         }
228
229         /**
230          * @return the description
231          */
232         public String getDescription() {
233                 return description;
234         }
235
236         /**
237          * @param description the description to set
238          */
239         public void setDescription(String description) {
240                 this.description = description;
241         }
242
243         /**
244          * @return the modifiedBy
245          */
246         public String getModifiedBy() {
247                 return modifiedBy;
248         }
249
250         /**
251          * @param modifiedBy the modifiedBy to set
252          */
253         public void setModifiedBy(String modifiedBy) {
254                 this.modifiedBy = modifiedBy;
255         }
256
257         /**
258          * @return the version
259          */
260         public int getVersion() {
261                 return version;
262         }
263
264         /**
265          * @return the createdDate
266          */
267         public Date getCreatedDate() {
268                 return createdDate;
269         }
270
271         /**
272          * @return the modifiedDate
273          */
274         public Date getModifiedDate() {
275                 return modifiedDate;
276         }
277
278         /**
279          * @return the deleted
280          */
281         public boolean isDeleted() {
282                 return deleted;
283         }
284
285         /**
286          * @param deleted the deleted to set
287          */
288         public void setDeleted(boolean deleted) {
289                 this.deleted = deleted;
290         }
291
292
293 }