Fixing SONAR bug + code smell 12/103012/3
authoraditya.puthuparambil <aditya.puthuparambil@est.tech>
Wed, 4 Mar 2020 14:31:19 +0000 (14:31 +0000)
committeraditya.puthuparambil <aditya.puthuparambil@est.tech>
Thu, 5 Mar 2020 14:11:51 +0000 (14:11 +0000)
Change-Id: If76ddc860b67e0d8dcd4c48bacb5436ffc773faa
Issue-ID: POLICY-1913
Signed-off-by: aditya.puthuparambil <aditya.puthuparambil@est.tech>
services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java
services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/ApexStarterParameterHandler.java
testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/testsuites/integration/common/model/java/DefaultTaskLogic.java

index 72987de..699ec45 100644 (file)
@@ -132,7 +132,6 @@ public class ApexEngineHandler {
             return path.toAbsolutePath().toString();
         } catch (final IOException e) {
             final String errorMessage = "error creating  from the properties received in PdpUpdate.";
-            LOGGER.error(errorMessage, e);
             throw new ApexStarterException(errorMessage, e);
         }
     }
index ed7c00f..03a8d6e 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
+ *  Copyright (C) 2019-2020 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -60,7 +60,6 @@ public class ApexStarterParameterHandler {
         } catch (final CoderException e) {
             final String errorMessage = "error reading parameters from \"" + arguments.getConfigurationFilePath()
                     + "\"\n" + "(" + e.getClass().getSimpleName() + "):" + e.getMessage();
-            LOGGER.error(errorMessage, e);
             throw new ApexStarterException(errorMessage, e);
         }
 
index e860da7..c1c6564 100644 (file)
@@ -1,26 +1,28 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ *  Modifications Copyright (C) 2020 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- * 
+ *
  * SPDX-License-Identifier: Apache-2.0
  * ============LICENSE_END=========================================================
  */
 
 package org.onap.policy.apex.testsuites.integration.common.model.java;
 
-import java.util.Random;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
 
 import org.onap.policy.apex.core.engine.executor.context.TaskExecutionContext;
 
@@ -34,37 +36,37 @@ public class DefaultTaskLogic {
      * Gets the event.
      *
      * @param executor the executor
-     * @return the event
+     * @return true , if the event exists
      */
     public boolean getEvent(final TaskExecutionContext executor) {
         String idString = executor.subject.getId();
         executor.logger.debug(idString);
-        
+
         String albumNameString = executor.getContextAlbum("GlobalContextAlbum").getName();
         executor.logger.debug(albumNameString);
-        
+
         String inFieldsString = executor.inFields.toString();
         executor.logger.debug(inFieldsString);
 
-        final Random rand = new Random();
-
-        if (executor.inFields.containsKey("TestDecideCaseSelected")) {
-            executor.outFields.put("TestActCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
-            executor.outFields.put("TestActStateTime", java.lang.System.nanoTime());
-        }
-        else if (executor.inFields.containsKey("TestEstablishCaseSelected")) {
-            executor.outFields.put("TestDecideCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
-            executor.outFields.put("TestDecideStateTime", java.lang.System.nanoTime());
+        try {
+            SecureRandom rand = SecureRandom.getInstanceStrong();
+            if (executor.inFields.containsKey("TestDecideCaseSelected")) {
+                executor.outFields.put("TestActCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
+                executor.outFields.put("TestActStateTime", System.nanoTime());
+            } else if (executor.inFields.containsKey("TestEstablishCaseSelected")) {
+                executor.outFields.put("TestDecideCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
+                executor.outFields.put("TestDecideStateTime", System.nanoTime());
+            } else if (executor.inFields.containsKey("TestMatchCaseSelected")) {
+                executor.outFields.put("TestEstablishCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
+                executor.outFields.put("TestEstablishStateTime", System.nanoTime());
+            } else {
+                executor.outFields.put("TestMatchCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
+                executor.outFields.put("TestMatchStateTime", System.nanoTime());
+            }
+        } catch (NoSuchAlgorithmException e) {
+            executor.logger.error("Exception during Random number generation ", e);
+            return false;
         }
-        else if (executor.inFields.containsKey("TestMatchCaseSelected")) {
-            executor.outFields.put("TestEstablishCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
-            executor.outFields.put("TestEstablishStateTime", java.lang.System.nanoTime());
-        }
-        else {
-            executor.outFields.put("TestMatchCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
-            executor.outFields.put("TestMatchStateTime", java.lang.System.nanoTime());
-        }
-
-        return true;
+       return true;
     }
 }