From 7457ecefb624682f6dddc558111b1d38f2a2ca83 Mon Sep 17 00:00:00 2001 From: JvD_Ericsson Date: Thu, 19 Jan 2023 14:43:33 +0000 Subject: Fix ability to add property to data type of different model Issue-ID: SDC-4339 Signed-off-by: JvD_Ericsson Change-Id: Ibc5b57a042ffc4e7f914d46ad264a0e16081b863 --- .../org/openecomp/sdc/be/servlets/DataTypeServlet.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'catalog-be/src/main') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java index e081110486..8139237e38 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java @@ -144,6 +144,20 @@ public class DataTypeServlet extends BeGenericServlet { public Response createProperty(@Parameter(in = ParameterIn.PATH, required = true, description = "The data type id") @PathParam("id") final String id, @RequestBody(description = "Property to add", required = true) final PropertyDefinitionDto propertyDefinitionDto) { + Optional dataType = dataTypeOperation.getDataTypeByUid(id); + dataType.ifPresentOrElse(dt -> { + String model = dt.getModel(); + Optional propertyDataType = dataTypeOperation.getDataTypeByNameAndModel(propertyDefinitionDto.getType(), model); + if (propertyDataType.isEmpty()) { + if (model == null || model.isEmpty()) { + model = "SDC AID"; + } + throw new OperationException(ActionStatus.INVALID_MODEL, + String.format("Property model is not the same as the data type model. Must be be '%s'", model)); + } + }, () -> { + throw new OperationException(ActionStatus.DATA_TYPE_NOT_FOUND, String.format("Failed to find data type '%s'", id)); + }); final PropertyDefinitionDto property = dataTypeOperation.createProperty(id, propertyDefinitionDto); dataTypeBusinessLogic.updateApplicationDataTypeCache(id); return Response.status(Status.CREATED).entity(property).build(); -- cgit 1.2.3-korg