Fix outstanding Sonar issues
[aai/babel.git] / src / main / java / org / onap / aai / babel / xml / generator / api / AaiArtifactGenerator.java
index fc5acda..57e8a67 100644 (file)
@@ -80,9 +80,16 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
             return createErrorData(e);
         }
 
+        String configLocation = System.getProperty(ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE);
+        if (configLocation == null) {
+            throw new IllegalArgumentException(
+                    String.format(ArtifactGeneratorToscaParser.GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND,
+                            ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE));
+        }
+
         try {
             ArtifactGeneratorToscaParser.initWidgetConfiguration();
-            ArtifactGeneratorToscaParser.initGroupFilterConfiguration();
+            ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(configLocation);
             ISdcCsarHelper csarHelper =
                     SdcToscaParserFactory.getInstance().getSdcCsarHelper(csarPath.toAbsolutePath().toString());
             return generateAllArtifacts(validateServiceVersion(additionalParams), csarHelper);
@@ -105,7 +112,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
      *
      * @param serviceVersion
      * @param csarHelper
-     *            interface to the TOSCA parser
+     *     interface to the TOSCA parser
      * @return the generated Artifacts (containing XML models)
      */
     private GenerationData generateAllArtifacts(final String serviceVersion, ISdcCsarHelper csarHelper) {
@@ -198,10 +205,11 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
             }
         } else {
             for (Group group : serviceGroups) {
-                if (group.getMembers().contains(nodeTemplate.getName())
+                ArrayList<String> members = group.getMembers();
+                if (members != null && members.contains(nodeTemplate.getName())
                         && WidgetConfigurationUtil.isSupportedInstanceGroup(group.getType())) {
                     log.debug(String.format("Adding group %s (type %s) with members %s", group.getName(),
-                            group.getType(), group.getMembers()));
+                            group.getType(), members));
 
                     Resource groupModel = parser.createInstanceGroupModel(
                             parser.mergeProperties(group.getMetadata().getAllProperties(), group.getProperties()));
@@ -219,9 +227,10 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
 
         Resource model = Model.getModelFor(nodeTypeName, nodeTemplate.getMetaData().getValue("type"));
 
-        Metadata metadata = nodeTemplate.getMetaData();
-        if (metadata != null && parser.hasAllottedResource(metadata.getAllProperties())) {
-            if (model.getWidgetType() == Type.VF) {
+        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);
             }
         }
@@ -232,6 +241,11 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
     private void generateResourceModel(ISdcCsarHelper csarHelper, List<Resource> resources,
             ArtifactGeneratorToscaParser parser, NodeTemplate nodeTemplate) {
         Resource resourceModel = getModelFor(parser, nodeTemplate);
+        if (resourceModel == null) {
+            log.info(ApplicationMsgs.DISTRIBUTION_EVENT, "Could not generate resource model");
+            return;
+        }
+
         Map<String, String> serviceMetadata = nodeTemplate.getMetaData().getAllProperties();
         resourceModel.populateModelIdentificationInformation(serviceMetadata);
 
@@ -286,7 +300,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
      * Method to generate the artifact name for an AAI model.
      *
      * @param model
-     *            AAI artifact model
+     *     AAI artifact model
      * @return Model artifact name
      */
     private String getArtifactName(Model model) {
@@ -310,9 +324,9 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
      * Create Resource artifact model from the AAI xml model string.
      *
      * @param resourceModel
-     *            Model of the resource artifact
+     *     Model of the resource artifact
      * @param aaiResourceModel
-     *            AAI model as string
+     *     AAI model as string
      * @return Generated {@link Artifact} model for the resource
      */
     private Artifact getResourceArtifact(Model resourceModel, String aaiResourceModel) {
@@ -342,9 +356,9 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
      * Create Service artifact model from the AAI XML model.
      *
      * @param serviceModel
-     *            Model of the service artifact
+     *     Model of the service artifact
      * @param aaiServiceModel
-     *            AAI model as string
+     *     AAI model as string
      * @return Generated {@link Artifact} model for the service
      */
     private Artifact getServiceArtifact(Service serviceModel, String aaiServiceModel) {