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;
156 public Attribute(String domain) {
157 this.xacmlId = domain;
160 public Attribute(Attribute copy) {
161 this(copy.getXacmlId() + ":(0)");
162 this.constraintType = copy.getConstraintType();
163 this.categoryBean = copy.getCategoryBean();
164 this.datatypeBean = copy.getDatatypeBean();
165 this.description = copy.getDescription();
166 for (ConstraintValue value : copy.getConstraintValues()) {
167 ConstraintValue newValue = new ConstraintValue(value);
168 newValue.setAttribute(this);
169 this.addConstraintValue(newValue);
174 public void prePersist() {
175 Date date = new Date();
176 this.createdDate = date;
177 this.modifiedDate = date;
181 public void preUpdate() {
182 this.modifiedDate = new Date();
184 this.userModifiedBy = XacmlAdminAuthorization.getUserId();
185 } catch (Exception e) {
186 logger.error("Exception caused While adding Modified by Role"+e);
194 public void setId(int id) {
198 public ConstraintType getConstraintType() {
199 return this.constraintType;
202 public void setConstraintType(ConstraintType constraintType) {
203 this.constraintType = constraintType;
206 public Date getCreatedDate() {
207 return this.createdDate;
210 public void setCreatedDate(Date createdDate) {
211 this.createdDate = createdDate;
214 public String getDescription() {
215 return this.description;
218 public void setDescription(String description) {
219 this.description = description;
222 public Date getModifiedDate() {
223 return this.modifiedDate;
226 public void setModifiedDate(Date modifiedDate) {
227 this.modifiedDate = modifiedDate;
230 public String getXacmlId() {
235 public Identifier getXacmlIdentifier() {
236 return new IdentifierImpl(this.xacmlId);
239 public void setXacmlId(String xacmlId) {
240 this.xacmlId = xacmlId;
243 public Set<ConstraintValue> getConstraintValues() {
244 return this.constraintValues;
247 public void setConstraintValues(Set<ConstraintValue> constraintValues) {
248 for (ConstraintValue value : this.constraintValues) {
249 value.setAttribute(this);
251 this.constraintValues = constraintValues;
254 public ConstraintValue addConstraintValue(ConstraintValue constraintValue) {
255 if (this.constraintValues == null) {
256 this.constraintValues = new HashSet<>();
258 this.constraintValues.add(constraintValue);
259 constraintValue.setAttribute(this);
261 return constraintValue;
264 public ConstraintValue removeConstraintValue(ConstraintValue constraintValue) {
265 this.constraintValues.remove(constraintValue);
266 constraintValue.setAttribute(null);
268 return constraintValue;
271 public void removeAllConstraintValues() {
272 if (this.constraintValues == null) {
275 for (ConstraintValue value : this.constraintValues) {
276 value.setAttribute(null);
278 this.constraintValues.clear();
281 public Category getCategoryBean() {
282 return this.categoryBean;
285 public void setCategoryBean(Category categoryBean) {
286 this.categoryBean = categoryBean;
289 public Datatype getDatatypeBean() {
290 return this.datatypeBean;
293 public void setDatatypeBean(Datatype datatypeBean) {
294 this.datatypeBean = datatypeBean;
297 public char getIsDesignator() {
298 return this.isDesignator;
301 public void setIsDesignator(char is) {
302 this.isDesignator = is;
305 public String getSelectorPath() {
306 return this.selectorPath;
309 public void setSelectorPath(String path) {
310 this.selectorPath = path;
314 public String getIssuer() {
319 public void setIssuer(String issuer) {
320 this.issuer = issuer;
324 public boolean isMustBePresent() {
325 return mustBePresent;
329 public void setMustBePresent(boolean mustBePresent) {
330 this.mustBePresent = mustBePresent;
334 public boolean isDesignator() {
335 return (this.isDesignator == '1');
339 public void setIsDesignator(boolean is) {
341 this.isDesignator = '1';
343 this.isDesignator = '0';
347 public String getPriority() {
351 public void setPriority(String priority) {
352 this.priority = priority;
355 public String getAttributeValue() {
356 return attributeValue;
359 public void setAttributeValue(String attributeValue) {
360 this.attributeValue = attributeValue;