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