summaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
authorJvD_Ericsson <jeff.van.dam@est.tech>2023-01-19 14:43:33 +0000
committerMichael Morris <michael.morris@est.tech>2023-01-23 15:44:25 +0000
commit7457ecefb624682f6dddc558111b1d38f2a2ca83 (patch)
tree52cbc05f95c23ac2c8d2b9be97a8ac19eec38ad3 /catalog-be/src
parent3da7d9867ab91b58f2a765d24731b45a3f43841c (diff)
Fix ability to add property to data type of different model
Issue-ID: SDC-4339 Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech> Change-Id: Ibc5b57a042ffc4e7f914d46ad264a0e16081b863
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java14
1 files changed, 14 insertions, 0 deletions
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<DataTypeDataDefinition> dataType = dataTypeOperation.getDataTypeByUid(id);
+ dataType.ifPresentOrElse(dt -> {
+ String model = dt.getModel();
+ Optional<DataTypeDataDefinition> 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();