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