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.openecomp.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.openecomp.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;
62 public static String ATTRIBUTE_DESIGNATOR = "Attribute Designator";
63 public static String ATTRIBUTE_SELECTOR = "Attribute Selector";
66 @GeneratedValue(strategy = GenerationType.AUTO)
70 //bi-directional many-to-one association to Category
72 @JoinColumn(name="constraint_type", nullable=true)
74 private ConstraintType constraintType;
76 @Temporal(TemporalType.TIMESTAMP)
77 @Column(name="created_date", updatable=false)
78 private Date createdDate;
80 @Column(name="description", nullable=true, length=2048)
81 private String description;
83 @Temporal(TemporalType.TIMESTAMP)
84 @Column(name="modified_date", nullable=false)
85 private Date modifiedDate;
87 @Column(name="PRIORITY", nullable=true)
89 private String priority;
91 @Column(name="ATTRIBUTE_VALUE", nullable=true)
93 private String attributeValue;
95 @Column(name="xacml_id", unique = true, nullable=false)
97 private String xacmlId = "urn";
99 //bi-directional many-to-one association to ConstraintValue
100 @OneToMany(mappedBy="attribute", orphanRemoval=true, cascade=CascadeType.REMOVE)
102 private Set<ConstraintValue> constraintValues = new HashSet<>();
104 //bi-directional many-to-one association to Category
106 @JoinColumn(name="category")
108 private Category categoryBean;
110 //bi-directional many-to-one association to Datatype
112 @JoinColumn(name="datatype")
113 private Datatype datatypeBean;
115 @Column(name="is_designator", nullable=false)
117 private char isDesignator = '1';
119 @Column(name="selector_path", nullable=true, length=2048)
120 private String selectorPath;
125 private String issuer = null;
128 private boolean mustBePresent = false;
130 @ManyToOne(optional = false)
131 @JoinColumn(name="created_by")
132 private UserInfo userCreatedBy;
134 @ManyToOne(optional = false)
135 @JoinColumn(name="modified_by")
136 private UserInfo userModifiedBy;
138 public UserInfo getUserCreatedBy() {
139 return userCreatedBy;
142 public void setUserCreatedBy(UserInfo userCreatedBy) {
143 this.userCreatedBy = userCreatedBy;
146 public UserInfo getUserModifiedBy() {
147 return userModifiedBy;
150 public void setUserModifiedBy(UserInfo userModifiedBy) {
151 this.userModifiedBy = userModifiedBy;
154 private static Log LOGGER = LogFactory.getLog(Attribute.class);
158 public Attribute(String domain) {
159 this.xacmlId = domain;
162 public Attribute(String domain, String user) {
166 public Attribute(Attribute copy, String user) {
167 this(copy.getXacmlId() + ":(0)", user);
168 this.constraintType = copy.getConstraintType();
169 this.categoryBean = copy.getCategoryBean();
170 this.datatypeBean = copy.getDatatypeBean();
171 this.description = copy.getDescription();
172 for (ConstraintValue value : copy.getConstraintValues()) {
173 ConstraintValue newValue = new ConstraintValue(value);
174 newValue.setAttribute(this);
175 this.addConstraintValue(newValue);
180 public void prePersist() {
181 Date date = new Date();
182 this.createdDate = date;
183 this.modifiedDate = date;
187 public void preUpdate() {
188 this.modifiedDate = new Date();
190 this.userModifiedBy = XacmlAdminAuthorization.getUserId();
191 } catch (Exception e) {
192 LOGGER.error("Exception caused While adding Modified by Role"+e);
200 public void setId(int id) {
204 public ConstraintType getConstraintType() {
205 return this.constraintType;
208 public void setConstraintType(ConstraintType constraintType) {
209 this.constraintType = constraintType;
212 public Date getCreatedDate() {
213 return this.createdDate;
216 public void setCreatedDate(Date createdDate) {
217 this.createdDate = createdDate;
220 public String getDescription() {
221 return this.description;
224 public void setDescription(String description) {
225 this.description = description;
228 public Date getModifiedDate() {
229 return this.modifiedDate;
232 public void setModifiedDate(Date modifiedDate) {
233 this.modifiedDate = modifiedDate;
236 public String getXacmlId() {
241 public Identifier getXacmlIdentifier() {
242 return new IdentifierImpl(this.xacmlId);
245 public void setXacmlId(String xacmlId) {
246 this.xacmlId = xacmlId;
249 public Set<ConstraintValue> getConstraintValues() {
250 return this.constraintValues;
253 public void setConstraintValues(Set<ConstraintValue> constraintValues) {
254 for (ConstraintValue value : this.constraintValues) {
255 value.setAttribute(this);
257 this.constraintValues = constraintValues;
260 public ConstraintValue addConstraintValue(ConstraintValue constraintValue) {
261 if (this.constraintValues == null) {
262 this.constraintValues = new HashSet<>();
264 this.constraintValues.add(constraintValue);
265 constraintValue.setAttribute(this);
267 return constraintValue;
270 public ConstraintValue removeConstraintValue(ConstraintValue constraintValue) {
271 this.constraintValues.remove(constraintValue);
272 constraintValue.setAttribute(null);
274 return constraintValue;
277 public void removeAllConstraintValues() {
278 if (this.constraintValues == null) {
281 for (ConstraintValue value : this.constraintValues) {
282 value.setAttribute(null);
284 this.constraintValues.clear();
287 public Category getCategoryBean() {
288 return this.categoryBean;
291 public void setCategoryBean(Category categoryBean) {
292 this.categoryBean = categoryBean;
295 public Datatype getDatatypeBean() {
296 return this.datatypeBean;
299 public void setDatatypeBean(Datatype datatypeBean) {
300 this.datatypeBean = datatypeBean;
303 public char getIsDesignator() {
304 return this.isDesignator;
307 public void setIsDesignator(char is) {
308 this.isDesignator = is;
311 public String getSelectorPath() {
312 return this.selectorPath;
315 public void setSelectorPath(String path) {
316 this.selectorPath = path;
320 public String getIssuer() {
325 public void setIssuer(String issuer) {
326 this.issuer = issuer;
330 public boolean isMustBePresent() {
331 return mustBePresent;
335 public void setMustBePresent(boolean mustBePresent) {
336 this.mustBePresent = mustBePresent;
340 public boolean isDesignator() {
341 return (this.isDesignator == '1');
345 public void setIsDesignator(boolean is) {
347 this.isDesignator = '1';
349 this.isDesignator = '0';
353 public String getPriority() {
357 public void setPriority(String priority) {
358 this.priority = priority;
361 public String getAttributeValue() {
362 return attributeValue;
365 public void setAttributeValue(String attributeValue) {
366 this.attributeValue = attributeValue;