[POLICY-73] replace openecomp for policy-engine
[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         public void resetPolicyVersion(){
142                 this.policyVersion = 1;
143         }
144         public void advancePolicyVersion(){
145                 this.policyVersion++;
146         }
147         public int getPolicyVersion(){
148                 return this.policyVersion;
149         }
150         public void setPolicyVersion(int polVer){
151                 this.policyVersion = polVer;
152         }
153         */
154
155         /**
156          * @return the policyId
157          */
158         public long getPolicyId() {
159                 return policyId;
160         }
161
162         /**
163          * @param policyId cannot be set
164          */
165
166         public String getPolicyName() {
167                 return policyName;
168         }
169
170         public void setPolicyName(String policyName) {
171                 this.policyName = policyName;
172         }
173
174         /**
175          * @return the policyData
176          */
177         public String getPolicyData() {
178                 return policyData;
179         }
180
181         /**
182          * @param policyData the policyData to set
183          */
184         public void setPolicyData(String policyData) {
185                 this.policyData = policyData;
186         }
187
188         /**
189          * @return the configurationDataEntity
190          */
191         public ConfigurationDataEntity getConfigurationData() {
192                 return configurationDataEntity;
193         }
194
195         /**
196          * @param configurationDataEntity the configurationDataEntity to set
197          */
198         public void setConfigurationData(ConfigurationDataEntity configurationDataEntity) {
199                 this.configurationDataEntity = configurationDataEntity;
200         }
201
202         /**
203          * @return the actionBodyEntity
204          */
205         public ActionBodyEntity getActionBodyEntity() {
206                 return actionBodyEntity;
207         }
208
209         /**
210          * @param actionBodyEntity the actionBodyEntity to set
211          */
212         public void setActionBodyEntity(ActionBodyEntity actionBodyEntity) {
213                 this.actionBodyEntity = actionBodyEntity;
214         }
215
216         /**
217          * @return the scope
218          */
219         public String getScope() {
220                 return scope;
221         }
222
223         /**
224          * @param scope the scope to set
225          */
226         public void setScope(String scope) {
227                 this.scope = scope;
228         }
229
230         /**
231          * @return the createdBy
232          */
233         public String getCreatedBy() {
234                 return createdBy;
235         }
236
237         /**
238          * @param createdBy the createdBy to set
239          */
240         public void setCreatedBy(String createdBy) {
241                 this.createdBy = createdBy;
242         }
243
244         /**
245          * @return the description
246          */
247         public String getDescription() {
248                 return description;
249         }
250
251         /**
252          * @param description the description to set
253          */
254         public void setDescription(String description) {
255                 this.description = description;
256         }
257
258         /**
259          * @return the modifiedBy
260          */
261         public String getModifiedBy() {
262                 return modifiedBy;
263         }
264
265         /**
266          * @param modifiedBy the modifiedBy to set
267          */
268         public void setModifiedBy(String modifiedBy) {
269                 this.modifiedBy = modifiedBy;
270         }
271
272         /**
273          * @return the version
274          */
275         public int getVersion() {
276                 return version;
277         }
278
279         /**
280          * @return the createdDate
281          */
282         public Date getCreatedDate() {
283                 return createdDate;
284         }
285
286         /**
287          * @return the modifiedDate
288          */
289         public Date getModifiedDate() {
290                 return modifiedDate;
291         }
292
293         /**
294          * @return the deleted
295          */
296         public boolean isDeleted() {
297                 return deleted;
298         }
299
300         /**
301          * @param deleted the deleted to set
302          */
303         public void setDeleted(boolean deleted) {
304                 this.deleted = deleted;
305         }
306
307
308 }