7b55e17957193e4665a5fd35c1040e91858f8132
[dcaegen2/platform.git] / mod / bpgenerator / src / main / java / org / onap / blueprintgenerator / models / blueprint / Imports.java
1 /**============LICENSE_START======================================================= 
2  org.onap.dcae 
3  ================================================================================ 
4  Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. 
5  ================================================================================ 
6  Licensed under the Apache License, Version 2.0 (the "License"); 
7  you may not use this file except in compliance with the License. 
8  You may obtain a copy of the License at 
9  
10       http://www.apache.org/licenses/LICENSE-2.0 
11  
12  Unless required by applicable law or agreed to in writing, software 
13  distributed under the License is distributed on an "AS IS" BASIS, 
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
15  See the License for the specific language governing permissions and 
16  limitations under the License. 
17  ============LICENSE_END========================================================= 
18  
19 */
20
21 package org.onap.blueprintgenerator.models.blueprint;
22
23 import com.fasterxml.jackson.annotation.JsonInclude;
24 import com.fasterxml.jackson.annotation.JsonInclude.Include;
25 import com.fasterxml.jackson.databind.ObjectMapper;
26 import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
27 import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
28 import java.io.File;
29 import java.io.IOException;
30 import java.util.ArrayList;
31 import lombok.Getter;
32 import lombok.Setter;
33
34 @Getter @Setter
35 @JsonInclude(value=Include.NON_NULL)
36 public class Imports {
37         /** The imports. */
38         private ArrayList<String> imports;
39
40         public static ArrayList<String> createOnapImports() {
41                 ArrayList<String> imps = new ArrayList<>();
42                 imps.add("https://www.getcloudify.org/spec/cloudify/4.5.5/types.yaml");
43                 imps.add("plugin:k8splugin?version=3.4.2");
44                 imps.add("plugin:dcaepolicyplugin?version=2.4.0");
45                 return imps;
46         }
47
48         public static ArrayList<String> createDmaapImports(){
49                 ArrayList<String> imps = new ArrayList<>();
50                 imps.add("https://www.getcloudify.org/spec/cloudify/4.5.5/types.yaml");
51                 imps.add("plugin:k8splugin?version=3.4.2");
52                 imps.add("plugin:dmaap?version=1.5.0");
53                 return imps;
54         }
55
56         public static ArrayList<String> createImportsFromFile(String path) {
57                 ObjectMapper importMapper = new ObjectMapper(new YAMLFactory().configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true));
58                 File importPath = new File(path);
59                 try {
60                         Imports imports = importMapper.readValue(importPath, Imports.class);
61                         imports.getImports().removeIf(String::isBlank);
62                         return imports.getImports();
63                 } catch (IOException e) {
64                         throw new RuntimeException(e);
65                 }
66         }
67 }