diff options
author | franciscovila <javier.paradela.vila@est.tech> | 2023-01-31 14:24:02 +0000 |
---|---|---|
committer | Vasyl Razinkov <vasyl.razinkov@est.tech> | 2023-02-08 22:19:53 +0000 |
commit | c6cb16f234b8ae9de4aede3ca09a57e6ca177abe (patch) | |
tree | f14c9a73bb1f78a928b6a9d6ffe9cee289be947e /catalog-model/src/main/java/org | |
parent | 442784e34ef8cae76cca559a600f360dfdeee97e (diff) |
Constraints in data type view
Develop all necessary changes in the UI to allow managing data type constraints
Issue-ID: SDC-4331
Signed-off-by: franciscovila <javier.paradela.vila@est.tech>
Change-Id: I337438ba088e4f2f4978a1aff2408eda8157b892
Diffstat (limited to 'catalog-model/src/main/java/org')
3 files changed, 29 insertions, 6 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/dto/PropertyDefinitionDto.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/dto/PropertyDefinitionDto.java index 4144e1f5b6..79643aa560 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/dto/PropertyDefinitionDto.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/dto/PropertyDefinitionDto.java @@ -23,7 +23,6 @@ package org.openecomp.sdc.be.model.dto; import java.util.List; import lombok.Data; -import org.openecomp.sdc.be.model.PropertyConstraint; @Data public class PropertyDefinitionDto { @@ -36,6 +35,6 @@ public class PropertyDefinitionDto { private Boolean required; private Object value; private Object defaultValue; - private List<PropertyConstraint> constraints; + private List<Object> constraints; } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/mapper/PropertyDefinitionDtoMapper.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/mapper/PropertyDefinitionDtoMapper.java index 67600a5dbe..6e8134c9a5 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/mapper/PropertyDefinitionDtoMapper.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/mapper/PropertyDefinitionDtoMapper.java @@ -21,9 +21,14 @@ package org.openecomp.sdc.be.model.mapper; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; import com.google.gson.Gson; import java.util.ArrayList; import java.util.List; +import java.util.Map; import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.apache.commons.collections4.CollectionUtils; @@ -33,10 +38,15 @@ import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition; import org.openecomp.sdc.be.model.PropertyConstraint; import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.dto.PropertyDefinitionDto; +import org.openecomp.sdc.be.model.operations.impl.PropertyOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class PropertyDefinitionDtoMapper { + private static final Logger LOGGER = LoggerFactory.getLogger(PropertyDefinitionDtoMapper.class); + public static PropertyDefinition mapTo(final PropertyDefinitionDto propertyDefinitionDto) { final var propertyDefinition = new PropertyDefinition(); propertyDefinition.setUniqueId(propertyDefinitionDto.getUniqueId()); @@ -52,8 +62,23 @@ public class PropertyDefinitionDtoMapper { } if (CollectionUtils.isNotEmpty(propertyDefinitionDto.getConstraints())) { final List<PropertyConstraint> propertyConstraints = new ArrayList<>(); + + propertyDefinitionDto.getConstraints().forEach(rawConstraint -> { + ObjectMapper mapper = new ObjectMapper(); + + SimpleModule module = new SimpleModule("customDeserializationModule"); + module.addDeserializer(PropertyConstraint.class, new PropertyOperation.PropertyConstraintJacksonDeserializer()); + mapper.registerModule(module); + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + try { + PropertyConstraint constraint = + mapper.readValue(new Gson().toJson(rawConstraint, Map.class), PropertyConstraint.class); + propertyConstraints.add(constraint); + } catch (JsonProcessingException e) { + LOGGER.error("Could not parse constraint '{}' for property '{}'", rawConstraint, propertyDefinitionDto.getName()); + } + }); propertyDefinition.setConstraints(propertyConstraints); - propertyConstraints.addAll(propertyDefinitionDto.getConstraints()); } propertyDefinition.setDescription(propertyDefinitionDto.getDescription()); propertyDefinition.setValue(new Gson().toJson(propertyDefinitionDto.getValue())); @@ -71,9 +96,7 @@ public class PropertyDefinitionDtoMapper { propertyDefinitionDto.setRequired(propertyDefinition.getRequired()); propertyDefinitionDto.setSchemaType(propertyDefinition.getSchemaType()); if (CollectionUtils.isNotEmpty(propertyDefinition.getConstraints())) { - final List<PropertyConstraint> propertyConstraints = new ArrayList<>(); - propertyDefinitionDto.setConstraints(propertyConstraints); - propertyConstraints.addAll(propertyDefinition.getConstraints()); + propertyDefinitionDto.setConstraints(new ArrayList<>(propertyDefinition.getConstraints())); } propertyDefinitionDto.setValue(new Gson().fromJson(propertyDataDefinition.getValue(), Object.class)); propertyDefinitionDto.setDefaultValue(new Gson().fromJson(propertyDataDefinition.getDefaultValue(), Object.class)); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java index 103221cb76..bbc70f6c3f 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java @@ -277,6 +277,7 @@ public class DataTypeOperation extends AbstractOperation { final PropertyData propertyData = resultEither.left().value(); final PropertyDataDefinition propertyDataDefinition = propertyData.getPropertyDataDefinition(); propertyDataDefinition.setName(propertyName); + propertyDataDefinition.setPropertyConstraints(propertyData.getConstraints()); return PropertyDefinitionDtoMapper.mapFrom(propertyDataDefinition); } |