Fixed the Sonar technical debt.
[policy/engine.git] / ONAP-REST / src / main / java / org / onap / policy / rest / jpa / RiskType.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  */
24 import java.io.Serializable;
25 import java.util.Date;
26
27 import javax.persistence.Column;
28 import javax.persistence.Entity;
29 import javax.persistence.GeneratedValue;
30 import javax.persistence.GenerationType;
31 import javax.persistence.Id;
32 import javax.persistence.JoinColumn;
33 import javax.persistence.ManyToOne;
34 import javax.persistence.NamedQuery;
35 import javax.persistence.OrderBy;
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
42 import org.apache.commons.logging.Log;
43 import org.apache.commons.logging.LogFactory;
44 import org.onap.policy.common.logging.eelf.MessageCodes;
45 import org.onap.policy.common.logging.eelf.PolicyLogger;
46 import org.onap.policy.rest.XacmlAdminAuthorization;
47
48
49 @Entity
50 @Table(name="RiskType")
51 @NamedQuery(name="RiskType.findAll", query="SELECT e FROM RiskType e ")
52 public class RiskType implements Serializable {
53         private static final long serialVersionUID = 1L;
54
55         private static String domain;
56
57         @Id
58         @GeneratedValue(strategy = GenerationType.AUTO)
59         @Column(name="id")
60         private int id;
61         
62         @Column(name="name", nullable=false, unique=true)
63         @OrderBy("asc")
64         private String name;
65
66         @Temporal(TemporalType.TIMESTAMP)
67         @Column(name="created_date", updatable=false)
68         private Date createdDate;
69
70         @Column(name="description", nullable=true, length=2048)
71         private String description;
72
73         @Temporal(TemporalType.TIMESTAMP)
74         @Column(name="modified_date", nullable=false)
75         private Date modifiedDate;
76         
77         @ManyToOne(optional = false)
78         @JoinColumn(name="created_by")
79         private UserInfo userCreatedBy;
80
81         @ManyToOne(optional = false)
82         @JoinColumn(name="modified_by")
83         private UserInfo userModifiedBy;
84         
85         public UserInfo getUserCreatedBy() {
86                 return userCreatedBy;
87         }
88
89         public void setUserCreatedBy(UserInfo userCreatedBy) {
90                 this.userCreatedBy = userCreatedBy;
91         }
92
93         public UserInfo getUserModifiedBy() {
94                 return userModifiedBy;
95         }
96
97         public void setUserModifiedBy(UserInfo userModifiedBy) {
98                 this.userModifiedBy = userModifiedBy;
99         }
100
101         private static Log LOGGER = LogFactory.getLog(RiskType.class);
102         
103         public RiskType() {
104                 // Empty constructor
105         }
106         
107         public RiskType(String string, String userid) {
108                 this(domain);
109         }
110         
111         public RiskType(String domain) {
112                 this.name = domain;
113         }       
114
115         @PrePersist
116         public void     prePersist() {
117                 Date date = new Date();
118                 this.createdDate = date;
119                 this.modifiedDate = date;
120         }
121
122         @PreUpdate
123         public void preUpdate() {
124                 this.modifiedDate = new Date();
125                 try {
126                         this.userModifiedBy =XacmlAdminAuthorization.getUserId();
127                 } catch (Exception e) {
128                         LOGGER.error("Exception caused While adding Modified by Role"+e);
129                         PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "RiskType", "Exception caused While adding Modified by Role");
130                 }
131         }
132         public String getRiskName() {
133                 return this.name;
134         }
135
136         public void setRiskName(String riskName) {
137                 this.name = riskName;
138
139         }
140         public int getId() {
141                 return this.id;
142         }
143
144         public void setId(int id) {
145                 this.id = id;
146         }
147
148         public Date getCreatedDate() {
149                 return this.createdDate;
150         }
151
152         public void setCreatedDate(Date createdDate) {
153                 this.createdDate = createdDate;
154         }
155
156         public String getDescription() {
157                 return this.description;
158         }
159
160         public void setDescription(String description) {
161                 this.description = description;
162         }
163
164         public Date getModifiedDate() {
165                 return this.modifiedDate;
166         }
167
168         public void setModifiedDate(Date modifiedDate) {
169                 this.modifiedDate = modifiedDate;
170         }
171
172 }