1 /**============LICENSE_START=======================================================
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
10 http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.blueprintgenerator.models.componentspec;
24 import java.io.IOException;
27 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
28 import com.fasterxml.jackson.annotation.JsonInclude;
29 import com.fasterxml.jackson.annotation.JsonInclude.Include;
30 import com.fasterxml.jackson.annotation.JsonProperty;
31 import com.fasterxml.jackson.databind.ObjectMapper;
33 import lombok.Getter; import lombok.Setter;
34 import lombok.NoArgsConstructor;
35 import org.onap.blueprintgenerator.models.componentspec.policy_info.PolicyInfo;
37 // TODO: Auto-generated Javadoc
39 * The Class ComponentSpec.
41 @JsonIgnoreProperties(ignoreUnknown = true)
44 * @see java.lang.Object#toString()
49 * @see java.lang.Object#toString()
54 * Instantiates a new component spec.
59 * Instantiates a new component spec.
61 * @param self the self
62 * @param services the services
63 * @param streams the streams
64 * @param parameters the parameters
65 * @param auxilary the auxilary
66 * @param artifacts the artifacts
69 @JsonInclude(value=Include.NON_NULL)
70 //main object that the component spec file is written in
71 public class ComponentSpec {
77 private Services services;
80 private Streams streams;
82 /** The parameters. */
83 private Parameters[] parameters;
86 private Auxilary auxilary;
88 @JsonProperty("policy_info")
89 private PolicyInfo policyInfo;
92 private Artifacts[] artifacts;
95 * Creates the component spec from file.
97 * @param path the path
99 public void createComponentSpecFromFile(String path) {
100 ObjectMapper componentMapper = new ObjectMapper();
101 File specPathFile = new File(path);
102 ComponentSpec cs = new ComponentSpec();
105 cs = componentMapper.readValue(specPathFile, ComponentSpec.class);
106 } catch (IOException e) {
107 throw new RuntimeException(e);
112 //set all the pieces of the component spec
113 this.setSelf(cs.getSelf());
114 this.setArtifacts(cs.getArtifacts());
115 this.setAuxilary(cs.getAuxilary());
116 this.setParameters(cs.getParameters());
117 this.setServices(cs.getServices());
118 this.setStreams(cs.getStreams());
119 this.setPolicyInfo(cs.getPolicyInfo());
124 * Creates the component spec from string.
126 * @param specString the spec string
128 public void createComponentSpecFromString(String specString) {
129 ObjectMapper componentMapper = new ObjectMapper();
130 ComponentSpec cs = new ComponentSpec();
132 cs = componentMapper.readValue(specString, ComponentSpec.class);
133 } catch (IOException e) {
134 throw new RuntimeException(e);
137 //set all the pieces of the component spec
138 this.setSelf(cs.getSelf());
139 this.setArtifacts(cs.getArtifacts());
140 this.setAuxilary(cs.getAuxilary());
141 this.setParameters(cs.getParameters());
142 this.setServices(cs.getServices());
143 this.setStreams(cs.getStreams());