X-Git-Url: https://gerrit.onap.org/r/gitweb?p=aai%2Fbabel.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fbabel%2Fxml%2Fgenerator%2FModelGenerator.java;h=65e0ada02fc496ca820c4bfc9dcd209e30540b3c;hp=c6def3d249cfb1b7a452cf7a56d95d661af6f5e1;hb=66b3afa06776e9944ad515206d281d67747c9770;hpb=161f5a7d9b900ae34a4886d7f7fb01ea496f71eb diff --git a/src/main/java/org/onap/aai/babel/xml/generator/ModelGenerator.java b/src/main/java/org/onap/aai/babel/xml/generator/ModelGenerator.java index c6def3d..65e0ada 100644 --- a/src/main/java/org/onap/aai/babel/xml/generator/ModelGenerator.java +++ b/src/main/java/org/onap/aai/babel/xml/generator/ModelGenerator.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017 European Software Marketing Ltd. + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 European Software Marketing Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,36 +17,33 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ package org.onap.aai.babel.xml.generator; +import java.util.Base64; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.regex.Pattern; import java.util.stream.Collectors; import org.onap.aai.babel.logging.ApplicationMsgs; +import org.onap.aai.babel.logging.LogHelper; import org.onap.aai.babel.service.data.BabelArtifact; +import org.onap.aai.babel.service.data.BabelArtifact.ArtifactType; +import org.onap.aai.babel.xml.generator.api.AaiArtifactGenerator; +import org.onap.aai.babel.xml.generator.data.AdditionalParams; +import org.onap.aai.babel.xml.generator.data.Artifact; +import org.onap.aai.babel.xml.generator.data.GenerationData; +import org.onap.aai.babel.xml.generator.data.GeneratorUtil; +import org.onap.aai.babel.xml.generator.data.GroupType; import org.onap.aai.cl.api.Logger; -import org.onap.aai.cl.eelf.LoggerFactory; -import org.openecomp.sdc.generator.data.AdditionalParams; -import org.openecomp.sdc.generator.data.Artifact; -import org.openecomp.sdc.generator.data.GenerationData; -import org.openecomp.sdc.generator.data.GeneratorUtil; -import org.openecomp.sdc.generator.data.GroupType; -import org.openecomp.sdc.generator.service.ArtifactGenerationService; /** * This class is responsible for generating xml model artifacts from a collection of csar file artifacts */ public class ModelGenerator implements ArtifactGenerator { - private static Logger logger = LoggerFactory.getInstance().getLogger(ModelGenerator.class); + private static final Logger logger = LogHelper.INSTANCE; - private static final String GENERATORCONFIG = "{\"artifactTypes\": [\"AAI\"]}"; - private static final Pattern UUID_NORMATIVE_NEW_VERSION = Pattern.compile("^\\d{1,}.0"); private static final String VERSION_DELIMITER = "."; private static final String VERSION_DELIMITER_REGEXP = "\\" + VERSION_DELIMITER; private static final String DEFAULT_SERVICE_VERSION = "1.0"; @@ -54,12 +51,14 @@ public class ModelGenerator implements ArtifactGenerator { /** * Invokes the TOSCA artifact generator API with the input artifacts. * + * @param csarArchive * @param csarArtifacts the input artifacts * @return {@link List} of output artifacts * @throws XmlArtifactGenerationException if there is an error trying to generate xml artifacts */ @Override - public List generateArtifacts(List csarArtifacts) throws XmlArtifactGenerationException { + public List generateArtifacts(byte[] csarArchive, List csarArtifacts) + throws XmlArtifactGenerationException { logger.info(ApplicationMsgs.DISTRIBUTION_EVENT, "Generating XML for " + csarArtifacts.size() + " CSAR artifacts."); @@ -70,19 +69,19 @@ public class ModelGenerator implements ArtifactGenerator { String serviceVersion = getServiceVersion(toscaVersion); logger.debug("The service version is " + serviceVersion); Map additionalParams = new HashMap<>(); - additionalParams.put(AdditionalParams.ServiceVersion.getName(), serviceVersion); + additionalParams.put(AdditionalParams.SERVICE_VERSION.getName(), serviceVersion); // Call ArtifactGenerator API logger.debug("Obtaining instance of ArtifactGenerationService"); - ArtifactGenerationService generationService = ArtifactGenerationService.lookup(); + org.onap.aai.babel.xml.generator.api.ArtifactGenerator generator = new AaiArtifactGenerator(); logger.debug("About to call generationService.generateArtifact()"); - GenerationData data = generationService.generateArtifact(csarArtifacts, GENERATORCONFIG, additionalParams); + GenerationData data = generator.generateArtifact(csarArchive, csarArtifacts, additionalParams); logger.debug("Call generationService.generateArtifact() has finished"); // Convert results into BabelArtifacts if (data.getErrorData().isEmpty()) { - return data.getResultData().stream().map(a -> new BabelArtifact(a.getName(), a.getType(), a.getPayload())) - .collect(Collectors.toList()); + return data.getResultData().stream().map(a -> new BabelArtifact(a.getName(), ArtifactType.MODEL, + new String(Base64.getDecoder().decode(a.getPayload())))).collect(Collectors.toList()); } else { throw new XmlArtifactGenerationException( "Error occurred during artifact generation: " + data.getErrorData().toString()); @@ -115,14 +114,10 @@ public class ModelGenerator implements ArtifactGenerator { String serviceVersion; try { - if (UUID_NORMATIVE_NEW_VERSION.matcher(artifactVersion).matches()) { - serviceVersion = artifactVersion; - } else { - String[] versionParts = artifactVersion.split(VERSION_DELIMITER_REGEXP); - Integer majorVersion = Integer.parseInt(versionParts[0]); + String[] versionParts = artifactVersion.split(VERSION_DELIMITER_REGEXP); + Integer majorVersion = Integer.parseInt(versionParts[0]); - serviceVersion = (majorVersion + 1) + VERSION_DELIMITER + "0"; - } + serviceVersion = majorVersion + VERSION_DELIMITER + "0"; } catch (Exception e) { logger.warn(ApplicationMsgs.DISTRIBUTION_EVENT, "Error generating service version from artifact version: " + artifactVersion