From: Remigiusz Janeczek Date: Fri, 25 Sep 2020 08:34:53 +0000 (+0000) Subject: Merge "Refactor, fix code formatting and add unittests" X-Git-Tag: 1.5.2~11 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=b50120936c0c848ef5c3ff1e46438f592aa83747;hp=-c;p=dcaegen2%2Fplatform.git Merge "Refactor, fix code formatting and add unittests" --- b50120936c0c848ef5c3ff1e46438f592aa83747 diff --combined mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Properties.java index 6edbe5c,5693f86..4140ea3 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Properties.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Properties.java @@@ -20,6 -20,10 +20,10 @@@ package org.onap.blueprintgenerator.models.blueprint; + import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.createBooleanInput; + import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.createIntegerInput; + import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.isMessageRouterType; + import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.isDataRouterType; import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.USE_EXTERNAL_TLS_FIELD; import com.fasterxml.jackson.annotation.JsonIgnore; @@@ -31,7 -35,6 +35,6 @@@ import java.util.Map import java.util.TreeMap; import lombok.Getter; import lombok.Setter; - import org.onap.blueprintgenerator.common.blueprint.BlueprintHelper; import org.onap.blueprintgenerator.models.blueprint.tls.ExternalCertificateParametersFactory; import org.onap.blueprintgenerator.models.blueprint.tls.ExternalTlsInfoFactory; import org.onap.blueprintgenerator.models.blueprint.tls.TlsInfo; @@@ -42,13 -45,12 +45,14 @@@ import org.onap.blueprintgenerator.mode import org.onap.blueprintgenerator.models.componentspec.Subscribes; import org.onap.blueprintgenerator.models.dmaapbp.DmaapStreams; + @Getter @Setter @JsonInclude(value = Include.NON_NULL) public class Properties { + ArrayList streams_publishes; + ArrayList streams_subscribes; private Appconfig application_config; private Auxilary docker_config; private Object image; @@@ -60,6 -62,8 +64,6 @@@ private String name; private GetInput topic_name; private GetInput feed_name; - ArrayList streams_publishes; - ArrayList streams_subscribes; private TlsInfo tls_info; private ExternalTlsInfo external_cert; private ResourceConfig resource_config; @@@ -102,7 -106,7 +106,7 @@@ GetInput replica = new GetInput(); replica.setBpInputName("replicas"); this.setReplicas(replica); - LinkedHashMap rep = BlueprintHelper.createInputValue("integer", "number of instances", 1); + LinkedHashMap rep = createIntegerInput("number of instances", 1); retInputs.put("replicas", rep); //set the dns name @@@ -126,7 -130,7 +130,7 @@@ // set always_pull_image this.always_pull_image = new GetInput(); this.always_pull_image.setBpInputName("always_pull_image"); - LinkedHashMap inputAlwaysPullImage = BlueprintHelper.createInputValue("boolean", + LinkedHashMap inputAlwaysPullImage = createBooleanInput( "Set to true if the image should always be pulled", true); retInputs.put("always_pull_image", inputAlwaysPullImage); @@@ -155,7 -159,8 +159,7 @@@ public TreeMap> createDmaapProperties( TreeMap> inps, ComponentSpec cs, String override) { - TreeMap> retInputs = new TreeMap>(); - retInputs = inps; + TreeMap> retInputs = inps; //set the image GetInput image = new GetInput(); @@@ -170,7 -175,7 +174,7 @@@ GetInput location = new GetInput(); location.setBpInputName("location_id"); this.setLocation_id(location); - LinkedHashMap locMap = new LinkedHashMap(); + LinkedHashMap locMap = new LinkedHashMap<>(); locMap.put("type", "string"); locMap.put("default", ""); retInputs.put("location_id", locMap); @@@ -196,7 -201,7 +200,7 @@@ GetInput replica = new GetInput(); replica.setBpInputName("replicas"); this.setReplicas(replica); - LinkedHashMap rep = BlueprintHelper.createInputValue("integer", "number of instances", 1); + LinkedHashMap rep = createIntegerInput( "number of instances", 1); retInputs.put("replicas", rep); // //set the dns name @@@ -218,49 -223,53 +222,53 @@@ this.setApplication_config(app); //set the stream publishes - ArrayList pubStreams = new ArrayList(); + ArrayList pubStreams = new ArrayList<>(); if (cs.getStreams().getPublishes() != null) { - for (Publishes p : cs.getStreams().getPublishes()) { - if (p.getType().equals("message_router") || p.getType().equals("message router")) { - String topic = p.getConfig_key() + "_topic"; + for (Publishes publishes : cs.getStreams().getPublishes()) { + if (isMessageRouterType(publishes.getType())) { + String topic = publishes.getConfig_key() + "_topic"; DmaapStreams mrStreams = new DmaapStreams(); retInputs = mrStreams - .createStreams(inps, cs, topic, p.getType(), p.getConfig_key(), p.getRoute(), 'p'); + .createStreams(inps, cs, topic, publishes.getType(), publishes.getConfig_key(), + publishes.getRoute(), 'p'); pubStreams.add(mrStreams); - } else if (p.getType().equals("data_router") || p.getType().equals("data router")) { - String feed = p.getConfig_key() + "_feed"; + } else if (isDataRouterType(publishes.getType())) { + String feed = publishes.getConfig_key() + "_feed"; DmaapStreams drStreams = new DmaapStreams(); retInputs = drStreams - .createStreams(inps, cs, feed, p.getType(), p.getConfig_key(), p.getRoute(), 'p'); + .createStreams(inps, cs, feed, publishes.getType(), publishes.getConfig_key(), + publishes.getRoute(), 'p'); pubStreams.add(drStreams); } } } //set the stream subscribes - ArrayList subStreams = new ArrayList(); + ArrayList subStreams = new ArrayList<>(); if (cs.getStreams().getSubscribes() != null) { - for (Subscribes s : cs.getStreams().getSubscribes()) { - if (s.getType().equals("message_router") || s.getType().equals("message router")) { - String topic = s.getConfig_key() + "_topic"; + for (Subscribes subscribes : cs.getStreams().getSubscribes()) { + if (isMessageRouterType(subscribes.getType())) { + String topic = subscribes.getConfig_key() + "_topic"; DmaapStreams mrStreams = new DmaapStreams(); retInputs = mrStreams - .createStreams(inps, cs, topic, s.getType(), s.getConfig_key(), s.getRoute(), 's'); + .createStreams(inps, cs, topic, subscribes.getType(), subscribes.getConfig_key(), + subscribes.getRoute(), 's'); subStreams.add(mrStreams); - } else if (s.getType().equals("data_router") || s.getType().equals("data router")) { - String feed = s.getConfig_key() + "_feed"; + } else if (isDataRouterType(subscribes.getType())) { + String feed = subscribes.getConfig_key() + "_feed"; DmaapStreams drStreams = new DmaapStreams(); retInputs = drStreams - .createStreams(inps, cs, feed, s.getType(), s.getConfig_key(), s.getRoute(), 's'); + .createStreams(inps, cs, feed, subscribes.getType(), subscribes.getConfig_key(), + subscribes.getRoute(), 's'); subStreams.add(drStreams); } } } - if (pubStreams.size() != 0) { + if (!pubStreams.isEmpty()) { this.setStreams_publishes(pubStreams); } - if (subStreams.size() != 0) { + if (!subStreams.isEmpty()) { this.setStreams_subscribes(subStreams); } @@@ -279,7 -288,7 +287,7 @@@ useTLSFlag.setBpInputName("use_tls"); tlsInfo.setUseTls(useTLSFlag); this.setTls_info(tlsInfo); - LinkedHashMap useTlsFlagInput = BlueprintHelper.createInputValue("boolean", + LinkedHashMap useTlsFlagInput = createBooleanInput( "flag to indicate tls enable/disable", cs.getAuxilary().getTls_info().get("use_tls")); retInputs.put("use_tls", useTlsFlagInput);