Fix sonar issues
[dcaegen2/platform.git] / mod / bpgenerator / onap / src / main / java / org / onap / blueprintgenerator / service / common / PropertiesService.java
index be79b25..2758f8c 100644 (file)
@@ -4,6 +4,7 @@
  *  *  org.onap.dcae
  *  *  ================================================================================
  *  *  Copyright (c) 2020  AT&T Intellectual Property. All rights reserved.
+ *  *  Copyright (c) 2021  Nokia. All rights reserved.
  *  *  ================================================================================
  *  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  *  you may not use this file except in compliance with the License.
 
 package org.onap.blueprintgenerator.service.common;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
 import org.onap.blueprintgenerator.constants.Constants;
 import org.onap.blueprintgenerator.model.common.Appconfig;
 import org.onap.blueprintgenerator.model.common.GetInput;
+import org.onap.blueprintgenerator.model.common.Properties;
 import org.onap.blueprintgenerator.model.common.ResourceConfig;
 import org.onap.blueprintgenerator.model.componentspec.OnapAuxilary;
 import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;
@@ -35,20 +42,12 @@ import org.onap.blueprintgenerator.model.dmaap.Streams;
 import org.onap.blueprintgenerator.model.dmaap.TlsInfo;
 import org.onap.blueprintgenerator.service.base.BlueprintHelperService;
 import org.onap.blueprintgenerator.service.dmaap.StreamsService;
-import org.onap.blueprintgenerator.model.common.Properties;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.ArrayList;
-import java.util.List;
-
 /**
  * @author : Ravi Mantena
- * @date 10/16/2020 Application: ONAP - Blueprint Generator Common ONAP Service to create Properties
- * Node
+ * @date 10/16/2020 Application: ONAP - Blueprint Generator Common ONAP Service to create Properties Node
  */
 @Service("onapPropertiesService")
 public class PropertiesService {
@@ -71,13 +70,13 @@ public class PropertiesService {
     /**
      * Creates ONAP properties
      *
-     * @param inputs Inputs
+     * @param inputs            Inputs
      * @param onapComponentSpec OnapComponentSpec
-     * @param override Override
+     * @param override          Override
      * @return
      */
     public Map<String, Object> createOnapProperties(
-        Map<String, LinkedHashMap<String, Object>> inputs,
+        Map<String, Map<String, Object>> inputs,
         OnapComponentSpec onapComponentSpec,
         String override) {
         Map<String, Object> response = new HashMap<>();
@@ -104,7 +103,7 @@ public class PropertiesService {
         replica.setBpInputName("replicas");
         properties.setReplicas(replica);
 
-        LinkedHashMap<String, Object> replicas =
+        Map<String, Object> replicas =
             blueprintHelperService.createIntegerInput("number of instances", 1);
         inputs.put("replicas", replicas);
 
@@ -113,8 +112,8 @@ public class PropertiesService {
         properties.setDocker_config(onapAuxilary);
 
         Map<String, Object> appConfigResponse =
-            appConfigService.createAppconfig(inputs, onapComponentSpec, override, false);
-        inputs = (Map<String, LinkedHashMap<String, Object>>) appConfigResponse.get("inputs");
+            appConfigService.createAppconfig(inputs, onapComponentSpec, false);
+        inputs = (Map<String, Map<String, Object>>) appConfigResponse.get("inputs");
         properties.setApplication_config((Appconfig) appConfigResponse.get("appconfig"));
 
         GetInput always_pull_image = new GetInput();
@@ -122,7 +121,7 @@ public class PropertiesService {
 
         properties.setAlways_pull_image(always_pull_image);
 
-        LinkedHashMap<String, Object> inputAlwaysPullImage =
+        Map<String, Object> inputAlwaysPullImage =
             blueprintHelperService.createBooleanInput(
                 "Set to true if the image should always be pulled", true);
         inputs.put("always_pull_image", inputAlwaysPullImage);
@@ -131,6 +130,9 @@ public class PropertiesService {
         sType = sType.replace('.', '-');
         properties.setService_component_type(sType);
 
+        inputs.put(Constants.SERVICE_COMPONENT_NAME_OVERRIDE,
+            addServiceComponentNameOverride(override, properties));
+
         Map<String, Object> tls_info = onapComponentSpec.getAuxilary().getTls_info();
         if (tls_info != null) {
             addTlsInfo(onapComponentSpec, inputs, properties);
@@ -142,7 +144,7 @@ public class PropertiesService {
         Map<String, Object> resourceConfigResponse =
             resourceConfigService
                 .createResourceConfig(inputs, onapComponentSpec.getSelf().getName());
-        inputs = (Map<String, LinkedHashMap<String, Object>>) resourceConfigResponse.get("inputs");
+        inputs = (Map<String, Map<String, Object>>) resourceConfigResponse.get("inputs");
         properties
             .setResource_config((ResourceConfig) resourceConfigResponse.get("resourceConfig"));
 
@@ -154,13 +156,13 @@ public class PropertiesService {
     /**
      * Creates Dmaap properties
      *
-     * @param inputs Inputs
+     * @param inputs            Inputs
      * @param onapComponentSpec OnapComponentSpec
-     * @param override Override
+     * @param override          Override
      * @return
      */
     public Map<String, Object> createDmaapProperties(
-        Map<String, LinkedHashMap<String, Object>> inputs,
+        Map<String, Map<String, Object>> inputs,
         OnapComponentSpec onapComponentSpec,
         String override) {
         Map<String, Object> response = new HashMap<>();
@@ -171,7 +173,7 @@ public class PropertiesService {
         image.setBpInputName("tag_version");
         properties.setImage(image);
 
-        LinkedHashMap<String, Object> img = new LinkedHashMap<>();
+        Map<String, Object> img = new LinkedHashMap<>();
         inputs.put(
             "tag_version",
             blueprintHelperService.createStringInput(onapComponentSpec.getArtifacts()[0].getUri()));
@@ -180,7 +182,7 @@ public class PropertiesService {
         location.setBpInputName("location_id");
         properties.setLocation_id(location);
 
-        LinkedHashMap<String, Object> locMap = new LinkedHashMap();
+        Map<String, Object> locMap = new LinkedHashMap();
         inputs.put("location_id", blueprintHelperService.createStringInput(Constants.EMPTY_VALUE));
 
         properties.setLog_info(onapComponentSpec.getAuxilary().getLog_info());
@@ -189,6 +191,9 @@ public class PropertiesService {
         sType = sType.replace('.', '-');
         properties.setService_component_type(sType);
 
+        inputs.put(Constants.SERVICE_COMPONENT_NAME_OVERRIDE,
+            addServiceComponentNameOverride(override, properties));
+
         Map<String, Object> tls_info = onapComponentSpec.getAuxilary().getTls_info();
         if (tls_info != null) {
             addTlsInfo(onapComponentSpec, inputs, properties);
@@ -201,7 +206,7 @@ public class PropertiesService {
         replica.setBpInputName("replicas");
         properties.setReplicas(replica);
 
-        LinkedHashMap<String, Object> rep =
+        Map<String, Object> rep =
             blueprintHelperService.createIntegerInput("number of instances", 1);
         inputs.put("replicas", rep);
 
@@ -210,8 +215,8 @@ public class PropertiesService {
         properties.setDocker_config(onapAuxilary);
 
         Map<String, Object> appConfigResponse =
-            appConfigService.createAppconfig(inputs, onapComponentSpec, override, true);
-        inputs = (Map<String, LinkedHashMap<String, Object>>) appConfigResponse.get("inputs");
+            appConfigService.createAppconfig(inputs, onapComponentSpec, true);
+        inputs = (Map<String, Map<String, Object>>) appConfigResponse.get("inputs");
         properties.setApplication_config((Appconfig) appConfigResponse.get("appconfig"));
 
         List<Streams> pubStreams = new ArrayList();
@@ -219,7 +224,7 @@ public class PropertiesService {
             if (onapComponentSpec.getStreams().getPublishes() != null) {
                 for (Publishes publishes : onapComponentSpec.getStreams().getPublishes()) {
                     if (blueprintHelperService.isMessageRouterType(publishes.getType())) {
-                        String topic = publishes.getConfig_key() + Constants._TOPIC;
+                        String topic = publishes.getConfig_key() + Constants.A_TOPIC;
                         Map<String, Object> streamsMessageRouterResponse =
                             streamsService.createStreams(
                                 inputs,
@@ -229,11 +234,11 @@ public class PropertiesService {
                                 publishes.getRoute(),
                                 'p');
                         inputs =
-                            (Map<String, LinkedHashMap<String, Object>>)
+                            (Map<String, Map<String, Object>>)
                                 streamsMessageRouterResponse.get("inputs");
                         pubStreams.add((Streams) streamsMessageRouterResponse.get("streams"));
                     } else if (blueprintHelperService.isDataRouterType(publishes.getType())) {
-                        String feed = publishes.getConfig_key() + Constants._FEED;
+                        String feed = publishes.getConfig_key() + Constants.A_FEED;
                         Map<String, Object> streamsDataRouterResponse =
                             streamsService.createStreams(
                                 inputs,
@@ -243,7 +248,7 @@ public class PropertiesService {
                                 publishes.getRoute(),
                                 'p');
                         inputs =
-                            (Map<String, LinkedHashMap<String, Object>>)
+                            (Map<String, Map<String, Object>>)
                                 streamsDataRouterResponse.get("inputs");
                         pubStreams.add((Streams) streamsDataRouterResponse.get("streams"));
                     }
@@ -256,7 +261,7 @@ public class PropertiesService {
             if (onapComponentSpec.getStreams().getSubscribes() != null) {
                 for (Subscribes subscribes : onapComponentSpec.getStreams().getSubscribes()) {
                     if (blueprintHelperService.isMessageRouterType(subscribes.getType())) {
-                        String topic = subscribes.getConfig_key() + Constants._TOPIC;
+                        String topic = subscribes.getConfig_key() + Constants.A_TOPIC;
                         Map<String, Object> streamsMessageRouterResponse =
                             streamsService.createStreams(
                                 inputs,
@@ -266,11 +271,11 @@ public class PropertiesService {
                                 subscribes.getRoute(),
                                 's');
                         inputs =
-                            (Map<String, LinkedHashMap<String, Object>>)
+                            (Map<String, Map<String, Object>>)
                                 streamsMessageRouterResponse.get("inputs");
                         subStreams.add((Streams) streamsMessageRouterResponse.get("streams"));
                     } else if (blueprintHelperService.isDataRouterType(subscribes.getType())) {
-                        String feed = subscribes.getConfig_key() + Constants._FEED;
+                        String feed = subscribes.getConfig_key() + Constants.A_FEED;
                         Map<String, Object> streamsDataRouterResponse =
                             streamsService.createStreams(
                                 inputs,
@@ -280,7 +285,7 @@ public class PropertiesService {
                                 subscribes.getRoute(),
                                 's');
                         inputs =
-                            (Map<String, LinkedHashMap<String, Object>>)
+                            (Map<String, Map<String, Object>>)
                                 streamsDataRouterResponse.get("inputs");
                         subStreams.add((Streams) streamsDataRouterResponse.get("streams"));
                     }
@@ -299,7 +304,7 @@ public class PropertiesService {
         Map<String, Object> resourceConfigResponse =
             resourceConfigService
                 .createResourceConfig(inputs, onapComponentSpec.getSelf().getName());
-        inputs = (Map<String, LinkedHashMap<String, Object>>) resourceConfigResponse.get("inputs");
+        inputs = (Map<String, Map<String, Object>>) resourceConfigResponse.get("inputs");
         properties
             .setResource_config((ResourceConfig) resourceConfigResponse.get("resourceConfig"));
 
@@ -308,9 +313,16 @@ public class PropertiesService {
         return response;
     }
 
+    private Map<String, Object> addServiceComponentNameOverride(String override, Properties properties) {
+        GetInput overrideGetInput = new GetInput();
+        overrideGetInput.setBpInputName(Constants.SERVICE_COMPONENT_NAME_OVERRIDE);
+        properties.setService_component_name_override(overrideGetInput);
+        return blueprintHelperService.createStringInput(override != null ? override : "");
+    }
+
     private void addTlsInfo(
         OnapComponentSpec onapComponentSpec,
-        Map<String, LinkedHashMap<String, Object>> inputs,
+        Map<String, Map<String, Object>> inputs,
         Properties properties) {
         TlsInfo tlsInfo = new TlsInfo();
         tlsInfo.setCertDirectory(
@@ -319,14 +331,14 @@ public class PropertiesService {
         useTLSFlag.setBpInputName("use_tls");
         tlsInfo.setUseTls(useTLSFlag);
         properties.setTls_info(tlsInfo);
-        LinkedHashMap<String, Object> useTlsFlagInput =
+        Map<String, Object> useTlsFlagInput =
             blueprintHelperService.createBooleanInput(
                 "flag to indicate tls enable/disable",
                 onapComponentSpec.getAuxilary().getTls_info().get("use_tls"));
         inputs.put("use_tls", useTlsFlagInput);
     }
 
-    private Map<String, LinkedHashMap<String, Object>> addExternalTlsInfo(
+    private Map<String, Map<String, Object>> addExternalTlsInfo(
         OnapComponentSpec onapComponentSpec, Properties properties) {
         properties.setExternal_cert(
             externalTlsInfoFactoryService.createFromComponentSpec(onapComponentSpec));