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.openecomp.policy.rest.jpa;
34 import java.io.Serializable;
35 import java.util.Date;
36 import java.util.List;
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;
60 import com.fasterxml.jackson.annotation.JsonManagedReference;
63 * The Entity class to persist a policy object and its configuration data
70 //Add a non-unique index and a constraint that says the combo of policyName and scopeId must be unique
71 @Table(name="GroupEntity")
74 @NamedQuery(name="GroupEntity.findAll", query="SELECT e FROM GroupEntity e "),
75 @NamedQuery(name="GroupEntity.deleteAll", query="DELETE FROM GroupEntity WHERE 1=1")
78 public class GroupEntity implements Serializable {
79 private static final long serialVersionUID = 1L;
82 @Column (name="groupKey", nullable=false)
83 //@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="seqGroup")
84 @GeneratedValue(strategy = GenerationType.AUTO)
85 private long groupKey;
87 @Column (name="groupId", nullable=false)
88 private String groupId;
90 @Column(name="groupName", nullable=false, unique=false, length=255)
91 private String groupName;
94 @Column(name="version")
98 @JoinTable(name="PolicyGroupEntity",joinColumns={@JoinColumn(name="groupKey", referencedColumnName="groupKey")},
99 inverseJoinColumns={@JoinColumn(name="policyId",referencedColumnName="policyId")})
100 @JsonManagedReference
101 private List<PolicyEntity> policies;
103 @Column(name="created_by", nullable=false, length=255)
104 private String createdBy = "guest";
106 @Temporal(TemporalType.TIMESTAMP)
107 @Column(name="created_date", updatable=false)
108 private Date createdDate;
110 @Column(name="description", nullable=false, length=2048)
111 private String description = "NoDescription";
113 @Column(name="modified_by", nullable=false, length=255)
114 private String modifiedBy = "guest";
116 @Temporal(TemporalType.TIMESTAMP)
117 @Column(name="modified_date", nullable=false)
118 private Date modifiedDate;
120 @Column(name="defaultGroup", nullable=false)
121 private boolean defaultGroup = false;
122 @Column(name="deleted", nullable=false)
123 private boolean deleted = false;
125 public GroupEntity() {
130 public void prePersist() {
131 Date date = new Date();
132 this.createdDate = date;
133 this.modifiedDate = date;
137 public void preUpdate() {
138 this.modifiedDate = new Date();
142 * @return the policyId
144 public String getGroupId() {
147 public long getGroupKey(){
151 public void setGroupId(String groupId){
152 this.groupId = groupId;
156 * @param policyId cannot be set
159 public String getgroupName() {
163 public void setGroupName(String groupName) {
164 this.groupName = groupName;
167 public boolean isDefaultGroup(){
171 public void setDefaultGroup(boolean isDefaultGroup){
172 this.defaultGroup = isDefaultGroup;
178 * @return the configurationDataEntity
180 public List<PolicyEntity> getPolicies() {
185 * @param configurationDataEntity the configurationDataEntity to set
187 public void addPolicyToGroup(PolicyEntity policy) {
188 if(!this.policies.contains(policy)){
189 this.policies.add(policy);
192 public void removePolicyFromGroup(PolicyEntity policy){
193 this.policies.remove(policy);
199 * @return the createdBy
201 public String getCreatedBy() {
206 * @param createdBy the createdBy to set
208 public void setCreatedBy(String createdBy) {
209 this.createdBy = createdBy;
213 * @return the description
215 public String getDescription() {
220 * @param description the description to set
222 public void setDescription(String description) {
223 this.description = description;
227 * @return the modifiedBy
229 public String getModifiedBy() {
234 * @param modifiedBy the modifiedBy to set
236 public void setModifiedBy(String modifiedBy) {
237 this.modifiedBy = modifiedBy;
241 * @return the version
243 public int getVersion() {
248 * @return the createdDate
250 public Date getCreatedDate() {
255 * @return the modifiedDate
257 public Date getModifiedDate() {
262 * @return the deleted
264 public boolean isDeleted() {
269 * @param deleted the deleted to set
271 public void setDeleted(boolean deleted) {
272 this.deleted = deleted;