Fixed the Sonar technical debt.
[policy/engine.git] / ONAP-REST / src / main / java / org / onap / policy / rest / jpa / ActionPolicyDict.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 /*
22  */
23 package org.onap.policy.rest.jpa;
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.NamedQueries;
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
48 @Entity
49 @Table(name="ActionPolicyDict")
50 @NamedQueries({
51         @NamedQuery(name="ActionPolicyDict.findAll", query="SELECT e FROM ActionPolicyDict e")
52 })
53 public class ActionPolicyDict implements Serializable {
54         private static final long serialVersionUID = 1L;
55         @Id
56         @GeneratedValue(strategy = GenerationType.AUTO)
57         @Column(name="id")
58         private int id;
59         
60         @Column(name="ATTRIBUTE_NAME", nullable=false)
61         @OrderBy("asc")
62         private String attributeName;
63         
64         @Column(name="Type", nullable=false)
65         @OrderBy("asc")
66         private String type;
67         
68         @Column(name="URL", nullable=false)
69         @OrderBy("asc")
70         private String url;
71         
72         @Column(name="Method", nullable=false)
73         @OrderBy("asc")
74         private String method;
75         
76         @Column(name="Headers", nullable=true)
77         @OrderBy("asc")
78         private String header;
79         
80         @Column(name="Body", nullable=true)
81         @OrderBy("asc")
82         private String body;    
83         
84         @Temporal(TemporalType.TIMESTAMP)
85         @Column(name="created_date", updatable=false)
86         private Date createdDate;
87         
88         @Column(name="description", nullable=true, length=2048)
89         private String description;
90         
91         @Temporal(TemporalType.TIMESTAMP)
92         @Column(name="modified_date", nullable=false)
93         private Date modifiedDate;
94         
95         @ManyToOne(optional = false)
96         @JoinColumn(name="created_by")
97         private UserInfo userCreatedBy;
98
99         @ManyToOne(optional = false)
100         @JoinColumn(name="modified_by")
101         private UserInfo userModifiedBy;
102         
103         public UserInfo getUserCreatedBy() {
104                 return userCreatedBy;
105         }
106
107         public void setUserCreatedBy(UserInfo userCreatedBy) {
108                 this.userCreatedBy = userCreatedBy;
109         }
110
111         public UserInfo getUserModifiedBy() {
112                 return userModifiedBy;
113         }
114
115         public void setUserModifiedBy(UserInfo userModifiedBy) {
116                 this.userModifiedBy = userModifiedBy;
117         }
118
119         private static Log logger = LogFactory.getLog(ActionPolicyDict.class);
120         public ActionPolicyDict() {
121                 //An empty constructor
122         }
123         
124         public ActionPolicyDict(String string, String userid) {
125                 this(string);
126         }
127         
128         public ActionPolicyDict(String domain) {
129                 this.type = domain;
130         }       
131         @PrePersist
132         public void     prePersist() {
133                 Date date = new Date();
134                 this.createdDate = date;
135                 this.modifiedDate = date;
136         }
137         @PreUpdate
138         public void preUpdate() {
139                 this.modifiedDate = new Date();
140                 try {
141                         this.userModifiedBy =XacmlAdminAuthorization.getUserId();
142                 } catch (Exception e) {
143                         logger.error("Exception caused While adding Modified by Role"+e);
144                 }
145         }
146         public int getId() {
147                 return this.id;
148         }
149         public void setId(int id) {
150                 this.id = id;
151         }
152         
153         public Date getCreatedDate() {
154                 return this.createdDate;
155         }
156         public void setCreatedDate(Date createdDate) {
157                 this.createdDate = createdDate;
158         }
159         public String getDescription() {
160                 return this.description;
161         }
162         public void setDescription(String description) {
163                 this.description = description;
164         }
165         
166         public Date getModifiedDate() {
167                 return this.modifiedDate;
168         }
169         public void setModifiedDate(Date modifiedDate) {
170                 this.modifiedDate = modifiedDate;
171         }
172         public String getType() {
173                 return type;
174         }
175         public void setType(String type) {
176                 this.type = type;
177         }
178         
179         public String getUrl() {
180                 return url;
181         }
182         public void setUrl(String url) {
183                 this.url = url;
184         }
185         public String getMethod() {
186                 return method;
187         }
188         public void setMethod(String method) {
189                 this.method = method;
190         }
191         public String getHeader() {
192                 return header;
193         }
194         public void setHeader(String header) {
195                 this.header = header;
196         }
197         
198         public String getBody() {
199                 return body;
200         }
201         public void setBody(String body) {
202                 this.body = body;
203         }
204         public String getAttributeName() {
205                 return attributeName;
206         }
207         public void setAttributeName(String attributeName) {
208                 this.attributeName = attributeName;
209         }
210 }