summaryrefslogtreecommitdiffstats
path: root/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/FixesService.java
diff options
context:
space:
mode:
Diffstat (limited to 'mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/FixesService.java')
-rw-r--r--mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/FixesService.java284
1 files changed, 158 insertions, 126 deletions
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 d848cac..4c6debc 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
@@ -26,7 +26,6 @@ package org.onap.blueprintgenerator.service.base;
import org.onap.blueprintgenerator.exception.FixesException;
import org.springframework.stereotype.Service;
-
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
@@ -38,133 +37,166 @@ import java.util.List;
/**
* @author : Ravi Mantena
- * @date 10/16/2020
- * Application: DCAE/ONAP - Blueprint Generator
- * Common Module: Used by both ONAp and DCAE Blueprint Applications
- * Service: For Blueprint Quotes Fixes
+ * @date 10/16/2020 Application: DCAE/ONAP - Blueprint Generator Common Module: Used by both ONAp
+ * and DCAE Blueprint Applications Service: For Blueprint Quotes Fixes
*/
-
@Service
public class FixesService {
- public void fixDcaeSingleQuotes(File file) {
- List<String> lines = new ArrayList<>();
- try {
- 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.replaceAll("'\\{", "{");
- line = line.replaceAll("}'", "}");
- line = line.replaceAll("'\\[", "[");
- line = line.replaceAll("]'", "]");
- line = line.replaceAll("'''''", "'");
- line = line.replaceAll("'''", "'");
- line = line.replaceAll("'''", "");
- line = line.replaceAll("''\\{", "'{");
- line = line.replaceAll("}''", "}'");
- line = line.replaceAll("''\\[", "'[");
- line = line.replaceAll("]''", "]'");
- line = line.replaceAll("\"''", "'");
- line = line.replaceAll("''\"", "'");
- }
- if(line.contains("get_input") || line.contains("get_secret") || line.contains("envs"))
- line = line.replaceAll("'", "");
-
- lines.add(line);
- }
-
- fr.close();
- br.close();
-
- FileWriter fw = new FileWriter(file);
- PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file, true)));
- for(String s: lines) {
- out.println();
- out.write(s);
- out.flush();
- }
- out.close();
- fw.close();
- } catch (Exception e) {
- throw new FixesException("Unable to Fix Single Quotes in Final DCAE Blueprint", e);
- }
- }
-
- public String fixStringQuotes(String string) {
- String sLines[] = string.split("\n");
- String ret = "";
- for(String line: sLines) {
- if(line.contains("get_input") || line.contains("get_secret") || ((line.contains("concat") || line.contains("default: ") || line.contains("description") || line.contains("dmaap") || line.contains(".\"'")) && line.contains("'")))
- line = line.replaceAll("'", "");
-
- if(line.contains("'")) {
- line = line.replaceAll("'\\{", "{");
- line = line.replaceAll("}'", "}");
- line = line.replaceAll("'\\[", "[");
- line = line.replaceAll("]'", "]");
- line = line.replaceAll("'''''", "'");
- line = line.replaceAll("'''", "'");
- line = line.replaceAll("'''", "");
- line = line.replaceAll("''\\{", "'{");
- line = line.replaceAll("}''", "}'");
- line = line.replaceAll("''\\[", "'[");
- line = line.replaceAll("]''", "]'");
- line = line.replaceAll("\"''", "'");
- line = line.replaceAll("''\"", "'");
- }
- ret = ret + "\n" + line;
- }
- return ret;
- }
-
- public void fixOnapSingleQuotes(File file) {
- List<String> lines = new ArrayList<>();
- try {
- 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("'", "");
- }
- if(line.contains("\"\"") && (line.contains("m") || line.contains("M"))) {
- line = line.replaceAll("\"\"", "\"");
- }
- lines.add(line);
-
- }
- fr.close();
- br.close();
- FileWriter fw = new FileWriter(file);
- PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file, true)));
- for(String s: lines) {
- out.println();
- out.write(s);
- out.flush();
- }
-
- out.close();
- fw.close();
-
- } catch (Exception e) {
- throw new FixesException("Unable to Fix Single Quotes in final ONAP Blueprint", e);
- }
- }
-
- private String ensureNoSingleQuotes(String line) {
- if ((line.contains("concat") || line.contains("default: ") || line.contains("description") || line.contains("dmaap") || line.contains(".\"'")) && line.contains("'"))
- return line.replace("'", "");
- else
- return line;
- }
-
- public String applyFixes(String bp) {
- List<String> lines = new ArrayList<>();
- String[] linesPre = bp.split("\n");
- for (String line : linesPre) {
- lines.add(ensureNoSingleQuotes(line));
- }
- return String.join("\n", lines);
- }
-
+ /**
+ * Interface to fix Single Quotes in the generated Blueprint
+ *
+ * @param file File
+ * @return
+ */
+ public void fixDcaeSingleQuotes(File file) {
+ List<String> lines = new ArrayList<>();
+ try {
+ 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);
+ }
+ if (line.contains("get_input") || line.contains("get_secret") || line
+ .contains("envs")) {
+ line = line.replaceAll("'", "");
+ }
+
+ lines.add(line);
+ }
+
+ fr.close();
+ br.close();
+
+ FileWriter fw = new FileWriter(file);
+ PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file, true)));
+ for (String s : lines) {
+ out.println();
+ out.write(s);
+ out.flush();
+ }
+ out.close();
+ fw.close();
+ } catch (Exception e) {
+ throw new FixesException("Unable to Fix Single Quotes in Final DCAE Blueprint", e);
+ }
+ }
+
+ /**
+ * Interface to fix String Quotes in the generated Blueprint
+ *
+ * @param string String
+ * @return
+ */
+ public String fixStringQuotes(String string) {
+ String sLines[] = string.split("\n");
+ String ret = "";
+ for (String line : sLines) {
+ if (line.contains("get_input")
+ || line.contains("get_secret")
+ || ((line.contains("concat")
+ || line.contains("default: ")
+ || line.contains("description")
+ || line.contains("dmaap")
+ || line.contains(".\"'"))
+ && line.contains("'"))) {
+ line = line.replaceAll("'", "");
+ }
+
+ if (line.contains("'")) {
+ line = processLine(line);
+ }
+ ret = ret + "\n" + line;
+ }
+ return ret;
+ }
+
+ /**
+ * Interface to fix Single Quotes in the generated ONAP Blueprint
+ *
+ * @param file File
+ * @return
+ */
+ public void fixOnapSingleQuotes(File file) {
+ List<String> lines = new ArrayList<>();
+ try {
+ 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("'", "");
+ }
+ if (line.contains("\"\"") && (line.contains("m") || line.contains("M"))) {
+ line = line.replaceAll("\"\"", "\"");
+ }
+ lines.add(line);
+ }
+ fr.close();
+ br.close();
+ FileWriter fw = new FileWriter(file);
+ PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file, true)));
+ for (String s : lines) {
+ out.println();
+ out.write(s);
+ out.flush();
+ }
+
+ out.close();
+ fw.close();
+
+ } catch (Exception e) {
+ throw new FixesException("Unable to Fix Single Quotes in final ONAP Blueprint", e);
+ }
+ }
+
+ /**
+ * Interface to fix Single Quotes for given line
+ *
+ * @param line Line
+ * @return
+ */
+ private String ensureNoSingleQuotes(String line) {
+ if ((line.contains("concat")
+ || line.contains("default: ")
+ || line.contains("description")
+ || line.contains("dmaap")
+ || line.contains(".\"'"))
+ && line.contains("'")) {
+ return line.replace("'", "");
+ } else {
+ return line;
+ }
+ }
+
+ /**
+ * Interface to Applt fixes for Quotes
+ *
+ * @param bp Blueprint
+ * @return
+ */
+ public String applyFixes(String bp) {
+ List<String> lines = new ArrayList<>();
+ String[] linesPre = bp.split("\n");
+ for (String line : linesPre) {
+ lines.add(ensureNoSingleQuotes(line));
+ }
+ return String.join("\n", lines);
+ }
+
+ private String processLine(String line) {
+ return line.replaceAll("'\\{", "{")
+ .replaceAll("}'", "}")
+ .replaceAll("'\\[", "[")
+ .replaceAll("]'", "]")
+ .replaceAll("'''''", "'")
+ .replaceAll("'''", "'")
+ .replaceAll("'''", "")
+ .replaceAll("''\\{", "'{")
+ .replaceAll("}''", "}'")
+ .replaceAll("''\\[", "'[")
+ .replaceAll("]''", "]'")
+ .replaceAll("\"''", "'")
+ .replaceAll("''\"", "'");
+ }
}