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