diff options
author | franciscovila <javier.paradela.vila@est.tech> | 2023-02-07 17:00:03 +0000 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2023-02-09 19:17:04 +0000 |
commit | abbc25ad32db4f4c898bdaaea0b66c0a1d5fd8da (patch) | |
tree | a760d6e5495b797a8ee28acc42a83439e9b1a68f /catalog-be/src/main/java | |
parent | be850f6e83cbaa5c16f79c2c8732583f42e55429 (diff) |
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 <javier.paradela.vila@est.tech>
Change-Id: I37749fd3d2992f3134a09c07bb43c0208ce12a23
Diffstat (limited to 'catalog-be/src/main/java')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java | 40 |
1 files changed, 40 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 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<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 (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) |