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 * @return the policyId
143 public long getPolicyId() {
148 * @param policyId cannot be set
151 public String getPolicyName() {
155 public void setPolicyName(String policyName) {
156 this.policyName = policyName;
160 * @return the policyData
162 public String getPolicyData() {
167 * @param policyData the policyData to set
169 public void setPolicyData(String policyData) {
170 this.policyData = policyData;
174 * @return the configurationDataEntity
176 public ConfigurationDataEntity getConfigurationData() {
177 return configurationDataEntity;
181 * @param configurationDataEntity the configurationDataEntity to set
183 public void setConfigurationData(ConfigurationDataEntity configurationDataEntity) {
184 this.configurationDataEntity = configurationDataEntity;
188 * @return the actionBodyEntity
190 public ActionBodyEntity getActionBodyEntity() {
191 return actionBodyEntity;
195 * @param actionBodyEntity the actionBodyEntity to set
197 public void setActionBodyEntity(ActionBodyEntity actionBodyEntity) {
198 this.actionBodyEntity = actionBodyEntity;
204 public String getScope() {
209 * @param scope the scope to set
211 public void setScope(String scope) {
216 * @return the createdBy
218 public String getCreatedBy() {
223 * @param createdBy the createdBy to set
225 public void setCreatedBy(String createdBy) {
226 this.createdBy = createdBy;
230 * @return the description
232 public String getDescription() {
237 * @param description the description to set
239 public void setDescription(String description) {
240 this.description = description;
244 * @return the modifiedBy
246 public String getModifiedBy() {
251 * @param modifiedBy the modifiedBy to set
253 public void setModifiedBy(String modifiedBy) {
254 this.modifiedBy = modifiedBy;
258 * @return the version
260 public int getVersion() {
265 * @return the createdDate
267 public Date getCreatedDate() {
272 * @return the modifiedDate
274 public Date getModifiedDate() {
279 * @return the deleted
281 public boolean isDeleted() {
286 * @param deleted the deleted to set
288 public void setDeleted(boolean deleted) {
289 this.deleted = deleted;