diff options
author | 2018-08-08 15:47:57 +0100 | |
---|---|---|
committer | 2018-08-08 15:50:49 +0100 | |
commit | 1790f2067c262c2a539950da0389c3e6a44dcf7e (patch) | |
tree | 092b5066235a5ab43545d66b449d17945555742e /src/main/java/org | |
parent | 93f9fec9586702a15d6a562ead3d0d432a12b487 (diff) |
Refactor method processServiceTosca for Sonar
Fix for a new Sonar issue detected when a method was moved within an
existing Java class file. See
https://sonar.onap.org/project/issues?id=org.onap.aai%3Ababel&open=AWUZW80uwGn37JfbxewF
Change-Id: I3ac7ecf74c261d39a8762fd39123f7f8048894e3
Issue-ID: AAI-1242
Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java | 65 |
1 files changed, 40 insertions, 25 deletions
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 2421d68..24e8199 100644 --- a/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java +++ b/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java @@ -131,29 +131,18 @@ public class ArtifactGeneratorToscaParser { */ public void processServiceTosca(Service service, Map<String, String> idTypeStore, List<NodeTemplate> nodeTemplates) { - log.debug("Inside Service Tosca "); - - // Get the resource/widgets in the service according to the node-template types - for (NodeTemplate node : nodeTemplates) { - if (node.getMetaData() != null) { - Model model = Model.getModelFor(correctNodeType(node)); - if (model != null) { - model.populateModelIdentificationInformation(node.getMetaData().getAllProperties()); - if (model instanceof Resource) { - // Keeping track of resource types and - // their uuid for identification during resource tosca processing - idTypeStore.put(model.getModelNameVersionId(), correctNodeType(node)); - service.addResource((Resource) model); - } else { - service.addWidget((Widget) model); - } - } + log.debug("Processing (TOSCA) Service object"); + + for (NodeTemplate nodeTemplate : nodeTemplates) { + if (nodeTemplate.getMetaData() != null) { + addNodeToService(idTypeStore, service, nodeTemplate); } else { - log.warn(ApplicationMsgs.MISSING_SERVICE_METADATA, node.getName()); + log.warn(ApplicationMsgs.MISSING_SERVICE_METADATA, nodeTemplate.getName()); } } } + /** * Generates a Resource List using input Service Node Templates. * @@ -201,6 +190,31 @@ public class ArtifactGeneratorToscaParser { } } + /** + * Add the supplied Node Template to the Service, provided that it is a valid Resource or Widget. If the Node + * Template is a Resource type, this is also recorded in the supplied nodesById Map. + * + * @param nodesById a map of Resource node type names, keyed by UUID + * @param service the Service to which the Node Template should be added + * @param nodeTemplate the Node Template to add (only if this is a Resource or Widget type) + */ + private void addNodeToService(Map<String, String> nodesById, Service service, NodeTemplate nodeTemplate) { + String nodeTypeName = normaliseNodeTypeName(nodeTemplate); + Model model = Model.getModelFor(nodeTypeName); + if (model != null) { + if (nodeTemplate.getMetaData() != null) { + model.populateModelIdentificationInformation(nodeTemplate.getMetaData().getAllProperties()); + } + + if (model instanceof Resource) { + nodesById.put(model.getModelNameVersionId(), nodeTypeName); + service.addResource((Resource) model); + } else { + service.addWidget((Widget) model); + } + } + } + private void processVfModules(List<Resource> resources, Model resourceModel, NodeTemplate serviceNode) { // Get the customisation UUID for each VF node and use it to get its Groups String uuid = csarHelper.getNodeTemplateCustomizationUuid(serviceNode); @@ -257,18 +271,18 @@ public class ArtifactGeneratorToscaParser { } } - private String correctNodeType(NodeTemplate nodeType) { - String correctedNodeType = nodeType.getType(); + private String normaliseNodeTypeName(NodeTemplate nodeType) { + String nodeTypeName = nodeType.getType(); Metadata metadata = nodeType.getMetaData(); if (metadata != null && hasAllottedResource(metadata.getAllProperties())) { if (nodeType.getType().contains("org.openecomp.resource.vf.")) { - correctedNodeType = "org.openecomp.resource.vf.allottedResource"; + nodeTypeName = "org.openecomp.resource.vf.allottedResource"; } if (nodeType.getType().contains("org.openecomp.resource.vfc.")) { - correctedNodeType = "org.openecomp.resource.vfc.AllottedResource"; + nodeTypeName = "org.openecomp.resource.vfc.AllottedResource"; } } - return correctedNodeType; + return nodeTypeName; } private boolean hasAllottedResource(Map<String, String> metadata) { @@ -295,7 +309,8 @@ public class ArtifactGeneratorToscaParser { boolean providingServiceFound = false; for (NodeTemplate resourceNodeTemplate : resourceNodes) { - Model resourceNode = Model.getModelFor(correctNodeType(resourceNodeTemplate)); + String nodeTypeName = normaliseNodeTypeName(resourceNodeTemplate); + Model resourceNode = Model.getModelFor(nodeTypeName); if (resourceNode instanceof ProvidingService) { providingServiceFound = true; Map<String, Property> nodeProperties = resourceNodeTemplate.getProperties(); @@ -309,7 +324,7 @@ public class ArtifactGeneratorToscaParser { resourceNode.populateModelIdentificationInformation(properties); resourceModel.addResource((Resource) resourceNode); } else if (resourceNode instanceof Resource && !(resourceNode.getWidgetType().equals(Widget.Type.L3_NET))) { - idTypeStore.put(resourceNode.getModelNameVersionId(), correctNodeType(resourceNodeTemplate)); + idTypeStore.put(resourceNode.getModelNameVersionId(), nodeTypeName); resourceModel.addResource((Resource) resourceNode); } } |