aboutsummaryrefslogtreecommitdiffstats
path: root/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2018-02-19 16:56:06 -0500
committerJim Hahn <jrh3@att.com>2018-02-20 09:59:15 -0500
commita45f8909871dc1ddb75845f067a602951afc8d11 (patch)
treefa72aff7ceede971d4e6922f62a503a8ee8924d5 /policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java
parent1708e9a45cb88571613c10b68d392811b2b3f0f4 (diff)
Sonar fixes to drools-pdp
Fixed most of the instances of the following sonar issues: Moved array designator Used diamond operator Changed System.out/err to use a logger Changed several Thread.sleep() in test code to a single sleep() Useless assignments Replaced comparison with "" to string.isEmpty() Merged if's Replaced ArrayList with List in method returns Reordered type modifiers Reordered constructor methods Defined constants for literals, or replaced them with method calls Removed "throws Xxx" for subclasses of RuntimeException Combined identical "catch" blocks Re-interrupted the current thread after catching an InterruptedException Removed tests against the literal "false" Fix indentation of new makeTopicOperError() method. Fix exception variable name in new methods, logNoUebEncoder() and logNoDmaapEncoder(). Change-Id: Iddae5210553662f733b67333b372dec8c3fe2c94 Issue-ID: POLICY-336 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java')
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java58
1 files changed, 37 insertions, 21 deletions
diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java
index 8a0073c0..1901526c 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-management
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -251,11 +251,10 @@ public class MavenDroolsController implements DroolsController {
String customGsonCoderClass = coderConfig.getCustomGsonCoder().getClassContainer();
if (!ReflectionUtil.isClass(this.policyContainer.getClassLoader(),
customGsonCoderClass)) {
- logger.error(customGsonCoderClass + " cannot be retrieved");
- throw new IllegalArgumentException(customGsonCoderClass + " cannot be retrieved");
+ throw makeRetrieveEx(customGsonCoderClass);
} else {
if (logger.isInfoEnabled())
- logger.info("CLASS FETCHED " + customGsonCoderClass);
+ logClassFetched(customGsonCoderClass);
}
}
@@ -267,11 +266,10 @@ public class MavenDroolsController implements DroolsController {
String customJacksonCoderClass = coderConfig.getCustomJacksonCoder().getClassContainer();
if (!ReflectionUtil.isClass(this.policyContainer.getClassLoader(),
customJacksonCoderClass)) {
- logger.error(customJacksonCoderClass + " cannot be retrieved");
- throw new IllegalArgumentException(customJacksonCoderClass + " cannot be retrieved");
+ throw makeRetrieveEx(customJacksonCoderClass);
} else {
if (logger.isInfoEnabled())
- logger.info("CLASS FETCHED " + customJacksonCoderClass);
+ logClassFetched(customJacksonCoderClass);
}
}
@@ -286,11 +284,10 @@ public class MavenDroolsController implements DroolsController {
if (!ReflectionUtil.isClass(this.policyContainer.getClassLoader(),
potentialCodedClass)) {
- logger.error(potentialCodedClass + " cannot be retrieved");
- throw new IllegalArgumentException(potentialCodedClass + " cannot be retrieved");
+ throw makeRetrieveEx(potentialCodedClass);
} else {
if (logger.isInfoEnabled())
- logger.info("CLASS FETCHED " + potentialCodedClass);
+ logClassFetched(potentialCodedClass);
}
if (decoder)
@@ -309,6 +306,24 @@ public class MavenDroolsController implements DroolsController {
}
}
+ /**
+ * Logs an error and makes an exception for an item that cannot be retrieved.
+ * @param itemName
+ * @return a new exception
+ */
+ private IllegalArgumentException makeRetrieveEx(String itemName) {
+ logger.error(itemName + " cannot be retrieved");
+ return new IllegalArgumentException(itemName + " cannot be retrieved");
+ }
+
+ /**
+ * Logs the name of the class that was fetched.
+ * @param className
+ */
+ private void logClassFetched(String className) {
+ logger.info("CLASS FETCHED " + className);
+ }
+
/**
* remove decoders.
@@ -521,8 +536,7 @@ public class MavenDroolsController implements DroolsController {
}
@Override
- public boolean deliver(TopicSink sink, Object event)
- throws UnsupportedOperationException {
+ public boolean deliver(TopicSink sink, Object event) {
if (logger.isInfoEnabled())
logger.info(this + "DELIVER: " + event + " FROM " + this + " TO " + sink);
@@ -665,13 +679,17 @@ public class MavenDroolsController implements DroolsController {
return session;
}
- throw new IllegalArgumentException("Invalid Session Name: " + sessionName);
+ throw invalidSessNameEx(sessionName);
+ }
+
+ private IllegalArgumentException invalidSessNameEx(String sessionName) {
+ return new IllegalArgumentException("Invalid Session Name: " + sessionName);
}
@Override
public Map<String,Integer> factClassNames(String sessionName) {
if (sessionName == null || sessionName.isEmpty())
- throw new IllegalArgumentException("Invalid Session Name: " + sessionName);
+ throw invalidSessNameEx(sessionName);
Map<String,Integer> classNames = new HashMap<>();
@@ -697,7 +715,7 @@ public class MavenDroolsController implements DroolsController {
@Override
public long factCount(String sessionName) {
if (sessionName == null || sessionName.isEmpty())
- throw new IllegalArgumentException("Invalid Session Name: " + sessionName);
+ throw invalidSessNameEx(sessionName);
PolicySession session = getSession(sessionName);
return session.getKieSession().getFactCount();
@@ -706,7 +724,7 @@ public class MavenDroolsController implements DroolsController {
@Override
public List<Object> facts(String sessionName, String className, boolean delete) {
if (sessionName == null || sessionName.isEmpty())
- throw new IllegalArgumentException("Invalid Session Name: " + sessionName);
+ throw invalidSessNameEx(sessionName);
if (className == null || className.isEmpty())
throw new IllegalArgumentException("Invalid Class Name: " + className);
@@ -738,7 +756,7 @@ public class MavenDroolsController implements DroolsController {
@Override
public List<Object> factQuery(String sessionName, String queryName, String queriedEntity, boolean delete, Object... queryParams) {
if (sessionName == null || sessionName.isEmpty())
- throw new IllegalArgumentException("Invalid Session Name: " + sessionName);
+ throw invalidSessNameEx(sessionName);
if (queryName == null || queryName.isEmpty())
throw new IllegalArgumentException("Invalid Query Name: " + queryName);
@@ -779,9 +797,7 @@ public class MavenDroolsController implements DroolsController {
@Override
public Class<?> fetchModelClass(String className) {
- Class<?> modelClass =
- ReflectionUtil.fetchClass(this.policyContainer.getClassLoader(), className);
- return modelClass;
+ return ReflectionUtil.fetchClass(this.policyContainer.getClassLoader(), className);
}
/**