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;
49 import org.openecomp.policy.rest.jpa.UserInfo;
51 import com.att.research.xacml.api.Identifier;
52 import com.att.research.xacml.std.IdentifierImpl;
53 import com.fasterxml.jackson.annotation.JsonBackReference;
54 import com.fasterxml.jackson.annotation.JsonIgnore;
55 import com.fasterxml.jackson.annotation.JsonManagedReference;
58 * The persistent class for the Attribute database table.
62 @Table(name="Attribute")
63 @NamedQuery(name="Attribute.findAll", query="SELECT a FROM Attribute a order by a.priority asc, a.xacmlId asc")
64 public class Attribute implements Serializable {
65 private static final long serialVersionUID = 1L;
67 public static String ATTRIBUTE_DESIGNATOR = "Attribute Designator";
68 public static String ATTRIBUTE_SELECTOR = "Attribute Selector";
71 @GeneratedValue(strategy = GenerationType.AUTO)
75 //bi-directional many-to-one association to Category
77 @JoinColumn(name="constraint_type", nullable=true)
79 private ConstraintType constraintType;
81 @Temporal(TemporalType.TIMESTAMP)
82 @Column(name="created_date", updatable=false)
83 private Date createdDate;
85 @Column(name="description", nullable=true, length=2048)
86 private String description;
88 @Temporal(TemporalType.TIMESTAMP)
89 @Column(name="modified_date", nullable=false)
90 private Date modifiedDate;
92 @Column(name="PRIORITY", nullable=true)
94 private String priority;
96 @Column(name="ATTRIBUTE_VALUE", nullable=true)
98 private String attributeValue;
100 @Column(name="xacml_id", unique = true, nullable=false)
102 private String xacmlId = "urn";
104 //bi-directional many-to-one association to ConstraintValue
105 @OneToMany(mappedBy="attribute", orphanRemoval=true, cascade=CascadeType.REMOVE)
107 private Set<ConstraintValue> constraintValues = new HashSet<ConstraintValue>();
109 //bi-directional many-to-one association to Category
111 @JoinColumn(name="category")
113 private Category categoryBean;
115 //bi-directional many-to-one association to Datatype
117 @JoinColumn(name="datatype")
118 private Datatype datatypeBean;
120 @Column(name="is_designator", nullable=false)
122 private char isDesignator = '1';
124 @Column(name="selector_path", nullable=true, length=2048)
125 private String selectorPath;
130 private String issuer = null;
133 private boolean mustBePresent = false;
135 @ManyToOne(optional = false)
136 @JoinColumn(name="created_by")
137 private UserInfo userCreatedBy;
139 @ManyToOne(optional = false)
140 @JoinColumn(name="modified_by")
141 private UserInfo userModifiedBy;
143 public UserInfo getUserCreatedBy() {
144 return userCreatedBy;
147 public void setUserCreatedBy(UserInfo userCreatedBy) {
148 this.userCreatedBy = userCreatedBy;
151 public UserInfo getUserModifiedBy() {
152 return userModifiedBy;
155 public void setUserModifiedBy(UserInfo userModifiedBy) {
156 this.userModifiedBy = userModifiedBy;
159 private static Log logger = LogFactory.getLog(Attribute.class);
163 public Attribute(String domain) {
164 this.xacmlId = domain;
167 public Attribute(String domain, String user) {
171 public Attribute(Attribute copy, String user) {
172 this(copy.getXacmlId() + ":(0)", user);
173 this.constraintType = copy.getConstraintType();
174 this.categoryBean = copy.getCategoryBean();
175 this.datatypeBean = copy.getDatatypeBean();
176 this.description = copy.getDescription();
177 for (ConstraintValue value : copy.getConstraintValues()) {
178 ConstraintValue newValue = new ConstraintValue(value);
179 newValue.setAttribute(this);
180 this.addConstraintValue(newValue);
185 public void prePersist() {
186 Date date = new Date();
187 this.createdDate = date;
188 this.modifiedDate = date;
192 public void preUpdate() {
193 this.modifiedDate = new Date();
195 this.userModifiedBy = XacmlAdminAuthorization.getUserId();
196 } catch (Exception e) {
197 logger.error("Exception caused While adding Modified by Role"+e);
198 // TODO:EELF Cleanup - Remove logger
199 //PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "Attribute", "Exception caused While adding Modified by Role");
207 public void setId(int id) {
211 public ConstraintType getConstraintType() {
212 return this.constraintType;
215 public void setConstraintType(ConstraintType constraintType) {
216 this.constraintType = constraintType;
219 public Date getCreatedDate() {
220 return this.createdDate;
223 public void setCreatedDate(Date createdDate) {
224 this.createdDate = createdDate;
227 public String getDescription() {
228 return this.description;
231 public void setDescription(String description) {
232 this.description = description;
235 public Date getModifiedDate() {
236 return this.modifiedDate;
239 public void setModifiedDate(Date modifiedDate) {
240 this.modifiedDate = modifiedDate;
243 public String getXacmlId() {
248 public Identifier getXacmlIdentifier() {
249 return new IdentifierImpl(this.xacmlId);
252 public void setXacmlId(String xacmlId) {
253 this.xacmlId = xacmlId;
256 public Set<ConstraintValue> getConstraintValues() {
257 return this.constraintValues;
260 public void setConstraintValues(Set<ConstraintValue> constraintValues) {
261 for (ConstraintValue value : this.constraintValues) {
262 value.setAttribute(this);
264 this.constraintValues = constraintValues;
267 public ConstraintValue addConstraintValue(ConstraintValue constraintValue) {
268 if (this.constraintValues == null) {
269 this.constraintValues = new HashSet<ConstraintValue>();
271 this.constraintValues.add(constraintValue);
272 constraintValue.setAttribute(this);
274 return constraintValue;
277 public ConstraintValue removeConstraintValue(ConstraintValue constraintValue) {
278 this.constraintValues.remove(constraintValue);
279 constraintValue.setAttribute(null);
281 return constraintValue;
284 public void removeAllConstraintValues() {
285 if (this.constraintValues == null) {
288 for (ConstraintValue value : this.constraintValues) {
289 value.setAttribute(null);
291 this.constraintValues.clear();
294 public Category getCategoryBean() {
295 return this.categoryBean;
298 public void setCategoryBean(Category categoryBean) {
299 this.categoryBean = categoryBean;
302 public Datatype getDatatypeBean() {
303 return this.datatypeBean;
306 public void setDatatypeBean(Datatype datatypeBean) {
307 this.datatypeBean = datatypeBean;
310 public char getIsDesignator() {
311 return this.isDesignator;
314 public void setIsDesignator(char is) {
315 this.isDesignator = is;
318 public String getSelectorPath() {
319 return this.selectorPath;
322 public void setSelectorPath(String path) {
323 this.selectorPath = path;
327 public String getIssuer() {
332 public void setIssuer(String issuer) {
333 this.issuer = issuer;
337 public boolean isMustBePresent() {
338 return mustBePresent;
342 public void setMustBePresent(boolean mustBePresent) {
343 this.mustBePresent = mustBePresent;
347 public boolean isDesignator() {
348 return (this.isDesignator == '1');
352 public void setIsDesignator(boolean is) {
354 this.isDesignator = '1';
356 this.isDesignator = '0';
360 public String getPriority() {
364 public void setPriority(String priority) {
365 this.priority = priority;
368 public String getAttributeValue() {
369 return attributeValue;
372 public void setAttributeValue(String attributeValue) {
373 this.attributeValue = attributeValue;