From daa096b8149e18e69e1344e01cf4627d7e0dede5 Mon Sep 17 00:00:00 2001 From: Joshua Reich Date: Fri, 21 Sep 2018 16:44:25 -0700 Subject: 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 --- .../eventmanager/ControlLoopEventManager.java | 4 +-- .../org/onap/policy/guard/PipEngineGetStatus.java | 31 +++++++++++----------- 2 files changed, 17 insertions(+), 18 deletions(-) (limited to 'controlloop/common') 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 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 setUids = new HashSet<>(); for (Attribute attributeUid : listUids) { Iterator> 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; } -- cgit 1.2.3-korg