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;
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.apache.commons.logging.Log;
43 import org.apache.commons.logging.LogFactory;
44 import org.openecomp.policy.rest.XacmlAdminAuthorization;
46 import com.att.research.xacml.api.Identifier;
47 import com.att.research.xacml.std.IdentifierImpl;
48 import com.fasterxml.jackson.annotation.JsonManagedReference;
50 import org.openecomp.policy.common.logging.eelf.MessageCodes;
51 import org.openecomp.policy.common.logging.eelf.PolicyLogger;
55 @Table(name="DecisionSettings")
56 @NamedQuery(name="DecisionSettings.findAll", query="SELECT a FROM DecisionSettings a order by a.priority asc, a.xacmlId asc")
57 public class DecisionSettings implements Serializable {
58 private static final long serialVersionUID = 1L;
61 @GeneratedValue(strategy = GenerationType.AUTO)
65 @Temporal(TemporalType.TIMESTAMP)
66 @Column(name="created_date", updatable=false)
67 private Date createdDate;
69 @Column(name="description", nullable=true, length=2048)
70 private String description;
72 @Temporal(TemporalType.TIMESTAMP)
73 @Column(name="modified_date", nullable=false)
74 private Date modifiedDate;
76 @Column(name="PRIORITY", nullable=true)
78 private String priority;
80 @Column(name="xacml_id", unique = true, nullable=false)
82 private String xacmlId = "urn";
84 //bi-directional many-to-one association to Datatype
86 @JoinColumn(name="datatype")
87 private Datatype datatypeBean;
90 private String issuer = null;
93 private boolean mustBePresent = false;
95 @ManyToOne(optional = false)
96 @JoinColumn(name="created_by")
97 private UserInfo userCreatedBy;
99 @ManyToOne(optional = false)
100 @JoinColumn(name="modified_by")
101 private UserInfo userModifiedBy;
103 public UserInfo getUserCreatedBy() {
104 return userCreatedBy;
107 public void setUserCreatedBy(UserInfo userCreatedBy) {
108 this.userCreatedBy = userCreatedBy;
111 public UserInfo getUserModifiedBy() {
112 return userModifiedBy;
115 public void setUserModifiedBy(UserInfo userModifiedBy) {
116 this.userModifiedBy = userModifiedBy;
119 private static Log logger = LogFactory.getLog(DecisionSettings.class);
120 public DecisionSettings() {
123 public DecisionSettings(String domain) {
124 this.xacmlId = domain;
127 public DecisionSettings(String domain, String user) {
130 public DecisionSettings(DecisionSettings copy, String user) {
131 this(copy.getXacmlId() + ":(0)", user);
132 this.datatypeBean = copy.getDatatypeBean();
133 this.description = copy.getDescription();
137 public String getDecisionSettings(){
141 public String setDecisionSettings(){
142 return this.xacmlId = xacmlId;
145 public void prePersist() {
146 Date date = new Date();
147 this.createdDate = date;
148 this.modifiedDate = date;
152 public void preUpdate() {
153 this.modifiedDate = new Date();
155 this.userModifiedBy = XacmlAdminAuthorization.getUserId();;
156 } catch (Exception e) {
157 logger.error("Exception caused While adding Modified by Role"+e);
158 // TODO:EELF Cleanup - Remove logger
159 PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "DecisionSettings", "Exception caused While adding Modified by Role");
167 public void setId(int id) {
172 public Date getCreatedDate() {
173 return this.createdDate;
176 public void setCreatedDate(Date createdDate) {
177 this.createdDate = createdDate;
180 public String getDescription() {
181 return this.description;
184 public void setDescription(String description) {
185 this.description = description;
188 public Date getModifiedDate() {
189 return this.modifiedDate;
192 public void setModifiedDate(Date modifiedDate) {
193 this.modifiedDate = modifiedDate;
196 public String getXacmlId() {
201 public Identifier getXacmlIdentifier() {
202 return new IdentifierImpl(this.xacmlId);
205 public void setXacmlId(String xacmlId) {
206 this.xacmlId = xacmlId;
209 public Datatype getDatatypeBean() {
210 return this.datatypeBean;
213 public void setDatatypeBean(Datatype datatypeBean) {
214 this.datatypeBean = datatypeBean;
218 public String getIssuer() {
223 public void setIssuer(String issuer) {
224 this.issuer = issuer;
228 public boolean isMustBePresent() {
229 return mustBePresent;
233 public void setMustBePresent(boolean mustBePresent) {
234 this.mustBePresent = mustBePresent;
237 public String getPriority() {
241 public void setPriority(String priority) {
242 this.priority = priority;