Fix critical sonar issues 55/63355/3
authorParshad Patel <pars.patel@samsung.com>
Wed, 29 Aug 2018 02:47:06 +0000 (11:47 +0900)
committerParshad Patel <pars.patel@samsung.com>
Mon, 10 Sep 2018 01:59:47 +0000 (10:59 +0900)
Fix DateFormat static declaration & log exception issue

Issue-ID: AAI-1368
Change-Id: Ie4c9677e5b8aad8a7220cf806ceb45a9484ccb07
Signed-off-by: Parshad Patel <pars.patel@samsung.com>
src/main/java/org/onap/aai/datacleanup/DataCleanupTasks.java
src/main/java/org/onap/aai/datasnapshot/DataSnapshotTasks.java

index 1931491..a281d70 100644 (file)
@@ -47,8 +47,7 @@ import com.att.eelf.configuration.EELFManager;
 public class DataCleanupTasks {\r
 \r
        private static final EELFLogger logger = EELFManager.getInstance().getLogger(DataCleanupTasks.class);\r
-       private static final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");\r
-       \r
+       private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");\r
        /**The function archives/deletes files that end in .out (Ie. dataGrooming.201511111305.out) that sit in our log/data directory structure.\r
                logDir is the {project_home}/logs\r
                archiveDir is the ARCHIVE directory where the files will be stored after 5 days.\r
index cc9ca97..404e243 100644 (file)
@@ -29,6 +29,7 @@ import org.onap.aai.datagrooming.DataGrooming;
 import org.onap.aai.datagrooming.DataGroomingTasks;
 import org.onap.aai.exceptions.AAIException;
 import org.onap.aai.logging.ErrorLogHelper;
+import org.onap.aai.logging.LogFormatTools;
 import org.onap.aai.logging.LoggingContext;
 import org.onap.aai.util.AAIConfig;
 import org.springframework.context.annotation.PropertySource;
@@ -42,7 +43,7 @@ import com.att.eelf.configuration.EELFManager;
 public class DataSnapshotTasks {
 
        private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(DataSnapshotTasks.class);
-       private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
+       private final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
        
        @Scheduled(cron = "${datasnapshottasks.cron}" )
        public void snapshotScheduleTask() throws AAIException, Exception {
@@ -66,10 +67,9 @@ public class DataSnapshotTasks {
                LOGGER.info("Started cron job dataSnapshot @ " + dateFormat.format(new Date()));
                try {
                        if (AAIConfig.get("aai.cron.enable.dataSnapshot").equals("true")) {
-                               DataSnapshot dataSnapshot = new DataSnapshot();
                                String [] dataSnapshotParms = AAIConfig.get("aai.datasnapshot.params",  "JUST_TAKE_SNAPSHOT").split("\\s+");
                                LOGGER.info("DataSnapshot Params {}", Arrays.toString(dataSnapshotParms));
-                               dataSnapshot.main(dataSnapshotParms);
+                               DataSnapshot.main(dataSnapshotParms);
                        }
                }
                catch (Exception e) {
@@ -93,7 +93,6 @@ public class DataSnapshotTasks {
                        InputStream is = process.getInputStream();
                        InputStreamReader isr = new InputStreamReader(is);
                        BufferedReader br = new BufferedReader(isr);
-
                        while (br.readLine() != null){
                                count++;
                        }
@@ -101,15 +100,11 @@ public class DataSnapshotTasks {
                        int exitVal = process.waitFor();
                        LOGGER.info("Exit value of the dataSnapshot check process: " + exitVal);
                } catch (Exception e) {
-                       e.printStackTrace();
+                       LOGGER.error("Exception in checkIfDataSnapshotIsRunning" + LogFormatTools.getStackTop(e));
                }
 
-               if(count > 0){
-                       return true;
-               } else {
-                       return false;
-               }
+               return count > 0;
        }
 }
                
-       
\ No newline at end of file
+