Fix more sonar issues 98/85398/1
authorLianhao Lu <lianhao.lu@intel.com>
Tue, 16 Apr 2019 02:37:32 +0000 (10:37 +0800)
committerLianhao Lu <lianhao.lu@intel.com>
Tue, 16 Apr 2019 02:46:15 +0000 (10:46 +0800)
Fixed the sonar issues: S134, S3725, S2129.

Issue-ID: POLICY-1638
Change-Id: I1a91b8e5e071a770faf8182e8ac1ada04b63599e
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarder.java
plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/file/FileSystemReceptionHandler.java

index d02d9bb..5170000 100644 (file)
@@ -55,7 +55,7 @@ public class FilePolicyForwarder implements PolicyForwarder {
         fileForwarderParameters = ParameterService.get(parameterGroupName);
         try {
             Path path = Paths.get(fileForwarderParameters.getPath());
-            if (!Files.exists(path)) {
+            if (!path.toFile().exists()) {
                 Files.createDirectories(path);
             }
         } catch (final InvalidPathException | IOException e) {
@@ -72,8 +72,8 @@ public class FilePolicyForwarder implements PolicyForwarder {
             if (policy instanceof OptimizationPolicy) {
                 forwardPolicy((OptimizationPolicy) policy);
             } else {
-                final String message = new String("Cannot forward policy " + policy
-                        + ". Unsupported policy type " + policy.getClass().getSimpleName());
+                final String message = "Cannot forward policy " + policy
+                     + ". Unsupported policy type " + policy.getClass().getSimpleName();
                 LOGGER.error(message);
                 throw new PolicyForwardingException(message);
             }
index 72341ee..df5302c 100644 (file)
@@ -123,24 +123,7 @@ public class FileSystemReceptionHandler extends AbstractReceptionHandler {
             running = true;
             while (running) {
                 key = watcher.take();
-
-                for (final WatchEvent<?> event : key.pollEvents()) {
-                    final WatchEvent<Path> ev = (WatchEvent<Path>) event;
-                    final Path fileName = ev.context();
-                    pool.execute(() -> {
-                        LOGGER.debug("new CSAR found: {}", fileName);
-                        DistributionStatisticsManager.updateTotalDistributionCount();
-                        final String fullFilePath = dir.toString() + File.separator + fileName.toString();
-                        try {
-                            waitForFileToBeReady(fullFilePath);
-                            createPolicyInputAndCallHandler(fullFilePath);
-                            LOGGER.debug("CSAR complete: {}", fileName);
-                        } catch (InterruptedException e) {
-                            LOGGER.error("waitForFileToBeReady interrupted", e);
-                            Thread.currentThread().interrupt();
-                        }
-                    });
-                }
+                processFileEvents(dir, key, pool);
                 final boolean valid = key.reset();
                 if (!valid) {
                     LOGGER.error("Watch key no longer valid!");
@@ -152,6 +135,26 @@ public class FileSystemReceptionHandler extends AbstractReceptionHandler {
         }
     }
 
+    private void processFileEvents(Path dir, WatchKey key, ExecutorService pool) {
+        for (final WatchEvent<?> event : key.pollEvents()) {
+            final WatchEvent<Path> ev = (WatchEvent<Path>) event;
+            final Path fileName = ev.context();
+            pool.execute(() -> {
+                LOGGER.debug("new CSAR found: {}", fileName);
+                DistributionStatisticsManager.updateTotalDistributionCount();
+                final String fullFilePath = dir.toString() + File.separator + fileName.toString();
+                try {
+                    waitForFileToBeReady(fullFilePath);
+                    createPolicyInputAndCallHandler(fullFilePath);
+                    LOGGER.debug("CSAR complete: {}", fileName);
+                } catch (InterruptedException e) {
+                    LOGGER.error("waitForFileToBeReady interrupted", e);
+                    Thread.currentThread().interrupt();
+                }
+            });
+        }
+    }
+
     /**
      * Method to create policy input & call policy handlers.
      *