3 * * ============LICENSE_START=======================================================
5 * * ================================================================================
6 * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
7 * * ================================================================================
8 * * Licensed under the Apache License, Version 2.0 (the "License");
9 * * you may not use this file except in compliance with the License.
10 * * You may obtain a copy of the License at
12 * * http://www.apache.org/licenses/LICENSE-2.0
14 * * Unless required by applicable law or agreed to in writing, software
15 * * distributed under the License is distributed on an "AS IS" BASIS,
16 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * * See the License for the specific language governing permissions and
18 * * limitations under the License.
19 * * ============LICENSE_END=========================================================
24 package org.onap.blueprintgenerator.service.base;
26 import org.onap.blueprintgenerator.exception.FixesException;
27 import org.springframework.stereotype.Service;
30 import java.io.BufferedReader;
31 import java.io.BufferedWriter;
32 import java.io.FileWriter;
33 import java.io.PrintWriter;
34 import java.io.FileReader;
36 import java.util.ArrayList;
37 import java.util.List;
40 * @author : Ravi Mantena
42 * Application: DCAE/ONAP - Blueprint Generator
43 * Common Module: Used by both ONAp and DCAE Blueprint Applications
44 * Service: For Blueprint Quotes Fixes
48 public class FixesService {
50 public void fixDcaeSingleQuotes(File file) {
51 List<String> lines = new ArrayList<>();
53 FileReader fr = new FileReader(file);
54 BufferedReader br = new BufferedReader(fr);
55 for (String line = br.readLine(); line != null; line = br.readLine()){
56 if(line.contains("'")) {
57 line = line.replaceAll("'\\{", "{");
58 line = line.replaceAll("}'", "}");
59 line = line.replaceAll("'\\[", "[");
60 line = line.replaceAll("]'", "]");
61 line = line.replaceAll("'''''", "'");
62 line = line.replaceAll("'''", "'");
63 line = line.replaceAll("'''", "");
64 line = line.replaceAll("''\\{", "'{");
65 line = line.replaceAll("}''", "}'");
66 line = line.replaceAll("''\\[", "'[");
67 line = line.replaceAll("]''", "]'");
68 line = line.replaceAll("\"''", "'");
69 line = line.replaceAll("''\"", "'");
71 if(line.contains("get_input") || line.contains("get_secret") || line.contains("envs"))
72 line = line.replaceAll("'", "");
80 FileWriter fw = new FileWriter(file);
81 PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file, true)));
82 for(String s: lines) {
89 } catch (Exception e) {
90 throw new FixesException("Unable to Fix Single Quotes in Final DCAE Blueprint", e);
94 public String fixStringQuotes(String string) {
95 String sLines[] = string.split("\n");
97 for(String line: sLines) {
98 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("'")))
99 line = line.replaceAll("'", "");
101 if(line.contains("'")) {
102 line = line.replaceAll("'\\{", "{");
103 line = line.replaceAll("}'", "}");
104 line = line.replaceAll("'\\[", "[");
105 line = line.replaceAll("]'", "]");
106 line = line.replaceAll("'''''", "'");
107 line = line.replaceAll("'''", "'");
108 line = line.replaceAll("'''", "");
109 line = line.replaceAll("''\\{", "'{");
110 line = line.replaceAll("}''", "}'");
111 line = line.replaceAll("''\\[", "'[");
112 line = line.replaceAll("]''", "]'");
113 line = line.replaceAll("\"''", "'");
114 line = line.replaceAll("''\"", "'");
116 ret = ret + "\n" + line;
121 public void fixOnapSingleQuotes(File file) {
122 List<String> lines = new ArrayList<>();
124 FileReader fr = new FileReader(file);
125 BufferedReader br = new BufferedReader(fr);
126 for (String line = br.readLine(); line != null; line = br.readLine()){
127 if(line.contains("'")) {
128 line = line.replace("'", "");
130 if(line.contains("\"\"") && (line.contains("m") || line.contains("M"))) {
131 line = line.replaceAll("\"\"", "\"");
138 FileWriter fw = new FileWriter(file);
139 PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file, true)));
140 for(String s: lines) {
149 } catch (Exception e) {
150 throw new FixesException("Unable to Fix Single Quotes in final ONAP Blueprint", e);
154 private String ensureNoSingleQuotes(String line) {
155 if ((line.contains("concat") || line.contains("default: ") || line.contains("description") || line.contains("dmaap") || line.contains(".\"'")) && line.contains("'"))
156 return line.replace("'", "");
161 public String applyFixes(String bp) {
162 List<String> lines = new ArrayList<>();
163 String[] linesPre = bp.split("\n");
164 for (String line : linesPre) {
165 lines.add(ensureNoSingleQuotes(line));
167 return String.join("\n", lines);