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