From 0dc7c10e3deed4e79163caed997cc8f40d9b073c Mon Sep 17 00:00:00 2001 From: Remigiusz Janeczek Date: Mon, 21 Sep 2020 11:52:05 +0200 Subject: Sonar fixes in bpgenerator models/blueprints package Issue-ID: DCAEGEN2-2449 Signed-off-by: Remigiusz Janeczek Change-Id: Ia696077e0e524515eac395ad81f1a59addb6d6b2 --- .../models/blueprint/Appconfig.java | 15 ++- .../models/blueprint/Blueprint.java | 122 ++++++--------------- .../models/blueprint/Imports.java | 15 +-- .../models/blueprint/Interfaces.java | 4 +- .../models/blueprint/Properties.java | 17 ++- .../models/blueprint/ResourceConfig.java | 19 ++-- .../blueprintgenerator/models/blueprint/Start.java | 8 +- .../models/blueprint/StartInputs.java | 13 +-- .../models/blueprint/dmaap/DmaapInfo.java | 8 +- .../models/blueprint/dmaap/DmaapObj.java | 16 +-- 10 files changed, 80 insertions(+), 157 deletions(-) (limited to 'mod/bpgenerator/src') diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Appconfig.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Appconfig.java index b39a8ec..75864be 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Appconfig.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Appconfig.java @@ -52,8 +52,7 @@ public class Appconfig { public TreeMap> createAppconfig(TreeMap> inps, ComponentSpec cs, String override, boolean isDmaap) { - TreeMap> retInputs = new TreeMap>(); - retInputs = inps; + TreeMap> retInputs = inps; //set service calls CallsObj[] call = new CallsObj[0]; @@ -83,7 +82,7 @@ public class Appconfig { } //set the stream publishes - TreeMap streamSubscribes = new TreeMap(); + TreeMap streamSubscribes = new TreeMap<>(); if(cs.getStreams().getSubscribes().length != 0) { for(Subscribes s: cs.getStreams().getSubscribes()) { @@ -110,7 +109,7 @@ public class Appconfig { this.setStreams_subscribes(streamSubscribes); //set the parameters into the appconfig - TreeMap parameters = new TreeMap(); + TreeMap parameters = new TreeMap<>(); for(Parameters p: cs.getParameters()) { String pName = p.getName(); if(p.isSourced_at_deployment()) { @@ -119,17 +118,17 @@ public class Appconfig { parameters.put(pName, paramInput); if(!p.getValue().equals("")) { - LinkedHashMap inputs = new LinkedHashMap(); + LinkedHashMap inputs = new LinkedHashMap<>(); inputs.put("type", "string"); inputs.put("default", p.getValue()); retInputs.put(pName, inputs); } else { - LinkedHashMap inputs = new LinkedHashMap(); + LinkedHashMap inputs = new LinkedHashMap<>(); inputs.put("type", "string"); retInputs.put(pName, inputs); } } else { - if(p.getType() == "string") { + if("string".equals(p.getType())) { String val =(String) p.getValue(); val = '"' + val + '"'; parameters.put(pName, val); @@ -143,7 +142,7 @@ public class Appconfig { GetInput ov = new GetInput(); ov.setBpInputName("service_component_name_override"); parameters.put("service_component_name_override", ov); - LinkedHashMap over = new LinkedHashMap(); + LinkedHashMap over = new LinkedHashMap<>(); over.put("type", "string"); over.put("default", override); retInputs.put("service_component_name_override", over); diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Blueprint.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Blueprint.java index c043a9e..f2ef7aa 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Blueprint.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Blueprint.java @@ -20,35 +20,27 @@ package org.onap.blueprintgenerator.models.blueprint; -import java.io.*; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.TreeMap; import java.util.regex.Pattern; - +import lombok.Getter; +import lombok.Setter; import org.onap.blueprintgenerator.core.Fixes; import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; -import org.onap.blueprintgenerator.models.componentspec.Parameters; -import org.onap.blueprintgenerator.models.componentspec.Publishes; -import org.onap.blueprintgenerator.models.componentspec.Subscribes; import org.onap.blueprintgenerator.models.dmaapbp.DmaapBlueprint; import org.onap.blueprintgenerator.models.onapbp.OnapBlueprint; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.core.JsonProcessingException; -//import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import org.yaml.snakeyaml.Yaml; - - @Getter @Setter @JsonInclude(JsonInclude.Include.NON_NULL) @@ -100,93 +92,43 @@ public class Blueprint { public void blueprintToYaml(String outputPath, String bluePrintName, ComponentSpec cs) { File outputFile; - - if(bluePrintName.equals("")) { - String name = cs.getSelf().getName(); - if(name.contains(".")) { - name = name.replaceAll(Pattern.quote("."), "_"); - } - if(name.contains(" ")) { - name = name.replaceAll(" ", ""); - } - String file = name + ".yaml"; - - - outputFile = new File(outputPath, file); - outputFile.getParentFile().mkdirs(); - try { - outputFile.createNewFile(); - } catch (IOException e) { - - throw new RuntimeException(e); - } - } else { - if(bluePrintName.contains(" ") || bluePrintName.contains(".")) { - bluePrintName = bluePrintName.replaceAll(Pattern.quote("."), "_"); - bluePrintName = bluePrintName.replaceAll(" ", ""); - } - String file = bluePrintName + ".yaml"; - outputFile = new File(outputPath, file); - outputFile.getParentFile().mkdirs(); - try { - outputFile.createNewFile(); - } catch (IOException e) { - throw new RuntimeException(e); - } + String name = bluePrintName.equals("") ? cs.getSelf().getName() : bluePrintName; + if(name.contains(".")) { + name = name.replaceAll(Pattern.quote("."), "_"); + } + if(name.contains(" ")) { + name = name.replaceAll(" ", ""); + } + String file = name + ".yaml"; + outputFile = new File(outputPath, file); + outputFile.getParentFile().mkdirs(); + try { + outputFile.createNewFile(); + } catch (IOException e) { + throw new RuntimeException(e); } String version = "#blueprint_version: " + cs.getSelf().getVersion() + '\n'; String description = "#description: " + cs.getSelf().getDescription() + '\n'; - BufferedWriter writer = null; - try { - writer = new BufferedWriter(new FileWriter(outputFile, false)); + try(BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile, false))) { + writer.write(description); + writer.write(version); } catch (IOException e1) { throw new RuntimeException(e1); } - if(writer != null) { - try { - writer.write(description); - } catch (IOException e) { - throw new RuntimeException(e); - } - try { - writer.write(version); - } catch (IOException e) { - throw new RuntimeException(e); - } - try { - writer.close(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - //read the translated blueprint into the file ObjectMapper blueprintMapper = new ObjectMapper(new YAMLFactory().configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true)); - PrintWriter out = null; - try { - out = new PrintWriter(new BufferedWriter(new FileWriter(outputFile, true))); + try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(outputFile, true)))) { + blueprintMapper.writeValue(out, this); } catch (IOException e) { throw new RuntimeException(e); } try { - if(out != null) { - blueprintMapper.writeValue(out, this); - out.close(); - } - } catch (IOException e) { - - throw new RuntimeException(e); - } - - - Fixes fix = new Fixes(); - try { - fix.fixSingleQuotes(outputFile); + Fixes.fixSingleQuotes(outputFile); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Imports.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Imports.java index b17b045..139790a 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Imports.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Imports.java @@ -21,21 +21,16 @@ package org.onap.blueprintgenerator.models.blueprint; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; - - import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; -import lombok.AllArgsConstructor; -import lombok.Getter; import lombok.Setter; -import lombok.NoArgsConstructor; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import lombok.Getter; +import lombok.Setter; diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Interfaces.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Interfaces.java index a3404f6..435059e 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Interfaces.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Interfaces.java @@ -31,11 +31,9 @@ import lombok.Getter; import lombok.Setter; public class Interfaces { private Start start; public TreeMap> createInterface(TreeMap> inps, ComponentSpec cs){ - TreeMap> retInputs = new TreeMap>(); - retInputs = inps; //create the start object Start start = new Start(); - retInputs = start.createOnapStart(retInputs, cs); + TreeMap> retInputs = start.createOnapStart(inps, cs); this.setStart(start); return retInputs; } diff --git 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 index d32d6f4..6edbe5c 100644 --- 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 @@ -47,6 +47,8 @@ import org.onap.blueprintgenerator.models.dmaapbp.DmaapStreams; @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; @@ -58,8 +60,6 @@ public class Properties { 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; @@ -155,8 +155,7 @@ public class Properties { 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(); @@ -171,7 +170,7 @@ public class Properties { 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); @@ -219,7 +218,7 @@ public class Properties { 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")) { @@ -239,7 +238,7 @@ public class Properties { } //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")) { @@ -258,10 +257,10 @@ public class Properties { } } - if (pubStreams.size() != 0) { + if (!pubStreams.isEmpty()) { this.setStreams_publishes(pubStreams); } - if (subStreams.size() != 0) { + if (!subStreams.isEmpty()) { this.setStreams_subscribes(subStreams); } diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/ResourceConfig.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/ResourceConfig.java index 13aa0d0..6595a67 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/ResourceConfig.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/ResourceConfig.java @@ -71,13 +71,12 @@ public class ResourceConfig { * @return the tree map */ public TreeMap> createResourceConfig(TreeMap> inps, String name){ - TreeMap> retInputs = inps; - LinkedHashMap mi = new LinkedHashMap(); + LinkedHashMap mi = new LinkedHashMap<>(); mi.put("type", "string"); mi.put("default", "128Mi"); - LinkedHashMap m = new LinkedHashMap(); + LinkedHashMap m = new LinkedHashMap<>(); m.put("type", "string"); m.put("default", "250m"); @@ -87,7 +86,7 @@ public class ResourceConfig { } //set the limits - TreeMap lim = new TreeMap(); + TreeMap lim = new TreeMap<>(); GetInput cpu = new GetInput(); cpu.setBpInputName(name + "cpu_limit"); @@ -97,13 +96,13 @@ public class ResourceConfig { memL.setBpInputName(name + "memory_limit"); lim.put("memory", memL); - retInputs.put(name + "cpu_limit", m); - retInputs.put(name + "memory_limit", mi); + inps.put(name + "cpu_limit", m); + inps.put(name + "memory_limit", mi); this.setLimits(lim); //set the requests - TreeMap req = new TreeMap(); + TreeMap req = new TreeMap<>(); GetInput cpuR = new GetInput(); cpuR.setBpInputName(name + "cpu_request"); @@ -113,12 +112,12 @@ public class ResourceConfig { memR.setBpInputName(name + "memory_request"); req.put("memory", memR); - retInputs.put(name + "cpu_request", m); - retInputs.put(name + "memory_request", mi); + inps.put(name + "cpu_request", m); + inps.put(name + "memory_request", mi); this.setRequests(req); - return retInputs; + return inps; } } diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Start.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Start.java index d9c885d..0b03777 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Start.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Start.java @@ -36,14 +36,12 @@ public class Start { private LinkedHashMap envs; public TreeMap> createOnapStart(TreeMap> inps, ComponentSpec cs) { - TreeMap> retInputs = inps; - retInputs = inps; - + //create the start inputs StartInputs inputs = new StartInputs(); - inputs.createOnapStartInputs(retInputs, cs); + inputs.createOnapStartInputs(inps, cs); this.setInputs(inputs); - return retInputs; + return inps; } } diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/StartInputs.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/StartInputs.java index 1055fbd..a0cfe20 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/StartInputs.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/StartInputs.java @@ -41,10 +41,9 @@ public class StartInputs { private Object envs; public TreeMap> createOnapStartInputs(TreeMap> inps, ComponentSpec cs){ - TreeMap> retInputs = inps; int count = 0; - ArrayList portList = new ArrayList(); + ArrayList portList = new ArrayList<>(); Auxilary aux = cs.getAuxilary(); if (aux.getPorts() != null) { @@ -56,10 +55,10 @@ public class StartInputs { , ports[0], count); portList.add(internal); - LinkedHashMap portType = new LinkedHashMap(); + LinkedHashMap portType = new LinkedHashMap<>(); portType.put("type", "string"); portType.put("default", ports[1]); - retInputs.put("external_port_" + count, portType); + inps.put("external_port_" + count, portType); count++; } @@ -98,7 +97,7 @@ public class StartInputs { // } //set the envs - LinkedHashMap eMap = new LinkedHashMap(); + LinkedHashMap eMap = new LinkedHashMap<>(); if(cs.getAuxilary().getDatabases() != null){ //set db env variables LinkedHashMap envVars = PgaasNodeBuilder.getEnvVariables(cs.getAuxilary().getDatabases()); @@ -111,9 +110,9 @@ public class StartInputs { this.setEnvs(env); eMap.put("default", "{}"); } - retInputs.put("envs", eMap); + inps.put("envs", eMap); - return retInputs; + return inps; } } diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/dmaap/DmaapInfo.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/dmaap/DmaapInfo.java index 464fc4a..0cec284 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/dmaap/DmaapInfo.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/dmaap/DmaapInfo.java @@ -46,9 +46,7 @@ public class DmaapInfo { public TreeMap> createOnapDmaapMRInfo( TreeMap> inps, String config, char type) { - TreeMap> retInputs = new TreeMap>(); - retInputs = inps; - LinkedHashMap stringType = new LinkedHashMap(); + LinkedHashMap stringType = new LinkedHashMap<>(); stringType.put("type", "string"); config = config.replaceAll("-", "_"); @@ -62,9 +60,9 @@ public class DmaapInfo { topic.setBpInputName(config); this.setTopic_url(topic); - retInputs.put(config, stringType); + inps.put(config, stringType); - return retInputs; + return inps; } public TreeMap> createOnapDmaapDRInfo( diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/dmaap/DmaapObj.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/dmaap/DmaapObj.java index 6af69e5..30f59e2 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/dmaap/DmaapObj.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/dmaap/DmaapObj.java @@ -40,10 +40,8 @@ public class DmaapObj { public TreeMap> createOnapDmaapMRObj(TreeMap> inps, String config, char type, String n, String num, boolean isDmaap) { - TreeMap> retInputs = new TreeMap>(); - LinkedHashMap stringType = new LinkedHashMap(); + LinkedHashMap stringType = new LinkedHashMap<>(); stringType.put("type", "string"); - retInputs = inps; //set the dmaapinfo DmaapInfo info = new DmaapInfo(); @@ -58,20 +56,18 @@ public class DmaapObj { GetInput u = new GetInput(); u.setBpInputName(config + "_" + num +"_aaf_username"); this.setUser(u); - retInputs.put(config + "_" + num +"_aaf_username", stringType); + inps.put(config + "_" + num +"_aaf_username", stringType); //set password GetInput p = new GetInput(); p.setBpInputName(config + "_" + num +"_aaf_password"); this.setPass(p); - retInputs.put(config + "_" + num +"_aaf_password", stringType); + inps.put(config + "_" + num +"_aaf_password", stringType); } - return retInputs; + return inps; } public TreeMap> createOnapDmaapDRObj(TreeMap> inps, String config, char type, String n, String num, boolean isDmaap) { - TreeMap> retInputs = new TreeMap>(); - retInputs = inps; - + //set the dmaapinfo DmaapInfo info = new DmaapInfo(); if(!isDmaap){ @@ -82,6 +78,6 @@ public class DmaapObj { String infoType = "<<" + n + ">>"; this.setDmaap_info(infoType); } - return retInputs; + return inps; } } -- cgit 1.2.3-korg