Initial OpenECOMP policy/engine commit
[policy/engine.git] / ECOMP-REST / src / main / java / org / openecomp / policy / rest / jpa / TermList.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 package org.openecomp.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.openecomp.policy.rest.XacmlAdminAuthorization;
44
45 import org.openecomp.policy.common.logging.eelf.MessageCodes;
46 import org.openecomp.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 UserInfo getUserCreatedBy() {
113                 return userCreatedBy;
114         }
115
116         public void setUserCreatedBy(UserInfo userCreatedBy) {
117                 this.userCreatedBy = userCreatedBy;
118         }
119
120         public UserInfo getUserModifiedBy() {
121                 return userModifiedBy;
122         }
123
124         public void setUserModifiedBy(UserInfo userModifiedBy) {
125                 this.userModifiedBy = userModifiedBy;
126         }
127
128         private static Log logger = LogFactory.getLog(TermList.class);
129         
130         public TermList() {
131                 
132         }
133         
134         private static final Log auditLogger = LogFactory
135                         .getLog("auditLogger");
136         
137         public TermList(String string, String userid) {
138                 this(domain);
139         }
140         public TermList(String domain) {
141                 this.termName = domain;
142         }       
143
144         @PrePersist
145         public void     prePersist() {
146                 Date date = new Date();
147                 this.createdDate = date;
148                 this.modifiedDate = date;
149                 auditLogger.debug("Added New Term Name: "+this.termName+" by "+this.userCreatedBy);
150                 
151         }
152         @PreUpdate
153         public void preUpdate() {
154                 this.modifiedDate = new Date();
155                 try {
156                         this.userModifiedBy =XacmlAdminAuthorization.getUserId();;
157                 } catch (Exception e) {
158                         logger.error("Exception caused While adding Modified by Role"+e);
159                         // TODO:EELF Cleanup - Remove logger
160                         PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "TermList", "Exception caused While adding Modified by Role");
161                 }
162                 auditLogger.debug("Updated Term Name: "+this.termName+" by "+this.userModifiedBy);
163         }
164         
165         public int getId() {
166                 return this.id;
167         }
168
169         public void setId(int id) {
170                 this.id = id;
171         }
172         
173         public String getTermName() {
174                 return this.termName;
175         }
176
177         public void setTermName(String termName) {
178                 this.termName = termName;
179         }
180         
181         public String getTermDescription() {
182                 return this.termDescription;
183         }
184
185         public void setDescription(String termDescription) {
186                 this.termDescription = termDescription;
187         }
188         
189         public String getFromZone() {
190                 return this.fromZone;
191         }
192
193         public void setFromZones(String fromZone) {
194                 this.fromZone = fromZone;
195         }
196         
197         public String getToZone() {
198                 return this.toZone;
199         }
200
201         public void setToZones(String toZone) {
202                 this.toZone = toZone;
203         }
204         
205         public String getSrcIPList() {
206                 return this.srcIPList;
207         }
208
209         public void setSrcIPList(String srcIPList) {
210                 this.srcIPList = srcIPList;
211         }
212         
213         public String getDestIPList() {
214                 return this.destIPList;
215         }
216
217         public void setDestIPList(String destIPList) {
218                 this.destIPList = destIPList;
219         }
220         
221         public String getProtocolList() {
222                 return this.protocolList;
223         }
224
225         public void setProtocolList(String protocolList) {
226                 this.protocolList = protocolList;
227         }
228         
229         public String getPortList() {
230                 return this.portList;
231         }
232
233         public void setPortList(String portList) {
234                 this.portList = portList;
235         }
236         
237         public String getSrcPortList() {
238                 return this.srcPortList;
239         }
240
241         public void setSrcPortList(String srcPortList) {
242                 this.srcPortList = srcPortList;
243         }
244         
245         public String getDestPortList() {
246                 return this.destPortList;
247         }
248
249         public void setDestPortList(String destPortList) {
250                 this.destPortList = destPortList;
251         }
252         
253         
254         public String getAction() {
255                 return this.action;
256         }
257
258         public void setAction(String action) {
259                 this.action = action;
260         }
261
262 }