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;
26 import javax.persistence.Column;
27 import javax.persistence.Entity;
28 import javax.persistence.GeneratedValue;
29 import javax.persistence.GenerationType;
30 import javax.persistence.Id;
31 import javax.persistence.JoinColumn;
32 import javax.persistence.ManyToOne;
33 import javax.persistence.NamedQuery;
34 import javax.persistence.OrderBy;
35 import javax.persistence.PrePersist;
36 import javax.persistence.PreUpdate;
37 import javax.persistence.Table;
38 import javax.persistence.Temporal;
39 import javax.persistence.TemporalType;
40 import javax.persistence.Transient;
42 import org.onap.policy.common.logging.eelf.MessageCodes;
43 import org.onap.policy.common.logging.eelf.PolicyLogger;
44 import org.onap.policy.rest.XacmlAdminAuthorization;
48 @Table(name="DecisionSettings")
49 @NamedQuery(name="DecisionSettings.findAll", query="SELECT a FROM DecisionSettings a order by a.priority asc, a.xacmlId asc")
50 public class DecisionSettings implements Serializable {
51 private static final long serialVersionUID = 1L;
54 @GeneratedValue(strategy = GenerationType.AUTO)
58 @Temporal(TemporalType.TIMESTAMP)
59 @Column(name="created_date", updatable=false)
60 private Date createdDate;
62 @Column(name="description", nullable=true, length=2048)
63 private String description;
65 @Temporal(TemporalType.TIMESTAMP)
66 @Column(name="modified_date", nullable=false)
67 private Date modifiedDate;
69 @Column(name="PRIORITY", nullable=true)
71 private String priority;
73 @Column(name="xacml_id", unique = true, nullable=false)
75 private String xacmlId = "urn";
77 //bi-directional many-to-one association to Datatype
79 @JoinColumn(name="datatype")
80 private Datatype datatypeBean;
83 private String issuer = null;
86 private boolean mustBePresent = false;
88 @ManyToOne(optional = false)
89 @JoinColumn(name="created_by")
90 private UserInfo userCreatedBy;
92 @ManyToOne(optional = false)
93 @JoinColumn(name="modified_by")
94 private UserInfo userModifiedBy;
96 public UserInfo getUserCreatedBy() {
100 public void setUserCreatedBy(UserInfo userCreatedBy) {
101 this.userCreatedBy = userCreatedBy;
104 public UserInfo getUserModifiedBy() {
105 return userModifiedBy;
108 public void setUserModifiedBy(UserInfo userModifiedBy) {
109 this.userModifiedBy = userModifiedBy;
112 public DecisionSettings() {
115 public DecisionSettings(String domain) {
116 this.xacmlId = domain;
119 public DecisionSettings(String domain, String user) {
122 public DecisionSettings(DecisionSettings copy, String user) {
123 this(copy.getXacmlId() + ":(0)", user);
124 this.datatypeBean = copy.getDatatypeBean();
125 this.description = copy.getDescription();
129 public String getDecisionSettings(){
133 public String setDecisionSettings(){
137 public void prePersist() {
138 Date date = new Date();
139 this.createdDate = date;
140 this.modifiedDate = date;
144 public void preUpdate() {
145 this.modifiedDate = new Date();
147 this.userModifiedBy = XacmlAdminAuthorization.getUserId();;
148 } catch (Exception e) {
149 PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "DecisionSettings", "Exception caused While adding Modified by Role");
157 public void setId(int id) {
162 public Date getCreatedDate() {
163 return this.createdDate;
166 public void setCreatedDate(Date createdDate) {
167 this.createdDate = createdDate;
170 public String getDescription() {
171 return this.description;
174 public void setDescription(String description) {
175 this.description = description;
178 public Date getModifiedDate() {
179 return this.modifiedDate;
182 public void setModifiedDate(Date modifiedDate) {
183 this.modifiedDate = modifiedDate;
186 public String getXacmlId() {
191 public Identifier getXacmlIdentifier() {
192 return new IdentifierImpl(this.xacmlId);
195 public void setXacmlId(String xacmlId) {
196 this.xacmlId = xacmlId;
199 public Datatype getDatatypeBean() {
200 return this.datatypeBean;
203 public void setDatatypeBean(Datatype datatypeBean) {
204 this.datatypeBean = datatypeBean;
208 public String getIssuer() {
213 public void setIssuer(String issuer) {
214 this.issuer = issuer;
218 public boolean isMustBePresent() {
219 return mustBePresent;
223 public void setMustBePresent(boolean mustBePresent) {
224 this.mustBePresent = mustBePresent;
227 public String getPriority() {
231 public void setPriority(String priority) {
232 this.priority = priority;