Fixed the Sonar technical debt.
[policy/engine.git] / ONAP-REST / src / main / java / org / onap / policy / rest / jpa / PolicyVersion.java
index d098ee5..663d34a 100644 (file)
@@ -21,9 +21,9 @@
 package org.onap.policy.rest.jpa;
 
 import java.io.Serializable;
-//import java.sql.Clob;
 import java.sql.Timestamp;
 import java.util.Date;
+import java.util.Objects;
 
 import javax.persistence.Column;
 import javax.persistence.Entity;
@@ -108,7 +108,7 @@ public class PolicyVersion implements Serializable {
        }
        
        public PolicyVersion(){
-               
+               // Empty constructor
        }
        
        @PrePersist
@@ -121,14 +121,6 @@ public class PolicyVersion implements Serializable {
        @PreUpdate
        public void preUpdate() {
                this.modifiedDate =  new Date();
-               /*
-                * The modifiedBy must be set via the setModifiedBy() method since PolicyVersion
-                * has been moved to XACML-REST module for access from the XACML-PAP-REST module
-                
-                  String userid = ((XacmlAdminUI) UI.getCurrent()).getLoginUserId();
-                  this.modifiedBy =userid;
-                * 
-                */
        }
        
        public int getId() {
@@ -167,7 +159,7 @@ public class PolicyVersion implements Serializable {
                return modifiedDate;
        }
 
-       public void setModifiedDate(Timestamp modifiedDate) {
+       public void setModifiedDate(Date modifiedDate) {
                this.modifiedDate = modifiedDate;
        }
 
@@ -178,6 +170,36 @@ public class PolicyVersion implements Serializable {
        public void setModifiedBy(String modifiedBy) {
                this.modifiedBy = modifiedBy;
        }
+       
+       @Override
+       public int hashCode() {
+       return Objects.hash(id, policyName,     activeVersion, higherVersion, createdDate, 
+                       createdBy, modifiedDate, modifiedBy);
+       }
+
+       @Override
+       public boolean equals(Object obj) {
+               if(obj == null){
+                       return false;
+               }
+               if(obj == this){
+                       return true;
+               }
+               if(!(obj instanceof PolicyVersion)){
+                       return false;
+               }
+
+               PolicyVersion p = (PolicyVersion) obj;
+               
+               return id == p.id &&
+                               policyName.equals(p.policyName) &&
+                               activeVersion == p.activeVersion &&
+                               higherVersion == p.higherVersion &&
+                               createdDate.equals(p.createdDate) &&
+                               createdBy.equals(p.createdBy) &&
+                               modifiedDate.equals(p.modifiedDate) &&
+                               modifiedBy.equals(p.modifiedBy);
+       }
 
 }