Fixed the Sonar technical debt.
[policy/engine.git] / ONAP-REST / src / main / java / org / onap / policy / rest / jpa / DecisionSettings.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-REST
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.policy.rest.jpa;
22
23 import java.io.Serializable;
24 import java.util.Date;
25
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;
41
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;
45
46
47 @Entity
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;
52
53         @Id
54         @GeneratedValue(strategy = GenerationType.AUTO)
55         @Column(name="id")
56         private int id;
57
58         @Temporal(TemporalType.TIMESTAMP)
59         @Column(name="created_date", updatable=false)
60         private Date createdDate;
61
62         @Column(name="description", nullable=true, length=2048)
63         private String description;
64
65         @Temporal(TemporalType.TIMESTAMP)
66         @Column(name="modified_date", nullable=false)
67         private Date modifiedDate;
68
69         @Column(name="PRIORITY", nullable=true)
70         @OrderBy("asc")
71         private String priority;
72         
73         @Column(name="xacml_id", unique = true, nullable=false)
74         @OrderBy("asc")
75         private String xacmlId = "urn";
76
77         //bi-directional many-to-one association to Datatype
78         @ManyToOne
79         @JoinColumn(name="datatype")
80         private Datatype datatypeBean;
81         
82         @Transient
83         private String issuer = null;
84         
85         @Transient
86         private boolean mustBePresent = false;
87
88         @ManyToOne(optional = false)
89         @JoinColumn(name="created_by")
90         private UserInfo userCreatedBy;
91
92         @ManyToOne(optional = false)
93         @JoinColumn(name="modified_by")
94         private UserInfo userModifiedBy;
95         
96         public UserInfo getUserCreatedBy() {
97                 return userCreatedBy;
98         }
99
100         public void setUserCreatedBy(UserInfo userCreatedBy) {
101                 this.userCreatedBy = userCreatedBy;
102         }
103
104         public UserInfo getUserModifiedBy() {
105                 return userModifiedBy;
106         }
107
108         public void setUserModifiedBy(UserInfo userModifiedBy) {
109                 this.userModifiedBy = userModifiedBy;
110         }
111         
112         public DecisionSettings() {
113                 //An empty constructor
114         }
115         
116         public DecisionSettings(String domain) {
117                 this.xacmlId = domain;
118         }
119         
120         public DecisionSettings(String domain, String user) {
121                 this(domain);
122         }
123         public DecisionSettings(DecisionSettings copy, String user) {
124                 this(copy.getXacmlId() + ":(0)", user);
125                 this.datatypeBean = copy.getDatatypeBean();
126                 this.description = copy.getDescription();
127                 
128         }
129         
130         public String getDecisionSettings(){
131                 return this.xacmlId;
132         }
133         
134         public String setDecisionSettings(){
135                 return this.xacmlId;
136         }
137         @PrePersist
138         public void     prePersist() {
139                 Date date = new Date();
140                 this.createdDate = date;
141                 this.modifiedDate = date;
142         }
143         
144         @PreUpdate
145         public void preUpdate() {
146                 this.modifiedDate = new Date();
147                 try {
148                         this.userModifiedBy = XacmlAdminAuthorization.getUserId();
149                 } catch (Exception e) {
150                         PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "DecisionSettings", "Exception caused While adding Modified by Role");
151                 }
152         }
153
154         public int getId() {
155                 return this.id;
156         }
157
158         public void setId(int id) {
159                 this.id = id;
160         }
161
162         
163         public Date getCreatedDate() {
164                 return this.createdDate;
165         }
166
167         public void setCreatedDate(Date createdDate) {
168                 this.createdDate = createdDate;
169         }
170
171         public String getDescription() {
172                 return this.description;
173         }
174
175         public void setDescription(String description) {
176                 this.description = description;
177         }
178
179         public Date getModifiedDate() {
180                 return this.modifiedDate;
181         }
182
183         public void setModifiedDate(Date modifiedDate) {
184                 this.modifiedDate = modifiedDate;
185         }
186
187         public String getXacmlId() {
188                 return this.xacmlId;
189         }
190
191         public void setXacmlId(String xacmlId) {
192                 this.xacmlId = xacmlId;
193         }
194         
195         public Datatype getDatatypeBean() {
196                 return this.datatypeBean;
197         }
198
199         public void setDatatypeBean(Datatype datatypeBean) {
200                 this.datatypeBean = datatypeBean;
201         }
202
203         @Transient
204         public String getIssuer() {
205                 return issuer;
206         }
207
208         @Transient
209         public void setIssuer(String issuer) {
210                 this.issuer = issuer;
211         }
212
213         @Transient
214         public boolean isMustBePresent() {
215                 return mustBePresent;
216         }
217
218         @Transient
219         public void setMustBePresent(boolean mustBePresent) {
220                 this.mustBePresent = mustBePresent;
221         }
222
223         public String getPriority() {
224                 return priority;
225         }
226
227         public void setPriority(String priority) {
228                 this.priority = priority;
229         }
230 }
231