Refactor babel-related code to not update parameter values
[aai/model-loader.git] / src / main / java / org / onap / aai / modelloader / notification / BabelArtifactConverter.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 European Software Marketing Ltd.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.aai.modelloader.notification;
22
23 import java.util.List;
24 import java.util.Objects;
25 import org.onap.aai.babel.service.data.BabelArtifact;
26 import org.onap.aai.modelloader.entity.Artifact;
27 import org.onap.aai.modelloader.entity.catalog.VnfCatalogArtifact;
28 import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException;
29 import org.onap.aai.modelloader.entity.model.ModelArtifact;
30 import org.onap.aai.modelloader.entity.model.ModelArtifactParser;
31 import org.springframework.stereotype.Component;
32
33 /**
34  * This class is responsible for converting TOSCA artifacts into instances of {@link ModelArtifact} ready for pushing
35  * the converted artifacts .
36  */
37 @Component
38 public class BabelArtifactConverter {
39
40     private final ModelArtifactParser modelArtifactParser;
41
42     public BabelArtifactConverter(ModelArtifactParser modelArtifactParser) {
43         this.modelArtifactParser = modelArtifactParser;
44     }
45
46     /**
47      * This method converts BabelArtifacts into instances of {@link ModelArtifact}.
48      *
49      * @param xmlArtifacts xml artifacts to be parsed
50      * @return List<org.openecomp.modelloader.entity.Artifact> list of converted model artifacts
51      * @throws BabelArtifactParsingException if an error occurs trying to parse the generated XML files that were
52      *         converted from tosca artifacts
53      */
54     public List<Artifact> convertToModel(BabelArtifact babelArtifact) throws BabelArtifactParsingException {
55         Objects.requireNonNull(babelArtifact);
56         List<Artifact> parsedArtifacts = modelArtifactParser.parse(babelArtifact.getPayload(), babelArtifact.getName());
57         
58         if (parsedArtifacts == null || parsedArtifacts.isEmpty()) {
59             throw new BabelArtifactParsingException("Could not parse generated XML: " + babelArtifact.getPayload());
60         }
61
62         return parsedArtifacts;
63     }
64
65     /**
66      * This method converts BabelArtifacts into instances of {@link VnfCatalogArtifact}.
67      *
68      * @param xmlArtifacts xml artifacts to be parsed
69      * @return List<org.openecomp.modelloader.entity.Artifact> list of converted catalog artifacts
70      */
71     public Artifact convertToCatalog(BabelArtifact babelArtifact) {
72         return new VnfCatalogArtifact(babelArtifact.getPayload());
73     }
74 }