summaryrefslogtreecommitdiffstats
path: root/mod/bpgenerator/common
diff options
context:
space:
mode:
authorJoanna Jeremicz <joanna.jeremicz@nokia.com>2021-02-25 15:24:34 +0100
committerJoanna Jeremicz <joanna.jeremicz@nokia.com>2021-03-02 12:53:02 +0100
commit72c2d38329865afa6692454b4fb90ab6f8a70638 (patch)
tree3aaaddd2d37fee4e2fa41a8c790a6f3ae975ec35 /mod/bpgenerator/common
parent87f19cde0f6532f5138822fa6f188b763a123235 (diff)
Fix sonar issues
- Use Map instead of LinkedHashMap when possible - Rename some constants - Remove some commented lines - Add logger - Other minor improvements and refactor Issue-ID: DCAEGEN2-2636 Signed-off-by: Joanna Jeremicz <joanna.jeremicz@nokia.com> Change-Id: I7a03cee453b3d254c4ff0fdf51c60a0ae4a61c42
Diffstat (limited to 'mod/bpgenerator/common')
-rw-r--r--mod/bpgenerator/common/pom.xml4
-rw-r--r--mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/constants/Constants.java8
-rw-r--r--mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/model/base/Blueprint.java4
-rw-r--r--mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/model/common/GetInput.java3
-rw-r--r--mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/model/componentspec/base/Auxilary.java4
-rw-r--r--mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/BlueprintHelperService.java29
-rw-r--r--mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/BlueprintService.java75
-rw-r--r--mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/FixesService.java61
8 files changed, 103 insertions, 85 deletions
diff --git a/mod/bpgenerator/common/pom.xml b/mod/bpgenerator/common/pom.xml
index ae4f716..35d57ca 100644
--- a/mod/bpgenerator/common/pom.xml
+++ b/mod/bpgenerator/common/pom.xml
@@ -29,7 +29,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>blueprint-generator-common</artifactId>
- <version>1.7.3-SNAPSHOT</version>
+ <version>1.8.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Common</name>
@@ -39,7 +39,7 @@
<parent>
<groupId>org.onap.dcaegen2.platform.mod</groupId>
<artifactId>blueprint-generator</artifactId>
- <version>1.7.3-SNAPSHOT</version>
+ <version>1.8.0-SNAPSHOT</version>
</parent>
diff --git a/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/constants/Constants.java b/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/constants/Constants.java
index e08b28d..87b5fc8 100644
--- a/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/constants/Constants.java
+++ b/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/constants/Constants.java
@@ -34,8 +34,10 @@ package org.onap.blueprintgenerator.constants;
public class Constants {
- public static final String _TOPIC = "_topic";
- public static final String _FEED = "_feed";
+ private Constants(){}
+
+ public static final String A_TOPIC = "_topic";
+ public static final String A_FEED = "_feed";
public static final String DATAROUTER_VALUE = "data router";
public static final String DATA_ROUTER = "data_router";
public static final String MESSAGEROUTER_VALUE = "message router";
@@ -73,7 +75,7 @@ public class Constants {
public static final String ONAP_INPUT_CPU_LIMIT = "dcae-ves-collector_cpu_limit";
public static final String ONAP_NODETEMPLATES = "dcae-ves-collector";
public static final String ONAP_NODETEMPLATES_TYPE = "dcae.nodes.ContainerizedServiceComponent";
- public static final String ONAP_DEFAULT250m = "\"250m\"";
+ public static final String ONAP_DEFAULT250M = "\"250m\"";
public static final String ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT = "\"\"";
public static final String DMAAP_NODETEMPLATES_TYPE =
"dcae.nodes.ContainerizedServiceComponentUsingDmaap";
diff --git a/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/model/base/Blueprint.java b/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/model/base/Blueprint.java
index 03215cf..deb8b21 100644
--- a/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/model/base/Blueprint.java
+++ b/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/model/base/Blueprint.java
@@ -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.
@@ -27,7 +28,6 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -47,5 +47,5 @@ public class Blueprint {
private List<String> imports;
- private Map<String, LinkedHashMap<String, Object>> inputs;
+ private Map<String, Map<String, Object>> inputs;
}
diff --git a/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/model/common/GetInput.java b/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/model/common/GetInput.java
index 57dab04..3133d2c 100644
--- a/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/model/common/GetInput.java
+++ b/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/model/common/GetInput.java
@@ -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.
@@ -42,8 +43,6 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
public class GetInput {
- // private Object get_input;
-
@JsonProperty("get_input")
private Object bpInputName;
}
diff --git a/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/model/componentspec/base/Auxilary.java b/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/model/componentspec/base/Auxilary.java
index 4bfc633..c9d06f3 100644
--- a/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/model/componentspec/base/Auxilary.java
+++ b/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/model/componentspec/base/Auxilary.java
@@ -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.
@@ -61,9 +62,6 @@ public class Auxilary {
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
private Map<String, String> databases;
- /* @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
- private Affinity affinity;*/
-
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
private Object hpa_config;
}
diff --git a/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/BlueprintHelperService.java b/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/BlueprintHelperService.java
index a84afb6..5009372 100644
--- a/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/BlueprintHelperService.java
+++ b/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/BlueprintHelperService.java
@@ -28,6 +28,7 @@ package org.onap.blueprintgenerator.service.base;
import org.onap.blueprintgenerator.constants.Constants;
import org.springframework.stereotype.Service;
+import java.util.Map;
import java.util.LinkedHashMap;
/**
@@ -46,7 +47,7 @@ public class BlueprintHelperService {
* @param defaultValue Default value of Type
* @return
*/
- public LinkedHashMap<String, Object> createInputValue(
+ public Map<String, Object> createInputValue(
String type, String description, Object defaultValue) {
LinkedHashMap<String, Object> inputMap = new LinkedHashMap<>();
inputMap.put("type", type);
@@ -62,7 +63,7 @@ public class BlueprintHelperService {
* @param description Description
* @return
*/
- public LinkedHashMap<String, Object> createInputValue(String type, String description) {
+ public Map<String, Object> createInputValue(String type, String description) {
LinkedHashMap<String, Object> inputMap = new LinkedHashMap<>();
inputMap.put("type", type);
inputMap.put("description", description);
@@ -76,7 +77,7 @@ public class BlueprintHelperService {
* @param defaultValue Default value of Type
* @return
*/
- public LinkedHashMap<String, Object> createInputValue(String type, Object defaultValue) {
+ public Map<String, Object> createInputValue(String type, Object defaultValue) {
LinkedHashMap<String, Object> inputMap = new LinkedHashMap<>();
inputMap.put("type", type);
inputMap.put("default", defaultValue);
@@ -90,7 +91,7 @@ public class BlueprintHelperService {
* @param defaultValue Default value of Type
* @return
*/
- public LinkedHashMap<String, Object> createIntegerInput(String description,
+ public Map<String, Object> createIntegerInput(String description,
Object defaultValue) {
return createInputValue(Constants.INTEGER_TYPE, description, defaultValue);
}
@@ -101,7 +102,7 @@ public class BlueprintHelperService {
* @param description Description
* @return
*/
- public LinkedHashMap<String, Object> createIntegerInput(String description) {
+ public Map<String, Object> createIntegerInput(String description) {
return createInputValue(Constants.INTEGER_TYPE, description);
}
@@ -111,7 +112,7 @@ public class BlueprintHelperService {
* @param defaultValue Default value of Type
* @return
*/
- public LinkedHashMap<String, Object> createIntegerInput(Object defaultValue) {
+ public Map<String, Object> createIntegerInput(Object defaultValue) {
return createInputValue(Constants.INTEGER_TYPE, defaultValue);
}
@@ -122,7 +123,7 @@ public class BlueprintHelperService {
* @param defaultValue Default value of Type
* @return
*/
- public LinkedHashMap<String, Object> createBooleanInput(String description,
+ public Map<String, Object> createBooleanInput(String description,
Object defaultValue) {
return createInputValue(Constants.BOOLEAN_TYPE, description, defaultValue);
}
@@ -133,7 +134,7 @@ public class BlueprintHelperService {
* @param description Description
* @return
*/
- public LinkedHashMap<String, Object> createBooleanInput(String description) {
+ public Map<String, Object> createBooleanInput(String description) {
return createInputValue(Constants.BOOLEAN_TYPE, description);
}
@@ -143,7 +144,7 @@ public class BlueprintHelperService {
* @param defaultValue Default value of Type
* @return
*/
- public LinkedHashMap<String, Object> createBooleanInput(Object defaultValue) {
+ public Map<String, Object> createBooleanInput(Object defaultValue) {
return createInputValue(Constants.BOOLEAN_TYPE, defaultValue);
}
@@ -154,22 +155,18 @@ public class BlueprintHelperService {
* @param defaultValue Default value of Type
* @return
*/
- public LinkedHashMap<String, Object> createStringInput(String description,
+ public Map<String, Object> createStringInput(String description,
Object defaultValue) {
return createInputValue(Constants.STRING_TYPE, description, defaultValue);
}
- /* public LinkedHashMap<String, Object> createStringInput(String description){
- return createInputValue(Constants.STRING_TYPE, description);
- }*/
-
/**
* creates String Input value for given Default value
*
* @param defaultValue Default value of Type
* @return
*/
- public LinkedHashMap<String, Object> createStringInput(Object defaultValue) {
+ public Map<String, Object> createStringInput(Object defaultValue) {
return createInputValue(Constants.STRING_TYPE, defaultValue);
}
@@ -182,7 +179,7 @@ public class BlueprintHelperService {
* @param defaultValue Default value of Type
* @return
*/
- public LinkedHashMap<String, Object> createInputByType(String inputType, Object defaultValue) {
+ public Map<String, Object> createInputByType(String inputType, Object defaultValue) {
switch (inputType) {
case "boolean":
return createBooleanInput(defaultValue);
diff --git a/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/BlueprintService.java b/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/BlueprintService.java
index c32e5b1..e98f057 100644
--- a/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/BlueprintService.java
+++ b/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/BlueprintService.java
@@ -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.
@@ -23,8 +24,9 @@
package org.onap.blueprintgenerator.service.base;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.FileReader;
-import java.nio.file.Paths;
import org.onap.blueprintgenerator.model.base.Blueprint;
import org.onap.blueprintgenerator.model.common.Input;
import org.onap.blueprintgenerator.model.componentspec.base.ComponentSpec;
@@ -56,6 +58,10 @@ import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
@Service
public class BlueprintService {
+ private static final String TYPE_KEY = "type";
+ private static final String DEFAULT_KEY = "default";
+ private static final Logger logger = LoggerFactory.getLogger(BlueprintService.class);
+
@Autowired
protected FixesService fixesService;
@@ -81,32 +87,17 @@ public class BlueprintService {
String comment = "# " + input.getComment() + '\n';
try {
- File outputFile;
String name =
StringUtils.isEmpty(bluePrintName) ? 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);
+ name = name.replace(" ", "");
}
- String appVersion = "";
- try {
- MavenXpp3Reader reader = new MavenXpp3Reader();
- Model model = reader.read(new FileReader("pom.xml"));
- appVersion = "#bpgen_application_version: " + model.getVersion() + '\n';
- } catch (Exception e) {
- e.printStackTrace();
- }
+ File outputFile = createFile(outputPath, name);
+ String appVersion = readAppVersion();
String version = "#blueprint_version: " + cs.getSelf().getVersion() + '\n';
String description = "#description: " + cs.getSelf().getDescription() + '\n';
@@ -134,9 +125,7 @@ public class BlueprintService {
fixesService.fixOnapSingleQuotes(outputFile);
}
- // new Yaml().load(new FileInputStream(outputFile));
-
- System.out.println("Blueprint is created with valid YAML Format");
+ logger.debug("Blueprint is created with valid YAML Format");
} catch (Exception ex) {
throw new RuntimeException(
"Unable to generate YAML file from Blueprint or the generated YAML is not valid",
@@ -155,12 +144,12 @@ public class BlueprintService {
inputs.forEach(
(key, value) -> {
- if (value.get("type") != null) {
- if (value.get("type").equals("string")
- && value.get("default") != null
+ if (value.get(TYPE_KEY) != null) {
+ if (value.get(TYPE_KEY).equals("string")
+ && value.get(DEFAULT_KEY) != null
&& !key.contains("policies")) {
- value.replace("default", "'" + value.get("default").toString() + "'");
- } else if (value.get("type").equals("map") || value.get("type")
+ value.replace(DEFAULT_KEY, "'" + value.get(DEFAULT_KEY).toString() + "'");
+ } else if (value.get(TYPE_KEY).equals("map") || value.get(TYPE_KEY)
.equals("list")) {
// Commented the Code as we need to read the object as is for Map and List. If the
// List object is to be converted to string uncomment the below code.
@@ -168,7 +157,7 @@ public class BlueprintService {
String temp = inputs.get(s).get("default").toString();
inputs.get(s).replace("default", temp);
}*/
- inputs.get(key).remove("type");
+ inputs.get(key).remove(TYPE_KEY);
}
}
});
@@ -215,4 +204,34 @@ public class BlueprintService {
|| input.getBpType().equals("m")
|| input.getBpType().equals("k");
}
+
+ private File createFile(String outputPath, String name) {
+ File outputFile;
+ String file = name + ".yaml";
+ outputFile = new File(outputPath, file);
+ outputFile.getParentFile().mkdirs();
+ try {
+ boolean isCreated = outputFile.createNewFile();
+ if (isCreated) {
+ logger.debug("The file " + file + " was successfully created.");
+ } else {
+ logger.debug("The file " + file + " already existed.");
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return outputFile;
+ }
+
+ private String readAppVersion() {
+ String appVersion = "";
+ try {
+ MavenXpp3Reader reader = new MavenXpp3Reader();
+ Model model = reader.read(new FileReader("pom.xml"));
+ appVersion = "#bpgen_application_version: " + model.getVersion() + '\n';
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return appVersion;
+ }
}
diff --git a/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/FixesService.java b/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/FixesService.java
index 4c6debc..961528b 100644
--- a/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/FixesService.java
+++ b/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/FixesService.java
@@ -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.
@@ -55,15 +56,15 @@ public class FixesService {
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
for (String line = br.readLine(); line != null; line = br.readLine()) {
- if (line.contains("'")) {
- line = processLine(line);
+ String newLine = line;
+ if (newLine.contains("'")) {
+ newLine = processLine(newLine);
}
- if (line.contains("get_input") || line.contains("get_secret") || line
+ if (newLine.contains("get_input") || newLine.contains("get_secret") || newLine
.contains("envs")) {
- line = line.replaceAll("'", "");
+ newLine = newLine.replace("'", "");
}
-
- lines.add(line);
+ lines.add(newLine);
}
fr.close();
@@ -90,8 +91,8 @@ public class FixesService {
* @return
*/
public String fixStringQuotes(String string) {
- String sLines[] = string.split("\n");
- String ret = "";
+ String[] sLines = string.split("\n");
+ StringBuilder ret = new StringBuilder();
for (String line : sLines) {
if (line.contains("get_input")
|| line.contains("get_secret")
@@ -101,15 +102,16 @@ public class FixesService {
|| line.contains("dmaap")
|| line.contains(".\"'"))
&& line.contains("'"))) {
- line = line.replaceAll("'", "");
+ line = line.replace("'", "");
}
if (line.contains("'")) {
line = processLine(line);
}
- ret = ret + "\n" + line;
+ ret.append("\n");
+ ret.append(line);
}
- return ret;
+ return ret.toString();
}
/**
@@ -124,13 +126,14 @@ public class FixesService {
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
for (String line = br.readLine(); line != null; line = br.readLine()) {
- if (line.contains("'")) {
- line = line.replace("'", "");
+ String newLine = line;
+ if (newLine.contains("'")) {
+ newLine = newLine.replace("'", "");
}
- if (line.contains("\"\"") && (line.contains("m") || line.contains("M"))) {
- line = line.replaceAll("\"\"", "\"");
+ if (newLine.contains("\"\"") && (newLine.contains("m") || newLine.contains("M"))) {
+ newLine = newLine.replace("\"\"", "\"");
}
- lines.add(line);
+ lines.add(newLine);
}
fr.close();
br.close();
@@ -185,18 +188,18 @@ public class FixesService {
}
private String processLine(String line) {
- return line.replaceAll("'\\{", "{")
- .replaceAll("}'", "}")
- .replaceAll("'\\[", "[")
- .replaceAll("]'", "]")
- .replaceAll("'''''", "'")
- .replaceAll("'''", "'")
- .replaceAll("'''", "")
- .replaceAll("''\\{", "'{")
- .replaceAll("}''", "}'")
- .replaceAll("''\\[", "'[")
- .replaceAll("]''", "]'")
- .replaceAll("\"''", "'")
- .replaceAll("''\"", "'");
+ return line.replace("'\\{", "{")
+ .replace("}'", "}")
+ .replace("'\\[", "[")
+ .replace("]'", "]")
+ .replace("'''''", "'")
+ .replace("'''", "'")
+ .replace("'''", "")
+ .replace("''\\{", "'{")
+ .replace("}''", "}'")
+ .replace("''\\[", "'[")
+ .replace("]''", "]'")
+ .replace("\"''", "'")
+ .replace("''\"", "'");
}
}