- 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()) {
+ String newLine = line;
+ if (newLine.contains("'")) {
+ newLine = processLine(newLine);
+ }
+ if (newLine.contains("get_input") || newLine.contains("get_secret") || newLine
+ .contains("envs")) {
+ newLine = newLine.replace("'", "");
+ }
+ lines.add(newLine);
+ }
+
+ 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");
+ StringBuilder ret = new StringBuilder();
+ 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.replace("'", "");
+ }
+
+ if (line.contains("'")) {
+ line = processLine(line);
+ }
+ ret.append("\n");
+ ret.append(line);
+ }
+ return ret.toString();
+ }
+
+ /**
+ * 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()) {
+ String newLine = line;
+ if (newLine.contains("'")) {
+ newLine = newLine.replace("'", "");
+ }
+ if (newLine.contains("\"\"") && (newLine.contains("m") || newLine.contains("M"))) {
+ newLine = newLine.replace("\"\"", "\"");
+ }
+ lines.add(newLine);
+ }
+ 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.replace("'\\{", "{")
+ .replace("}'", "}")
+ .replace("'\\[", "[")
+ .replace("]'", "]")
+ .replace("'''''", "'")
+ .replace("'''", "'")
+ .replace("'''", "")
+ .replace("''\\{", "'{")
+ .replace("}''", "}'")
+ .replace("''\\[", "'[")
+ .replace("]''", "]'")
+ .replace("\"''", "'")
+ .replace("''\"", "'");
+ }