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