Fix more sonar issues 72/85472/1
authorJim Hahn <jrh3@att.com>
Tue, 16 Apr 2019 13:31:48 +0000 (09:31 -0400)
committerJim Hahn <jrh3@att.com>
Tue, 16 Apr 2019 13:46:18 +0000 (09:46 -0400)
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 <jrh3@att.com>
main/src/main/java/org/onap/policy/pap/main/comm/msgdata/RequestImpl.java
main/src/main/java/org/onap/policy/pap/main/rest/depundep/ProviderBase.java
main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java

index b9a0a6d..c17d408 100644 (file)
@@ -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;
             }
index 999941f..07d04c2 100644 (file)
@@ -148,11 +148,10 @@ public abstract class ProviderBase<R extends SimpleResponse> {
      * @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);
     }
index b7aff76..5cd2f80 100644 (file)
@@ -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<ToscaPolicy> 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.