2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.rest.jpa;
24 import com.fasterxml.jackson.annotation.JsonIgnore;
26 import java.io.Serializable;
27 import java.util.Date;
28 import java.util.HashSet;
31 import javax.persistence.CascadeType;
32 import javax.persistence.Column;
33 import javax.persistence.Entity;
34 import javax.persistence.GeneratedValue;
35 import javax.persistence.GenerationType;
36 import javax.persistence.Id;
37 import javax.persistence.JoinColumn;
38 import javax.persistence.ManyToOne;
39 import javax.persistence.NamedQuery;
40 import javax.persistence.OneToMany;
41 import javax.persistence.OrderBy;
42 import javax.persistence.PrePersist;
43 import javax.persistence.PreUpdate;
44 import javax.persistence.Table;
45 import javax.persistence.Temporal;
46 import javax.persistence.TemporalType;
47 import javax.persistence.Transient;
53 * The persistent class for the Attribute database table.
57 @Table(name = "Attribute")
58 @NamedQuery(name = "Attribute.findAll", query = "SELECT a FROM Attribute a order by a.priority asc, a.xacmlId asc")
61 * Gets the user modified by.
63 * @return the user modified by
68 * Sets the user modified by.
70 * @param userModifiedBy the new user modified by
73 public class Attribute implements Serializable {
74 private static final long serialVersionUID = 1L;
77 @GeneratedValue(strategy = GenerationType.AUTO)
81 // bi-directional many-to-one association to Category
83 @JoinColumn(name = "constraint_type", nullable = true)
85 private ConstraintType constraintType;
87 @Temporal(TemporalType.TIMESTAMP)
88 @Column(name = "created_date", updatable = false)
89 private Date createdDate;
91 @Column(name = "description", nullable = true, length = 2048)
92 private String description;
94 @Temporal(TemporalType.TIMESTAMP)
95 @Column(name = "modified_date", nullable = false)
96 private Date modifiedDate;
98 @Column(name = "PRIORITY", nullable = true)
100 private String priority;
102 @Column(name = "ATTRIBUTE_VALUE", nullable = true)
104 private String attributeValue;
106 @Column(name = "xacml_id", unique = true, nullable = false)
108 private String xacmlId = "urn";
110 // bi-directional many-to-one association to ConstraintValue
111 @OneToMany(mappedBy = "attribute", orphanRemoval = true, cascade = CascadeType.REMOVE)
113 private Set<ConstraintValue> constraintValues = new HashSet<>();
115 // bi-directional many-to-one association to Category
117 @JoinColumn(name = "category")
119 private Category categoryBean;
121 // bi-directional many-to-one association to Datatype
123 @JoinColumn(name = "datatype")
124 private Datatype datatypeBean;
126 @Column(name = "is_designator", nullable = false)
128 private char isDesignator = '1';
130 @Column(name = "selector_path", nullable = true, length = 2048)
131 private String selectorPath;
134 private String issuer = null;
137 private boolean mustBePresent = false;
139 @ManyToOne(optional = false)
140 @JoinColumn(name = "created_by")
141 private UserInfo userCreatedBy;
143 @ManyToOne(optional = false)
144 @JoinColumn(name = "modified_by")
145 private UserInfo userModifiedBy;
148 * Default constructor.
151 // An empty constructor
155 * Constructor with domain.
157 * @param domain the domain to use to construct the object
159 public Attribute(String domain) {
160 this.xacmlId = domain;
166 * @param copy the copy to copy from
168 public Attribute(Attribute copy) {
169 this(copy.getXacmlId() + ":(0)");
170 this.constraintType = copy.getConstraintType();
171 this.categoryBean = copy.getCategoryBean();
172 this.datatypeBean = copy.getDatatypeBean();
173 this.description = copy.getDescription();
174 for (ConstraintValue value : copy.getConstraintValues()) {
175 ConstraintValue newValue = new ConstraintValue(value);
176 newValue.setAttribute(this);
177 this.addConstraintValue(newValue);
182 * Called before an instance is persisted.
185 public void prePersist() {
186 Date date = new Date();
187 this.createdDate = date;
188 this.modifiedDate = date;
192 * Called before an instance is updated.
195 public void preUpdate() {
196 this.modifiedDate = new Date();
200 * Sets the constraint values.
202 * @param constraintValues the new constraint values
204 public void setConstraintValues(Set<ConstraintValue> constraintValues) {
205 if (this.constraintValues == null) {
206 this.constraintValues = new HashSet<>();
208 for (ConstraintValue value : this.constraintValues) {
209 value.setAttribute(this);
211 this.constraintValues = constraintValues;
215 * Adds the constraint value.
217 * @param constraintValue the constraint value
218 * @return the constraint value
220 public ConstraintValue addConstraintValue(ConstraintValue constraintValue) {
221 if (this.constraintValues == null) {
222 this.constraintValues = new HashSet<>();
224 this.constraintValues.add(constraintValue);
225 constraintValue.setAttribute(this);
227 return constraintValue;
231 * Removes the constraint value.
233 * @param constraintValue the constraint value
234 * @return the constraint value
236 public ConstraintValue removeConstraintValue(ConstraintValue constraintValue) {
237 this.constraintValues.remove(constraintValue);
238 constraintValue.setAttribute(null);
240 return constraintValue;
244 * Removes the all constraint values.
246 public void removeAllConstraintValues() {
247 if (this.constraintValues == null) {
250 for (ConstraintValue value : this.constraintValues) {
251 value.setAttribute(null);
253 this.constraintValues.clear();
262 public String getIssuer() {
269 * @param issuer the new issuer
272 public void setIssuer(String issuer) {
273 this.issuer = issuer;
277 * Checks if is must be present.
279 * @return true, if is must be present
282 public boolean isMustBePresent() {
283 return mustBePresent;
287 * Sets the must be present.
289 * @param mustBePresent the new must be present
292 public void setMustBePresent(boolean mustBePresent) {
293 this.mustBePresent = mustBePresent;
297 * Checks if is designator.
299 * @return true, if is designator
302 public boolean isDesignator() {
303 return this.isDesignator == '1';
307 * Sets the checks if is designator.
309 * @param is the new checks if is designator
312 public void setIsDesignator(boolean is) {
314 this.isDesignator = '1';
316 this.isDesignator = '0';