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;
29 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
30 import com.fasterxml.jackson.annotation.JsonInclude;
31 import com.fasterxml.jackson.annotation.JsonInclude.Include;
32 import com.fasterxml.jackson.core.JsonParseException;
33 import com.fasterxml.jackson.databind.JsonMappingException;
34 import com.fasterxml.jackson.databind.ObjectMapper;
36 import lombok.AllArgsConstructor;
37 import lombok.Builder;
39 import lombok.EqualsAndHashCode;
40 import lombok.Getter; import lombok.Setter;
41 import lombok.NoArgsConstructor;
43 // TODO: Auto-generated Javadoc
45 * The Class ComponentSpec.
47 @JsonIgnoreProperties(ignoreUnknown = true)
50 * @see java.lang.Object#toString()
55 * @see java.lang.Object#toString()
60 * Instantiates a new component spec.
65 * Instantiates a new component spec.
67 * @param self the self
68 * @param services the services
69 * @param streams the streams
70 * @param parameters the parameters
71 * @param auxilary the auxilary
72 * @param artifacts the artifacts
75 @JsonInclude(value=Include.NON_NULL)
76 //main object that the component spec file is written in
77 public class ComponentSpec {
83 private Services services;
86 private Streams streams;
88 /** The parameters. */
89 private Parameters[] parameters;
92 private Auxilary auxilary;
95 private Artifacts[] artifacts;
98 * Creates the component spec from file.
100 * @param path the path
102 public void createComponentSpecFromFile(String path) {
103 ObjectMapper componentMapper = new ObjectMapper();
104 File specPathFile = new File(path);
105 ComponentSpec cs = new ComponentSpec();
108 cs = componentMapper.readValue(specPathFile, ComponentSpec.class);
109 } catch (IOException e) {
110 throw new RuntimeException(e);
115 //set all the pieces of the component spec
116 this.setSelf(cs.getSelf());
117 this.setArtifacts(cs.getArtifacts());
118 this.setAuxilary(cs.getAuxilary());
119 this.setParameters(cs.getParameters());
120 this.setServices(cs.getServices());
121 this.setStreams(cs.getStreams());
126 * Creates the component spec from string.
128 * @param specString the spec string
130 public void createComponentSpecFromString(String specString) {
131 ObjectMapper componentMapper = new ObjectMapper();
132 ComponentSpec cs = new ComponentSpec();
134 cs = componentMapper.readValue(specString, ComponentSpec.class);
135 } catch (IOException e) {
136 throw new RuntimeException(e);
139 //set all the pieces of the component spec
140 this.setSelf(cs.getSelf());
141 this.setArtifacts(cs.getArtifacts());
142 this.setAuxilary(cs.getAuxilary());
143 this.setParameters(cs.getParameters());
144 this.setServices(cs.getServices());
145 this.setStreams(cs.getStreams());