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