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=========================================================
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 org.apache.commons.logging.Log;
47 import org.apache.commons.logging.LogFactory;
48 import org.onap.policy.rest.XacmlAdminAuthorization;
50 import com.fasterxml.jackson.annotation.JsonIgnore;
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")
59 public class Attribute implements Serializable {
60 private static final long serialVersionUID = 1L;
61 private static final Log logger = LogFactory.getLog(Attribute.class);
64 @GeneratedValue(strategy = GenerationType.AUTO)
68 //bi-directional many-to-one association to Category
70 @JoinColumn(name="constraint_type", nullable=true)
72 private ConstraintType constraintType;
74 @Temporal(TemporalType.TIMESTAMP)
75 @Column(name="created_date", updatable=false)
76 private Date createdDate;
78 @Column(name="description", nullable=true, length=2048)
79 private String description;
81 @Temporal(TemporalType.TIMESTAMP)
82 @Column(name="modified_date", nullable=false)
83 private Date modifiedDate;
85 @Column(name="PRIORITY", nullable=true)
87 private String priority;
89 @Column(name="ATTRIBUTE_VALUE", nullable=true)
91 private String attributeValue;
93 @Column(name="xacml_id", unique = true, nullable=false)
95 private String xacmlId = "urn";
97 //bi-directional many-to-one association to ConstraintValue
98 @OneToMany(mappedBy="attribute", orphanRemoval=true, cascade=CascadeType.REMOVE)
100 private Set<ConstraintValue> constraintValues = new HashSet<>();
102 //bi-directional many-to-one association to Category
104 @JoinColumn(name="category")
106 private Category categoryBean;
108 //bi-directional many-to-one association to Datatype
110 @JoinColumn(name="datatype")
111 private Datatype datatypeBean;
113 @Column(name="is_designator", nullable=false)
115 private char isDesignator = '1';
117 @Column(name="selector_path", nullable=true, length=2048)
118 private String selectorPath;
123 private String issuer = null;
126 private boolean mustBePresent = false;
128 @ManyToOne(optional = false)
129 @JoinColumn(name="created_by")
130 private UserInfo userCreatedBy;
132 @ManyToOne(optional = false)
133 @JoinColumn(name="modified_by")
134 private UserInfo userModifiedBy;
136 public UserInfo getUserCreatedBy() {
137 return userCreatedBy;
140 public void setUserCreatedBy(UserInfo userCreatedBy) {
141 this.userCreatedBy = userCreatedBy;
144 public UserInfo getUserModifiedBy() {
145 return userModifiedBy;
148 public void setUserModifiedBy(UserInfo userModifiedBy) {
149 this.userModifiedBy = userModifiedBy;
154 //An empty constructor
157 public Attribute(String domain) {
158 this.xacmlId = domain;
161 public Attribute(Attribute copy) {
162 this(copy.getXacmlId() + ":(0)");
163 this.constraintType = copy.getConstraintType();
164 this.categoryBean = copy.getCategoryBean();
165 this.datatypeBean = copy.getDatatypeBean();
166 this.description = copy.getDescription();
167 for (ConstraintValue value : copy.getConstraintValues()) {
168 ConstraintValue newValue = new ConstraintValue(value);
169 newValue.setAttribute(this);
170 this.addConstraintValue(newValue);
175 public void prePersist() {
176 Date date = new Date();
177 this.createdDate = date;
178 this.modifiedDate = date;
182 public void preUpdate() {
183 this.modifiedDate = new Date();
185 this.userModifiedBy = XacmlAdminAuthorization.getUserId();
186 } catch (Exception e) {
187 logger.error("Exception caused While adding Modified by Role"+e);
195 public void setId(int id) {
199 public ConstraintType getConstraintType() {
200 return this.constraintType;
203 public void setConstraintType(ConstraintType constraintType) {
204 this.constraintType = constraintType;
207 public Date getCreatedDate() {
208 return this.createdDate;
211 public void setCreatedDate(Date createdDate) {
212 this.createdDate = createdDate;
215 public String getDescription() {
216 return this.description;
219 public void setDescription(String description) {
220 this.description = description;
223 public Date getModifiedDate() {
224 return this.modifiedDate;
227 public void setModifiedDate(Date modifiedDate) {
228 this.modifiedDate = modifiedDate;
231 public String getXacmlId() {
236 public void setXacmlId(String xacmlId) {
237 this.xacmlId = xacmlId;
240 public Set<ConstraintValue> getConstraintValues() {
241 return this.constraintValues;
244 public void setConstraintValues(Set<ConstraintValue> constraintValues) {
245 for (ConstraintValue value : this.constraintValues) {
246 value.setAttribute(this);
248 this.constraintValues = constraintValues;
251 public ConstraintValue addConstraintValue(ConstraintValue constraintValue) {
252 if (this.constraintValues == null) {
253 this.constraintValues = new HashSet<>();
255 this.constraintValues.add(constraintValue);
256 constraintValue.setAttribute(this);
258 return constraintValue;
261 public ConstraintValue removeConstraintValue(ConstraintValue constraintValue) {
262 this.constraintValues.remove(constraintValue);
263 constraintValue.setAttribute(null);
265 return constraintValue;
268 public void removeAllConstraintValues() {
269 if (this.constraintValues == null) {
272 for (ConstraintValue value : this.constraintValues) {
273 value.setAttribute(null);
275 this.constraintValues.clear();
278 public Category getCategoryBean() {
279 return this.categoryBean;
282 public void setCategoryBean(Category categoryBean) {
283 this.categoryBean = categoryBean;
286 public Datatype getDatatypeBean() {
287 return this.datatypeBean;
290 public void setDatatypeBean(Datatype datatypeBean) {
291 this.datatypeBean = datatypeBean;
294 public char getIsDesignator() {
295 return this.isDesignator;
298 public void setIsDesignator(char is) {
299 this.isDesignator = is;
302 public String getSelectorPath() {
303 return this.selectorPath;
306 public void setSelectorPath(String path) {
307 this.selectorPath = path;
311 public String getIssuer() {
316 public void setIssuer(String issuer) {
317 this.issuer = issuer;
321 public boolean isMustBePresent() {
322 return mustBePresent;
326 public void setMustBePresent(boolean mustBePresent) {
327 this.mustBePresent = mustBePresent;
331 public boolean isDesignator() {
332 return this.isDesignator == '1';
336 public void setIsDesignator(boolean is) {
338 this.isDesignator = '1';
340 this.isDesignator = '0';
344 public String getPriority() {
348 public void setPriority(String priority) {
349 this.priority = priority;
352 public String getAttributeValue() {
353 return attributeValue;
356 public void setAttributeValue(String attributeValue) {
357 this.attributeValue = attributeValue;