2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.rest.jpa;
26 import com.fasterxml.jackson.annotation.JsonBackReference;
27 import com.fasterxml.jackson.annotation.JsonManagedReference;
29 import java.io.Serializable;
30 import java.util.Date;
32 import javax.persistence.Column;
33 import javax.persistence.Entity;
34 import javax.persistence.GeneratedValue;
35 import javax.persistence.GenerationType;
36 import javax.persistence.Id;
37 import javax.persistence.JoinColumn;
38 import javax.persistence.Lob;
39 import javax.persistence.NamedQueries;
40 import javax.persistence.NamedQuery;
41 import javax.persistence.OneToOne;
42 import javax.persistence.PrePersist;
43 import javax.persistence.PreUpdate;
44 import javax.persistence.Table;
45 import javax.persistence.Temporal;
46 import javax.persistence.TemporalType;
47 import javax.persistence.Version;
49 import lombok.EqualsAndHashCode;
54 * The Entity class to persist a policy object and its configuration data.
58 // Add a non-unique index and a constraint that says the combo of policyName and scopeId must be unique
59 @Table(name = "PolicyEntity")
63 name = "PolicyEntity.findAll",
64 query = "SELECT e FROM PolicyEntity e "
67 name = "PolicyEntity.findAllByDeletedFlag",
68 query = "SELECT e FROM PolicyEntity e WHERE e.deleted = :deleted"
71 name = "PolicyEntity.FindById",
72 query = "SELECT e FROM PolicyEntity e WHERE e.policyId = :id"
75 name = "PolicyEntity.deleteAll",
76 query = "DELETE FROM PolicyEntity WHERE 1=1"
79 name = "PolicyEntity.findByNameAndScope",
80 query = "SELECT e FROM PolicyEntity e WHERE e.policyName = :name AND e.scope = :scope"
88 public class PolicyEntity implements Serializable {
89 private static final long serialVersionUID = 1L;
92 @GeneratedValue(strategy = GenerationType.AUTO)
93 @Column(name = "policyId")
95 private long policyId;
97 @Column(name = "policyName", nullable = false, unique = false, length = 255)
98 private String policyName;
100 // The scope is the directory structure in dot notation. For example: org.onap.myproject
101 @Column(name = "scope", nullable = false, unique = false, length = 255)
102 private String scope;
105 @Column(name = "version")
108 // not going to be used
109 @Column(name = "policyVersion")
110 private int policyVersion = 0;
113 @Column(name = "policyData", nullable = false, columnDefinition = "TEXT")
114 private String policyData = "NoData";
116 @OneToOne(optional = true, orphanRemoval = true)
117 @JoinColumn(name = "configurationDataId")
118 @JsonManagedReference
119 private ConfigurationDataEntity configurationDataEntity;
121 @OneToOne(optional = true, orphanRemoval = true)
122 @JoinColumn(name = "actionBodyId")
123 @JsonManagedReference
124 private ActionBodyEntity actionBodyEntity;
126 @Column(name = "created_by", nullable = false, length = 255)
127 private String createdBy = "guest";
129 @Temporal(TemporalType.TIMESTAMP)
130 @Column(name = "created_date", updatable = false)
131 private Date createdDate;
133 @Column(name = "description", nullable = false, length = 2048)
134 private String description = "NoDescription";
136 @Column(name = "modified_by", nullable = false, length = 255)
137 private String modifiedBy = "guest";
139 @Temporal(TemporalType.TIMESTAMP)
140 @Column(name = "modified_date", nullable = false)
141 private Date modifiedDate;
143 @Column(name = "deleted", nullable = false)
144 private boolean deleted = false;
146 @Column(name = "delete_reason_code", nullable = true, length = 100)
147 private String deleteReasonCode;
149 @Column(name = "deleted_by", nullable = true, length = 45)
150 private String deletedBy;
152 public PolicyEntity() {
157 * Set default values.
160 public void prePersist() {
161 Date date = new Date();
162 this.createdDate = date;
163 this.modifiedDate = date;
167 public void preUpdate() {
168 this.modifiedDate = new Date();
172 * Returns configurationDataEntity.
174 * @return the configurationDataEntity
176 public ConfigurationDataEntity getConfigurationData() {
177 return configurationDataEntity;
181 * Set configurationDataEntity.
183 * @param configurationDataEntity the configurationDataEntity to set
185 public void setConfigurationData(ConfigurationDataEntity configurationDataEntity) {
186 this.configurationDataEntity = configurationDataEntity;