[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / ONAP-REST / src / main / java / org / onap / policy / rest / jpa / PolicyVersion.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.sql.Clob;
25 import java.sql.Timestamp;
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.NamedQueries;
34 import javax.persistence.NamedQuery;
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
42 @Entity
43 @Table(name="PolicyVersion")
44 @NamedQueries({
45         @NamedQuery(name="PolicyVersion.findAll", query="SELECT p FROM PolicyVersion p"),
46         @NamedQuery(name="PolicyVersion.deleteAll", query="DELETE FROM PolicyVersion WHERE 1=1"),
47         @NamedQuery(name="PolicyVersion.findByPolicyName", query="Select p from PolicyVersion p where p.policyName=:pname"),
48         @NamedQuery(name="PolicyVersion.findAllCount", query="SELECT COUNT(p) FROM PolicyVersion p")
49 })
50 public class PolicyVersion implements Serializable {
51         private static final long serialVersionUID = 1L;
52
53         @Id
54         @GeneratedValue(strategy = GenerationType.AUTO)
55         
56         @Column(name="id")
57         private int id;
58
59         @Column(name="POLICY_NAME", nullable=false, length=255)
60         private String policyName;      
61         
62         @Column(name="ACTIVE_VERSION")
63         private int activeVersion;
64         
65         @Column(name="HIGHEST_VERSION")
66         private int higherVersion;
67         
68         @Temporal(TemporalType.TIMESTAMP)
69         @Column(name="created_date", nullable=false)
70         private Date createdDate;
71         
72         
73         public int getActiveVersion() {
74                 return activeVersion;
75         }
76
77         public void setActiveVersion(int activeVersion) {
78                 this.activeVersion = activeVersion;
79         }
80
81         public int getHigherVersion() {
82                 return higherVersion;
83         }
84
85         public void setHigherVersion(int higherVersion) {
86                 this.higherVersion = higherVersion;
87         }
88
89         @Column(name="CREATED_BY", nullable=false, length=45)
90         private String createdBy;
91         
92         @Temporal(TemporalType.TIMESTAMP)
93         @Column(name="modified_date", nullable=false)
94         private Date modifiedDate;
95         
96         
97         @Column(name="modified_by", nullable=false, length=45)
98         private String modifiedBy;
99
100         public PolicyVersion(String domain, String loginUserId) {
101                 this(domain);
102                 this.createdBy = loginUserId;
103                 this.modifiedBy = loginUserId;
104         }
105         
106         public PolicyVersion(String domain) {
107                 this.policyName = domain;
108         }
109         
110         public PolicyVersion(){
111                 
112         }
113         
114         @PrePersist
115         public void     prePersist() {
116                 Date date = new Date();
117                 this.createdDate = date;
118                 this.modifiedDate = date;
119         }
120
121         @PreUpdate
122         public void preUpdate() {
123                 this.modifiedDate =  new Date();
124                 /*
125                  * The modifiedBy must be set via the setModifiedBy() method since PolicyVersion
126                  * has been moved to XACML-REST module for access from the XACML-PAP-REST module
127                  
128                    String userid = ((XacmlAdminUI) UI.getCurrent()).getLoginUserId();
129                    this.modifiedBy =userid;
130                  * 
131                  */
132         }
133         
134         public int getId() {
135                 return id;
136         }
137
138         public void setId(int id) {
139                 this.id = id;
140         }
141
142         public String getPolicyName() {
143                 return policyName;
144         }
145
146         public void setPolicyName(String policyName) {
147                 this.policyName = policyName;
148         }
149         
150         public Date getCreatedDate() {
151                 return createdDate;
152         }
153
154         public void setCreatedDate(Timestamp createdDate) {
155                 this.createdDate = createdDate;
156         }
157
158         public String getCreatedBy() {
159                 return createdBy;
160         }
161
162         public void setCreatedBy(String createdBy) {
163                 this.createdBy = createdBy;
164         }
165
166         public Date getModifiedDate() {
167                 return modifiedDate;
168         }
169
170         public void setModifiedDate(Timestamp modifiedDate) {
171                 this.modifiedDate = modifiedDate;
172         }
173
174         public String getModifiedBy() {
175                 return modifiedBy;
176         }
177
178         public void setModifiedBy(String modifiedBy) {
179                 this.modifiedBy = modifiedBy;
180         }
181
182 }
183