BpGen refactor Code Quality Issue-ID: DCAEGEN2-2502
[dcaegen2/platform.git] / mod / bpgenerator / onap / src / main / java / org / onap / blueprintgenerator / service / common / ImportsService.java
1 /*
2  *
3  *  * ============LICENSE_START=======================================================
4  *  *  org.onap.dcae
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
11  *  *
12  *  *       http://www.apache.org/licenses/LICENSE-2.0
13  *  *
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=========================================================
20  *
21  *
22  */
23
24 package org.onap.blueprintgenerator.service.common;
25
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import org.onap.blueprintgenerator.model.common.Imports;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.beans.factory.annotation.Qualifier;
30 import org.springframework.beans.factory.annotation.Value;
31 import org.springframework.stereotype.Service;
32
33 import java.io.File;
34 import java.io.IOException;
35 import java.util.ArrayList;
36 import java.util.List;
37
38 /**
39  * @author : Ravi Mantena
40  * @date 10/16/2020 Application: DCAE/ONAP - Blueprint Generator Common Module: Used by ONAP
41  * Blueprint Application Service: For Imports
42  */
43 @Service
44 public class ImportsService {
45
46     @Value("${imports.onap.types}")
47     private String importsOnapTypes;
48
49     @Value("${imports.onap.K8s.plugintypes}")
50     private String importsOnapK8sPlugintypes;
51
52     @Value("${imports.onap.K8s.dcaepolicyplugin}")
53     private String importsOnapK8sDcaepolicyplugin;
54
55     @Value("${imports.dmaap.dmaapplugin}")
56     private String importsDmaapDmaapplugin;
57
58     @Value("${import.Postgres}")
59     private String importPostgres;
60
61     @Value("${import.Clamp}")
62     private String importClamp;
63
64     @Qualifier("yamlObjectMapper")
65     @Autowired
66     protected ObjectMapper yamlObjectMapper;
67
68     /**
69      * Creates Imports for Blueprint based on Blueprint Type
70      *
71      * @param bpType Blueprint Type
72      * @return
73      */
74     public List<String> createImports(String bpType) {
75         List<String> imports = new ArrayList<>();
76         if (bpType.equals("o")) {
77             imports.add(importsOnapTypes);
78             imports.add(importsOnapK8sPlugintypes);
79             imports.add(importsOnapK8sDcaepolicyplugin);
80             imports.add(importPostgres);
81             imports.add(importClamp);
82         } else {
83             imports.add(importsOnapTypes);
84             imports.add(importsOnapK8sPlugintypes);
85             imports.add(importsDmaapDmaapplugin);
86             imports.add(importPostgres);
87             imports.add(importClamp);
88         }
89         return imports;
90     }
91
92     /**
93      * Creates Imports for Blueprint from the file path provided
94      *
95      * @param path Path of Import File
96      * @return
97      */
98     public List<String> createImportsFromFile(String path) throws IOException {
99         File importPath = new File(path);
100         Imports imports = yamlObjectMapper.readValue(importPath, Imports.class);
101         imports.getImports().removeIf(String::isBlank);
102         return imports.getImports();
103     }
104 }