From 3bdc959fb751bd85544cbbe003cd46b721e17375 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Tue, 16 Apr 2019 09:31:48 -0400 Subject: Fix more sonar issues Added another unused parameter from RequestImpl to a logging message. Removed "throws PfModelException" from ProviderBase. Shorten lambda function in SessionData. Change-Id: I5c0ba99bd92ac94bdeacd2398fbc65f081ef85ad Issue-ID: POLICY-1542 Signed-off-by: Jim Hahn --- .../policy/pap/main/comm/msgdata/RequestImpl.java | 2 +- .../pap/main/rest/depundep/ProviderBase.java | 7 ++-- .../policy/pap/main/rest/depundep/SessionData.java | 38 +++++++++++++--------- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/RequestImpl.java b/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/RequestImpl.java index b9a0a6dc..c17d4086 100644 --- a/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/RequestImpl.java +++ b/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/RequestImpl.java @@ -260,7 +260,7 @@ public abstract class RequestImpl implements Request { String reason = checkResponse(response); if (reason != null) { - logger.info("{} PDP data mismatch via {}: {}", getName(), infra, reason); + logger.info("{} PDP data mismatch via {} {}: {}", getName(), infra, topic, reason); listener.failure(pdpName, reason); return; } diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/depundep/ProviderBase.java b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/ProviderBase.java index 999941f2..07d04c24 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/depundep/ProviderBase.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/ProviderBase.java @@ -148,11 +148,10 @@ public abstract class ProviderBase { * @param desiredPolicy the policy desired, with the "name" and optional * "policyVersion" populated * @return the matching Policy type - * @throws PfModelException if a DAO error occurred - * @throws PolicyPapRuntimeException if there is no matching policy type + * @throws PolicyPapRuntimeException if there is no matching policy type or a DAO + * error occurs */ - private ToscaPolicy getPolicy(SessionData data, ToscaPolicyIdentifierOptVersion desiredPolicy) - throws PfModelException { + private ToscaPolicy getPolicy(SessionData data, ToscaPolicyIdentifierOptVersion desiredPolicy) { return data.getPolicy(desiredPolicy); } diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java index b7aff765..5cd2f803 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java @@ -102,21 +102,7 @@ public class SessionData { try { ToscaPolicyFilterBuilder filterBuilder = ToscaPolicyFilter.builder().name(desiredPolicy.getName()); - - String version = desiredPolicy.getVersion(); - if (version == null) { - // no version specified - get the latest - filterBuilder.version(ToscaPolicyFilter.LATEST_VERSION); - - } else if (VERSION_PREFIX_PAT.matcher(version).matches()) { - // version prefix provided - match the prefix and then pick the latest - filterBuilder.versionPrefix(version + ".").version(ToscaPolicyFilter.LATEST_VERSION); - - } else { - // must be an exact match - filterBuilder.version(version); - } - + setPolicyFilterVersion(filterBuilder, desiredPolicy.getVersion()); List lst = dao.getFilteredPolicyList(filterBuilder.build()); if (lst.isEmpty()) { @@ -138,6 +124,28 @@ public class SessionData { return policy; } + /** + * Sets the "version" in a policy filter. + * + * @param filterBuilder filter builder whose version should be set + * @param desiredVersion desired version + */ + private void setPolicyFilterVersion(ToscaPolicyFilterBuilder filterBuilder, String desiredVersion) { + + if (desiredVersion == null) { + // no version specified - get the latest + filterBuilder.version(ToscaPolicyFilter.LATEST_VERSION); + + } else if (VERSION_PREFIX_PAT.matcher(desiredVersion).matches()) { + // version prefix provided - match the prefix and then pick the latest + filterBuilder.versionPrefix(desiredVersion + ".").version(ToscaPolicyFilter.LATEST_VERSION); + + } else { + // must be an exact match + filterBuilder.version(desiredVersion); + } + } + /** * Adds an update and state-change to the sets, replacing any previous entries for the * given PDP. -- cgit 1.2.3-korg