2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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;
24 import java.io.Serializable;
25 import java.util.Date;
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;
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;
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;
56 @GeneratedValue(strategy = GenerationType.AUTO)
60 @Column(name="name", nullable=false, unique=true)
64 @Temporal(TemporalType.TIMESTAMP)
65 @Column(name="created_date", updatable=false)
66 private Date createdDate;
68 @Column(name="description", nullable=true, length=2048)
69 private String description;
71 @Temporal(TemporalType.TIMESTAMP)
72 @Column(name="modified_date", nullable=false)
73 private Date modifiedDate;
75 @ManyToOne(optional = false)
76 @JoinColumn(name="created_by")
77 private UserInfo userCreatedBy;
79 @ManyToOne(optional = false)
80 @JoinColumn(name="modified_by")
81 private UserInfo userModifiedBy;
83 public UserInfo getUserCreatedBy() {
87 public void setUserCreatedBy(UserInfo userCreatedBy) {
88 this.userCreatedBy = userCreatedBy;
91 public UserInfo getUserModifiedBy() {
92 return userModifiedBy;
95 public void setUserModifiedBy(UserInfo userModifiedBy) {
96 this.userModifiedBy = userModifiedBy;
99 private static Log LOGGER = LogFactory.getLog(RiskType.class);
102 public void prePersist() {
103 Date date = new Date();
104 this.createdDate = date;
105 this.modifiedDate = date;
109 public void preUpdate() {
110 this.modifiedDate = new Date();
112 this.userModifiedBy =XacmlAdminAuthorization.getUserId();
113 } catch (Exception e) {
114 LOGGER.error("Exception caused While adding Modified by Role"+e);
115 PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "RiskType", "Exception caused While adding Modified by Role");
118 public String getRiskName() {
122 public void setRiskName(String riskName) {
123 this.name = riskName;
130 public void setId(int id) {
134 public Date getCreatedDate() {
135 return this.createdDate;
138 public void setCreatedDate(Date createdDate) {
139 this.createdDate = createdDate;
142 public String getDescription() {
143 return this.description;
146 public void setDescription(String description) {
147 this.description = description;
150 public Date getModifiedDate() {
151 return this.modifiedDate;
154 public void setModifiedDate(Date modifiedDate) {
155 this.modifiedDate = modifiedDate;