1 /*============LICENSE_START=======================================================
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
11 http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.blueprintgenerator.models.componentspec;
25 import java.io.IOException;
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;
36 import lombok.NoArgsConstructor;
37 import org.onap.blueprintgenerator.models.componentspec.policy_info.PolicyInfo;
39 // TODO: Auto-generated Javadoc
42 * The Class ComponentSpec.
44 @JsonIgnoreProperties(ignoreUnknown = true)
47 * @see java.lang.Object#toString()
53 * @see java.lang.Object#toString()
57 * Instantiates a new component spec.
62 * Instantiates a new component spec.
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
72 @JsonInclude(value = Include.NON_NULL)
73 //main object that the component spec file is written in
74 public class ComponentSpec {
84 private Services services;
89 private Streams streams;
94 private Parameters[] parameters;
99 private Auxilary auxilary;
101 @JsonProperty("policy_info")
102 private PolicyInfo policyInfo;
107 private Artifacts[] artifacts;
110 * Creates the component spec from file.
112 * @param path the path
114 public void createComponentSpecFromFile(String path) {
115 ObjectMapper componentMapper = new ObjectMapper();
116 File specPathFile = new File(path);
117 ComponentSpec cs = new ComponentSpec();
120 cs = componentMapper.readValue(specPathFile, ComponentSpec.class);
121 } catch (IOException e) {
122 throw new RuntimeException(e);
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());
137 * Creates the component spec from string.
139 * @param specString the spec string
141 public void createComponentSpecFromString(String specString) {
142 ObjectMapper componentMapper = new ObjectMapper();
143 ComponentSpec cs = new ComponentSpec();
145 cs = componentMapper.readValue(specString, ComponentSpec.class);
146 } catch (IOException e) {
147 throw new RuntimeException(e);
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());
159 public String getImageUri() {
160 return artifacts[0].getUri();
163 public String getSelfName() {
164 return this.self.getName();