From abbc25ad32db4f4c898bdaaea0b66c0a1d5fd8da Mon Sep 17 00:00:00 2001 From: franciscovila Date: Tue, 7 Feb 2023 17:00:03 +0000 Subject: Edit properties of non-normative data types Develop all necessary changes in the UI to allow editing of non-normative data types Issue-ID: SDC-4373 Signed-off-by: franciscovila Change-Id: I37749fd3d2992f3134a09c07bb43c0208ce12a23 --- .../openecomp/sdc/be/servlets/DataTypeServlet.java | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'catalog-be/src/main/java/org/openecomp') 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 0f6257157c..05c1fb7ad3 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 @@ -38,6 +38,7 @@ import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.HeaderParam; import javax.ws.rs.POST; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -169,6 +170,45 @@ public class DataTypeServlet extends BeGenericServlet { return Response.status(Status.CREATED).entity(property).build(); } + @PUT + @Path("{id}/properties") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Operation(summary = "Update a property in the given data type", method = "POST", description = "Update a property in the given data type", + responses = { + @ApiResponse(content = @Content(schema = @Schema(implementation = PropertyDefinitionDto.class))), + @ApiResponse(responseCode = "201", description = "Property updated in the data type"), + @ApiResponse(responseCode = "400", description = "Invalid payload"), + @ApiResponse(responseCode = "403", description = "Restricted operation"), + @ApiResponse(responseCode = "404", description = "Data type not found") + }) + @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) + public Response updateProperty(@Parameter(in = ParameterIn.PATH, required = true, description = "The data type id") + @PathParam("id") final String id, + @RequestBody(description = "Property to update", required = true) final PropertyDefinitionDto propertyDefinitionDto) { + Optional 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 propertyDataType = dataTypeOperation.getDataTypeByNameAndModel(propertyDefinitionDto.getType(), model); + if (propertyDataType.isEmpty()) { + if (StringUtils.isEmpty(model)) { + model = Constants.DEFAULT_MODEL_NAME; + } + throw new OperationException(ActionStatus.INVALID_MODEL, + String.format("Property model is not the same as the data type model. Must be '%s'", model)); + } + if (StringUtils.isEmpty(dataType.getModel())) { + dataType.setModel(Constants.DEFAULT_MODEL_NAME); + } + final PropertyDefinitionDto property = dataTypeOperation.updateProperty(id, propertyDefinitionDto); + dataTypeOperation.addPropertyToAdditionalTypeDataType(dataType, property); + dataTypeBusinessLogic.updateApplicationDataTypeCache(id); + return Response.status(Status.CREATED).entity(property).build(); + } + @GET @Path("{dataTypeName}/models") @Consumes(MediaType.APPLICATION_JSON) -- cgit 1.2.3-korg