cb9c03cb9cf39e91c27fce6e489f9763883e29d4
[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
41  * Application: DCAE/ONAP - Blueprint Generator
42  * Common Module: Used by ONAP Blueprint Application
43  * Service: For Imports
44  */
45
46 @Service
47 public class ImportsService {
48
49     @Value("${imports.onap.types}")
50     private String importsOnapTypes;
51
52     @Value("${imports.onap.K8s.plugintypes}")
53     private String importsOnapK8sPlugintypes;
54
55     @Value("${imports.onap.K8s.dcaepolicyplugin}")
56     private String importsOnapK8sDcaepolicyplugin;
57
58     @Value("${imports.dmaap.dmaapplugin}")
59     private String importsDmaapDmaapplugin;
60
61     @Value("${import.Postgres}")
62     private String importPostgres;
63
64     @Value("${import.Clamp}")
65     private String importClamp;
66
67
68     @Qualifier("yamlObjectMapper")
69     @Autowired
70     protected ObjectMapper yamlObjectMapper;
71
72     public List<String> createImports(String bpType) {
73         List<String> imports = new ArrayList<>();
74         if (bpType.equals("o")) {
75             imports.add(importsOnapTypes);
76             imports.add(importsOnapK8sPlugintypes);
77             imports.add(importsOnapK8sDcaepolicyplugin);
78             imports.add(importPostgres);
79             imports.add(importClamp);
80         }
81         else {
82             imports.add(importsOnapTypes);
83             imports.add(importsOnapK8sPlugintypes);
84             imports.add(importsDmaapDmaapplugin);
85             imports.add(importPostgres);
86             imports.add(importClamp);
87         }
88         return imports;
89     }
90
91     public List<String> createImportsFromFile(String path) throws IOException {
92         File importPath = new File(path);
93         Imports imports = yamlObjectMapper.readValue(importPath, Imports.class);
94         imports.getImports().removeIf(String::isBlank);
95         return imports.getImports();
96     }
97
98 }