From 7a3dcaaba77cf6ab3212db9ce7539ee90cb33eab Mon Sep 17 00:00:00 2001 From: vasraz Date: Mon, 12 Dec 2022 15:18:18 +0000 Subject: Fix bug 'Pattern constraint validation failure' Signed-off-by: Vasyl Razinkov Change-Id: If7c59aa37db974c57195775f963c8400cf474a51 Issue-ID: SDC-4294 --- .../openecomp/sdc/be/tosca/PropertyConvertor.java | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'catalog-be/src') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java index 2ad6a942d0..ae97b89b78 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java @@ -92,9 +92,9 @@ public class PropertyConvertor { if (props != null) { Map properties = new HashMap<>(); // take only the properties of this resource - props.stream().filter(p -> p.getOwnerId() == null || p.getOwnerId().equals(component.getUniqueId())).forEach(property -> { - properties.put(property.getName(), convertProperty(dataTypes, property, PropertyType.PROPERTY)); - }); + props.stream().filter(p -> p.getOwnerId() == null || p.getOwnerId().equals(component.getUniqueId())).forEach(property -> + properties.put(property.getName(), convertProperty(dataTypes, property, PropertyType.PROPERTY)) + ); if (!properties.isEmpty()) { toscaNodeType.setProperties(properties); } @@ -129,18 +129,16 @@ public class PropertyConvertor { prop.setStatus(property.getStatus()); } prop.setMetadata(property.getMetadata()); - - List constraints = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(property.getConstraints())) { - constraints = convertConstraints(property.getConstraints()); - prop.setConstraints(constraints); + prop.setConstraints(convertConstraints(property.getConstraints())); } return prop; } - + private List convertConstraints(List constraints) { List convertedConstraints = new ArrayList<>(); - for (PropertyConstraint constraint: constraints){ + for (PropertyConstraint constraint : constraints) { if (constraint instanceof EqualConstraint) { convertedConstraints.add(new ToscaPropertyConstraintEqual(((EqualConstraint) constraint).getEqual())); } @@ -260,10 +258,10 @@ public class PropertyConvertor { .convertDataTypeToToscaObject(innerType, dataTypes, innerConverter, isScalar, jsonElement, preserveEmptyValue); } return convertedValue; - + } catch (JsonParseException e) { log.trace("{} not parsable as JSON. Convert as YAML instead", value); - return new Yaml().load(value); + return new Yaml().load(value); } catch (Exception e) { log.debug("convertToToscaValue failed to parse json value :", e); return null; -- cgit 1.2.3-korg