From 18dfd9a1c12cdf70f62d3e901b218cc532874812 Mon Sep 17 00:00:00 2001
From: gavgitid <grigorios.avgitidis@cern.ch>
Date: Mon, 5 Mar 2018 18:13:38 +0100
Subject: [PATCH 1/2] NXCALS-1464 Fixes sonarqube issues on monitoring-producer

---
 .../nxcals/monitoring/producer/Application.java | 17 ++++++++---------
 .../producer/service/DataPublisherImpl.java     |  6 +++---
 2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/Application.java b/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/Application.java
index b6cbae2c3c..475c878fbb 100644
--- a/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/Application.java
+++ b/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/Application.java
@@ -5,14 +5,18 @@
 package cern.accsoft.nxcals.monitoring.producer;
 
 import cern.accsoft.nxcals.monitoring.producer.service.DataPublisher;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.system.ApplicationPidFileWriter;
 import org.springframework.context.ApplicationContext;
 
+/**
+ * Represents an application class that bootstraps and launches a Spring application from a Java main
+ * method.
+ */
 @SpringBootApplication
+@Slf4j
 public class Application {
     static {
         System.setProperty("log4j.debug", "true");
@@ -20,21 +24,16 @@ public class Application {
 
     }
 
-    private static final Logger LOGGER = LoggerFactory.getLogger(Application.class);
-
     public static void main(String[] args) throws Exception {
         try {
-
             SpringApplication app = new SpringApplication(Application.class);
             app.addListeners(new ApplicationPidFileWriter());
             ApplicationContext ctx = app.run();
 
             DataPublisher dataPublisher = ctx.getBean(DataPublisher.class);
             dataPublisher.start();
-
-        } catch (Throwable e) {
-            e.printStackTrace();
-            LOGGER.error("Exception while running publisher app", e);
+        } catch (Throwable throwable) {
+            log.error("Exception while running publisher app", throwable);
             System.exit(1);
         }
 
diff --git a/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/service/DataPublisherImpl.java b/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/service/DataPublisherImpl.java
index dbb4d71401..566c8148ae 100644
--- a/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/service/DataPublisherImpl.java
+++ b/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/service/DataPublisherImpl.java
@@ -74,10 +74,10 @@ public class DataPublisherImpl implements DataPublisher {
                         .computeIfAbsent(recordConfig.getSystem(), this.publisherCreator);
 
                 CompletableFuture<Result> future = publisher.publishAsync(data);
-                future.whenComplete((v, e) -> {
-                    if (e != null) {
+                future.whenComplete((result, throwable) -> {
+                    if (throwable != null) {
                         log.error("Cannot send data with keys={}  for timestamp={}", recordConfig.getRecordKeys(),
-                                timestamp, e);
+                                timestamp, throwable);
                     }
                 });
                 //This sleep is needed to avoid messages order problem when schema changes
-- 
GitLab


From cb6397c9187e0a7345b397b91a720da0ad5df623 Mon Sep 17 00:00:00 2001
From: gavgitid <grigorios.avgitidis@cern.ch>
Date: Tue, 6 Mar 2018 20:56:45 +0100
Subject: [PATCH 2/2] NXCALS-1464 Fixes sonar issues on monitoring-producer

---
 .../monitoring/producer/Application.java      |  6 +--
 .../producer/service/DataPublisherImpl.java   |  1 -
 .../producer/service/ValueCreatorImpl.java    | 52 ++-----------------
 3 files changed, 5 insertions(+), 54 deletions(-)

diff --git a/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/Application.java b/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/Application.java
index 475c878fbb..b5eac46bb5 100644
--- a/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/Application.java
+++ b/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/Application.java
@@ -20,8 +20,6 @@ import org.springframework.context.ApplicationContext;
 public class Application {
     static {
         System.setProperty("log4j.debug", "true");
-        // System.setProperty("log4j.configuration", "extr-log4j.properties");
-
     }
 
     public static void main(String[] args) throws Exception {
@@ -32,8 +30,8 @@ public class Application {
 
             DataPublisher dataPublisher = ctx.getBean(DataPublisher.class);
             dataPublisher.start();
-        } catch (Throwable throwable) {
-            log.error("Exception while running publisher app", throwable);
+        } catch (Exception ex) {
+            log.error("Exception while running publisher app", ex);
             System.exit(1);
         }
 
diff --git a/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/service/DataPublisherImpl.java b/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/service/DataPublisherImpl.java
index 566c8148ae..f3fa73bfd6 100644
--- a/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/service/DataPublisherImpl.java
+++ b/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/service/DataPublisherImpl.java
@@ -68,7 +68,6 @@ public class DataPublisherImpl implements DataPublisher {
                 long timestamp = (timeInMillis + i * 1000) * 1_000_000;
                 ImmutableData data = valueCreator
                         .createData(recordConfig.getRecordKeys(), recordConfig.getTimestampKeyName(), timestamp);
-                //log.debug("Publishing value {}", data);
 
                 Publisher<ImmutableData> publisher = publishers
                         .computeIfAbsent(recordConfig.getSystem(), this.publisherCreator);
diff --git a/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/service/ValueCreatorImpl.java b/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/service/ValueCreatorImpl.java
index a1c9735989..b81df5f62d 100644
--- a/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/service/ValueCreatorImpl.java
+++ b/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/service/ValueCreatorImpl.java
@@ -19,7 +19,6 @@ public class ValueCreatorImpl implements ValueCreator {
 
     public ValueCreatorImpl() {
         this.random = new Random();
-
     }
 
     private String getRandomFieldName(long timestamp) {
@@ -32,7 +31,7 @@ public class ValueCreatorImpl implements ValueCreator {
 
         DataBuilder builder = ImmutableData.builder();
 
-        requiredKeyValues.forEach((key, value) -> builder.add(key, value));
+        requiredKeyValues.forEach(builder::add);
 
         builder.add(timestampKeyName, timestamp)
                 .add("boolField", random.nextBoolean())
@@ -45,7 +44,8 @@ public class ValueCreatorImpl implements ValueCreator {
                 //those 2 fields should not be checked for logging
                 .add("longField3_DoNotLog", 1L)
                 .add("longField4_DoNotLog", 1L)
-                //This is a random field that is changed to generate schema changes, this is not logged anyway as it is random name and not visible nor set in the CCDB editor.
+                //This is a random field that is changed to generate schema changes, this is not logged anyway
+                //as it is random name and not visible nor set in the CCDB editor.
                 //This field will nevertheless be in the schema and change the schema if changed.
                 .add(getRandomFieldName(timestamp), 0)
 
@@ -73,52 +73,6 @@ public class ValueCreatorImpl implements ValueCreator {
 
         return builder.build();
 
-        // No multiarray in JAPC.
-        //        data.appendMultiArray("boolMultiArrayField1", new boolean[]{true, false, true, false}, new int[]{2, 2});
-        //        data.appendMultiArray("byteMultiArrayField1", new byte[]{1, 2, 3, 4}, new int[]{2, 2});
-        //        data.appendMultiArray("shortMultiArrayField1", new short[]{1, 2, 3, 4}, new int[]{2, 2});
-        //        data.appendMultiArray("intMultiArrayField1", new int[]{1, 2, 3, 4}, new int[]{2, 2});
-        //        data.appendMultiArray("longMultiArrayField1", new long[]{1, 2, 3, 4}, new int[]{2, 2});
-        //        data.appendMultiArray("doubleMultiArrayField1", new double[]{1, 2, 3, 4}, new int[]{2, 2});
-        //        data.appendMultiArray("floatMultiArrayField1", new float[]{1, 2, 3, 4}, new int[]{2, 2});
-        //        data.appendMultiArray("stringMultiArrayField1", new String[]{"aaaa", "bbbb", "cccc", "dddd"},
-        //                new int[]{2, 2});
-        //        data.appendMultiArray("stringMultiArrayField2", new String[]{"aaaa", "bbbb", "cccc", "dddd"},
-        //                new int[]{2, 2});
-
-        // Currently a bug - https://issues.cern.ch/browse/CALS-4955
-        //data.setDiscreteFunction("ddfField1", DomainValueFactory.newDiscreteFunction(new double[]{1.0, 2.0}, new double[]{1.0, 2.0}));
-        //data.setDiscreteFunction("ddfField2", DomainValueFactory.newDiscreteFunction(new double[]{1.0, 2.0}, new double[]{1.0, 2.0}));
-
-        //        data.setDiscreteFunctionList("ddfArrayField1",
-        //                DomainValueFactory.newDiscreteFunctionList(
-        //                        DomainValueFactory.newDiscreteFunction(new double[]{1.0, 2.0}, new double[]{1.0, 2.0}),
-        //                        DomainValueFactory.newDiscreteFunction(new double[]{1.0, 2.0, 3.0}, new double[]{1.0, 2.0, 3.0})));
-        //
-        //        data.setDiscreteFunctionList("ddfArrayField2",
-        //                DomainValueFactory.newDiscreteFunctionList(
-        //                        DomainValueFactory.newDiscreteFunction(new double[]{1.0, 2.0}, new double[]{1.0, 2.0}),
-        //                        DomainValueFactory.newDiscreteFunction(new double[]{1.0, 2.0, 3.0}, new double[]{1.0, 2.0, 3.0})));
-
-        // No nested data in JAPC.
-        //        Data secondNestedData = DataFactory.createData();
-        //        secondNestedData.append("longField1", 1L);
-        //        secondNestedData.append("discreteFunctionField",
-        //                DataFactory.createDiscreteFunction(new double[]{1.0, 2.0}, new double[]{1.0, 2.0}));
-        //        secondNestedData.appendMultiArray("multiArrayLong", new short[]{1, 2, 3, 4}, new int[]{2, 2});
-        //
-        //        Data nestedData = DataFactory.createData();
-        //        nestedData.append("boolField", true);
-        //        nestedData.append("longField", 1L);
-        //        // here nothing happens, the record version is ignored.
-        //        nestedData.append("record_version1", "ver1");
-        //        nestedData.append("record_version2", 12);
-        //        nestedData.appendArray2D("boolArray2DField2", new boolean[]{true, false}, 1, 2);
-        //        nestedData.appendArray("byteArrayField", new byte[]{1, 2, 3, 4});
-        //        nestedData.append("dataField", secondNestedData);
-        //
-        //        data.append("dataField", nestedData);
-
     }
 
 }
-- 
GitLab