Remove all references to artifactgenerator config
[aai/babel.git] / src / main / java / org / onap / aai / babel / xml / generator / api / AaiArtifactGenerator.java
index 4415c47..11c1471 100644 (file)
@@ -2,8 +2,8 @@
  * ============LICENSE_START=======================================================
  * org.onap.aai
  * ================================================================================
- * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2019 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.
@@ -45,7 +45,8 @@ import org.onap.aai.babel.xml.generator.model.Model;
 import org.onap.aai.babel.xml.generator.model.Resource;
 import org.onap.aai.babel.xml.generator.model.Service;
 import org.onap.aai.babel.xml.generator.model.Widget;
-import org.onap.aai.babel.xml.generator.model.Widget.Type;
+import org.onap.aai.babel.xml.generator.model.WidgetType;
+import org.onap.aai.babel.xml.generator.types.ModelType;
 import org.onap.aai.cl.api.Logger;
 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
 import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
@@ -68,7 +69,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
     private static final String GENERATOR_AAI_INVALID_SERVICE_VERSION =
             "Cannot generate artifacts. Service version is incorrect";
 
-    private AaiModelGenerator modelGenerator = new AaiModelGeneratorImpl();
+    private AaiModelGenerator modelGenerator = new AaiModelGenerator();
 
     @Override
     public GenerationData generateArtifact(byte[] csarArchive, List<Artifact> input,
@@ -81,10 +82,9 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
         }
 
         try {
-            ArtifactGeneratorToscaParser.initWidgetConfiguration();
             ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(configLocation);
         } catch (IOException e) {
-            log.error(ApplicationMsgs.LOAD_PROPERTIES, e);
+            log.error(ApplicationMsgs.LOAD_PROPERTIES, e, configLocation);
             return createErrorData(e);
         }
 
@@ -123,8 +123,9 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
      *            interface to the TOSCA parser
      * @return the generated Artifacts (containing XML models)
      * @throws XmlArtifactGenerationException
+     *             if the configured widget mappings do not support processed widget type(s)
      */
-    private GenerationData generateAllArtifacts(final String serviceVersion, ISdcCsarHelper csarHelper)
+    public GenerationData generateAllArtifacts(final String serviceVersion, ISdcCsarHelper csarHelper)
             throws XmlArtifactGenerationException {
         List<NodeTemplate> serviceNodeTemplates = csarHelper.getServiceNodeTemplates();
         if (serviceNodeTemplates == null) {
@@ -181,6 +182,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
      * @param serviceModel
      * @return the generated Models
      * @throws XmlArtifactGenerationException
+     *             if the configured widget mappings do not support processed widget type(s)
      */
     private List<Resource> generateResourceModels(ISdcCsarHelper csarHelper, List<NodeTemplate> serviceNodeTemplates,
             Service serviceModel) throws XmlArtifactGenerationException {
@@ -200,6 +202,16 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
         return resources;
     }
 
+    /**
+     * @param csarHelper
+     * @param serviceModel
+     * @param resources
+     * @param serviceGroups
+     * @param parser
+     * @param nodeTemplate
+     * @throws XmlArtifactGenerationException
+     *             if the configured widget mappings do not support processed widget type(s)
+     */
     private void generateModelFromNodeTemplate(ISdcCsarHelper csarHelper, Service serviceModel,
             List<Resource> resources, final List<Group> serviceGroups, ArtifactGeneratorToscaParser parser,
             NodeTemplate nodeTemplate) throws XmlArtifactGenerationException {
@@ -211,7 +223,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
             }
 
             parser.addRelatedModel(serviceModel, model);
-            if (model.isResource()) {
+            if (model.getModelType() == ModelType.RESOURCE) {
                 generateResourceModel(csarHelper, resources, parser, nodeTemplate);
             }
         } else {
@@ -241,14 +253,22 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
         if (model != null) {
             Metadata metadata = nodeTemplate.getMetaData();
             if (metadata != null && parser.hasAllottedResource(metadata.getAllProperties())
-                    && model.getWidgetType() == Type.VF) {
-                model = new Resource(Type.ALLOTTED_RESOURCE, true);
+                    && model.hasWidgetType("VF")) {
+                model = new Resource(WidgetType.valueOf("ALLOTTED_RESOURCE"), true);
             }
         }
 
         return model;
     }
 
+    /**
+     * @param csarHelper
+     * @param resources
+     * @param parser
+     * @param nodeTemplate
+     * @throws XmlArtifactGenerationException
+     *             if the configured widget mappings do not support processed widget type(s)
+     */
     private void generateResourceModel(ISdcCsarHelper csarHelper, List<Resource> resources,
             ArtifactGeneratorToscaParser parser, NodeTemplate nodeTemplate) throws XmlArtifactGenerationException {
         Resource resourceModel = getModelFor(parser, nodeTemplate);
@@ -267,11 +287,11 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
         }
 
         if (parser.hasSubCategoryTunnelXConnect(serviceMetadata) && parser.hasAllottedResource(serviceMetadata)) {
-            resourceModel.addWidget(Widget.getWidget(Type.TUNNEL_XCONNECT));
+            resourceModel.addWidget(Widget.createWidget("TUNNEL_XCONNECT"));
         }
 
         resources.addAll(parser.processInstanceGroups(resourceModel, nodeTemplate));
-        resources.add((Resource) resourceModel);
+        resources.add(resourceModel);
     }
 
     /**
@@ -303,7 +323,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
     private String getArtifactLabel(Model model) {
         StringBuilder artifactName = new StringBuilder(ArtifactType.AAI.name());
         artifactName.append("-");
-        artifactName.append(model.getModelType().name().toLowerCase());
+        artifactName.append(model.getModelTypeName());
         artifactName.append("-");
         artifactName.append(hashCodeUuId(model.getModelNameVersionId()));
         return (artifactName.toString()).replaceAll("[^a-zA-Z0-9 +]+", "-");
@@ -324,7 +344,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
         artifactName.append(truncatedArtifactName);
 
         artifactName.append("-");
-        artifactName.append(model.getModelType().name().toLowerCase());
+        artifactName.append(model.getModelTypeName());
         artifactName.append("-");
         artifactName.append(model.getModelVersion());
 
@@ -342,7 +362,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
      *            AAI model as string
      * @return Generated {@link Artifact} model for the resource
      */
-    private Artifact getResourceArtifact(Model resourceModel, String aaiResourceModel) {
+    private Artifact getResourceArtifact(Resource resourceModel, String aaiResourceModel) {
         final String resourceArtifactLabel = getArtifactLabel(resourceModel);
         MDC.put(MDC_PARAM_MODEL_INFO, resourceModel.getModelName() + "," + resourceArtifactLabel);
         final byte[] bytes = aaiResourceModel.getBytes();
@@ -351,7 +371,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
                 GeneratorUtil.checkSum(bytes), GeneratorUtil.encode(bytes));
         artifact.setName(getArtifactName(resourceModel));
         artifact.setLabel(resourceArtifactLabel);
-        artifact.setDescription(ArtifactGeneratorToscaParser.getArtifactDescription(resourceModel));
+        artifact.setDescription("AAI Resource Model");
         return artifact;
     }
 
@@ -381,8 +401,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
         String serviceArtifactLabel = getArtifactLabel(serviceModel);
         artifact.setName(serviceArtifactName);
         artifact.setLabel(serviceArtifactLabel);
-        String description = ArtifactGeneratorToscaParser.getArtifactDescription(serviceModel);
-        artifact.setDescription(description);
+        artifact.setDescription("AAI Service Model");
         return artifact;
     }