diff options
author | 2019-09-11 13:50:46 +0100 | |
---|---|---|
committer | 2019-11-04 13:33:00 +0000 | |
commit | 5775dd13964a56a60dfbe8fc72e5977672d5acb8 (patch) | |
tree | 5ce7f67dc963e219d338cde4a152f90f9dccc2fc /openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/Transformation.java | |
parent | dd22ca7a392b6532f6ed74d2aa985e14035828d1 (diff) |
Transform custom types for PNFD.
Transformation of customized Node Types for PNFD.
Issue-ID: SDC-2561
Change-Id: Id3e07edff0e5a8cb134aa12c07878e14c33d1512
Signed-off-by: aribeiro <anderson.ribeiro@est.tech>
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/Transformation.java')
-rw-r--r-- | openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/Transformation.java | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/Transformation.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/Transformation.java index fa4a9336e3..a3f7ca0626 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/Transformation.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/Transformation.java @@ -21,9 +21,12 @@ package org.openecomp.core.converter.pnfd.model; import java.util.List; import java.util.Objects; +import java.util.Optional; +import java.util.Set; import lombok.Getter; import lombok.Setter; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; /** * Represents a transformation from the PNFD transformation descriptor. @@ -35,6 +38,7 @@ public class Transformation { private String name; private String description; private TransformationBlock block; + private Set<TransformationProperty> propertySet; private ConversionQuery conversionQuery; private List<ConversionDefinition> conversionDefinitionList; @@ -44,6 +48,9 @@ public class Transformation { * @return {code true} if the instance is valid, {code false} otherwise */ public boolean isValid() { + if (block == TransformationBlock.GET_INPUT_FUNCTION) { + return !StringUtils.isEmpty(name) && !CollectionUtils.isEmpty(conversionDefinitionList); + } return block != null && conversionQuery != null && !CollectionUtils.isEmpty(conversionDefinitionList); } @@ -55,9 +62,9 @@ public class Transformation { if (o == null || getClass() != o.getClass()) { return false; } - Transformation that = (Transformation) o; + final Transformation that = (Transformation) o; //if there is no query, compares by block and name. - if (conversionQuery != null && conversionQuery.getQuery() == null && that.conversionQuery.getQuery() == null) { + if (conversionQuery == null && that.conversionQuery == null) { return block == that.block && Objects.equals(name, that.name); } @@ -70,4 +77,24 @@ public class Transformation { public int hashCode() { return Objects.hash(block, conversionQuery); } + + public <T> Optional<T> getPropertyValue(final TransformationPropertyType type, Class<T> clazz) { + if (CollectionUtils.isEmpty(propertySet)) { + return Optional.empty(); + } + + final Optional<TransformationProperty> transformationProperty = propertySet.stream() + .filter(transformationProperty1 -> transformationProperty1.getType() == type) + .findFirst(); + if (transformationProperty.isPresent()) { + try { + T value = clazz.cast(transformationProperty.get().getValue()); + return Optional.of(value); + } catch (final ClassCastException ignored) { + return Optional.empty(); + } + } + + return Optional.empty(); + } } |