Updated pom to remove distribution-management section and corrected aai base image...
[aai/babel.git] / src / main / java / org / onap / aai / babel / xml / generator / ModelGenerator.java
index 65e0ada..f94da4a 100644 (file)
@@ -2,8 +2,8 @@
  * ============LICENSE_START=======================================================
  * org.onap.aai
  * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.
@@ -18,6 +18,7 @@
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aai.babel.xml.generator;
 
 import java.util.Base64;
@@ -35,14 +36,14 @@ 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 javax.ws.rs.core.Response;
 
 /**
- * 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 final Logger logger = LogHelper.INSTANCE;
+    private static final LogHelper logger = LogHelper.INSTANCE;
 
     private static final String VERSION_DELIMITER = ".";
     private static final String VERSION_DELIMITER_REGEXP = "\\" + VERSION_DELIMITER;
@@ -52,9 +53,11 @@ public class ModelGenerator implements ArtifactGenerator {
      * Invokes the TOSCA artifact generator API with the input artifacts.
      *
      * @param csarArchive
-     * @param csarArtifacts the input artifacts
+     * @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<BabelArtifact> generateArtifacts(byte[] csarArchive, List<Artifact> csarArtifacts)
@@ -64,8 +67,6 @@ public class ModelGenerator implements ArtifactGenerator {
 
         // 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<String, String> additionalParams = new HashMap<>();
@@ -91,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) {
@@ -111,21 +115,17 @@ public class ModelGenerator implements ArtifactGenerator {
     }
 
     private static String getServiceVersion(String artifactVersion) {
-        String serviceVersion;
-
+        logger.debug("Artifact version=" + artifactVersion);
         try {
-            String[] versionParts = artifactVersion.split(VERSION_DELIMITER_REGEXP);
-            Integer majorVersion = Integer.parseInt(versionParts[0]);
-
-            serviceVersion = majorVersion + VERSION_DELIMITER + "0";
+            return String.valueOf(Float.parseFloat(artifactVersion));
         } catch (Exception e) {
+            logger.setContextValue(LogHelper.MdcParameter.RESPONSE_CODE, String.valueOf(Response.Status.BAD_REQUEST.getStatusCode()));
+            logger.setContextValue(LogHelper.MdcParameter.RESPONSE_DESCRIPTION, "Invalid Artifact version");
             logger.warn(ApplicationMsgs.DISTRIBUTION_EVENT,
                     "Error generating service version from artifact version: " + artifactVersion
                             + ". Using default service version of: " + DEFAULT_SERVICE_VERSION + ". Error details: "
                             + e);
             return DEFAULT_SERVICE_VERSION;
         }
-
-        return serviceVersion;
     }
 }