aboutsummaryrefslogtreecommitdiffstats
path: root/integrity-monitor
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-06-29 16:48:07 -0400
committerJim Hahn <jrh3@att.com>2021-06-29 17:08:10 -0400
commit749ee9da67d32ca8e33169607fcd7139632b29e7 (patch)
treec8d3fc059b663e6215bec8a347fe4cbb0117e686 /integrity-monitor
parentfbaec67cb146add874f2aedeb5ba624f74e62d5e (diff)
Address sonars in common
Fixed: - use "var" - duplicate code block Issue-ID: POLICY-3284 Change-Id: I8cd7f2588353a2e7702c90d37d7b9f972634dca9 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'integrity-monitor')
-rw-r--r--integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/DateEntity.java68
-rw-r--r--integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ForwardProgressEntity.java29
-rw-r--r--integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ResourceRegistrationEntity.java32
3 files changed, 72 insertions, 57 deletions
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
index 00000000..769aa9d9
--- /dev/null
+++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/DateEntity.java
@@ -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();
+ }
+}
diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ForwardProgressEntity.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ForwardProgressEntity.java
index ad1ef365..13595028 100644
--- a/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ForwardProgressEntity.java
+++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ForwardProgressEntity.java
@@ -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();
}
}
diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ResourceRegistrationEntity.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ResourceRegistrationEntity.java
index 1754c405..a8726f0f 100644
--- a/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ResourceRegistrationEntity.java
+++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ResourceRegistrationEntity.java
@@ -20,24 +20,17 @@
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();
- }
}