From 762a1a320d92ca7415265066dbe4dfd7df91c2ec Mon Sep 17 00:00:00 2001 From: Francis Toth Date: Sun, 3 May 2020 10:01:47 -0400 Subject: Refactor CsarUtils::collectComponentTypeArtifacts This commit is a minor refactoring required to refactor CsarUtils::collectComponentInstanceArtifacts. In order to keep this commit small, we only focused CsarUtils::collectComponentTypeArtifacts, and removed any output that is not reflected by the function's result type. Modifying an argument is a actually a bad practice as explained in Clean Code by Robert Martin (cf. "Output arguments should be avoided"). This commit aims to enforce this aspect. Change-Id: Ice4d6c9a78e7706c639dd60bc272253e298bc7be Signed-off-by: Francis Toth Issue-ID: SDC-2812 --- .../java/org/openecomp/sdc/be/tosca/CsarUtils.java | 36 +++++++++++++--------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'catalog-be/src/main') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java index 85d0c78727..47a84789f1 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java @@ -1124,6 +1124,10 @@ public class CsarUtils { return artifactsInfoField.isEmpty(); } + public boolean isNotEmpty() { + return !isEmpty(); + } + } /** @@ -1290,19 +1294,13 @@ public class CsarUtils { return result.toString(); } - private ComponentTypeArtifacts collectComponentTypeArtifacts(Map resourcesArtifacts, ComponentInstance componentInstance, - Component fetchedComponent) { - String toscaComponentName = componentInstance.getToscaComponentName() + "_v" + componentInstance.getComponentVersion(); - - ComponentTypeArtifacts componentArtifactsInfo = resourcesArtifacts.get(toscaComponentName); - //if there are no artifacts for this component type we need to fetch and build them - if (componentArtifactsInfo==null){ - ArtifactsInfo componentArtifacts = collectComponentArtifacts(fetchedComponent); - componentArtifactsInfo = new ComponentTypeArtifacts(); - if (!componentArtifacts.isEmpty()){ - componentArtifactsInfo.setComponentArtifacts(componentArtifacts); - resourcesArtifacts.put(toscaComponentName, componentArtifactsInfo); - } + private ComponentTypeArtifacts collectComponentTypeArtifacts( + Component fetchedComponent + ) { + ArtifactsInfo componentArtifacts = collectComponentArtifacts(fetchedComponent); + ComponentTypeArtifacts componentArtifactsInfo = new ComponentTypeArtifacts(); + if (componentArtifacts.isNotEmpty()) { + componentArtifactsInfo.setComponentArtifacts(componentArtifacts); } return componentArtifactsInfo; } @@ -1327,7 +1325,17 @@ public class CsarUtils { Component fetchedComponent = component.left().value(); //2. fill the artifacts for the current component parent type - ComponentTypeArtifacts componentParentArtifacts = collectComponentTypeArtifacts(resourcesTypeArtifacts, componentInstance, fetchedComponent); + String toscaComponentName = + componentInstance.getToscaComponentName() + "_v" + componentInstance.getComponentVersion(); + + // if there are no artifacts for this component type we need to fetch and build them + ComponentTypeArtifacts componentParentArtifacts = Optional + .ofNullable(resourcesTypeArtifacts.get(toscaComponentName)) + .orElseGet(() -> collectComponentTypeArtifacts(fetchedComponent)); + + if (componentParentArtifacts.getComponentArtifacts().isNotEmpty()) { + resourcesTypeArtifacts.put(toscaComponentName, componentParentArtifacts); + } //3. find the artifacts specific to the instance Map> componentInstanceSpecificInformationalArtifacts = -- cgit 1.2.3-korg