2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.policy.rest.jpa;
23 import java.io.Serializable;
24 //import java.sql.Clob;
25 import java.sql.Timestamp;
26 import java.util.Date;
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;
43 @Table(name="PolicyVersion")
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")
50 public class PolicyVersion implements Serializable {
51 private static final long serialVersionUID = 1L;
54 @GeneratedValue(strategy = GenerationType.AUTO)
59 @Column(name="POLICY_NAME", nullable=false, length=255)
60 private String policyName;
62 @Column(name="ACTIVE_VERSION")
63 private int activeVersion;
65 @Column(name="HIGHEST_VERSION")
66 private int higherVersion;
68 @Temporal(TemporalType.TIMESTAMP)
69 @Column(name="created_date", nullable=false)
70 private Date createdDate;
73 public int getActiveVersion() {
77 public void setActiveVersion(int activeVersion) {
78 this.activeVersion = activeVersion;
81 public int getHigherVersion() {
85 public void setHigherVersion(int higherVersion) {
86 this.higherVersion = higherVersion;
89 @Column(name="CREATED_BY", nullable=false, length=45)
90 private String createdBy;
92 @Temporal(TemporalType.TIMESTAMP)
93 @Column(name="modified_date", nullable=false)
94 private Date modifiedDate;
97 @Column(name="modified_by", nullable=false, length=45)
98 private String modifiedBy;
100 public PolicyVersion(String domain, String loginUserId) {
102 this.createdBy = loginUserId;
103 this.modifiedBy = loginUserId;
106 public PolicyVersion(String domain) {
107 this.policyName = domain;
110 public PolicyVersion(){
115 public void prePersist() {
116 Date date = new Date();
117 this.createdDate = date;
118 this.modifiedDate = date;
122 public void preUpdate() {
123 this.modifiedDate = new Date();
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
128 String userid = ((XacmlAdminUI) UI.getCurrent()).getLoginUserId();
129 this.modifiedBy =userid;
138 public void setId(int id) {
142 public String getPolicyName() {
146 public void setPolicyName(String policyName) {
147 this.policyName = policyName;
150 public Date getCreatedDate() {
154 public void setCreatedDate(Timestamp createdDate) {
155 this.createdDate = createdDate;
158 public String getCreatedBy() {
162 public void setCreatedBy(String createdBy) {
163 this.createdBy = createdBy;
166 public Date getModifiedDate() {
170 public void setModifiedDate(Timestamp modifiedDate) {
171 this.modifiedDate = modifiedDate;
174 public String getModifiedBy() {
178 public void setModifiedBy(String modifiedBy) {
179 this.modifiedBy = modifiedBy;