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