Fixed the Sonar technical debt.
[policy/engine.git] / ONAP-REST / src / main / java / org / onap / policy / rest / jpa / ClosedLoopD2Services.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 import java.io.Serializable;
26 import java.util.Date;
27
28 import javax.persistence.Column;
29 import javax.persistence.Entity;
30 import javax.persistence.GeneratedValue;
31 import javax.persistence.GenerationType;
32 import javax.persistence.Id;
33 import javax.persistence.JoinColumn;
34 import javax.persistence.ManyToOne;
35 import javax.persistence.NamedQuery;
36 import javax.persistence.OrderBy;
37 import javax.persistence.PrePersist;
38 import javax.persistence.PreUpdate;
39 import javax.persistence.Table;
40 import javax.persistence.Temporal;
41 import javax.persistence.TemporalType;
42
43 import org.apache.commons.logging.Log;
44 import org.apache.commons.logging.LogFactory;
45 import org.onap.policy.common.logging.eelf.MessageCodes;
46 import org.onap.policy.common.logging.eelf.PolicyLogger;
47 import org.onap.policy.rest.XacmlAdminAuthorization;
48
49
50 @Entity
51 @Table(name = "ClosedLoopD2Services")
52 @NamedQuery(name="ClosedLoopD2Services.findAll", query="SELECT c FROM ClosedLoopD2Services c ")
53 public class ClosedLoopD2Services implements Serializable{
54         private static final long serialVersionUID = 1L;
55         
56         private static String domain;
57
58         
59         @Id
60         @Column(name ="id")
61         @GeneratedValue(strategy = GenerationType.AUTO)
62         private int id;
63         
64         @Column(name="service_Name", nullable=false, unique=true)
65         @OrderBy("asc")
66         private String serviceName;
67
68         @Column(name="description", nullable=true, length=2048)
69         private String description;
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(ClosedLoopD2Services.class);
104         
105         public ClosedLoopD2Services(){
106                 //An empty constructor
107         }
108         
109         public ClosedLoopD2Services(String string, String userid) {
110                 this(domain);
111         }
112         
113         public ClosedLoopD2Services(String domain) {
114                 this.serviceName = 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                         PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "ClosedLoopD2Services", "Exception caused While adding Modified by Role");
132                 }
133         }
134         
135         public int getId() {
136                 return id;
137         }
138
139         public void setId(int id) {
140                 this.id = id;
141         }
142
143         public String getServiceName() {
144                 return serviceName;
145         }
146
147         public void setServiceName(String serviceName) {
148                 this.serviceName = serviceName;
149         }
150
151         public String getDescription() {
152                 return description;
153         }
154
155         public void setDescription(String description) {
156                 this.description = description;
157         }
158
159         public Date getCreatedDate() {
160                 return createdDate;
161         }
162
163         public void setCreatedDate(Date createdDate) {
164                 this.createdDate = createdDate;
165         }
166         
167         public Date getModifiedDate() {
168                 return modifiedDate;
169         }
170
171         public void setModifiedDate(Date modifiedDate) {
172                 this.modifiedDate = modifiedDate;
173         }
174
175 }