From 85bf9c859768611cf1cc9ab38cf8f75ec33fc0ee Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Wed, 14 Jul 2021 16:47:14 -0400 Subject: Use lombok in xacml-pdp Also: - changed a few fields to private/protected. - swwapped out gson for coder Issue-ID: POLICY-3400 Change-Id: I9a4dba939b77078f78583ada00af182b1a7d95c5 Signed-off-by: Jim Hahn --- .../pdpx/main/comm/XacmlPdpPapRegistration.java | 12 +--- .../pdpx/main/comm/XacmlPdpUpdatePublisher.java | 14 +---- .../main/parameters/XacmlPdpParameterHandler.java | 12 ++-- .../pdpx/main/rest/XacmlPdpStatisticsManager.java | 72 ++-------------------- .../rest/serialization/XacmlExceptionMapper.java | 6 +- .../startstop/XacmlPdpCommandLineArguments.java | 44 ++----------- .../parameters/TestXacmlPdpParameterHandler.java | 12 ++-- 7 files changed, 31 insertions(+), 141 deletions(-) (limited to 'main/src') diff --git a/main/src/main/java/org/onap/policy/pdpx/main/comm/XacmlPdpPapRegistration.java b/main/src/main/java/org/onap/policy/pdpx/main/comm/XacmlPdpPapRegistration.java index a848f523..d477ed0b 100644 --- a/main/src/main/java/org/onap/policy/pdpx/main/comm/XacmlPdpPapRegistration.java +++ b/main/src/main/java/org/onap/policy/pdpx/main/comm/XacmlPdpPapRegistration.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 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. @@ -22,25 +22,19 @@ package org.onap.policy.pdpx.main.comm; +import lombok.AllArgsConstructor; import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClient; import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClientException; import org.onap.policy.models.pdp.concepts.PdpStatus; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@AllArgsConstructor public class XacmlPdpPapRegistration { private static final Logger LOGGER = LoggerFactory.getLogger(XacmlPdpPapRegistration.class); private final TopicSinkClient client; - /** - * Constructs the object. - * @param client name of the TopickSinkClient - */ - public XacmlPdpPapRegistration(TopicSinkClient client) { - this.client = client; - } - /** * Sends PDP register and unregister message to the PAP. * @param status of the PDP diff --git a/main/src/main/java/org/onap/policy/pdpx/main/comm/XacmlPdpUpdatePublisher.java b/main/src/main/java/org/onap/policy/pdpx/main/comm/XacmlPdpUpdatePublisher.java index 39af6fd6..da6fdb2c 100644 --- a/main/src/main/java/org/onap/policy/pdpx/main/comm/XacmlPdpUpdatePublisher.java +++ b/main/src/main/java/org/onap/policy/pdpx/main/comm/XacmlPdpUpdatePublisher.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; +import lombok.AllArgsConstructor; import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClient; import org.onap.policy.models.pdp.concepts.PdpStatus; import org.onap.policy.models.pdp.concepts.PdpUpdate; @@ -39,6 +40,7 @@ import org.onap.policy.pdpx.main.rest.XacmlPdpStatisticsManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@AllArgsConstructor public class XacmlPdpUpdatePublisher { private static final Logger LOGGER = LoggerFactory.getLogger(XacmlPdpUpdatePublisher.class); @@ -47,18 +49,6 @@ public class XacmlPdpUpdatePublisher { private final XacmlState state; private final XacmlPdpApplicationManager appManager; - /** - * Constructs the object. - * @param client messages are published to this client - * @param state tracks the state of this PDP - * @param appManager application manager - */ - public XacmlPdpUpdatePublisher(TopicSinkClient client, XacmlState state, XacmlPdpApplicationManager appManager) { - this.client = client; - this.state = state; - this.appManager = appManager; - } - /** * Handle the PDP Update message. * diff --git a/main/src/main/java/org/onap/policy/pdpx/main/parameters/XacmlPdpParameterHandler.java b/main/src/main/java/org/onap/policy/pdpx/main/parameters/XacmlPdpParameterHandler.java index aac05752..539716b8 100644 --- a/main/src/main/java/org/onap/policy/pdpx/main/parameters/XacmlPdpParameterHandler.java +++ b/main/src/main/java/org/onap/policy/pdpx/main/parameters/XacmlPdpParameterHandler.java @@ -20,10 +20,10 @@ package org.onap.policy.pdpx.main.parameters; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import java.io.FileReader; +import java.io.File; import org.onap.policy.common.parameters.ValidationResult; +import org.onap.policy.common.utils.coder.Coder; +import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.pdpx.main.PolicyXacmlPdpException; import org.onap.policy.pdpx.main.startstop.XacmlPdpCommandLineArguments; import org.slf4j.Logger; @@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory; */ public class XacmlPdpParameterHandler { private static final Logger LOGGER = LoggerFactory.getLogger(XacmlPdpParameterHandler.class); - private static final Gson gson = new GsonBuilder().create(); + private static final Coder CODER = new StandardCoder(); /** * Read the parameters from the parameter file. @@ -51,8 +51,8 @@ public class XacmlPdpParameterHandler { XacmlPdpParameterGroup xacmlPdpParameterGroup = null; try { - // Read the parameters from JSON using Gson - xacmlPdpParameterGroup = gson.fromJson(new FileReader(arguments.getFullConfigurationFilePath()), + // Read the parameters from JSON + xacmlPdpParameterGroup = CODER.decode(new File(arguments.getFullConfigurationFilePath()), XacmlPdpParameterGroup.class); } catch (final Exception e) { final String errorMessage = "error reading parameters from \"" + arguments.getConfigurationFilePath() diff --git a/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpStatisticsManager.java b/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpStatisticsManager.java index a696ea43..63d9f513 100644 --- a/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpStatisticsManager.java +++ b/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpStatisticsManager.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 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,7 @@ import lombok.Setter; * Class to hold statistical data for xacmlPdp component. * */ +@Getter public class XacmlPdpStatisticsManager { @Getter @Setter @@ -34,7 +35,7 @@ public class XacmlPdpStatisticsManager { private long totalPolicyTypesCount; private long totalPoliciesCount; - private long errorsCount; + private long errorCount; private long permitDecisionsCount; private long denyDecisionsCount; private long indeterminantDecisionsCount; @@ -70,7 +71,7 @@ public class XacmlPdpStatisticsManager { * @return the errorDecisionsCount */ public long updateErrorCount() { - return ++errorsCount; + return ++errorCount; } /** @@ -109,76 +110,13 @@ public class XacmlPdpStatisticsManager { return ++notApplicableDecisionsCount; } - /** - * Returns the current value of totalPolicyTypesCount. - - * @return the totalPolicyTypesCount - */ - public long getTotalPolicyTypesCount() { - return totalPolicyTypesCount; - } - - /** - * Returns the current value of totalPoliciesCount. - - * @return the totalPoliciesCount - */ - public long getTotalPoliciesCount() { - return totalPoliciesCount; - } - - /** - * Returns the current value of errorDecisionsCount. - - * @return the permitDecisionsCount - */ - public long getErrorCount() { - return errorsCount; - } - - /** - * Returns the current value of permitDecisionsCount. - - * @return the permitDecisionsCount - */ - public long getPermitDecisionsCount() { - return permitDecisionsCount; - } - - /** - * Returns the current value of denyDecisionsCount. - - * @return the denyDecisionsCount - */ - public long getDenyDecisionsCount() { - return denyDecisionsCount; - } - - /** - * Returns the current value of indeterminantDecisionsCount. - - * @return the indeterminantDecisionsCount - */ - public long getIndeterminantDecisionsCount() { - return indeterminantDecisionsCount; - } - - /** - * Returns the current value of notApplicableDecisionsCount. - - * @return the notApplicableDecisionsCount - */ - public long getNotApplicableDecisionsCount() { - return notApplicableDecisionsCount; - } - /** * Reset all the statistics counts to 0. */ public void resetAllStatistics() { totalPolicyTypesCount = 0L; totalPoliciesCount = 0L; - errorsCount = 0L; + errorCount = 0L; permitDecisionsCount = 0L; denyDecisionsCount = 0L; indeterminantDecisionsCount = 0L; diff --git a/main/src/main/java/org/onap/policy/pdpx/main/rest/serialization/XacmlExceptionMapper.java b/main/src/main/java/org/onap/policy/pdpx/main/rest/serialization/XacmlExceptionMapper.java index 4112e64e..a2a78a89 100644 --- a/main/src/main/java/org/onap/policy/pdpx/main/rest/serialization/XacmlExceptionMapper.java +++ b/main/src/main/java/org/onap/policy/pdpx/main/rest/serialization/XacmlExceptionMapper.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-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. @@ -36,9 +36,9 @@ public abstract class XacmlExceptionMapper implements ExceptionMapper new XacmlPdpParameterHandler().getParameters(badArguments)) - .hasMessage("error reading parameters from \"parameters/BadParameters.json\"\n" - + "(JsonSyntaxException):java.lang.IllegalStateException: " - + "Expected a string but was BEGIN_ARRAY at line 2 column 14 path $.name"); + .hasMessageContaining("error reading parameters from", "parameters/BadParameters.json", + "JsonSyntaxException", "java.lang.IllegalStateException", + "Expected a string but was BEGIN_ARRAY at line 2 column 14 path $.name"); } @@ -81,9 +81,9 @@ public class TestXacmlPdpParameterHandler { invalidArguments.parse(invalidArgumentString); assertThatThrownBy(() -> new XacmlPdpParameterHandler().getParameters(invalidArguments)) - .hasMessage("error reading parameters from \"parameters/InvalidParameters.json\"\n" - + "(JsonSyntaxException):java.lang.IllegalStateException: " - + "Expected a string but was BEGIN_ARRAY at line 2 column 14 path $.name"); + .hasMessageContaining("error reading parameters from", "parameters/InvalidParameters.json", + "JsonSyntaxException", "java.lang.IllegalStateException", + "Expected a string but was BEGIN_ARRAY at line 2 column 14 path $.name"); } @Test -- cgit 1.2.3-korg