Fix Checkstyle issues
[clamp.git] / src / main / java / org / onap / clamp / clds / config / sdc / SdcSingleControllerConfiguration.java
index ca756aa..052ea73 100644 (file)
@@ -25,8 +25,8 @@ package org.onap.clamp.clds.config.sdc;
 
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
-import com.fasterxml.jackson.databind.JsonNode;
 
+import com.google.gson.JsonObject;
 import java.security.GeneralSecurityException;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -52,7 +52,7 @@ public class SdcSingleControllerConfiguration implements IConfiguration {
     /**
      * The root of the JSON.
      */
-    private JsonNode jsonRootNode;
+    private JsonObject jsonRootNode;
     // All keys that can be present in the JSON
     public static final String CONSUMER_GROUP_ATTRIBUTE_NAME = "consumerGroup";
     public static final String CONSUMER_ID_ATTRIBUTE_NAME = "consumerId";
@@ -81,7 +81,7 @@ public class SdcSingleControllerConfiguration implements IConfiguration {
     public static final String TOSCA_CSAR = "TOSCA_CSAR";
     public static final String VF_MODULES_METADATA = "VF_MODULES_METADATA";
     private static final String[] SUPPORTED_ARTIFACT_TYPES = {
-            TOSCA_CSAR, VF_MODULES_METADATA
+        TOSCA_CSAR, VF_MODULES_METADATA
     };
     public static final List<String> SUPPORTED_ARTIFACT_TYPES_LIST = Collections
             .unmodifiableList(Arrays.asList(SUPPORTED_ARTIFACT_TYPES));
@@ -90,12 +90,12 @@ public class SdcSingleControllerConfiguration implements IConfiguration {
      * This constructor builds a SdcSingleControllerConfiguration from the
      * corresponding json.
      * 
-     * @param jsonRootNode
+     * @param jsonNode
      *            The JSON node
      * @param controllerName
      *            The controller name that must appear in the JSON
      */
-    public SdcSingleControllerConfiguration(JsonNode jsonNode, String controllerName) {
+    public SdcSingleControllerConfiguration(JsonObject jsonNode, String controllerName) {
         jsonRootNode = jsonNode;
         setSdcControllerName(controllerName);
         testAllRequiredParameters();
@@ -105,6 +105,11 @@ public class SdcSingleControllerConfiguration implements IConfiguration {
         return sdcControllerName;
     }
 
+    /**
+     * Sets SDC controller name.
+     *
+     * @param controllerName SDC controller name
+     */
     public void setSdcControllerName(String controllerName) {
         this.sdcControllerName = controllerName;
         errorMessageKeyNotFound = " parameter cannot be found in config file for controller name" + sdcControllerName;
@@ -113,7 +118,7 @@ public class SdcSingleControllerConfiguration implements IConfiguration {
 
     private String getStringConfig(String key) {
         if (jsonRootNode != null && jsonRootNode.get(key) != null) {
-            String config = jsonRootNode.get(key).asText();
+            String config = jsonRootNode.get(key).getAsString();
             return config.isEmpty() ? null : config;
         }
         return null;
@@ -121,7 +126,7 @@ public class SdcSingleControllerConfiguration implements IConfiguration {
 
     private Integer getIntConfig(String key) {
         if (jsonRootNode != null && jsonRootNode.get(key) != null) {
-            return jsonRootNode.get(key).asInt();
+            return jsonRootNode.get(key).getAsInt();
         } else {
             return 0;
         }
@@ -129,8 +134,8 @@ public class SdcSingleControllerConfiguration implements IConfiguration {
 
     private String getEncryptedStringConfig(String key) throws GeneralSecurityException, DecoderException {
         if (jsonRootNode != null && jsonRootNode.get(key) != null) {
-            return jsonRootNode.get(key).asText().isEmpty() ? null
-                    : CryptoUtils.decrypt(jsonRootNode.get(key).asText());
+            return jsonRootNode.get(key).getAsString().isEmpty() ? null
+                    : CryptoUtils.decrypt(jsonRootNode.get(key).getAsString());
         }
         return null;
     }
@@ -143,7 +148,7 @@ public class SdcSingleControllerConfiguration implements IConfiguration {
     @Override
     public String getConsumerGroup() {
         if (jsonRootNode != null && jsonRootNode.get(CONSUMER_GROUP_ATTRIBUTE_NAME) != null) {
-            String config = jsonRootNode.get(CONSUMER_GROUP_ATTRIBUTE_NAME).asText();
+            String config = jsonRootNode.get(CONSUMER_GROUP_ATTRIBUTE_NAME).getAsString();
             return "NULL".equals(config) || config.isEmpty() ? null : config;
         }
         return null;
@@ -198,8 +203,9 @@ public class SdcSingleControllerConfiguration implements IConfiguration {
 
     @Override
     public boolean activateServerTLSAuth() {
-        if (jsonRootNode != null && jsonRootNode.get(ACTIVATE_SERVER_TLS_AUTH) != null) {
-            return jsonRootNode.get(ACTIVATE_SERVER_TLS_AUTH).asBoolean(false);
+        if (jsonRootNode != null && jsonRootNode.get(ACTIVATE_SERVER_TLS_AUTH) != null
+                && jsonRootNode.get(ACTIVATE_SERVER_TLS_AUTH).isJsonPrimitive()) {
+            return jsonRootNode.get(ACTIVATE_SERVER_TLS_AUTH).getAsBoolean();
         } else {
             return false;
         }
@@ -231,7 +237,7 @@ public class SdcSingleControllerConfiguration implements IConfiguration {
             throw new SdcParametersException("Json is null for controller " + this.getSdcControllerName());
         }
         if (this.getConsumerGroup() == null && (jsonRootNode.get(CONSUMER_GROUP_ATTRIBUTE_NAME) == null
-                || !"NULL".equals(jsonRootNode.get(CONSUMER_GROUP_ATTRIBUTE_NAME).asText()))) {
+                || !"NULL".equals(jsonRootNode.get(CONSUMER_GROUP_ATTRIBUTE_NAME).getAsString()))) {
             throw new SdcParametersException(CONSUMER_GROUP_ATTRIBUTE_NAME + errorMessageKeyNotFound);
         }
         if (this.getConsumerID() == null || this.getConsumerID().isEmpty()) {
@@ -277,7 +283,7 @@ public class SdcSingleControllerConfiguration implements IConfiguration {
     public List<String> getMsgBusAddress() {
         List<String> addressesList = new ArrayList<>();
         if (jsonRootNode != null && jsonRootNode.get(MESSAGE_BUS_ADDRESSES) != null) {
-            jsonRootNode.get(MESSAGE_BUS_ADDRESSES).forEach(k -> addressesList.add(k.asText()));
+            jsonRootNode.get(MESSAGE_BUS_ADDRESSES).getAsJsonArray().forEach(k -> addressesList.add(k.getAsString()));
             return addressesList;
         } else {
             return addressesList;