Address sonars in common 49/122349/2
authorJim Hahn <jrh3@att.com>
Tue, 29 Jun 2021 20:48:07 +0000 (16:48 -0400)
committerJim Hahn <jrh3@att.com>
Tue, 29 Jun 2021 21:08:10 +0000 (17:08 -0400)
Fixed:
- use "var"
- duplicate code block

Issue-ID: POLICY-3284
Change-Id: I8cd7f2588353a2e7702c90d37d7b9f972634dca9
Signed-off-by: Jim Hahn <jrh3@att.com>
integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/DateEntity.java [new file with mode: 0644]
integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ForwardProgressEntity.java
integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ResourceRegistrationEntity.java
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/parameters/RestClientParameters.java

diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/DateEntity.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/DateEntity.java
new file mode 100644 (file)
index 0000000..769aa9d
--- /dev/null
@@ -0,0 +1,68 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Integrity Monitor
+ * ================================================================================
+ * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.im.jpa;
+
+import java.io.Serializable;
+import java.util.Date;
+import javax.persistence.Column;
+import javax.persistence.MappedSuperclass;
+import javax.persistence.PrePersist;
+import javax.persistence.PreUpdate;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import org.onap.policy.common.im.MonitorTime;
+
+/*
+ * Superclass of Entities having create and update timestamps.
+ */
+@MappedSuperclass
+@Getter
+@Setter
+@NoArgsConstructor
+public class DateEntity implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    @Temporal(TemporalType.TIMESTAMP)
+    @Column(name = "created_date", updatable = false)
+    private Date createdDate;
+
+    @Temporal(TemporalType.TIMESTAMP)
+    @Column(name = "last_updated")
+    private Date lastUpdated;
+
+    /**
+     * PrePersist callback method.
+     */
+    @PrePersist
+    public void prePersist() {
+        var date = MonitorTime.getInstance().getDate();
+        this.createdDate = date;
+        this.lastUpdated = date;
+    }
+
+    @PreUpdate
+    public void preUpdate() {
+        this.lastUpdated = MonitorTime.getInstance().getDate();
+    }
+}
index ad1ef36..1359502 100644 (file)
@@ -20,8 +20,6 @@
 
 package org.onap.policy.common.im.jpa;
 
-import java.io.Serializable;
-import java.util.Date;
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
@@ -29,18 +27,11 @@ import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.NamedQuery;
 import javax.persistence.PrePersist;
-import javax.persistence.PreUpdate;
 import javax.persistence.Table;
-import javax.persistence.Temporal;
-import javax.persistence.TemporalType;
 import lombok.AccessLevel;
 import lombok.Getter;
 import lombok.NoArgsConstructor;
 import lombok.Setter;
-/*
- * The Entity class to persist a policy object ForwardProgress
- */
-import org.onap.policy.common.im.MonitorTime;
 
 @Entity
 @Table(name = "ForwardProgressEntity")
@@ -50,7 +41,7 @@ import org.onap.policy.common.im.MonitorTime;
 @Getter
 @Setter
 @NoArgsConstructor
-public class ForwardProgressEntity implements Serializable {
+public class ForwardProgressEntity extends DateEntity {
     private static final long serialVersionUID = 1L;
 
     @Id
@@ -66,27 +57,13 @@ public class ForwardProgressEntity implements Serializable {
     @Column(name = "fpc_count", nullable = false)
     private long fpcCount;
 
-    @Temporal(TemporalType.TIMESTAMP)
-    @Column(name = "created_date", updatable = false)
-    private Date createdDate;
-
-    @Temporal(TemporalType.TIMESTAMP)
-    @Column(name = "last_updated")
-    private Date lastUpdated;
-
     /**
      * PrePersist callback method.
      */
     @PrePersist
+    @Override
     public void prePersist() {
-        var date = MonitorTime.getInstance().getDate();
-        this.createdDate = date;
-        this.lastUpdated = date;
         this.fpcCount = 0;
-    }
-
-    @PreUpdate
-    public void preUpdate() {
-        this.lastUpdated = MonitorTime.getInstance().getDate();
+        super.prePersist();
     }
 }
index 1754c40..a8726f0 100644 (file)
 
 package org.onap.policy.common.im.jpa;
 
-import java.io.Serializable;
-import java.util.Date;
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.NamedQuery;
-import javax.persistence.PrePersist;
-import javax.persistence.PreUpdate;
 import javax.persistence.Table;
-import javax.persistence.Temporal;
-import javax.persistence.TemporalType;
 import lombok.AccessLevel;
 import lombok.Getter;
 import lombok.NoArgsConstructor;
 import lombok.Setter;
-import org.onap.policy.common.im.MonitorTime;
 /*
  * The Entity class to persist a policy object ResourceRegistration
  */
@@ -50,7 +43,7 @@ import org.onap.policy.common.im.MonitorTime;
 @Getter
 @Setter
 @NoArgsConstructor
-public class ResourceRegistrationEntity implements Serializable {
+public class ResourceRegistrationEntity extends DateEntity {
     private static final long serialVersionUID = 1L;
 
     @Id
@@ -71,27 +64,4 @@ public class ResourceRegistrationEntity implements Serializable {
 
     @Column(name = "nodeType", nullable = true, length = 50)
     private String nodeType;
-
-    @Temporal(TemporalType.TIMESTAMP)
-    @Column(name = "created_date", updatable = false)
-    private Date createdDate;
-
-    @Temporal(TemporalType.TIMESTAMP)
-    @Column(name = "last_updated")
-    private Date lastUpdated;
-
-    /**
-     * PrePersist callback method.
-     */
-    @PrePersist
-    public void prePersist() {
-        var date = MonitorTime.getInstance().getDate();
-        this.createdDate = date;
-        this.lastUpdated = date;
-    }
-
-    @PreUpdate
-    public void preUpdate() {
-        this.lastUpdated = MonitorTime.getInstance().getDate();
-    }
 }
index e23b29e..5d02e75 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2021 Nordix Foundation.
+ *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -41,7 +42,7 @@ public class RestClientParameters extends BusTopicParams implements ParameterGro
 
     @Override
     public BeanValidationResult validate() {
-        BeanValidationResult result = new BeanValidationResult(getClientName(), this);
+        var result = new BeanValidationResult(getClientName(), this);
         if (isHostnameInvalid()) {
             result.addResult("hostname", getHostname(), ValidationStatus.INVALID, MSG_IS_BLANK);
         }