Merge "Added Junits for Policy PAP-REST"
[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         @Id
57         @Column(name ="id")
58         @GeneratedValue(strategy = GenerationType.AUTO)
59         private int id;
60         
61         @Column(name="service_Name", nullable=false, unique=true)
62         @OrderBy("asc")
63         private String serviceName;
64
65         @Column(name="description", nullable=true, length=2048)
66         private String description;
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(ClosedLoopD2Services.class);
101         
102         public ClosedLoopD2Services(){
103                 //An empty constructor
104         }
105
106         @PrePersist
107         public void     prePersist() {
108                 Date date = new Date();
109                 this.createdDate = date;
110                 this.modifiedDate = date;
111         }
112
113         @PreUpdate
114         public void preUpdate() {
115                 this.modifiedDate = new Date();
116                 try {
117                         this.userModifiedBy = XacmlAdminAuthorization.getUserId();;
118                 } catch (Exception e) {
119                         LOGGER.error("Exception caused While adding Modified by Role"+e);
120                         PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "ClosedLoopD2Services", "Exception caused While adding Modified by Role");
121                 }
122         }
123         
124         public int getId() {
125                 return id;
126         }
127
128         public void setId(int id) {
129                 this.id = id;
130         }
131
132         public String getServiceName() {
133                 return serviceName;
134         }
135
136         public void setServiceName(String serviceName) {
137                 this.serviceName = serviceName;
138         }
139
140         public String getDescription() {
141                 return description;
142         }
143
144         public void setDescription(String description) {
145                 this.description = description;
146         }
147
148         public Date getCreatedDate() {
149                 return createdDate;
150         }
151
152         public void setCreatedDate(Date createdDate) {
153                 this.createdDate = createdDate;
154         }
155         
156         public Date getModifiedDate() {
157                 return modifiedDate;
158         }
159
160         public void setModifiedDate(Date modifiedDate) {
161                 this.modifiedDate = modifiedDate;
162         }
163
164 }