From da1b7d9f04453e94fb77ebe4213f456a0be63fc2 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Thu, 5 Aug 2021 14:53:19 -0400 Subject: Use lombok in drools-pdp #2 Updated feature-session-persistence thru drools-domains. Issue-ID: POLICY-3397 Change-Id: I0b1c6da8b2301c00dd792675e8cf1f49888edb9f Signed-off-by: Jim Hahn --- .../policy/drools/statemanagement/DbAudit.java | 18 +++++-------- .../statemanagement/DroolsPdpIntegrityMonitor.java | 31 +++------------------- .../drools/statemanagement/RepositoryAudit.java | 30 ++++----------------- .../statemanagement/StateManagementProperties.java | 14 +++++----- .../statemanagement/test/StateManagementTest.java | 4 +-- 5 files changed, 24 insertions(+), 73 deletions(-) (limited to 'feature-state-management') diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DbAudit.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DbAudit.java index 2dc751b1..0c750065 100644 --- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DbAudit.java +++ b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DbAudit.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * feature-state-management * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019, 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. @@ -27,6 +27,8 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.Properties; import java.util.UUID; +import lombok.Getter; +import lombok.Setter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,7 +44,9 @@ public class DbAudit extends DroolsPdpIntegrityMonitor.AuditBase { // invoked -- doing this avoids the need to create the table in advance. private static boolean createTableNeeded = true; - private static boolean isJunit = false; + @Getter + @Setter + private static boolean junit = false; /** Constructor - set the name to 'Database'. */ private DbAudit() { @@ -53,14 +57,6 @@ public class DbAudit extends DroolsPdpIntegrityMonitor.AuditBase { DbAudit.createTableNeeded = isNeeded; } - public static synchronized void setIsJunit(boolean isJUnit) { - DbAudit.isJunit = isJUnit; - } - - public static boolean isJunit() { - return DbAudit.isJunit; - } - /** * Get the instance. * @@ -77,7 +73,7 @@ public class DbAudit extends DroolsPdpIntegrityMonitor.AuditBase { @Override public void invoke(Properties properties) { logger.debug("Running 'DbAudit.invoke'"); - boolean doCreate = createTableNeeded && !isJunit; + boolean doCreate = createTableNeeded && !isJunit(); if (!isActive()) { logger.info("DbAudit.invoke: exiting because isActive = false"); diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPdpIntegrityMonitor.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPdpIntegrityMonitor.java index 09dd275e..da94302f 100644 --- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPdpIntegrityMonitor.java +++ b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPdpIntegrityMonitor.java @@ -23,6 +23,8 @@ package org.onap.policy.drools.statemanagement; import java.io.IOException; import java.util.List; import java.util.Properties; +import lombok.Getter; +import lombok.Setter; import org.onap.policy.common.capabilities.Startable; import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; @@ -305,11 +307,13 @@ public class DroolsPdpIntegrityMonitor extends IntegrityMonitor { /** * This is the base class for audits invoked in 'subsystemTest'. */ + @Getter public abstract static class AuditBase { // name of the audit protected String name; // non-null indicates the error response + @Setter protected String response; /** @@ -322,33 +326,6 @@ public class DroolsPdpIntegrityMonitor extends IntegrityMonitor { this.response = null; } - /** - * Get the name. - * - * @return the name of this audit - */ - public String getName() { - return name; - } - - /** - * Get the response. - * - * @return the response String (non-null indicates the error message) - */ - public String getResponse() { - return response; - } - - /** - * Set the response string to the specified value. - * - * @param value the new value of the response string (null = no errors) - */ - public void setResponse(String value) { - response = value; - } - /** * Abstract method to invoke the audit. * diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java index 438b6ec8..29576c4d 100644 --- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java +++ b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * feature-state-management * ================================================================================ - * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-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. @@ -37,6 +37,8 @@ import java.util.TreeSet; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; +import lombok.AllArgsConstructor; +import lombok.Getter; import org.onap.policy.common.im.IntegrityMonitorException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,6 +54,7 @@ public class RepositoryAudit extends DroolsPdpIntegrityMonitor.AuditBase { private static final Logger logger = LoggerFactory.getLogger(RepositoryAudit.class); // single global instance of this audit object + @Getter private static RepositoryAudit instance = new RepositoryAudit(); // Regex pattern used to find additional repos in the form "repository(number).id.url" @@ -64,15 +67,6 @@ public class RepositoryAudit extends DroolsPdpIntegrityMonitor.AuditBase { super("Repository"); } - /** - * Get the integrity monitor instance. - * - * @return the single 'RepositoryAudit' instance - */ - public static DroolsPdpIntegrityMonitor.AuditBase getInstance() { - return instance; - } - /** * First, get the names of each property from StateManagementProperties. For each property name, check if it is of * the form "repository(number).audit.id" If so, we extract the number and determine if there exists another @@ -560,27 +554,13 @@ public class RepositoryAudit extends DroolsPdpIntegrityMonitor.AuditBase { /** * An instance of this class exists for each artifact that we are trying to download. */ + @AllArgsConstructor static class Artifact { String groupId; String artifactId; String version; String type; - /** - * Constructor - populate the 'Artifact' instance. - * - * @param groupId groupId of artifact - * @param artifactId artifactId of artifact - * @param version version of artifact - * @param type type of the artifact (e.g. "jar") - */ - Artifact(String groupId, String artifactId, String version, String type) { - this.groupId = groupId; - this.artifactId = artifactId; - this.version = version; - this.type = type; - } - /** * Constructor - populate an 'Artifact' instance. * diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementProperties.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementProperties.java index 20494b0f..1582ace0 100644 --- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementProperties.java +++ b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementProperties.java @@ -21,12 +21,16 @@ package org.onap.policy.drools.statemanagement; import java.util.Properties; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; import org.eclipse.persistence.config.PersistenceUnitProperties; import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class StateManagementProperties { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class StateManagementProperties { // get an instance of logger private static final Logger logger = LoggerFactory.getLogger(StateManagementProperties.class); @@ -62,11 +66,9 @@ public class StateManagementProperties { public static final String WRITE_FPC_INTERVAL = "write_fpc_interval"; public static final String DEPENDENCY_GROUPS = "dependency_groups"; + @Getter private static Properties properties = null; - private StateManagementProperties() { - } - /** * Initialize the parameter values from the feature-state-management.properties file values. * @@ -88,8 +90,4 @@ public class StateManagementProperties { public static String getProperty(String key) { return properties.getProperty(key); } - - public static Properties getProperties() { - return properties; - } } diff --git a/feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/StateManagementTest.java b/feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/StateManagementTest.java index 8d47e1d6..578b6222 100644 --- a/feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/StateManagementTest.java +++ b/feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/StateManagementTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-persistence * ================================================================================ - * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-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. @@ -110,7 +110,7 @@ public class StateManagementTest { String configDir = "src/test/resources"; - DbAudit.setIsJunit(true); + DbAudit.setJunit(true); Properties fsmProperties = new Properties(); fsmProperties.load(new FileInputStream(new File( -- cgit 1.2.3-korg