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