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=========================================================
20 package org.onap.policy.rest.jpa;
23 import java.io.Serializable;
24 import java.util.Date;
25 import java.util.List;
27 import javax.persistence.CascadeType;
28 import javax.persistence.Column;
29 import javax.persistence.Entity;
30 import javax.persistence.GeneratedValue;
31 import javax.persistence.GenerationType;
32 import javax.persistence.Id;
33 import javax.persistence.JoinColumn;
34 import javax.persistence.JoinTable;
35 import javax.persistence.ManyToMany;
36 import javax.persistence.NamedQueries;
37 import javax.persistence.NamedQuery;
38 import javax.persistence.PrePersist;
39 import javax.persistence.PreUpdate;
40 import javax.persistence.Table;
41 import javax.persistence.Temporal;
42 import javax.persistence.TemporalType;
43 import javax.persistence.Version;
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="GroupEntity")
59 @NamedQuery(name="GroupEntity.findAll", query="SELECT e FROM GroupEntity e "),
60 @NamedQuery(name="GroupEntity.deleteAll", query="DELETE FROM GroupEntity WHERE 1=1")
63 public class GroupEntity implements Serializable {
64 private static final long serialVersionUID = 1L;
67 @Column (name="groupKey", nullable=false)
68 @GeneratedValue(strategy = GenerationType.AUTO)
69 private long groupKey;
71 @Column (name="groupId", nullable=false)
72 private String groupId;
74 @Column(name="groupName", nullable=false, unique=false, length=255)
75 private String groupName;
78 @Column(name="version")
81 @ManyToMany(cascade = CascadeType.ALL)
82 @JoinTable(name="PolicyGroupEntity",joinColumns={@JoinColumn(name="groupKey")}, inverseJoinColumns={@JoinColumn(name="policyId")})
84 private List<PolicyEntity> policies;
86 @Column(name="created_by", nullable=false, length=255)
87 private String createdBy = "guest";
89 @Temporal(TemporalType.TIMESTAMP)
90 @Column(name="created_date", updatable=false)
91 private Date createdDate;
93 @Column(name="description", nullable=false, length=2048)
94 private String description = "NoDescription";
96 @Column(name="modified_by", nullable=false, length=255)
97 private String modifiedBy = "guest";
99 @Temporal(TemporalType.TIMESTAMP)
100 @Column(name="modified_date", nullable=false)
101 private Date modifiedDate;
103 @Column(name="defaultGroup", nullable=false)
104 private boolean defaultGroup = false;
105 @Column(name="deleted", nullable=false)
106 private boolean deleted = false;
108 public GroupEntity() {
113 public void prePersist() {
114 Date date = new Date();
115 this.createdDate = date;
116 this.modifiedDate = date;
120 public void preUpdate() {
121 this.modifiedDate = new Date();
125 * @return the policyId
127 public String getGroupId() {
130 public long getGroupKey(){
134 public void setGroupId(String groupId){
135 this.groupId = groupId;
139 * @param policyId cannot be set
142 public String getgroupName() {
146 public void setGroupName(String groupName) {
147 this.groupName = groupName;
150 public boolean isDefaultGroup(){
154 public void setDefaultGroup(boolean isDefaultGroup){
155 this.defaultGroup = isDefaultGroup;
161 * @return the configurationDataEntity
163 public List<PolicyEntity> getPolicies() {
168 * @param configurationDataEntity the configurationDataEntity to set
170 public void addPolicyToGroup(PolicyEntity policy) {
171 if(!this.policies.contains(policy)){
172 this.policies.add(policy);
175 public void removePolicyFromGroup(PolicyEntity policy){
176 this.policies.remove(policy);
182 * @return the createdBy
184 public String getCreatedBy() {
189 * @param createdBy the createdBy to set
191 public void setCreatedBy(String createdBy) {
192 this.createdBy = createdBy;
196 * @return the description
198 public String getDescription() {
203 * @param description the description to set
205 public void setDescription(String description) {
206 this.description = description;
210 * @return the modifiedBy
212 public String getModifiedBy() {
217 * @param modifiedBy the modifiedBy to set
219 public void setModifiedBy(String modifiedBy) {
220 this.modifiedBy = modifiedBy;
224 * @return the version
226 public int getVersion() {
231 * @return the createdDate
233 public Date getCreatedDate() {
238 * @return the modifiedDate
240 public Date getModifiedDate() {
245 * @return the deleted
247 public boolean isDeleted() {
252 * @param deleted the deleted to set
254 public void setDeleted(boolean deleted) {
255 this.deleted = deleted;