aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris André <chris.andre@yoppworks.com>2020-04-28 18:28:27 -0400
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-05-05 08:16:01 +0000
commit722eed1c46361a2d8136f1fac528a96749f5dbbd (patch)
tree4c10f660646c696f2d7038ce127641a16eaa81bf
parent908793f04e9a595734a6e0e189b846ed062bfc7d (diff)
Remove call to `get` on Optional variables
- Made multiple variables Optional Issue-ID: SDC-2991 Signed-off-by: Chris Andre <chris.andre@yoppworks.com> Change-Id: If3dbfd37e933d10698ad1a93b6762c84e30f69b8
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java33
1 files changed, 21 insertions, 12 deletions
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<ComponentInstanceProperty> instancePropertyOpt = isCapabilityProperty(input.getInputId(),
+ component);
+ Optional<String> parentPropertyIdOpt = instancePropertyOpt.map(PropertyDataDefinition::getParentUniqueId);
Map<String, List<CapabilityDefinition>> componentCapabilities = component.getCapabilities();
if(MapUtils.isNotEmpty(componentCapabilities)) {
List<CapabilityDefinition> capabilityDefinitionList = componentCapabilities.values().stream()
- .flatMap(Collection::stream).filter(capabilityDefinition -> capabilityDefinition.getOwnerId()
- .equals(component.getUniqueId())).collect(Collectors.toList());
- Optional<CapabilityDefinition> 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());