From be30876e3a3872a7274c944995544836ff31913c Mon Sep 17 00:00:00 2001 From: "mark.j.leonard" Date: Tue, 19 Feb 2019 19:09:00 +0000 Subject: Fix outstanding Sonar issues Change-Id: I9699ee13321f136b4460d5c85d49ab13378f52b4 Issue-ID: AAI-2121 Signed-off-by: mark.j.leonard --- .../babel/parser/ArtifactGeneratorToscaParser.java | 43 +++++++++++----------- .../xml/generator/api/AaiArtifactGenerator.java | 24 +++++++----- .../aai/babel/xml/generator/model/Resource.java | 5 ++- 3 files changed, 39 insertions(+), 33 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java b/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java index 50c6edf..3fb77be 100644 --- a/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java +++ b/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java @@ -85,7 +85,7 @@ public class ArtifactGeneratorToscaParser { * Constructs using csarHelper * * @param csarHelper - * The csar helper + * The csar helper */ public ArtifactGeneratorToscaParser(ISdcCsarHelper csarHelper) { this.csarHelper = csarHelper; @@ -95,7 +95,7 @@ public class ArtifactGeneratorToscaParser { * Get or create the artifact description. * * @param model - * the artifact model + * the artifact model * @return the artifact model's description */ public static String getArtifactDescription(Model model) { @@ -136,9 +136,9 @@ public class ArtifactGeneratorToscaParser { * Initialises the group filtering and TOSCA mapping configuration. * * @param configLocation - * the pathname to the JSON config file + * the pathname to the JSON config file * @throws FileNotFoundException - * if the file cannot be opened for reading + * if the file cannot be opened for reading */ public static void initToscaMappingsConfiguration(String configLocation) throws FileNotFoundException { log.debug("Getting TOSCA Mappings Configuration"); @@ -181,9 +181,9 @@ public class ArtifactGeneratorToscaParser { * duplicate keys then the TOSCA Property value takes precedence. * * @param stringProps - * initial Map of String property values (e.g. from the TOSCA YAML metadata section) + * initial Map of String property values (e.g. from the TOSCA YAML metadata section) * @param toscaProps - * Map of TOSCA Property Type Object values to merge in (or overwrite) + * Map of TOSCA Property Type Object values to merge in (or overwrite) * @return a Map of the property values converted to String */ public Map mergeProperties(Map stringProps, Map toscaProps) { @@ -253,13 +253,12 @@ public class ArtifactGeneratorToscaParser { String metaDataType = Optional.ofNullable(metadata).map(m -> m.getValue("type")).orElse(nodeTypeName); Resource model = Model.getModelFor(nodeTypeName, metaDataType); - if (metadata != null && hasAllottedResource(metadata.getAllProperties())) { - if (model.getWidgetType() == Type.VSERVER) { - model = new Resource(Type.ALLOTTED_RESOURCE, false); - Map props = new HashMap<>(); - props.put("providingService", true); - model.setProperties(props); - } + if (metadata != null && hasAllottedResource(metadata.getAllProperties()) + && model.getWidgetType() == Type.VSERVER) { + model = new Resource(Type.ALLOTTED_RESOURCE, false); + Map props = new HashMap<>(); + props.put("providingService", true); + model.setProperties(props); } foundProvidingService |= processModel(resourceModel, metadata, model, resourceNodeTemplate.getProperties()); @@ -276,13 +275,13 @@ public class ArtifactGeneratorToscaParser { * Create an Instance Group Model and populate it with the supplied data. * * @param resourceModel - * the Resource node template Model + * the Resource node template Model * @param memberNodes - * the Resources and Widgets belonging to the Group + * the Resources and Widgets belonging to the Group * @param metaProperties - * the metadata of the Group + * the metadata of the Group * @param properties - * the properties of the Group + * the properties of the Group * @return the Instance Group and Member resource models */ private List processInstanceGroup(Model resourceModel, ArrayList memberNodes, @@ -385,7 +384,7 @@ public class ArtifactGeneratorToscaParser { * Create a Map of property name against String property value from the input Map * * @param inputMap - * The input Map + * The input Map * @return Map of property name against String property value */ private Map populateStringProperties(Map inputMap) { @@ -398,13 +397,13 @@ public class ArtifactGeneratorToscaParser { * is ProvidingService then return true, otherwise return false. * * @param resourceModel - * parent Resource + * parent Resource * @param metaData - * for populating the Resource IDs + * for populating the Resource IDs * @param resourceNode - * any Model (will be ignored if not a Resource) + * any Model (will be ignored if not a Resource) * @param nodeProperties - * the node properties + * the node properties * @return whether or not a ProvidingService was processed */ private boolean processModel(Model resourceModel, Metadata metaData, Resource resourceNode, diff --git a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java index 19b3d80..57e8a67 100644 --- a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java +++ b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java @@ -112,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) { @@ -229,10 +229,9 @@ public class AaiArtifactGenerator implements ArtifactGenerator { if (model != null) { Metadata metadata = nodeTemplate.getMetaData(); - if (metadata != null && parser.hasAllottedResource(metadata.getAllProperties())) { - if (model.getWidgetType() == Type.VF) { - model = new Resource(Type.ALLOTTED_RESOURCE, true); - } + if (metadata != null && parser.hasAllottedResource(metadata.getAllProperties()) + && model.getWidgetType() == Type.VF) { + model = new Resource(Type.ALLOTTED_RESOURCE, true); } } @@ -242,6 +241,11 @@ public class AaiArtifactGenerator implements ArtifactGenerator { private void generateResourceModel(ISdcCsarHelper csarHelper, List 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 serviceMetadata = nodeTemplate.getMetaData().getAllProperties(); resourceModel.populateModelIdentificationInformation(serviceMetadata); @@ -296,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) { @@ -320,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) { @@ -352,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) { diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java b/src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java index d6a9405..d655ca6 100644 --- a/src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java +++ b/src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java @@ -57,14 +57,17 @@ public class Resource extends Model { return false; } + @Override public boolean getDeleteFlag() { return deleteFlag; } + @Override public String getWidgetInvariantId() { return Widget.getWidget(getWidgetType()).getWidgetId(); } + @Override public String getWidgetId() { return Widget.getWidget(getWidgetType()).getId(); } @@ -100,7 +103,7 @@ public class Resource extends Model { * Adds a Widget. * * @param widget - * the widget + * the widget * @return the boolean */ @Override -- cgit 1.2.3-korg