Included Policy GUI Enhancements and validations
[policy/engine.git] / ONAP-REST / src / main / java / org / onap / policy / rest / jpa / TermList.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 import java.io.Serializable;
24 import java.util.Date;
25
26 import javax.persistence.Column;
27 import javax.persistence.Entity;
28 import javax.persistence.GeneratedValue;
29 import javax.persistence.GenerationType;
30 import javax.persistence.Id;
31 import javax.persistence.JoinColumn;
32 import javax.persistence.ManyToOne;
33 import javax.persistence.NamedQuery;
34 import javax.persistence.OrderBy;
35 import javax.persistence.PrePersist;
36 import javax.persistence.PreUpdate;
37 import javax.persistence.Table;
38 import javax.persistence.Temporal;
39 import javax.persistence.TemporalType;
40
41 import org.apache.commons.logging.Log;
42 import org.apache.commons.logging.LogFactory;
43 import org.onap.policy.rest.XacmlAdminAuthorization;
44
45 import org.onap.policy.common.logging.eelf.MessageCodes;
46 import org.onap.policy.common.logging.eelf.PolicyLogger;
47
48
49 @Entity
50 @Table(name="TERM")
51 @NamedQuery(name="TermList.findAll", query="SELECT e FROM TermList e")
52 public class TermList implements Serializable {
53         private static final long serialVersionUID = 1L;
54
55         private static String domain;
56
57         @Id
58         @GeneratedValue(strategy = GenerationType.AUTO)
59         @Column(name="id")
60         private int id;
61         
62         @Column(name="termName", nullable=false)
63         @OrderBy("asc")
64         private String termName;
65         
66         @Column(name="description")
67         private String termDescription;
68         
69         @Column(name="fromzone")
70         private String fromZone;
71         
72         @Column(name="tozone")
73         private String toZone;
74         
75         @Column(name="srcIPList")
76         private String srcIPList;
77         
78         @Column(name="destIPList")
79         private String destIPList;
80         
81         @Column(name="protocolList")
82         private String protocolList;
83         
84         @Column(name="portList")
85         private String portList;
86         
87         @Column(name="srcPortList")
88         private String srcPortList;
89         
90         @Column(name="destPortList")
91         private String destPortList;
92         
93         @Column(name="action")
94         private String action;
95
96         @Temporal(TemporalType.TIMESTAMP)
97         @Column(name="created_date", updatable=false)
98         private Date createdDate;
99
100         @Temporal(TemporalType.TIMESTAMP)
101         @Column(name="modified_date", nullable=false)
102         private Date modifiedDate;
103         
104         @ManyToOne(optional = false)
105         @JoinColumn(name="created_by")
106         private UserInfo userCreatedBy;
107
108         @ManyToOne(optional = false)
109         @JoinColumn(name="modified_by")
110         private UserInfo userModifiedBy;
111         
112         public Date getCreatedDate() {
113                 return this.createdDate;
114         }
115         public void setCreatedDate(Date createdDate) {
116                 this.createdDate = createdDate;
117         }
118         
119         public Date getModifiedDate() {
120                 return this.modifiedDate;
121         }
122         public void setModifiedDate(Date modifiedDate) {
123                 this.modifiedDate = modifiedDate;
124         }
125         
126         public UserInfo getUserCreatedBy() {
127                 return userCreatedBy;
128         }
129
130         public void setUserCreatedBy(UserInfo userCreatedBy) {
131                 this.userCreatedBy = userCreatedBy;
132         }
133
134         public UserInfo getUserModifiedBy() {
135                 return userModifiedBy;
136         }
137
138         public void setUserModifiedBy(UserInfo userModifiedBy) {
139                 this.userModifiedBy = userModifiedBy;
140         }
141
142         private static Log LOGGER = LogFactory.getLog(TermList.class);
143         
144         public TermList() {
145                 // Empty constructor
146         }
147         
148         private static final Log auditLogger = LogFactory
149                         .getLog("auditLogger");
150         
151         public TermList(String string, String userid) {
152                 this(domain);
153         }
154         public TermList(String domain) {
155                 this.termName = domain;
156         }       
157
158         @PrePersist
159         public void     prePersist() {
160                 Date date = new Date();
161                 this.createdDate = date;
162                 this.modifiedDate = date;
163                 auditLogger.debug("Added New Term Name: "+this.termName+" by "+this.userCreatedBy);
164                 
165         }
166         @PreUpdate
167         public void preUpdate() {
168                 this.modifiedDate = new Date();
169                 try {
170                         this.userModifiedBy =XacmlAdminAuthorization.getUserId();;
171                 } catch (Exception e) {
172                         LOGGER.error("Exception caused While adding Modified by Role"+e);
173                         PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "TermList", "Exception caused While adding Modified by Role");
174                 }
175                 auditLogger.debug("Updated Term Name: "+this.termName+" by "+this.userModifiedBy);
176         }
177         
178         public int getId() {
179                 return this.id;
180         }
181
182         public void setId(int id) {
183                 this.id = id;
184         }
185         
186         public String getTermName() {
187                 return this.termName;
188         }
189
190         public void setTermName(String termName) {
191                 this.termName = termName;
192         }
193         
194         public String getTermDescription() {
195                 return this.termDescription;
196         }
197
198         public void setDescription(String termDescription) {
199                 this.termDescription = termDescription;
200         }
201         
202         public String getFromZone() {
203                 return this.fromZone;
204         }
205
206         public void setFromZones(String fromZone) {
207                 this.fromZone = fromZone;
208         }
209         
210         public String getToZone() {
211                 return this.toZone;
212         }
213
214         public void setToZones(String toZone) {
215                 this.toZone = toZone;
216         }
217         
218         public String getSrcIPList() {
219                 return this.srcIPList;
220         }
221
222         public void setSrcIPList(String srcIPList) {
223                 this.srcIPList = srcIPList;
224         }
225         
226         public String getDestIPList() {
227                 return this.destIPList;
228         }
229
230         public void setDestIPList(String destIPList) {
231                 this.destIPList = destIPList;
232         }
233         
234         public String getProtocolList() {
235                 return this.protocolList;
236         }
237
238         public void setProtocolList(String protocolList) {
239                 this.protocolList = protocolList;
240         }
241         
242         public String getPortList() {
243                 return this.portList;
244         }
245
246         public void setPortList(String portList) {
247                 this.portList = portList;
248         }
249         
250         public String getSrcPortList() {
251                 return this.srcPortList;
252         }
253
254         public void setSrcPortList(String srcPortList) {
255                 this.srcPortList = srcPortList;
256         }
257         
258         public String getDestPortList() {
259                 return this.destPortList;
260         }
261
262         public void setDestPortList(String destPortList) {
263                 this.destPortList = destPortList;
264         }
265         
266         
267         public String getAction() {
268                 return this.action;
269         }
270
271         public void setAction(String action) {
272                 this.action = action;
273         }
274
275 }