X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fbabel%2Fxml%2Fgenerator%2FModelGenerator.java;h=c5ea37a068ecf2bd53999cb37326150b7199744e;hb=e3de90587ada88dcb3cb0a87fbfe283b2ae9f08b;hp=c6def3d249cfb1b7a452cf7a56d95d661af6f5e1;hpb=1433a67a9e3dcad20d0dda8edcaad9403320f4f9;p=aai%2Fbabel.git 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..c5ea37a 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 (c) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2017-2019 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,34 @@ * 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 + * This class is responsible for generating XML model artifacts from a collection of CSAR 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,35 +52,37 @@ public class ModelGenerator implements ArtifactGenerator { /** * Invokes the TOSCA artifact generator API with the input artifacts. * - * @param csarArtifacts 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 + * @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."); // Get the service version to pass into the generator String toscaVersion = csarArtifacts.get(0).getVersion(); - logger.debug( - "Getting the service version for Tosca Version of the yml file. The Tosca Version is " + toscaVersion); 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()); @@ -92,9 +92,12 @@ public class ModelGenerator implements ArtifactGenerator { /** * Creates an instance of an input artifact for the generator. * - * @param payload the payload downloaded from SDC - * @param artifactName name of the artifact to create - * @param artifactVersion version of the artifact to create + * @param payload + * the payload downloaded from SDC + * @param artifactName + * name of the artifact to create + * @param artifactVersion + * version of the artifact to create * @return an {@link Artifact} object constructed from the payload and artifactInfo */ public static Artifact createArtifact(byte[] payload, String artifactName, String artifactVersion) { @@ -112,17 +115,12 @@ public class ModelGenerator implements ArtifactGenerator { } private static String getServiceVersion(String artifactVersion) { - String serviceVersion; - + logger.debug("Artifact version=" + artifactVersion ); + + // As of 1902, AAI-16260, we no longer edit the passed in artifact/service version. 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]); - - serviceVersion = (majorVersion + 1) + VERSION_DELIMITER + "0"; - } + // just make sure it's an integer + Integer.parseInt(artifactVersion.split(VERSION_DELIMITER_REGEXP)[0]); } catch (Exception e) { logger.warn(ApplicationMsgs.DISTRIBUTION_EVENT, "Error generating service version from artifact version: " + artifactVersion @@ -131,6 +129,7 @@ public class ModelGenerator implements ArtifactGenerator { return DEFAULT_SERVICE_VERSION; } - return serviceVersion; + logger.debug("Use Artifact version as the serviceVersion=" + artifactVersion ); + return artifactVersion; } }