From 57ac9cec55b6470da859330a0fcab70e35422b3c Mon Sep 17 00:00:00 2001 From: Chris André Date: Tue, 21 Apr 2020 12:25:29 -0400 Subject: Handle null case in `addCalculatedCapabilitiesWithPropertiesToComponent` - Change code to handle a null value for `groupDefinitions` as if it was an empty List Issue-ID: SDC-2910 Signed-off-by: Chris Andre Change-Id: I5fca0ab76886e5f6a73a8f05ec35d38848f96dd8 --- .../sdc/be/components/impl/GroupBusinessLogic.java | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'catalog-be/src/main/java') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java index 417380b5d9..e0bf727408 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java @@ -23,6 +23,7 @@ package org.openecomp.sdc.be.components.impl; import fj.data.Either; +import java.util.Vector; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.io.FilenameUtils; @@ -1181,12 +1182,20 @@ public class GroupBusinessLogic extends BaseBusinessLogic { } } - private void addCalculatedCapabilitiesWithPropertiesToComponent(Component component, final List groupDefinitions, boolean fromCsar) { - groupDefinitions.forEach(GroupDefinition::updateEmptyCapabilitiesOwnerFields); - StorageOperationStatus status = groupsOperation.addCalculatedCapabilitiesWithProperties(component.getUniqueId(), - extractCapabilitiesFromGroups(groupDefinitions), extractCapabilityPropertiesFromGroups(groupDefinitions, fromCsar)); - if(status != StorageOperationStatus.OK){ - log.error("#addCalculatedCapabilitiesWithPropertiesToComponent - failed to add the groups' calculated capabilities with the properties to the component {}. ", component.getUniqueId()); + private void addCalculatedCapabilitiesWithPropertiesToComponent(Component component, + final List groupDefinitions, boolean fromCsar) { + final List nonNullGroupDefinitions = + (groupDefinitions == null) ? Collections.emptyList() : groupDefinitions; + + nonNullGroupDefinitions.forEach(GroupDefinition::updateEmptyCapabilitiesOwnerFields); + StorageOperationStatus status = groupsOperation.addCalculatedCapabilitiesWithProperties( + component.getUniqueId(), + extractCapabilitiesFromGroups(nonNullGroupDefinitions), + extractCapabilityPropertiesFromGroups(nonNullGroupDefinitions, fromCsar)); + if (status != StorageOperationStatus.OK) { + log.error( + "#addCalculatedCapabilitiesWithPropertiesToComponent - failed to add the groups' calculated capabilities with the properties to the component {}. ", + component.getUniqueId()); rollbackWithException(componentsUtils.convertFromStorageResponse(status)); } } -- cgit 1.2.3-korg