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