Unit/SONAR/Checkstyle in ONAP-REST
[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-2019 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2019 Nordix Foundation.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.rest.jpa;
23
24 import java.io.Serializable;
25 import java.util.Date;
26
27 import javax.persistence.Column;
28 import javax.persistence.Entity;
29 import javax.persistence.GeneratedValue;
30 import javax.persistence.GenerationType;
31 import javax.persistence.Id;
32 import javax.persistence.NamedQueries;
33 import javax.persistence.NamedQuery;
34 import javax.persistence.PrePersist;
35 import javax.persistence.PreUpdate;
36 import javax.persistence.Table;
37 import javax.persistence.Temporal;
38 import javax.persistence.TemporalType;
39
40 import lombok.EqualsAndHashCode;
41 import lombok.Getter;
42 import lombok.Setter;
43
44 /**
45  * The Class PolicyVersion.
46  */
47 // @formatter:off
48 @Entity
49 @Table(name = "PolicyVersion")
50 @NamedQueries(
51     {
52         @NamedQuery(
53             name = "PolicyVersion.findAll", query = "SELECT p FROM PolicyVersion p"
54         ),
55         @NamedQuery(
56             name = "PolicyVersion.deleteAll", query = "DELETE FROM PolicyVersion WHERE 1=1"
57         ),
58         @NamedQuery(
59             name = "PolicyVersion.findByPolicyName", query = "Select p from PolicyVersion p where p.policyName=:pname"
60         ),
61         @NamedQuery(
62             name = "PolicyVersion.findAllCount", query = "SELECT COUNT(p) FROM PolicyVersion p"
63         )
64     }
65 )
66 @Getter
67 @Setter
68 @EqualsAndHashCode
69 // @formatter:on
70 public class PolicyVersion implements Serializable {
71     private static final long serialVersionUID = 1L;
72
73     @Id
74     @GeneratedValue(strategy = GenerationType.AUTO)
75
76     @Column(name = "id")
77     private int id;
78
79     @Column(name = "POLICY_NAME", nullable = false, length = 255)
80     private String policyName;
81
82     @Column(name = "ACTIVE_VERSION")
83     private int activeVersion;
84
85     @Column(name = "HIGHEST_VERSION")
86     private int higherVersion;
87
88     @Temporal(TemporalType.TIMESTAMP)
89     @Column(name = "created_date", nullable = false)
90     private Date createdDate;
91
92     @Column(name = "CREATED_BY", nullable = false, length = 45)
93     private String createdBy;
94
95     @Temporal(TemporalType.TIMESTAMP)
96     @Column(name = "modified_date", nullable = false)
97     private Date modifiedDate;
98
99     @Column(name = "modified_by", nullable = false, length = 45)
100     private String modifiedBy;
101
102     /**
103      * Instantiates a new policy version.
104      */
105     public PolicyVersion() {
106         this.modifiedDate = new Date();
107         this.createdDate = new Date();
108     }
109
110     /**
111      * Instantiates a new policy version.
112      *
113      * @param domain the domain
114      * @param loginUserId the login user id
115      */
116     public PolicyVersion(String domain, String loginUserId) {
117         this(domain);
118         this.createdBy = loginUserId;
119         this.modifiedBy = loginUserId;
120     }
121
122     /**
123      * Instantiates a new policy version.
124      *
125      * @param domain the domain
126      */
127     public PolicyVersion(String domain) {
128         this.policyName = domain;
129     }
130
131     /**
132      * Pre persist.
133      */
134     @PrePersist
135     public void prePersist() {
136         Date date = new Date();
137         this.createdDate = date;
138         this.modifiedDate = date;
139     }
140
141     /**
142      * Pre update.
143      */
144     @PreUpdate
145     public void preUpdate() {
146         this.modifiedDate = new Date();
147     }
148 }