Fixing Sonar issues 63/68863/2
authorpwielebs <piotr.wielebski@nokia.com>
Tue, 25 Sep 2018 13:16:23 +0000 (15:16 +0200)
committerpwielebs <piotr.wielebski@nokia.com>
Fri, 28 Sep 2018 08:21:01 +0000 (10:21 +0200)
Change-Id: I67360cd501630adad8166c9278e9955c6be7758f
Issue-ID: DCAEGEN2-835
Signed-off-by: pwielebs <piotr.wielebski@nokia.com>
datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/SchedulerConfig.java
datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParser.java
datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/CloudConfigParserTest.java
datafile-commons/src/main/java/org/onap/dcaegen2/collectors/datafile/model/CommonFunctions.java
datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/consumer/DmaapConsumerReactiveHttpClient.java

index 512a217..c42749c 100644 (file)
@@ -44,7 +44,7 @@ public class SchedulerConfig extends DatafileAppConfig {
 
     private static final int SCHEDULING_DELAY_FOR_DATAFILE_COLLECTOR_TASKS = 10;
     private static final int SCHEDULING_REQUEST_FOR_CONFIGURATION_DELAY = 5;
-    private static volatile List<ScheduledFuture> scheduledFutureList = new ArrayList<ScheduledFuture>();
+    private static volatile List<ScheduledFuture> scheduledFutureList = new ArrayList<>();
 
     private final TaskScheduler taskScheduler;
     private final ScheduledTasks scheduledTask;
index 7226dfa..619ccc1 100644 (file)
@@ -167,19 +167,17 @@ public class DmaapConsumerJsonParser {
 
     private boolean isNotificationFieldsHeaderNotEmpty(String changeIdentifier, String changeType,
         String notificationFieldsVersion) {
-        return ((changeIdentifier != null && !changeIdentifier.isEmpty())
-            && (changeType != null && !changeType.isEmpty())
-            && (notificationFieldsVersion != null && !notificationFieldsVersion.isEmpty()));
+        return isStringIsNotNullAndNotEmpty(changeIdentifier) && isStringIsNotNullAndNotEmpty(changeType)
+            && isStringIsNotNullAndNotEmpty(notificationFieldsVersion);
     }
 
     private boolean isFileFormatFieldsNotEmpty(String fileFormatVersion, String fileFormatType) {
-        return ((fileFormatVersion != null && !fileFormatVersion.isEmpty())
-            && (fileFormatType != null && !fileFormatType.isEmpty()));
+        return isStringIsNotNullAndNotEmpty(fileFormatVersion) && isStringIsNotNullAndNotEmpty(fileFormatType);
     }
 
     private boolean isNameAndLocationAndCompressionNotEmpty(String name, String location, String compression) {
-        return (name != null && !name.isEmpty()) && (location != null && !location.isEmpty())
-            && (compression != null && !compression.isEmpty());
+        return isStringIsNotNullAndNotEmpty(name) && isStringIsNotNullAndNotEmpty(location) &&
+                isStringIsNotNullAndNotEmpty(compression);
     }
 
     private boolean containsHeader(JsonObject jsonObject) {
@@ -189,4 +187,8 @@ public class DmaapConsumerJsonParser {
     private boolean containsHeader(JsonObject jsonObject, String topHeader, String header) {
         return jsonObject.has(topHeader) && jsonObject.getAsJsonObject(topHeader).has(header);
     }
+
+    private boolean isStringIsNotNullAndNotEmpty(String string) {
+        return string != null && !string.isEmpty();
+    }
 }
index a4f098b..60968c0 100644 (file)
@@ -31,7 +31,7 @@ import org.onap.dcaegen2.collectors.datafile.config.ImmutableDmaapPublisherConfi
 
 class CloudConfigParserTest {
 
-    private static final String correctJson =
+    private static final String CORRECT_JSON =
         "{\"dmaap.dmaapProducerConfiguration.dmaapTopicName\": \"/events/unauthenticated.VES_NOTIFICATION_OUTPUT\", "
             + "\"dmaap.dmaapConsumerConfiguration.timeoutMS\": -1,"
             + " \"dmaap.dmaapConsumerConfiguration.dmaapHostName\": \"message-router.onap.svc.cluster.local\","
@@ -78,7 +78,7 @@ class CloudConfigParserTest {
             .build();
 
     private CloudConfigParser cloudConfigParser = new CloudConfigParser(
-        new Gson().fromJson(correctJson, JsonObject.class));
+        new Gson().fromJson(CORRECT_JSON, JsonObject.class));
 
 
     @Test
index d7bcbe4..e02476a 100644 (file)
@@ -21,17 +21,11 @@ package org.onap.dcaegen2.collectors.datafile.model;
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 
 public class CommonFunctions {
 
-    private static final Logger logger = LoggerFactory.getLogger(CommonFunctions.class);
-
     private static Gson gson = new GsonBuilder().create();
 
-
     private CommonFunctions() {}
 
     public static String createJsonBody(ConsumerDmaapModel consumerDmaapModel) {
index f32b22c..c4bf161 100644 (file)
@@ -70,9 +70,7 @@ public class DmaapConsumerReactiveHttpClient {
     }
 
     private Consumer<HttpHeaders> getHeaders() {
-        return httpHeaders -> {
-            httpHeaders.set(HttpHeaders.CONTENT_TYPE, contentType);
-        };
+        return httpHeaders -> httpHeaders.set(HttpHeaders.CONTENT_TYPE, contentType);
     }
 
     private String createRequestPath() {