From 722eed1c46361a2d8136f1fac528a96749f5dbbd Mon Sep 17 00:00:00 2001 From: Chris André Date: Tue, 28 Apr 2020 18:28:27 -0400 Subject: Remove call to `get` on Optional variables - Made multiple variables Optional Issue-ID: SDC-2991 Signed-off-by: Chris Andre Change-Id: If3dbfd37e933d10698ad1a93b6762c84e30f69b8 --- .../impl/InterfaceOperationBusinessLogic.java | 33 ++++++++++++++-------- 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'catalog-be') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java index b6d64d2fc7..1dc55f5874 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java @@ -21,6 +21,7 @@ import com.google.gson.Gson; import fj.data.Either; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.tuple.ImmutablePair; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.utils.InterfaceOperationUtils; import org.openecomp.sdc.be.components.validation.InterfaceOperationValidation; @@ -30,6 +31,7 @@ import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus; import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; +import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.model.ArtifactDefinition; import org.openecomp.sdc.be.model.CapabilityDefinition; @@ -474,22 +476,29 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { setParentPropertyTypeAndInputPath(input, component); defaultInputValue = createMappedInputPropertyDefaultValue(propertyName); } else if (isCapabilityProperty(input.getInputId(), component).isPresent()) { - ComponentInstanceProperty instanceProperty = isCapabilityProperty(input.getInputId(), component).get(); - String parentPropertyId = instanceProperty.getParentUniqueId(); + Optional instancePropertyOpt = isCapabilityProperty(input.getInputId(), + component); + Optional parentPropertyIdOpt = instancePropertyOpt.map(PropertyDataDefinition::getParentUniqueId); Map> componentCapabilities = component.getCapabilities(); if(MapUtils.isNotEmpty(componentCapabilities)) { List capabilityDefinitionList = componentCapabilities.values().stream() - .flatMap(Collection::stream).filter(capabilityDefinition -> capabilityDefinition.getOwnerId() - .equals(component.getUniqueId())).collect(Collectors.toList()); - Optional propertyCapability = getPropertyCapabilityFromAllCapProps(parentPropertyId, - capabilityDefinitionList); - if (propertyCapability.isPresent()) { - String propertyName = instanceProperty.getName(); - defaultInputValue = createMappedCapabilityPropertyDefaultValue(propertyCapability.get().getName(), - propertyName); - } + .flatMap(Collection::stream) + .filter(capabilityDefinition -> capabilityDefinition.getOwnerId().equals(component.getUniqueId())) + .collect(Collectors.toList()); + + defaultInputValue = parentPropertyIdOpt + .flatMap(parentPropertyId -> + getPropertyCapabilityFromAllCapProps(parentPropertyId, capabilityDefinitionList)) + .flatMap(capability -> + instancePropertyOpt.map(instanceProperty -> + new ImmutablePair<>(capability.getName(), instanceProperty.getName()))) + .map(tuple -> { + String propertyName = tuple.right; + String capabilityName = tuple.left; + + return createMappedCapabilityPropertyDefaultValue(capabilityName, propertyName); + }).orElse(null); } - } else { //Currently inputs can only be mapped to a declared input or an other operation outputs defaultInputValue = createMappedOutputDefaultValue(SELF, input.getInputId()); -- cgit 1.2.3-korg