a53ac2d580caf509b767f5432c1240c684b10b84
[policy/engine.git] / ONAP-REST / src / main / java / org / onap / policy / rest / jpa / GroupEntity.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-REST
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 /*
22  *                        AT&T - PROPRIETARY
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.
26  *
27  *          Copyright (c) 2013 AT&T Knowledge Ventures
28  *              Unpublished and Not for Publication
29  *                     All Rights Reserved
30  */
31 package org.onap.policy.rest.jpa;
32 /*
33  */
34 import java.io.Serializable;
35 import java.util.Date;
36 import java.util.List;
37
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;
55
56 import com.fasterxml.jackson.annotation.JsonManagedReference;
57
58 /*
59  * The Entity class to persist a policy object and its configuration data
60  */
61
62 /**
63  *
64  */
65 @Entity
66 //Add a non-unique index and a constraint that says the combo of policyName and scopeId must be unique
67 @Table(name="GroupEntity")
68
69 @NamedQueries({
70         @NamedQuery(name="GroupEntity.findAll", query="SELECT e FROM GroupEntity e "),
71         @NamedQuery(name="GroupEntity.deleteAll", query="DELETE FROM GroupEntity WHERE 1=1")
72 })
73
74 public class GroupEntity implements Serializable {
75         private static final long serialVersionUID = 1L;
76
77         @Id
78         @Column (name="groupKey", nullable=false)
79         @GeneratedValue(strategy = GenerationType.AUTO)
80         private long groupKey;
81         
82         @Column (name="groupId", nullable=false)
83         private String groupId;
84
85         @Column(name="groupName", nullable=false, unique=false, length=255)
86         private String groupName;
87         
88         @Version 
89         @Column(name="version")
90         private int version;
91         
92         @ManyToMany(cascade = CascadeType.ALL)
93         @JoinTable(name="PolicyGroupEntity",joinColumns={@JoinColumn(name="groupKey")}, inverseJoinColumns={@JoinColumn(name="policyId")})
94         @JsonManagedReference
95         private List<PolicyEntity> policies;
96         
97         @Column(name="created_by", nullable=false, length=255)
98         private String createdBy = "guest";
99
100         @Temporal(TemporalType.TIMESTAMP)
101         @Column(name="created_date", updatable=false)
102         private Date createdDate;
103
104         @Column(name="description", nullable=false, length=2048)
105         private String description = "NoDescription";
106
107         @Column(name="modified_by", nullable=false, length=255)
108         private String modifiedBy = "guest";
109
110         @Temporal(TemporalType.TIMESTAMP)
111         @Column(name="modified_date", nullable=false)
112         private Date modifiedDate;
113         
114         @Column(name="defaultGroup", nullable=false)
115         private boolean defaultGroup = false;
116         @Column(name="deleted", nullable=false)
117         private boolean deleted = false;
118
119         public GroupEntity() {
120                 super();
121         }
122
123         @PrePersist
124         public void     prePersist() {
125                 Date date = new Date();
126                 this.createdDate = date;
127                 this.modifiedDate = date;
128         }
129
130         @PreUpdate
131         public void preUpdate() {
132                 this.modifiedDate = new Date();
133         }
134
135         /**
136          * @return the policyId
137          */
138         public String getGroupId() {
139                 return groupId;
140         }
141         public long getGroupKey(){
142                 return groupKey;
143         }
144         
145         public void setGroupId(String groupId){
146                 this.groupId = groupId;
147         }
148
149         /**
150          * @param policyId cannot be set
151          */
152
153         public String getgroupName() {
154                 return groupName;
155         }
156
157         public void setGroupName(String groupName) {
158                 this.groupName = groupName;
159         }
160         
161         public boolean isDefaultGroup(){
162                 return defaultGroup;
163         }
164         
165         public void setDefaultGroup(boolean isDefaultGroup){
166                 this.defaultGroup = isDefaultGroup;
167         }
168
169
170
171         /**
172          * @return the configurationDataEntity
173          */
174         public List<PolicyEntity> getPolicies() {
175                 return policies;
176         }
177
178         /**
179          * @param configurationDataEntity the configurationDataEntity to set
180          */
181         public void addPolicyToGroup(PolicyEntity policy) {
182                 if(!this.policies.contains(policy)){
183                         this.policies.add(policy);
184                 }
185         }
186         public void removePolicyFromGroup(PolicyEntity policy){
187                 this.policies.remove(policy);
188         }
189
190
191
192         /**
193          * @return the createdBy
194          */
195         public String getCreatedBy() {
196                 return createdBy;
197         }
198
199         /**
200          * @param createdBy the createdBy to set
201          */
202         public void setCreatedBy(String createdBy) {
203                 this.createdBy = createdBy;
204         }
205
206         /**
207          * @return the description
208          */
209         public String getDescription() {
210                 return description;
211         }
212
213         /**
214          * @param description the description to set
215          */
216         public void setDescription(String description) {
217                 this.description = description;
218         }
219
220         /**
221          * @return the modifiedBy
222          */
223         public String getModifiedBy() {
224                 return modifiedBy;
225         }
226
227         /**
228          * @param modifiedBy the modifiedBy to set
229          */
230         public void setModifiedBy(String modifiedBy) {
231                 this.modifiedBy = modifiedBy;
232         }
233
234         /**
235          * @return the version
236          */
237         public int getVersion() {
238                 return version;
239         }
240
241         /**
242          * @return the createdDate
243          */
244         public Date getCreatedDate() {
245                 return createdDate;
246         }
247
248         /**
249          * @return the modifiedDate
250          */
251         public Date getModifiedDate() {
252                 return modifiedDate;
253         }
254
255         /**
256          * @return the deleted
257          */
258         public boolean isDeleted() {
259                 return deleted;
260         }
261
262         /**
263          * @param deleted the deleted to set
264          */
265         public void setDeleted(boolean deleted) {
266                 this.deleted = deleted;
267         }
268
269
270 }