2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 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;
21 import com.fasterxml.jackson.annotation.JsonManagedReference;
24 import java.io.Serializable;
25 import java.util.Date;
26 import java.util.List;
27 import javax.persistence.CascadeType;
28 import javax.persistence.Column;
29 import javax.persistence.Entity;
30 import javax.persistence.FetchType;
31 import javax.persistence.GeneratedValue;
32 import javax.persistence.GenerationType;
33 import javax.persistence.Id;
34 import javax.persistence.JoinColumn;
35 import javax.persistence.JoinTable;
36 import javax.persistence.ManyToMany;
37 import javax.persistence.NamedQueries;
38 import javax.persistence.NamedQuery;
39 import javax.persistence.PrePersist;
40 import javax.persistence.PreUpdate;
41 import javax.persistence.Table;
42 import javax.persistence.Temporal;
43 import javax.persistence.TemporalType;
44 import javax.persistence.Version;
47 * The Entity class to persist a policy object and its configuration data
54 //Add a non-unique index and a constraint that says the combo of policyName and scopeId must be unique
55 @Table(name="GroupEntity")
58 @NamedQuery(name="GroupEntity.findAll", query="SELECT e FROM GroupEntity e "),
59 @NamedQuery(name="GroupEntity.deleteAll", query="DELETE FROM GroupEntity WHERE 1=1")
62 public class GroupEntity implements Serializable {
63 private static final long serialVersionUID = 1L;
66 @Column (name="groupKey", nullable=false)
67 @GeneratedValue(strategy = GenerationType.AUTO)
68 private long groupKey;
70 @Column (name="groupId", nullable=false)
71 private String groupId;
73 @Column(name="groupName", nullable=false, unique=false, length=255)
74 private String groupName;
77 @Column(name="version")
80 @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
81 @JoinTable(name="PolicyGroupEntity",joinColumns={@JoinColumn(name="groupKey")}, inverseJoinColumns={@JoinColumn(name="policyId")})
83 private List<PolicyEntity> policies;
85 @Column(name="created_by", nullable=false, length=255)
86 private String createdBy = "guest";
88 @Temporal(TemporalType.TIMESTAMP)
89 @Column(name="created_date", updatable=false)
90 private Date createdDate;
92 @Column(name="description", nullable=false, length=2048)
93 private String description = "NoDescription";
95 @Column(name="modified_by", nullable=false, length=255)
96 private String modifiedBy = "guest";
98 @Temporal(TemporalType.TIMESTAMP)
99 @Column(name="modified_date", nullable=false)
100 private Date modifiedDate;
102 @Column(name="defaultGroup", nullable=false)
103 private boolean defaultGroup = false;
104 @Column(name="deleted", nullable=false)
105 private boolean deleted = false;
107 public GroupEntity() {
112 public void prePersist() {
113 Date date = new Date();
114 this.createdDate = date;
115 this.modifiedDate = date;
119 public void preUpdate() {
120 this.modifiedDate = new Date();
124 * @return the policyId
126 public String getGroupId() {
129 public long getGroupKey(){
133 public void setGroupId(String groupId){
134 this.groupId = groupId;
138 * @param policyId cannot be set
141 public String getgroupName() {
145 public void setGroupName(String groupName) {
146 this.groupName = groupName;
149 public boolean isDefaultGroup(){
153 public void setDefaultGroup(boolean isDefaultGroup){
154 this.defaultGroup = isDefaultGroup;
160 * @return the configurationDataEntity
162 public List<PolicyEntity> getPolicies() {
167 * @param configurationDataEntity the configurationDataEntity to set
169 public void addPolicyToGroup(PolicyEntity policy) {
170 if(!this.policies.contains(policy)){
171 this.policies.add(policy);
174 public void removePolicyFromGroup(PolicyEntity policy){
175 this.policies.remove(policy);
181 * @return the createdBy
183 public String getCreatedBy() {
188 * @param createdBy the createdBy to set
190 public void setCreatedBy(String createdBy) {
191 this.createdBy = createdBy;
195 * @return the description
197 public String getDescription() {
202 * @param description the description to set
204 public void setDescription(String description) {
205 this.description = description;
209 * @return the modifiedBy
211 public String getModifiedBy() {
216 * @param modifiedBy the modifiedBy to set
218 public void setModifiedBy(String modifiedBy) {
219 this.modifiedBy = modifiedBy;
223 * @return the version
225 public int getVersion() {
230 * @return the createdDate
232 public Date getCreatedDate() {
237 * @return the modifiedDate
239 public Date getModifiedDate() {
244 * @return the deleted
246 public boolean isDeleted() {
251 * @param deleted the deleted to set
253 public void setDeleted(boolean deleted) {
254 this.deleted = deleted;