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.NamedQuery;
35 import javax.persistence.OneToMany;
36 import javax.persistence.PrePersist;
37 import javax.persistence.PreUpdate;
38 import javax.persistence.Table;
39 import javax.persistence.Temporal;
40 import javax.persistence.TemporalType;
41 import javax.persistence.Transient;
43 import com.att.research.xacml.api.Identifier;
46 * The persistent class for the Obadvice database table.
50 @Table(name="Obadvice")
51 @NamedQuery(name="Obadvice.findAll", query="SELECT o FROM Obadvice o")
52 public class Obadvice implements Serializable {
53 private static final long serialVersionUID = 1L;
55 public static final String OBLIGATION = "Obligation";
56 public static final String ADVICE = "Advice";
57 public static final String EFFECT_PERMIT = "Permit";
58 public static final String EFFECT_DENY = "Deny";
60 @GeneratedValue(strategy = GenerationType.AUTO)
64 @Column(name="type", nullable=false)
67 @Column(name="xacml_id", nullable=false, length=255)
68 private String xacmlId;
70 @Column(name="fulfill_on", nullable=true, length=32)
71 private String fulfillOn;
73 @Column(name="description", nullable=true, length=2048)
74 private String description;
76 //bi-directional one-to-many association to Attribute Assignment
77 @OneToMany(mappedBy="obadvice", orphanRemoval=true, cascade=CascadeType.REMOVE)
78 private Set<ObadviceExpression> obadviceExpressions = new HashSet<>(2);
80 @Column(name="created_by", nullable=false, length=255)
81 private String createdBy;
83 @Temporal(TemporalType.TIMESTAMP)
84 @Column(name="created_date", nullable=false, updatable=false)
85 private Date createdDate;
87 @Column(name="modified_by", nullable=false, length=255)
88 private String modifiedBy;
90 @Temporal(TemporalType.TIMESTAMP)
91 @Column(name="modified_date", nullable=false)
92 private Date modifiedDate;
95 this.type = Obadvice.OBLIGATION;
96 this.fulfillOn = Obadvice.EFFECT_PERMIT;
99 public Obadvice(String domain, String userid) {
100 this.xacmlId = domain;
101 this.type = Obadvice.OBLIGATION;
102 this.fulfillOn = Obadvice.EFFECT_PERMIT;
103 this.createdBy = userid;
104 this.modifiedBy = userid;
107 public Obadvice(Identifier id, String userid) {
108 this(id.stringValue(), userid);
112 public void prePersist() {
113 Date date = new Date();
114 this.createdDate = date;
115 this.modifiedDate = date;
119 public void preUpdate() {
120 this.modifiedDate = new Date();
127 public void setId(int id) {
131 public String getCreatedBy() {
132 return this.createdBy;
135 public void setCreatedBy(String createdBy) {
136 this.createdBy = createdBy;
139 public String getDescription() {
140 return this.description;
143 public void setDescription(String description) {
144 this.description = description;
147 public String getFulfillOn() {
148 return this.fulfillOn;
151 public void setFulfillOn(String fulfillOn) {
152 this.fulfillOn = fulfillOn;
155 public String getModifiedBy() {
156 return this.modifiedBy;
159 public void setModifiedBy(String modifiedBy) {
160 this.modifiedBy = modifiedBy;
163 public String getType() {
167 public void setType(String type) {
171 public String getXacmlId() {
175 public void setXacmlId(String xacmlId) {
176 this.xacmlId = xacmlId;
179 public Set<ObadviceExpression> getObadviceExpressions() {
180 return this.obadviceExpressions;
183 public void setObadviceExpressions(Set<ObadviceExpression> obadviceExpressions) {
184 this.obadviceExpressions = obadviceExpressions;
187 public ObadviceExpression addObadviceExpression(ObadviceExpression obadviceExpression) {
188 this.obadviceExpressions.add(obadviceExpression);
189 obadviceExpression.setObadvice(this);
191 return obadviceExpression;
194 public ObadviceExpression removeObadviceExpression(ObadviceExpression obadviceExpression) {
195 this.obadviceExpressions.remove(obadviceExpression);
196 obadviceExpression.setObadvice(null);
198 return obadviceExpression;
201 public void removeAllExpressions() {
202 if (this.obadviceExpressions == null) {
205 for (ObadviceExpression expression : this.obadviceExpressions) {
206 expression.setObadvice(null);
208 this.obadviceExpressions.clear();
212 public Obadvice clone() {
213 Obadvice obadvice = new Obadvice();
215 obadvice.type = this.type;
216 obadvice.xacmlId = this.xacmlId;
217 obadvice.fulfillOn = this.fulfillOn;
218 obadvice.description = this.description;
219 obadvice.createdBy = this.createdBy;
220 obadvice.modifiedBy = this.modifiedBy;
221 for (ObadviceExpression exp: this.obadviceExpressions) {
222 obadvice.addObadviceExpression(exp.clone());