diff options
Diffstat (limited to 'catalog-be/src/main')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java | 25 |
1 files changed, 13 insertions, 12 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 a7327bf184..13e2ba3259 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,21 +144,22 @@ 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)); - } - }, () -> { + Optional<DataTypeDataDefinition> dataTypeOptional = dataTypeOperation.getDataTypeByUid(id); + dataTypeOptional.orElseThrow(() -> { throw new OperationException(ActionStatus.DATA_TYPE_NOT_FOUND, String.format("Failed to find data type '%s'", id)); }); + DataTypeDataDefinition dataType = dataTypeOptional.get(); + String model = dataType.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)); + } final PropertyDefinitionDto property = dataTypeOperation.createProperty(id, propertyDefinitionDto); + dataTypeOperation.addPropertyToAdditionalTypeDataType(dataType, property); dataTypeBusinessLogic.updateApplicationDataTypeCache(id); return Response.status(Status.CREATED).entity(property).build(); } |