2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.rest.jpa;
24 import java.io.Serializable;
25 import java.util.Date;
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;
44 import com.fasterxml.jackson.annotation.JsonBackReference;
45 import com.fasterxml.jackson.annotation.JsonManagedReference;
48 * The Entity class to persist a policy object and its configuration data
55 //Add a non-unique index and a constraint that says the combo of policyName and scopeId must be unique
56 @Table(name="PolicyEntity")
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")
66 public class PolicyEntity implements Serializable {
67 private static final long serialVersionUID = 1L;
70 @GeneratedValue(strategy = GenerationType.AUTO)
71 @Column (name="policyId")
73 private long policyId;
75 @Column(name="policyName", nullable=false, unique=false, length=255)
76 private String policyName;
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)
83 @Column(name="version")
86 //not going to be used
87 @Column(name="policyVersion")
88 private int policyVersion = 0;
91 @Column(name="policyData", nullable=false, columnDefinition="TEXT")
92 private String policyData = "NoData";
94 @OneToOne(optional=true, orphanRemoval=true)
95 @JoinColumn(name="configurationDataId")
97 private ConfigurationDataEntity configurationDataEntity;
99 @OneToOne(optional=true, orphanRemoval=true)
100 @JoinColumn(name="actionBodyId")
101 @JsonManagedReference
102 private ActionBodyEntity actionBodyEntity;
104 @Column(name="created_by", nullable=false, length=255)
105 private String createdBy = "guest";
107 @Temporal(TemporalType.TIMESTAMP)
108 @Column(name="created_date", updatable=false)
109 private Date createdDate;
111 @Column(name="description", nullable=false, length=2048)
112 private String description = "NoDescription";
114 @Column(name="modified_by", nullable=false, length=255)
115 private String modifiedBy = "guest";
117 @Temporal(TemporalType.TIMESTAMP)
118 @Column(name="modified_date", nullable=false)
119 private Date modifiedDate;
121 @Column(name="deleted", nullable=false)
122 private boolean deleted = false;
124 public PolicyEntity() {
129 public void prePersist() {
130 Date date = new Date();
131 this.createdDate = date;
132 this.modifiedDate = date;
136 public void preUpdate() {
137 this.modifiedDate = new Date();
141 public void resetPolicyVersion(){
142 this.policyVersion = 1;
144 public void advancePolicyVersion(){
145 this.policyVersion++;
147 public int getPolicyVersion(){
148 return this.policyVersion;
150 public void setPolicyVersion(int polVer){
151 this.policyVersion = polVer;
156 * @return the policyId
158 public long getPolicyId() {
163 * @param policyId cannot be set
166 public String getPolicyName() {
170 public void setPolicyName(String policyName) {
171 this.policyName = policyName;
175 * @return the policyData
177 public String getPolicyData() {
182 * @param policyData the policyData to set
184 public void setPolicyData(String policyData) {
185 this.policyData = policyData;
189 * @return the configurationDataEntity
191 public ConfigurationDataEntity getConfigurationData() {
192 return configurationDataEntity;
196 * @param configurationDataEntity the configurationDataEntity to set
198 public void setConfigurationData(ConfigurationDataEntity configurationDataEntity) {
199 this.configurationDataEntity = configurationDataEntity;
203 * @return the actionBodyEntity
205 public ActionBodyEntity getActionBodyEntity() {
206 return actionBodyEntity;
210 * @param actionBodyEntity the actionBodyEntity to set
212 public void setActionBodyEntity(ActionBodyEntity actionBodyEntity) {
213 this.actionBodyEntity = actionBodyEntity;
219 public String getScope() {
224 * @param scope the scope to set
226 public void setScope(String scope) {
231 * @return the createdBy
233 public String getCreatedBy() {
238 * @param createdBy the createdBy to set
240 public void setCreatedBy(String createdBy) {
241 this.createdBy = createdBy;
245 * @return the description
247 public String getDescription() {
252 * @param description the description to set
254 public void setDescription(String description) {
255 this.description = description;
259 * @return the modifiedBy
261 public String getModifiedBy() {
266 * @param modifiedBy the modifiedBy to set
268 public void setModifiedBy(String modifiedBy) {
269 this.modifiedBy = modifiedBy;
273 * @return the version
275 public int getVersion() {
280 * @return the createdDate
282 public Date getCreatedDate() {
287 * @return the modifiedDate
289 public Date getModifiedDate() {
294 * @return the deleted
296 public boolean isDeleted() {
301 * @param deleted the deleted to set
303 public void setDeleted(boolean deleted) {
304 this.deleted = deleted;