Fixed the Sonar technical debt.
[policy/engine.git] / ONAP-REST / src / main / java / org / onap / policy / rest / jpa / FWTag.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.common.logging.eelf.MessageCodes;
44 import org.onap.policy.common.logging.eelf.PolicyLogger;
45 import org.onap.policy.rest.XacmlAdminAuthorization;
46
47 @Entity
48 @Table(name = "FWTag")
49 @NamedQuery(name = "FWTag.findAll", query= "Select p from FWTag p")
50 public class FWTag implements Serializable {
51         private static final long serialVersionUID = 1L;
52         @Id
53         @GeneratedValue(strategy = GenerationType.AUTO)
54         @Column(name = "Id")
55         private int id;
56
57         @Column(name="tagName", nullable=false)
58         @OrderBy("asc")
59         private String fwTagName;
60
61         @Column(name="description", nullable=true, length=2048)
62         private String description;
63
64         @Column(name="tagValues", nullable=true)
65         @OrderBy("asc")
66         private String tagValues;
67
68         @Temporal(TemporalType.TIMESTAMP)
69         @Column(name="created_date", updatable=false)
70         private Date createdDate;
71
72         @Temporal(TemporalType.TIMESTAMP)
73         @Column(name="modified_date", nullable=false)
74         private Date modifiedDate;
75
76         @ManyToOne(optional = false)
77         @JoinColumn(name="created_by")
78         private UserInfo userCreatedBy;
79
80         @ManyToOne(optional = false)
81         @JoinColumn(name="modified_by")
82         private UserInfo userModifiedBy;
83         
84         public UserInfo getUserCreatedBy() {
85                 return userCreatedBy;
86         }
87
88         public void setUserCreatedBy(UserInfo userCreatedBy) {
89                 this.userCreatedBy = userCreatedBy;
90         }
91
92         public UserInfo getUserModifiedBy() {
93                 return userModifiedBy;
94         }
95
96         public void setUserModifiedBy(UserInfo userModifiedBy) {
97                 this.userModifiedBy = userModifiedBy;
98         }
99
100         private static Log LOGGER = LogFactory.getLog(FWTag.class);
101         
102         public FWTag(){
103                 //An empty constructor
104         }
105         
106         public FWTag(String string, String userid) {
107                 this(string);
108         }
109
110         public FWTag(String domain) {
111                 this.fwTagName = domain;
112         }       
113         
114         @PrePersist
115         public void     prePersist() {
116                 Date date = new Date();
117                 this.createdDate = date;
118                 this.modifiedDate = date;
119         }
120         
121         @PreUpdate
122         public void preUpdate() {
123                 this.modifiedDate = new Date();
124                 try {
125                         this.userModifiedBy =XacmlAdminAuthorization.getUserId();;
126                 } catch (Exception e) {
127                         LOGGER.error("Exception caused While adding Modified by Role"+e);
128                         PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "FWTag", "Exception caused While adding Modified by Role");
129                 }
130         }
131         
132         public int getId() {
133                 return this.id;
134         }
135         public void setId(int id) {
136                 this.id = id;
137         }
138         
139         public String getFwTagName() {
140                 return fwTagName;
141         }
142
143         public void setFwTagName(String fwTagName) {
144                 this.fwTagName = fwTagName;
145         }
146
147         public String getTagValues() {
148                 return tagValues;
149         }
150
151         public void setTagValues(String tagValues) {
152                 this.tagValues = tagValues;
153         }
154         
155         
156         public Date getCreatedDate() {
157                 return this.createdDate;
158         }
159         
160         public void setCreatedDate(Date createdDate) {
161                 this.createdDate = createdDate;
162         }
163         
164         public String getDescription() {
165                 return this.description;
166         }
167         
168         public void setDescription(String description) {
169                 this.description = description;
170         }
171         
172         public Date getModifiedDate() {
173                 return this.modifiedDate;
174         }
175         
176         public void setModifiedDate(Date modifiedDate) {
177                 this.modifiedDate = modifiedDate;
178         }
179
180 }