bf8a7316158685b52bd29669d06302fe1e278c7f
[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                 
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                         //PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "ActionPolicyDict", "Exception caused While adding Modified by Role");
145                 }
146         }
147         public int getId() {
148                 return this.id;
149         }
150         public void setId(int id) {
151                 this.id = id;
152         }
153         
154         public Date getCreatedDate() {
155                 return this.createdDate;
156         }
157         public void setCreatedDate(Date createdDate) {
158                 this.createdDate = createdDate;
159         }
160         public String getDescription() {
161                 return this.description;
162         }
163         public void setDescription(String description) {
164                 this.description = description;
165         }
166         
167         public Date getModifiedDate() {
168                 return this.modifiedDate;
169         }
170         public void setModifiedDate(Date modifiedDate) {
171                 this.modifiedDate = modifiedDate;
172         }
173         public String getType() {
174                 return type;
175         }
176         public void setType(String type) {
177                 this.type = type;
178         }
179         
180         public String getUrl() {
181                 return url;
182         }
183         public void setUrl(String url) {
184                 this.url = url;
185         }
186         public String getMethod() {
187                 return method;
188         }
189         public void setMethod(String method) {
190                 this.method = method;
191         }
192         public String getHeader() {
193                 return header;
194         }
195         public void setHeader(String header) {
196                 this.header = header;
197         }
198         
199         public String getBody() {
200                 return body;
201         }
202         public void setBody(String body) {
203                 this.body = body;
204         }
205         public String getAttributeName() {
206                 return attributeName;
207         }
208         public void setAttributeName(String attributeName) {
209                 this.attributeName = attributeName;
210         }
211 }