bp-gen code clone from cli repo
[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  ================================================================================ 
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.componentspec;
22
23 import java.io.File;
24 import java.io.IOException;
25 import java.util.Map;
26
27
28
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;
35
36 import lombok.AllArgsConstructor;
37 import lombok.Builder;
38 import lombok.Data;
39 import lombok.EqualsAndHashCode;
40 import lombok.Getter; import lombok.Setter;
41 import lombok.NoArgsConstructor;
42
43 // TODO: Auto-generated Javadoc
44 /**
45  * The Class ComponentSpec.
46  */
47 @JsonIgnoreProperties(ignoreUnknown = true)
48
49 /* (non-Javadoc)
50  * @see java.lang.Object#toString()
51  */
52 @Getter @Setter
53
54 /* (non-Javadoc)
55  * @see java.lang.Object#toString()
56  */
57
58
59 /**
60  * Instantiates a new component spec.
61  */
62 @NoArgsConstructor
63
64 /**
65  * Instantiates a new component spec.
66  *
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
73  */
74
75 @JsonInclude(value=Include.NON_NULL)
76 //main object that the component spec file is written in
77 public class ComponentSpec {
78         
79         /** The self. */
80         private Self self; 
81         
82         /** The services. */
83         private Services services;
84         
85         /** The streams. */
86         private Streams streams;
87         
88         /** The parameters. */
89         private Parameters[] parameters;
90         
91         /** The auxilary. */
92         private Auxilary auxilary;
93         
94         /** The artifacts. */
95         private Artifacts[] artifacts;
96
97         /**
98          * Creates the component spec from file.
99          *
100          * @param path the path
101          */
102         public void createComponentSpecFromFile(String path) {
103                 ObjectMapper componentMapper = new ObjectMapper();
104                 File specPathFile = new File(path);
105                 ComponentSpec cs = new ComponentSpec();
106
107                 try {
108                         cs = componentMapper.readValue(specPathFile, ComponentSpec.class);
109                 } catch (IOException e) {
110                         throw new RuntimeException(e);
111                 }
112
113
114
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());
122         }
123
124
125         /**
126          * Creates the component spec from string.
127          *
128          * @param specString the spec string
129          */
130         public void createComponentSpecFromString(String specString) {
131                 ObjectMapper componentMapper = new ObjectMapper();
132                 ComponentSpec cs = new ComponentSpec();
133                 try {
134                         cs = componentMapper.readValue(specString, ComponentSpec.class);
135                 } catch (IOException e) {
136                         throw new RuntimeException(e);
137                 }
138
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());
146         }
147
148
149 }