2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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=========================================================
21 package org.onap.policy.rest.jpa;
23 import java.io.Serializable;
24 import java.util.Date;
25 import java.util.HashSet;
28 import javax.persistence.CascadeType;
29 import javax.persistence.Column;
30 import javax.persistence.Entity;
31 import javax.persistence.GeneratedValue;
32 import javax.persistence.GenerationType;
33 import javax.persistence.Id;
34 import javax.persistence.JoinColumn;
35 import javax.persistence.ManyToOne;
36 import javax.persistence.NamedQuery;
37 import javax.persistence.OneToMany;
38 import javax.persistence.OrderBy;
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.Transient;
46 import com.fasterxml.jackson.annotation.JsonIgnore;
49 * The persistent class for the Attribute database table.
53 @Table(name="Attribute")
54 @NamedQuery(name="Attribute.findAll", query="SELECT a FROM Attribute a order by a.priority asc, a.xacmlId asc")
55 public class Attribute implements Serializable {
56 private static final long serialVersionUID = 1L;
59 @GeneratedValue(strategy = GenerationType.AUTO)
63 //bi-directional many-to-one association to Category
65 @JoinColumn(name="constraint_type", nullable=true)
67 private ConstraintType constraintType;
69 @Temporal(TemporalType.TIMESTAMP)
70 @Column(name="created_date", updatable=false)
71 private Date createdDate;
73 @Column(name="description", nullable=true, length=2048)
74 private String description;
76 @Temporal(TemporalType.TIMESTAMP)
77 @Column(name="modified_date", nullable=false)
78 private Date modifiedDate;
80 @Column(name="PRIORITY", nullable=true)
82 private String priority;
84 @Column(name="ATTRIBUTE_VALUE", nullable=true)
86 private String attributeValue;
88 @Column(name="xacml_id", unique = true, nullable=false)
90 private String xacmlId = "urn";
92 //bi-directional many-to-one association to ConstraintValue
93 @OneToMany(mappedBy="attribute", orphanRemoval=true, cascade=CascadeType.REMOVE)
95 private Set<ConstraintValue> constraintValues = new HashSet<>();
97 //bi-directional many-to-one association to Category
99 @JoinColumn(name="category")
101 private Category categoryBean;
103 //bi-directional many-to-one association to Datatype
105 @JoinColumn(name="datatype")
106 private Datatype datatypeBean;
108 @Column(name="is_designator", nullable=false)
110 private char isDesignator = '1';
112 @Column(name="selector_path", nullable=true, length=2048)
113 private String selectorPath;
118 private String issuer = null;
121 private boolean mustBePresent = false;
123 @ManyToOne(optional = false)
124 @JoinColumn(name="created_by")
125 private UserInfo userCreatedBy;
127 @ManyToOne(optional = false)
128 @JoinColumn(name="modified_by")
129 private UserInfo userModifiedBy;
131 public UserInfo getUserCreatedBy() {
132 return userCreatedBy;
135 public void setUserCreatedBy(UserInfo userCreatedBy) {
136 this.userCreatedBy = userCreatedBy;
139 public UserInfo getUserModifiedBy() {
140 return userModifiedBy;
143 public void setUserModifiedBy(UserInfo userModifiedBy) {
144 this.userModifiedBy = userModifiedBy;
149 //An empty constructor
152 public Attribute(String domain) {
153 this.xacmlId = domain;
156 public Attribute(Attribute copy) {
157 this(copy.getXacmlId() + ":(0)");
158 this.constraintType = copy.getConstraintType();
159 this.categoryBean = copy.getCategoryBean();
160 this.datatypeBean = copy.getDatatypeBean();
161 this.description = copy.getDescription();
162 for (ConstraintValue value : copy.getConstraintValues()) {
163 ConstraintValue newValue = new ConstraintValue(value);
164 newValue.setAttribute(this);
165 this.addConstraintValue(newValue);
170 public void prePersist() {
171 Date date = new Date();
172 this.createdDate = date;
173 this.modifiedDate = date;
177 public void preUpdate() {
178 this.modifiedDate = new Date();
185 public void setId(int id) {
189 public ConstraintType getConstraintType() {
190 return this.constraintType;
193 public void setConstraintType(ConstraintType constraintType) {
194 this.constraintType = constraintType;
197 public Date getCreatedDate() {
198 return this.createdDate;
201 public void setCreatedDate(Date createdDate) {
202 this.createdDate = createdDate;
205 public String getDescription() {
206 return this.description;
209 public void setDescription(String description) {
210 this.description = description;
213 public Date getModifiedDate() {
214 return this.modifiedDate;
217 public void setModifiedDate(Date modifiedDate) {
218 this.modifiedDate = modifiedDate;
221 public String getXacmlId() {
226 public void setXacmlId(String xacmlId) {
227 this.xacmlId = xacmlId;
230 public Set<ConstraintValue> getConstraintValues() {
231 return this.constraintValues;
234 public void setConstraintValues(Set<ConstraintValue> constraintValues) {
235 for (ConstraintValue value : this.constraintValues) {
236 value.setAttribute(this);
238 this.constraintValues = constraintValues;
241 public ConstraintValue addConstraintValue(ConstraintValue constraintValue) {
242 if (this.constraintValues == null) {
243 this.constraintValues = new HashSet<>();
245 this.constraintValues.add(constraintValue);
246 constraintValue.setAttribute(this);
248 return constraintValue;
251 public ConstraintValue removeConstraintValue(ConstraintValue constraintValue) {
252 this.constraintValues.remove(constraintValue);
253 constraintValue.setAttribute(null);
255 return constraintValue;
258 public void removeAllConstraintValues() {
259 if (this.constraintValues == null) {
262 for (ConstraintValue value : this.constraintValues) {
263 value.setAttribute(null);
265 this.constraintValues.clear();
268 public Category getCategoryBean() {
269 return this.categoryBean;
272 public void setCategoryBean(Category categoryBean) {
273 this.categoryBean = categoryBean;
276 public Datatype getDatatypeBean() {
277 return this.datatypeBean;
280 public void setDatatypeBean(Datatype datatypeBean) {
281 this.datatypeBean = datatypeBean;
284 public char getIsDesignator() {
285 return this.isDesignator;
288 public void setIsDesignator(char is) {
289 this.isDesignator = is;
292 public String getSelectorPath() {
293 return this.selectorPath;
296 public void setSelectorPath(String path) {
297 this.selectorPath = path;
301 public String getIssuer() {
306 public void setIssuer(String issuer) {
307 this.issuer = issuer;
311 public boolean isMustBePresent() {
312 return mustBePresent;
316 public void setMustBePresent(boolean mustBePresent) {
317 this.mustBePresent = mustBePresent;
321 public boolean isDesignator() {
322 return this.isDesignator == '1';
326 public void setIsDesignator(boolean is) {
328 this.isDesignator = '1';
330 this.isDesignator = '0';
334 public String getPriority() {
338 public void setPriority(String priority) {
339 this.priority = priority;
342 public String getAttributeValue() {
343 return attributeValue;
346 public void setAttributeValue(String attributeValue) {
347 this.attributeValue = attributeValue;