-public abstract class BlueprintService {
-
- @Autowired
- protected FixesService fixesService;
-
- @Qualifier("objectMapper")
- @Autowired
- protected ObjectMapper objectMapper;
-
- @Qualifier("yamlObjectMapper")
- @Autowired
- protected ObjectMapper yamlObjectMapper;
-
- public void blueprintToYaml(ComponentSpec cs, Blueprint blueprint, Input input) {
- String bluePrintName = input.getBluePrintName();
- String outputPath = input.getOutputPath();
- 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(" ", "");
+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;
+
+ @Qualifier("objectMapper")
+ @Autowired
+ protected ObjectMapper objectMapper;
+
+ @Qualifier("yamlObjectMapper")
+ @Autowired
+ protected ObjectMapper yamlObjectMapper;
+
+ /**
+ * Convertes blueprint to Yaml for given ComponentSpec, Blueprint and input
+ *
+ * @param cs ComponentSpec
+ * @param blueprint Blueprint
+ * @param input Input
+ * @return
+ */
+ public void blueprintToYaml(ComponentSpec cs, Blueprint blueprint, Input input) {
+ String bluePrintName = input.getBluePrintName();
+ String outputPath = input.getOutputPath();
+ String comment = "# " + input.getComment() + '\n';
+
+ try {
+ String name =
+ StringUtils.isEmpty(bluePrintName) ? cs.getSelf().getName() : bluePrintName;
+ if (name.contains(".")) {
+ name = name.replaceAll(Pattern.quote("."), "_");
+ }
+ if (name.contains(" ")) {
+ name = name.replace(" ", "");
+ }
+
+ File outputFile = createFile(outputPath, name);
+ String appVersion = readAppVersion();
+
+ String version = "#blueprint_version: " + cs.getSelf().getVersion() + '\n';
+ String description = "#description: " + cs.getSelf().getDescription() + '\n';
+ String date = "#blueprint_created_date: " + new Date() + '\n';
+
+ BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile, false));
+ writer.write(description);
+ writer.write(version);
+ writer.write(date);
+ writer.write(appVersion);
+
+ if (isBpTypeMatches(input)) {
+ writer.write(comment);
+ }
+
+ writer.close();
+
+ PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(outputFile, true)));
+ yamlObjectMapper.writeValue(out, blueprint);
+ out.close();
+
+ if (isBpTypeMatches(input)) {
+ fixesService.fixDcaeSingleQuotes(outputFile);
+ } else {
+ fixesService.fixOnapSingleQuotes(outputFile);
+ }
+
+ 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",
+ ex);
+ }