updating docker repository to onap nexus
[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
26
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;
32
33 import lombok.Getter; import lombok.Setter;
34 import lombok.NoArgsConstructor;
35 import org.onap.blueprintgenerator.models.componentspec.policy_info.PolicyInfo;
36
37 // TODO: Auto-generated Javadoc
38 /**
39  * The Class ComponentSpec.
40  */
41 @JsonIgnoreProperties(ignoreUnknown = true)
42
43 /* (non-Javadoc)
44  * @see java.lang.Object#toString()
45  */
46 @Getter @Setter
47
48 /* (non-Javadoc)
49  * @see java.lang.Object#toString()
50  */
51
52
53 /**
54  * Instantiates a new component spec.
55  */
56 @NoArgsConstructor
57
58 /**
59  * Instantiates a new component spec.
60  *
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
67  */
68
69 @JsonInclude(value=Include.NON_NULL)
70 //main object that the component spec file is written in
71 public class ComponentSpec {
72         
73         /** The self. */
74         private Self self; 
75         
76         /** The services. */
77         private Services services;
78         
79         /** The streams. */
80         private Streams streams;
81         
82         /** The parameters. */
83         private Parameters[] parameters;
84         
85         /** The auxilary. */
86         private Auxilary auxilary;
87
88         @JsonProperty("policy_info")
89         private PolicyInfo policyInfo;
90         
91         /** The artifacts. */
92         private Artifacts[] artifacts;
93
94         /**
95          * Creates the component spec from file.
96          *
97          * @param path the path
98          */
99         public void createComponentSpecFromFile(String path) {
100                 ObjectMapper componentMapper = new ObjectMapper();
101                 File specPathFile = new File(path);
102                 ComponentSpec cs = new ComponentSpec();
103
104                 try {
105                         cs = componentMapper.readValue(specPathFile, ComponentSpec.class);
106                 } catch (IOException e) {
107                         throw new RuntimeException(e);
108                 }
109
110
111
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());
120         }
121
122
123         /**
124          * Creates the component spec from string.
125          *
126          * @param specString the spec string
127          */
128         public void createComponentSpecFromString(String specString) {
129                 ObjectMapper componentMapper = new ObjectMapper();
130                 ComponentSpec cs = new ComponentSpec();
131                 try {
132                         cs = componentMapper.readValue(specString, ComponentSpec.class);
133                 } catch (IOException e) {
134                         throw new RuntimeException(e);
135                 }
136
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());
144         }
145
146
147 }