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=========================================================
23 * THIS FILE CONTAINS PROPRIETARY INFORMATION OF
24 * AT&T AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN
25 * ACCORDANCE WITH APPLICABLE AGREEMENTS.
27 * Copyright (c) 2013 AT&T Knowledge Ventures
28 * Unpublished and Not for Publication
31 package org.onap.policy.rest.jpa;
34 import java.io.Serializable;
35 import java.util.Date;
36 import java.util.List;
38 import javax.persistence.CascadeType;
39 import javax.persistence.Column;
40 import javax.persistence.Entity;
41 import javax.persistence.GeneratedValue;
42 import javax.persistence.GenerationType;
43 import javax.persistence.Id;
44 import javax.persistence.JoinColumn;
45 import javax.persistence.JoinTable;
46 import javax.persistence.ManyToMany;
47 import javax.persistence.NamedQueries;
48 import javax.persistence.NamedQuery;
49 import javax.persistence.PrePersist;
50 import javax.persistence.PreUpdate;
51 import javax.persistence.Table;
52 import javax.persistence.Temporal;
53 import javax.persistence.TemporalType;
54 import javax.persistence.Version;
56 import com.fasterxml.jackson.annotation.JsonManagedReference;
59 * The Entity class to persist a policy object and its configuration data
66 //Add a non-unique index and a constraint that says the combo of policyName and scopeId must be unique
67 @Table(name="GroupEntity")
70 @NamedQuery(name="GroupEntity.findAll", query="SELECT e FROM GroupEntity e "),
71 @NamedQuery(name="GroupEntity.deleteAll", query="DELETE FROM GroupEntity WHERE 1=1")
74 public class GroupEntity implements Serializable {
75 private static final long serialVersionUID = 1L;
78 @Column (name="groupKey", nullable=false)
79 @GeneratedValue(strategy = GenerationType.AUTO)
80 private long groupKey;
82 @Column (name="groupId", nullable=false)
83 private String groupId;
85 @Column(name="groupName", nullable=false, unique=false, length=255)
86 private String groupName;
89 @Column(name="version")
92 @ManyToMany(cascade = CascadeType.ALL)
93 @JoinTable(name="PolicyGroupEntity",joinColumns={@JoinColumn(name="groupKey")}, inverseJoinColumns={@JoinColumn(name="policyId")})
95 private List<PolicyEntity> policies;
97 @Column(name="created_by", nullable=false, length=255)
98 private String createdBy = "guest";
100 @Temporal(TemporalType.TIMESTAMP)
101 @Column(name="created_date", updatable=false)
102 private Date createdDate;
104 @Column(name="description", nullable=false, length=2048)
105 private String description = "NoDescription";
107 @Column(name="modified_by", nullable=false, length=255)
108 private String modifiedBy = "guest";
110 @Temporal(TemporalType.TIMESTAMP)
111 @Column(name="modified_date", nullable=false)
112 private Date modifiedDate;
114 @Column(name="defaultGroup", nullable=false)
115 private boolean defaultGroup = false;
116 @Column(name="deleted", nullable=false)
117 private boolean deleted = false;
119 public GroupEntity() {
124 public void prePersist() {
125 Date date = new Date();
126 this.createdDate = date;
127 this.modifiedDate = date;
131 public void preUpdate() {
132 this.modifiedDate = new Date();
136 * @return the policyId
138 public String getGroupId() {
141 public long getGroupKey(){
145 public void setGroupId(String groupId){
146 this.groupId = groupId;
150 * @param policyId cannot be set
153 public String getgroupName() {
157 public void setGroupName(String groupName) {
158 this.groupName = groupName;
161 public boolean isDefaultGroup(){
165 public void setDefaultGroup(boolean isDefaultGroup){
166 this.defaultGroup = isDefaultGroup;
172 * @return the configurationDataEntity
174 public List<PolicyEntity> getPolicies() {
179 * @param configurationDataEntity the configurationDataEntity to set
181 public void addPolicyToGroup(PolicyEntity policy) {
182 if(!this.policies.contains(policy)){
183 this.policies.add(policy);
186 public void removePolicyFromGroup(PolicyEntity policy){
187 this.policies.remove(policy);
193 * @return the createdBy
195 public String getCreatedBy() {
200 * @param createdBy the createdBy to set
202 public void setCreatedBy(String createdBy) {
203 this.createdBy = createdBy;
207 * @return the description
209 public String getDescription() {
214 * @param description the description to set
216 public void setDescription(String description) {
217 this.description = description;
221 * @return the modifiedBy
223 public String getModifiedBy() {
228 * @param modifiedBy the modifiedBy to set
230 public void setModifiedBy(String modifiedBy) {
231 this.modifiedBy = modifiedBy;
235 * @return the version
237 public int getVersion() {
242 * @return the createdDate
244 public Date getCreatedDate() {
249 * @return the modifiedDate
251 public Date getModifiedDate() {
256 * @return the deleted
258 public boolean isDeleted() {
263 * @param deleted the deleted to set
265 public void setDeleted(boolean deleted) {
266 this.deleted = deleted;