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