Initial OpenECOMP policy/engine commit
[policy/engine.git] / ECOMP-REST / src / main / java / org / openecomp / policy / rest / jpa / VarbindDictionary.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 @Entity
49 @Table(name="VarbindDictionary")
50 @NamedQuery(name = "VarbindDictionary.findAll", query = "Select v FROM VarbindDictionary v")
51 public class VarbindDictionary implements Serializable{
52         private static final long serialVersionUID = 1L;
53         
54         private static String domain;
55         
56         @Id
57         @GeneratedValue(strategy = GenerationType.AUTO)
58         @Column(name = "Id")
59         private int id;
60         
61         @Column(name ="varbind_Name", nullable = false, unique = true)
62         @OrderBy("asc")
63         private String varbindName;
64
65         @Column(name = "varbind_Description", nullable = true, length = 2048)
66         private String varbindDescription;
67         
68         @Column(name = "varbind_oid", nullable = false)
69         private String varbindOID;
70
71         @Temporal(TemporalType.TIMESTAMP)
72         @Column(name="created_date", updatable=false)
73         private Date createdDate;
74
75         @Temporal(TemporalType.TIMESTAMP)
76         @Column(name="modified_date", nullable=false)
77         private Date modifiedDate;
78         
79         @ManyToOne(optional = false)
80         @JoinColumn(name="created_by")
81         private UserInfo userCreatedBy;
82
83         @ManyToOne(optional = false)
84         @JoinColumn(name="modified_by")
85         private UserInfo userModifiedBy;
86         
87         public UserInfo getUserCreatedBy() {
88                 return userCreatedBy;
89         }
90
91         public void setUserCreatedBy(UserInfo userCreatedBy) {
92                 this.userCreatedBy = userCreatedBy;
93         }
94
95         public UserInfo getUserModifiedBy() {
96                 return userModifiedBy;
97         }
98
99         public void setUserModifiedBy(UserInfo userModifiedBy) {
100                 this.userModifiedBy = userModifiedBy;
101         }
102
103         private static Log logger = LogFactory.getLog(VarbindDictionary.class);
104         
105         public VarbindDictionary() {
106                 
107         }
108         
109         public VarbindDictionary(String string, String userid) {
110                 this(domain);
111         }
112         
113         public VarbindDictionary(String domain) {
114                 this.varbindName = domain;
115         }       
116
117         @PrePersist
118         public void     prePersist() {
119                 Date date = new Date();
120                 this.createdDate = date;
121                 this.modifiedDate = date;
122         }
123
124         @PreUpdate
125         public void preUpdate() {
126                 this.modifiedDate = new Date();
127                 try {
128                         this.userModifiedBy =XacmlAdminAuthorization.getUserId();;
129                 } catch (Exception e) {
130                         logger.error("Exception caused While adding Modified by Role"+e);
131                         // TODO:EELF Cleanup - Remove logger
132                         PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "VarbindDictionary", "Exception caused While adding Modified by Role");
133                 }
134         }
135         
136         public int getId() {
137                 return this.id;
138         }
139
140         public void setId(int id) {
141                 this.id = id;
142         }
143
144         public String getVarbindName() {
145                 return varbindName;
146         }
147
148         public void setVarbindName(String varbindName) {
149                 this.varbindName = varbindName;
150         }
151
152         public String getVarbindDescription() {
153                 return varbindDescription;
154         }
155
156         public void setVarbindDescription(String varbindDescription) {
157                 this.varbindDescription = varbindDescription;
158         }
159
160         public String getVarbindOID() {
161                 return varbindOID;
162         }
163
164         public void setVarbindOID(String varbindOID) {
165                 this.varbindOID = varbindOID;
166         }
167
168         public Date getCreatedDate() {
169                 return createdDate;
170         }
171
172         public void setCreatedDate(Date createdDate) {
173                 this.createdDate = createdDate;
174         }
175         
176         public Date getModifiedDate() {
177                 return modifiedDate;
178         }
179
180         public void setModifiedDate(Date modifiedDate) {
181                 this.modifiedDate = modifiedDate;
182         }
183         
184
185 }