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