aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoshua Reich <jreich@research.att.com>2018-09-21 16:44:25 -0700
committerJoshua Reich <jreich@research.att.com>2018-09-27 12:53:38 -0700
commitdaa096b8149e18e69e1344e01cf4627d7e0dede5 (patch)
treec8dd5ea368d5ef615bb5e3780fcf751de4371c99
parent72d5a239ff15617b2d218d3b8f3f8a2099007142 (diff)
Yet more sonar issues in drools-applications
removed unused imports and variable definitions moved variable declarations above methods refactored deeply nested if/while removed code smell due to unecessary use of static keyword moved string literals to left side of comparator fixed logging of exceptions immediately return expression instead of assigning it to the temporary variable Change-Id: Idfd2a2bdf3c2f3bbfcb54a06b713d57bc867b3ab Issue-ID: POLICY-1129 Signed-off-by: Joshua Reich <jreich@research.att.com>
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java4
-rw-r--r--controlloop/common/guard/src/main/java/org/onap/policy/guard/PipEngineGetStatus.java31
-rw-r--r--controlloop/templates/template.demo.clc/src/main/java/org/onap/policy/guard/CallGuardTaskEmbedded.java2
-rw-r--r--controlloop/templates/template.demo.clc/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelperEmbedded.java25
4 files changed, 30 insertions, 32 deletions
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
index 4ab7b494f..e9fc27734 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
@@ -499,9 +499,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
this.currentOperation.getTargetEntity(),
this.onset.getRequestId(), this);
this.targetLock = lock;
- LockResult<GuardResult, TargetLock> lockResult =
- LockResult.createLockResult(GuardResult.LOCK_ACQUIRED, lock);
- return lockResult;
+ return LockResult.createLockResult(GuardResult.LOCK_ACQUIRED, lock);
}
//
// Have we acquired it already?
diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PipEngineGetStatus.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PipEngineGetStatus.java
index 36bb36f5c..b61ab5d73 100644
--- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PipEngineGetStatus.java
+++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PipEngineGetStatus.java
@@ -148,7 +148,7 @@ public class PipEngineGetStatus extends StdConfigurableEngine {
try {
pipResponse = pipFinder.getMatchingAttributes(pipRequest, this);
} catch (PIPException ex) {
- logger.error("getAttribute threw:", ex);
+ logger.error("getAttribute threw", ex);
return null;
}
if (pipResponse == null) {
@@ -197,16 +197,17 @@ public class PipEngineGetStatus extends StdConfigurableEngine {
Set<String> setUids = new HashSet<>();
for (Attribute attributeUid : listUids) {
Iterator<AttributeValue<String>> iterAttributeValues = attributeUid.findValues(DataTypes.DT_STRING);
- if (iterAttributeValues != null) {
- while (iterAttributeValues.hasNext()) {
- String uid = iterAttributeValues.next().getValue();
- if (uid != null) {
- setUids.add(uid);
- }
+ if (iterAttributeValues == null) {
+ continue;
+ }
+ while (iterAttributeValues.hasNext()) {
+ String uid = iterAttributeValues.next().getValue();
+ if (uid == null) {
+ continue;
}
+ setUids.add(uid);
}
}
-
return setUids;
}
@@ -220,13 +221,13 @@ public class PipEngineGetStatus extends StdConfigurableEngine {
props.put(Util.ECLIPSE_LINK_KEY_USER, PolicyEngine.manager.getEnvironmentProperty(Util.ONAP_KEY_USER));
props.put(Util.ECLIPSE_LINK_KEY_PASS, PolicyEngine.manager.getEnvironmentProperty(Util.ONAP_KEY_PASS));
} catch (NullPointerException e) {
- logger.error("getStatusFromDB: {} when setting properties", e.getMessage());
+ logger.error("getStatusFromDb: when setting properties", e);
}
//
// Set opsHistPu to the correct value and clear properties if necessary.
//
String opsHistPu = System.getProperty("OperationsHistoryPU");
- if (opsHistPu == null || !opsHistPu.equals("TestOperationsHistoryPU")) {
+ if (!"TestOperationsHistoryPU".equals(opsHistPu)) {
opsHistPu = "OperationsHistoryPU";
} else {
props.clear();
@@ -240,14 +241,14 @@ public class PipEngineGetStatus extends StdConfigurableEngine {
emf = Persistence.createEntityManagerFactory(opsHistPu, props);
} catch (Exception ex) {
logger.error("PIP thread got Exception. Can't connect to Operations History DB -- {}", opsHistPu);
- logger.error("getStatusFromDb threw: ", ex);
+ logger.error("getStatusFromDb threw", ex);
return null;
}
try {
em = emf.createEntityManager();
} catch (Exception ex) {
logger.error("PIP thread got Exception. Problem creating EntityManager");
- logger.error("getStatusFromDb threw: ", ex);
+ logger.error("getStatusFromDb threw", ex);
emf.close();
return null;
}
@@ -269,7 +270,7 @@ public class PipEngineGetStatus extends StdConfigurableEngine {
try {
ret = ((String)nq.getSingleResult());
} catch (NoResultException ex) {
- logger.debug("NoResultException for getSingleResult()");
+ logger.debug("NoResultException for getSingleResult()", ex);
ret = "NO_MATCHING_ENTRY";
} catch (Exception ex) {
logger.error("getStatusFromDB threw an exception", ex);
@@ -283,12 +284,12 @@ public class PipEngineGetStatus extends StdConfigurableEngine {
try {
em.close();
} catch (Exception ex) {
- logger.error("getStatusFromDB threw an exception ", ex);
+ logger.error("getStatusFromDB threw an exception", ex);
}
try {
emf.close();
} catch (Exception ex) {
- logger.error("getStatusFromDB threw an exception ", ex);
+ logger.error("getStatusFromDB threw an exception", ex);
}
return ret;
}
diff --git a/controlloop/templates/template.demo.clc/src/main/java/org/onap/policy/guard/CallGuardTaskEmbedded.java b/controlloop/templates/template.demo.clc/src/main/java/org/onap/policy/guard/CallGuardTaskEmbedded.java
index 7abf38620..c75c8a0b7 100644
--- a/controlloop/templates/template.demo.clc/src/main/java/org/onap/policy/guard/CallGuardTaskEmbedded.java
+++ b/controlloop/templates/template.demo.clc/src/main/java/org/onap/policy/guard/CallGuardTaskEmbedded.java
@@ -151,7 +151,7 @@ public class CallGuardTaskEmbedded implements Runnable {
//
// Create an artificial Guard response in case we didn't get a clear Permit or Deny
//
- if (guardResponse.getResult().equals("Indeterminate")) {
+ if ("Indeterminate".equals(guardResponse.getResult())) {
guardResponse.setOperation(recipe);
guardResponse.setRequestID(UUID.fromString(requestId));
}
diff --git a/controlloop/templates/template.demo.clc/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelperEmbedded.java b/controlloop/templates/template.demo.clc/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelperEmbedded.java
index e14946274..64fb70bbd 100644
--- a/controlloop/templates/template.demo.clc/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelperEmbedded.java
+++ b/controlloop/templates/template.demo.clc/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelperEmbedded.java
@@ -60,9 +60,14 @@ public class PolicyGuardXacmlHelperEmbedded {
private static final Logger netLogger =
LoggerFactory.getLogger(org.onap.policy.common.endpoints.event.comm.Topic.NETWORK_LOGGER);
- // Constant for the systme line separator
+ // Constant for the system line separator
private static final String SYSTEM_LS = System.lineSeparator();
- private static String propfile;
+ private String propfile;
+ private UrlEntry[] restUrls = null;
+ private int restUrlIndex = 0;
+
+ // REST timeout, initialized from 'pdpx.timeout' property
+ private int timeout = 20000;
public PolicyGuardXacmlHelperEmbedded() {
init(PolicyEngine.manager.getEnvironment());
@@ -82,12 +87,6 @@ public class PolicyGuardXacmlHelperEmbedded {
String environment = null;
}
- private UrlEntry[] restUrls = null;
- private int restUrlIndex = 0;
-
- // REST timeout, initialized from 'pdpx.timeout' property
- private int timeout = 20000;
-
/**
* Call PDP.
*
@@ -133,7 +132,7 @@ public class PolicyGuardXacmlHelperEmbedded {
urlEntry.authorization, urlEntry.clientAuth, urlEntry.environment);
netLogger.info("[IN|{}|{}|]{}{}", "GUARD", urlEntry.restUrl, SYSTEM_LS, response);
} catch (Exception e) {
- logger.error("Error in sending RESTful request: ", e);
+ logger.error("Error in sending RESTful request", e);
}
return response;
@@ -235,7 +234,7 @@ public class PolicyGuardXacmlHelperEmbedded {
* @param xacmlReq the XACML request
* @return the response
*/
- public static String callEmbeddedPdp(PolicyGuardXacmlRequestAttributes xacmlReq) {
+ public String callEmbeddedPdp(PolicyGuardXacmlRequestAttributes xacmlReq) {
com.att.research.xacml.api.Response response = null;
Properties props = new Properties();
//
@@ -246,7 +245,7 @@ public class PolicyGuardXacmlHelperEmbedded {
BufferedReader br = new BufferedReader(isr) ) {
props.load(br);
} catch (Exception e) {
- logger.error("Unable to load properties file {} {}", propfile, e.getMessage());
+ logger.error("Unable to load properties file {}", propfile, e);
}
//
// Create embedded PDPEngine
@@ -255,7 +254,7 @@ public class PolicyGuardXacmlHelperEmbedded {
try {
xacmlPdpEngine = ATTPDPEngineFactory.newInstance().newEngine(props);
} catch (Exception e) {
- logger.error("Failed to create new PDPEngine {}", e.getMessage());
+ logger.error("callEmbeddedPdpEngine failed to create new PDPEngine", e);
return null;
}
logger.debug("embedded Engine created");
@@ -269,7 +268,7 @@ public class PolicyGuardXacmlHelperEmbedded {
try {
response = xacmlPdpEngine.decide(RequestParser.parseRequest(xacmlReq));
} catch (Exception e) {
- logger.error(e.getMessage(), e);
+ logger.error("callEmbeddedPdpEngine failed on decide", e);
}
long timeEnd = System.currentTimeMillis();
logger.debug("Elapsed Time: {} ms", (timeEnd - timeStart));