2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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;
25 import com.fasterxml.jackson.annotation.JsonBackReference;
26 import com.fasterxml.jackson.annotation.JsonManagedReference;
27 import java.io.Serializable;
28 import java.util.Date;
29 import java.util.Objects;
30 import javax.persistence.Column;
31 import javax.persistence.Entity;
32 import javax.persistence.GeneratedValue;
33 import javax.persistence.GenerationType;
34 import javax.persistence.Id;
35 import javax.persistence.JoinColumn;
36 import javax.persistence.Lob;
37 import javax.persistence.NamedQueries;
38 import javax.persistence.NamedQuery;
39 import javax.persistence.OneToOne;
40 import javax.persistence.PrePersist;
41 import javax.persistence.PreUpdate;
42 import javax.persistence.Table;
43 import javax.persistence.Temporal;
44 import javax.persistence.TemporalType;
45 import javax.persistence.Version;
49 * The Entity class to persist a policy object and its configuration data
53 // Add a non-unique index and a constraint that says the combo of policyName and scopeId must be unique
54 @Table(name = "PolicyEntity")
56 @NamedQuery(name = "PolicyEntity.findAll", query = "SELECT e FROM PolicyEntity e "),
57 @NamedQuery(name = "PolicyEntity.findAllByDeletedFlag",
58 query = "SELECT e FROM PolicyEntity e WHERE e.deleted = :deleted"),
59 @NamedQuery(name = "PolicyEntity.FindById", query = "SELECT e FROM PolicyEntity e WHERE e.policyId = :id"),
60 @NamedQuery(name = "PolicyEntity.deleteAll", query = "DELETE FROM PolicyEntity WHERE 1=1"),
61 @NamedQuery(name = "PolicyEntity.findByNameAndScope",
62 query = "SELECT e FROM PolicyEntity e WHERE e.policyName = :name AND e.scope = :scope")
64 public class PolicyEntity implements Serializable {
65 private static final long serialVersionUID = 1L;
68 @GeneratedValue(strategy = GenerationType.AUTO)
69 @Column(name = "policyId")
71 private long policyId;
73 @Column(name = "policyName", nullable = false, unique = false, length = 255)
74 private String policyName;
76 // The scope is the directory structure in dot notation. For example: org.onap.myproject
77 @Column(name = "scope", nullable = false, unique = false, length = 255)
81 @Column(name = "version")
84 // not going to be used
85 @Column(name = "policyVersion")
86 private int policyVersion = 0;
89 @Column(name = "policyData", nullable = false, columnDefinition = "TEXT")
90 private String policyData = "NoData";
92 @OneToOne(optional = true, orphanRemoval = true)
93 @JoinColumn(name = "configurationDataId")
95 private ConfigurationDataEntity configurationDataEntity;
97 @OneToOne(optional = true, orphanRemoval = true)
98 @JoinColumn(name = "actionBodyId")
100 private ActionBodyEntity actionBodyEntity;
102 @Column(name = "created_by", nullable = false, length = 255)
103 private String createdBy = "guest";
105 @Temporal(TemporalType.TIMESTAMP)
106 @Column(name = "created_date", updatable = false)
107 private Date createdDate;
109 @Column(name = "description", nullable = false, length = 2048)
110 private String description = "NoDescription";
112 @Column(name = "modified_by", nullable = false, length = 255)
113 private String modifiedBy = "guest";
115 @Temporal(TemporalType.TIMESTAMP)
116 @Column(name = "modified_date", nullable = false)
117 private Date modifiedDate;
119 @Column(name = "deleted", nullable = false)
120 private boolean deleted = false;
122 @Column(name = "delete_reason_code", nullable = true, length = 100)
123 private String deleteReasonCode;
125 @Column(name = "deleted_by", nullable = true, length = 45)
126 private String deletedBy;
128 public PolicyEntity() {
133 * Set default values.
136 public void prePersist() {
137 Date date = new Date();
138 this.createdDate = date;
139 this.modifiedDate = date;
143 public void preUpdate() {
144 this.modifiedDate = new Date();
149 * @return the policyId
151 public long getPolicyId() {
156 * Returns policy name.
157 * @return the policy name
159 public String getPolicyName() {
163 public void setPolicyName(String policyName) {
164 this.policyName = policyName;
168 * Returns policy data.
169 * @return the policyData
171 public String getPolicyData() {
177 * @param policyData the policyData to set
179 public void setPolicyData(String policyData) {
180 this.policyData = policyData;
184 * Returns configurationDataEntity.
185 * @return the configurationDataEntity
187 public ConfigurationDataEntity getConfigurationData() {
188 return configurationDataEntity;
192 * Set configurationDataEntity.
193 * @param configurationDataEntity the configurationDataEntity to set
195 public void setConfigurationData(ConfigurationDataEntity configurationDataEntity) {
196 this.configurationDataEntity = configurationDataEntity;
200 * Returns actionBodyEntity.
201 * @return the actionBodyEntity
203 public ActionBodyEntity getActionBodyEntity() {
204 return actionBodyEntity;
208 * Set actionBodyEntity.
209 * @param actionBodyEntity the actionBodyEntity to set
211 public void setActionBodyEntity(ActionBodyEntity actionBodyEntity) {
212 this.actionBodyEntity = actionBodyEntity;
219 public String getScope() {
225 * @param scope the scope to set
227 public void setScope(String scope) {
233 * @return the createdBy
235 public String getCreatedBy() {
241 * @param createdBy the createdBy to set
243 public void setCreatedBy(String createdBy) {
244 this.createdBy = createdBy;
248 * Returns description.
249 * @return the description
251 public String getDescription() {
257 * @param description the description to set
259 public void setDescription(String description) {
260 this.description = description;
264 * Returns modifiedBy.
265 * @return the modifiedBy
267 public String getModifiedBy() {
273 * @param modifiedBy the modifiedBy to set
275 public void setModifiedBy(String modifiedBy) {
276 this.modifiedBy = modifiedBy;
283 public int getVersion() {
288 * Returns createdDate.
289 * @return the createdDate
291 public Date getCreatedDate() {
296 * Returns modifiedDate.
297 * @return the modifiedDate
299 public Date getModifiedDate() {
305 * @return the deleted
307 public boolean isDeleted() {
313 * @param deleted the deleted to set
315 public void setDeleted(boolean deleted) {
316 this.deleted = deleted;
320 * Return the reason code.
321 * @return deleted reason code
323 public String getDeleteReasonCode() {
324 return deleteReasonCode;
328 * Set the reason of deletion.
329 * @param deleteReasonCode String object
331 public void setDeleteReasonCode(String deleteReasonCode) {
332 this.deleteReasonCode = deleteReasonCode;
339 public String getDeletedBy() {
345 * @param deletedBy String object
347 public void setDeletedBy(String deletedBy) {
348 this.deletedBy = deletedBy;
352 public int hashCode() {
353 return Objects.hash(policyId, policyName, scope, version, policyVersion, policyData, configurationDataEntity,
354 actionBodyEntity, createdBy, createdDate, description, modifiedBy, modifiedDate, deleted);
358 public boolean equals(Object obj) {
365 if (!(obj instanceof PolicyEntity)) {
369 PolicyEntity p = (PolicyEntity) obj;
371 return policyId == p.policyId
372 && policyName.equals(p.policyName)
373 && scope.equals(p.scope)
374 && version == p.version
375 && policyVersion == p.policyVersion
376 && policyData.equals(p.policyData)
377 && ((configurationDataEntity == null && p.configurationDataEntity == null)
378 || (configurationDataEntity != null
379 && configurationDataEntity
380 .equals(p.configurationDataEntity)))
381 && ((actionBodyEntity == null && p.actionBodyEntity == null) || (actionBodyEntity != null
383 .equals(p.actionBodyEntity))) && createdBy.equals(p.createdBy)
384 && createdDate.equals(p.createdDate) && description.equals(p.description)
385 && modifiedBy.equals(p.modifiedBy) && modifiedDate.equals(p.modifiedDate) && deleted == p.deleted;