diff options
author | vasraz <vasyl.razinkov@est.tech> | 2022-08-30 18:17:21 +0100 |
---|---|---|
committer | Vasyl Razinkov <vasyl.razinkov@est.tech> | 2022-09-02 12:46:09 +0000 |
commit | 3f48762a391733561bb1ed171ea0a15bf0ea50ee (patch) | |
tree | 2adc1aee69d1253c7a0c3d4fbc7f5440067b8d2f /catalog-be/src | |
parent | 97b5fa431d5924d90e97adedf76f3ce5648cd938 (diff) |
Allow to select properties in the get_attribute function
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Change-Id: Ib35d5d1e3d83ed8e87ce45c20e9cc1a641c5bde2
Issue-ID: SDC-4149
Diffstat (limited to 'catalog-be/src')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/validation/ToscaFunctionValidatorImpl.java | 71 |
1 files changed, 41 insertions, 30 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/validation/ToscaFunctionValidatorImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/validation/ToscaFunctionValidatorImpl.java index ed37347a45..083a03fb42 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/validation/ToscaFunctionValidatorImpl.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/validation/ToscaFunctionValidatorImpl.java @@ -24,6 +24,8 @@ package org.openecomp.sdc.be.components.impl.validation; import fj.data.Either; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.onap.sdc.tosca.datatypes.model.PropertyType; @@ -63,42 +65,51 @@ public class ToscaFunctionValidatorImpl implements ToscaFunctionValidator { private <T extends PropertyDataDefinition> void validateToscaGetFunction(T property, Component parentComponent) { final ToscaGetFunctionDataDefinition toscaGetFunction = (ToscaGetFunctionDataDefinition) property.getToscaFunction(); validateGetToscaFunctionAttributes(toscaGetFunction); - validateGetPropertySource(toscaGetFunction.getFunctionType(), toscaGetFunction.getPropertySource()); - if (toscaGetFunction.getFunctionType() == ToscaGetFunctionType.GET_INPUT) { - validateGetFunction(property, parentComponent.getInputs(), parentComponent.getModel()); - return; - } - if (toscaGetFunction.getFunctionType() == ToscaGetFunctionType.GET_PROPERTY) { - if (toscaGetFunction.getPropertySource() == PropertySource.SELF) { - validateGetFunction(property, parentComponent.getProperties(), parentComponent.getModel()); - } else if (toscaGetFunction.getPropertySource() == PropertySource.INSTANCE) { - final ComponentInstance componentInstance = - parentComponent.getComponentInstanceById(toscaGetFunction.getSourceUniqueId()) + final ToscaGetFunctionType functionType = toscaGetFunction.getFunctionType(); + validateGetPropertySource(functionType, toscaGetFunction.getPropertySource()); + final String model = parentComponent.getModel(); + switch (functionType) { + case GET_INPUT: + validateGetFunction(property, parentComponent.getInputs(), model); + break; + case GET_PROPERTY: + if (toscaGetFunction.getPropertySource() == PropertySource.SELF) { + validateGetFunction(property, parentComponent.getProperties(), model); + } else if (toscaGetFunction.getPropertySource() == PropertySource.INSTANCE) { + final ComponentInstance componentInstance = + parentComponent.getComponentInstanceById(toscaGetFunction.getSourceUniqueId()) + .orElseThrow(ToscaGetFunctionExceptionSupplier.instanceNotFound(toscaGetFunction.getSourceName())); + validateGetFunction(property, componentInstance.getProperties(), model); + } + break; + case GET_ATTRIBUTE: + if (toscaGetFunction.getPropertySource() == PropertySource.SELF) { + validateGetFunction(property, combine(parentComponent.getProperties(), parentComponent.getAttributes()), model); + } else if (toscaGetFunction.getPropertySource() == PropertySource.INSTANCE) { + final ComponentInstance componentInstance = parentComponent.getComponentInstanceById(toscaGetFunction.getSourceUniqueId()) .orElseThrow(ToscaGetFunctionExceptionSupplier.instanceNotFound(toscaGetFunction.getSourceName())); - validateGetFunction(property, componentInstance.getProperties(), parentComponent.getModel()); - } - - return; - } - if (toscaGetFunction.getFunctionType() == ToscaGetFunctionType.GET_ATTRIBUTE) { - if (toscaGetFunction.getPropertySource() == PropertySource.SELF) { - validateGetFunction(property, parentComponent.getAttributes(), parentComponent.getModel()); - } else if (toscaGetFunction.getPropertySource() == PropertySource.INSTANCE) { - final ComponentInstance componentInstance = - parentComponent.getComponentInstanceById(toscaGetFunction.getSourceUniqueId()) - .orElseThrow(ToscaGetFunctionExceptionSupplier.instanceNotFound(toscaGetFunction.getSourceName())); - validateGetFunction(property, componentInstance.getAttributes(), parentComponent.getModel()); - } - - return; + validateGetFunction(property, combine(componentInstance.getProperties(), componentInstance.getAttributes()), model); + } + break; + default: + throw ToscaGetFunctionExceptionSupplier.functionNotSupported(functionType).get(); } + } - throw ToscaGetFunctionExceptionSupplier.functionNotSupported(toscaGetFunction.getFunctionType()).get(); + private List<? extends ToscaPropertyData> combine(final List<? extends ToscaPropertyData> parentProperties, + final List<? extends ToscaPropertyData> parentAttributes) { + if (CollectionUtils.isNotEmpty(parentProperties) && CollectionUtils.isNotEmpty(parentAttributes)) { + return Stream.concat(parentProperties.stream(), parentAttributes.stream()).collect(Collectors.toList()); + } + if (CollectionUtils.isEmpty(parentProperties)) { + return parentAttributes; + } + return parentProperties; } private <T extends PropertyDataDefinition> void validateGetFunction(final T property, - final List<? extends ToscaPropertyData> parentProperties, - final String model) { + final List<? extends ToscaPropertyData> parentProperties, + final String model) { final ToscaGetFunctionDataDefinition toscaGetFunction = (ToscaGetFunctionDataDefinition) property.getToscaFunction(); if (CollectionUtils.isEmpty(parentProperties)) { throw ToscaGetFunctionExceptionSupplier |