diff options
author | Francis Toth <francis.toth@yoppworks.com> | 2020-05-03 10:01:47 -0400 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2020-05-05 08:14:59 +0000 |
commit | 762a1a320d92ca7415265066dbe4dfd7df91c2ec (patch) | |
tree | 13abf9ad9948dca73403ba4720920b26ed15477b /catalog-be | |
parent | 8394fae8e6fca37ad8f3e10ade82d8d2507585d1 (diff) |
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 <francis.toth@yoppworks.com>
Issue-ID: SDC-2812
Diffstat (limited to 'catalog-be')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java | 36 |
1 files changed, 22 insertions, 14 deletions
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<String, ComponentTypeArtifacts> 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<String, List<ArtifactDefinition>> componentInstanceSpecificInformationalArtifacts = |