0cd2b722d8fb6d03b32000e4cb7e1039ac222eb2
[dcaegen2/platform.git] / mod / bpgenerator / src / main / java / org / onap / blueprintgenerator / models / componentspec / ComponentSpec.java
1 /*============LICENSE_START=======================================================
2  org.onap.dcae
3  ================================================================================
4  Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
5  Copyright (c) 2020 Nokia. All rights reserved.
6  ================================================================================
7  Licensed under the Apache License, Version 2.0 (the "License");
8  you may not use this file except in compliance with the License.
9  You may obtain a copy of the License at
10
11       http://www.apache.org/licenses/LICENSE-2.0
12
13  Unless required by applicable law or agreed to in writing, software
14  distributed under the License is distributed on an "AS IS" BASIS,
15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  See the License for the specific language governing permissions and
17  limitations under the License.
18  ============LICENSE_END=========================================================
19
20  */
21
22 package org.onap.blueprintgenerator.models.componentspec;
23
24 import java.io.File;
25 import java.io.IOException;
26
27
28 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
29 import com.fasterxml.jackson.annotation.JsonInclude;
30 import com.fasterxml.jackson.annotation.JsonInclude.Include;
31 import com.fasterxml.jackson.annotation.JsonProperty;
32 import com.fasterxml.jackson.databind.ObjectMapper;
33
34 import lombok.Getter;
35 import lombok.Setter;
36 import lombok.NoArgsConstructor;
37 import org.onap.blueprintgenerator.models.componentspec.policy_info.PolicyInfo;
38
39 // TODO: Auto-generated Javadoc
40
41 /**
42  * The Class ComponentSpec.
43  */
44 @JsonIgnoreProperties(ignoreUnknown = true)
45
46 /* (non-Javadoc)
47  * @see java.lang.Object#toString()
48  */
49 @Getter
50 @Setter
51
52 /* (non-Javadoc)
53  * @see java.lang.Object#toString()
54  */
55
56 /**
57  * Instantiates a new component spec.
58  */
59 @NoArgsConstructor
60
61 /**
62  * Instantiates a new component spec.
63  *
64  * @param self the self
65  * @param services the services
66  * @param streams the streams
67  * @param parameters the parameters
68  * @param auxilary the auxilary
69  * @param artifacts the artifacts
70  */
71
72 @JsonInclude(value = Include.NON_NULL)
73 //main object that the component spec file is written in
74 public class ComponentSpec {
75
76     /**
77      * The self.
78      */
79     private Self self;
80
81     /**
82      * The services.
83      */
84     private Services services;
85
86     /**
87      * The streams.
88      */
89     private Streams streams;
90
91     /**
92      * The parameters.
93      */
94     private Parameters[] parameters;
95
96     /**
97      * The auxilary.
98      */
99     private Auxilary auxilary;
100
101     @JsonProperty("policy_info")
102     private PolicyInfo policyInfo;
103
104     /**
105      * The artifacts.
106      */
107     private Artifacts[] artifacts;
108
109     /**
110      * Creates the component spec from file.
111      *
112      * @param path the path
113      */
114     public void createComponentSpecFromFile(String path) {
115         ObjectMapper componentMapper = new ObjectMapper();
116         File specPathFile = new File(path);
117         ComponentSpec cs = new ComponentSpec();
118
119         try {
120             cs = componentMapper.readValue(specPathFile, ComponentSpec.class);
121         } catch (IOException e) {
122             throw new RuntimeException(e);
123         }
124
125         //set all the pieces of the component spec
126         this.setSelf(cs.getSelf());
127         this.setArtifacts(cs.getArtifacts());
128         this.setAuxilary(cs.getAuxilary());
129         this.setParameters(cs.getParameters());
130         this.setServices(cs.getServices());
131         this.setStreams(cs.getStreams());
132         this.setPolicyInfo(cs.getPolicyInfo());
133     }
134
135
136     /**
137      * Creates the component spec from string.
138      *
139      * @param specString the spec string
140      */
141     public void createComponentSpecFromString(String specString) {
142         ObjectMapper componentMapper = new ObjectMapper();
143         ComponentSpec cs = new ComponentSpec();
144         try {
145             cs = componentMapper.readValue(specString, ComponentSpec.class);
146         } catch (IOException e) {
147             throw new RuntimeException(e);
148         }
149
150         //set all the pieces of the component spec
151         this.setSelf(cs.getSelf());
152         this.setArtifacts(cs.getArtifacts());
153         this.setAuxilary(cs.getAuxilary());
154         this.setParameters(cs.getParameters());
155         this.setServices(cs.getServices());
156         this.setStreams(cs.getStreams());
157     }
158
159     public String getImageUri() {
160         return artifacts[0].getUri();
161     }
162
163     public String getSelfName() {
164         return this.self.getName();
165     }
166 }