2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.onap.aai.babel.csar;
25 import java.util.List;
26 import java.util.Objects;
27 import org.onap.aai.babel.csar.extractor.InvalidArchiveException;
28 import org.onap.aai.babel.csar.extractor.YamlExtractor;
29 import org.onap.aai.babel.logging.ApplicationMsgs;
30 import org.onap.aai.babel.service.data.BabelArtifact;
31 import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
32 import org.onap.aai.babel.xml.generator.ArtifactGenerator;
33 import org.onap.aai.babel.xml.generator.ModelGenerator;
34 import org.onap.aai.cl.api.Logger;
35 import org.onap.aai.cl.eelf.LoggerFactory;
37 import org.openecomp.sdc.generator.data.Artifact;
40 * This class is responsible for converting content in a csar archive into one or more xml artifacts.
42 public class CsarToXmlConverter {
43 private static Logger logger = LoggerFactory.getInstance().getLogger(CsarToXmlConverter.class);
46 * This method is responsible for extracting one or more yaml files from the given csarArtifact and then using them
47 * to generate xml artifacts.
49 * @param csarArchive the artifact that contains the csar archive to generate xml artifacts from
50 * @param name the name of the archive file
51 * @param version the version of the archive file
52 * @return List<org.openecomp.sdc.generator.data.Artifact> a list of generated xml artifacts
53 * @throws CsarConverterException if there is an error either extracting the yaml files or generating xml artifacts
55 public List<BabelArtifact> generateXmlFromCsar(byte[] csarArchive, String name, String version)
56 throws CsarConverterException {
57 validateArguments(csarArchive, name, version);
59 logger.info(ApplicationMsgs.DISTRIBUTION_EVENT,
60 "Starting to process csarArchive to convert contents to xml artifacts");
61 List<BabelArtifact> xmlArtifacts;
64 logger.debug("Calling YamlExtractor to extract ymlFiles");
65 List<Artifact> ymlFiles = YamlExtractor.extract(csarArchive, name, version);
67 logger.debug("Calling XmlArtifactGenerator to generateXmlArtifacts");
68 ArtifactGenerator modelGenerator = new ModelGenerator();
69 xmlArtifacts = modelGenerator.generateArtifacts(ymlFiles);
71 logger.debug(xmlArtifacts.size() + " xml artifacts have been generated");
72 } catch (InvalidArchiveException e) {
73 throw new CsarConverterException(
74 "An error occurred trying to extract the yml files from the csar file : " + e);
75 } catch (XmlArtifactGenerationException e) {
76 throw new CsarConverterException(
77 "An error occurred trying to generate xml files from a collection of yml files : " + e);
83 private void validateArguments(byte[] csarArchive, String name, String version) {
84 Objects.requireNonNull(csarArchive);
85 Objects.requireNonNull(name);
86 Objects.requireNonNull(version);