From 5e71c18416adc5c136ea9053a6bbac819da18c60 Mon Sep 17 00:00:00 2001 From: "andre.schmid" Date: Wed, 12 Oct 2022 18:14:23 +0100 Subject: Implement create data type property MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allows to add a new data type property and visualize the properties details. Change-Id: Ib7bcd4b0bd8213dbe8ee8a3762a0636e22dc67eb Issue-ID: SDC-4258 Signed-off-by: André Schmid --- .../files/default/error-configuration.yaml | 15 +++++++++++- .../openecomp/sdc/be/servlets/DataTypeServlet.java | 28 +++++++++++++++++++++- .../servlets/exception/DefaultExceptionMapper.java | 9 +++---- .../main/resources/config/error-configuration.yaml | 14 +++++++++++ .../config/catalog-be/error-configuration.yaml | 22 ++++++++++++++++- 5 files changed, 81 insertions(+), 7 deletions(-) (limited to 'catalog-be') diff --git a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml index 75f8904519..4be1cbab66 100644 --- a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml +++ b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml @@ -2833,4 +2833,17 @@ errors: DATA_TYPE_NOT_FOUND: code: 404 message: "Data type '%1' was not found." - messageId: "SVC4011" \ No newline at end of file + messageId: "SVC4011" + + # %1 - The data type Uid + # %2 - The property name + DATA_TYPE_PROPERTY_ALREADY_EXISTS: + code: 409 + message: "Data type '%1' property '%2' already exists." + messageId: "SVC4012" + + # %1 - The operation that the error occurred + UNEXPECTED_ERROR: + code: 500 + message: "An unexpected error occurred while %1." + messageId: "SVC4013" 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 e39e0d2c0d..711ebcbd9c 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 @@ -22,9 +22,12 @@ package org.openecomp.sdc.be.servlets; import com.jcabi.aspects.Loggable; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.servers.Server; import io.swagger.v3.oas.annotations.tags.Tag; @@ -41,6 +44,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; import org.openecomp.sdc.be.components.impl.aaf.AafPermission; import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed; import org.openecomp.sdc.be.config.BeEcompErrorManager; @@ -114,9 +118,31 @@ public class DataTypeServlet extends BeGenericServlet { @ApiResponse(responseCode = "403", description = "Restricted operation"), @ApiResponse(responseCode = "404", description = "Data type not found")}) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) - public Response fetchProperties(@PathParam("id") final String id) { + public Response fetchProperties(@Parameter(in = ParameterIn.PATH, required = true, description = "The data type id") + @PathParam("id") final String id) { final List allProperties = dataTypeOperation.findAllProperties(id); return buildOkResponse(allProperties); } + @POST + @Path("{id}/properties") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Operation(summary = "Create a property in the given data type", method = "POST", description = "Create a property in the given data type", + responses = { + @ApiResponse(content = @Content(schema = @Schema(implementation = PropertyDefinitionDto.class))), + @ApiResponse(responseCode = "201", description = "Property created in the data type"), + @ApiResponse(responseCode = "400", description = "Invalid payload"), + @ApiResponse(responseCode = "409", description = "Property already exists in the data type"), + @ApiResponse(responseCode = "403", description = "Restricted operation"), + @ApiResponse(responseCode = "404", description = "Data type not found") + }) + @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) + 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) { + final PropertyDefinitionDto property = dataTypeOperation.createProperty(id, propertyDefinitionDto); + return Response.status(Status.CREATED).entity(property).build(); + } + } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/exception/DefaultExceptionMapper.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/exception/DefaultExceptionMapper.java index 6b161f9d4e..a2a8659b71 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/exception/DefaultExceptionMapper.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/exception/DefaultExceptionMapper.java @@ -23,18 +23,19 @@ import javax.ws.rs.core.Response; import javax.ws.rs.ext.ExceptionMapper; import javax.ws.rs.ext.Provider; import org.eclipse.jetty.http.HttpStatus; -import org.openecomp.sdc.common.log.wrappers.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @Component @Provider public class DefaultExceptionMapper implements ExceptionMapper { - private static final Logger log = Logger.getLogger(DefaultExceptionMapper.class); + private static final Logger LOGGER = LoggerFactory.getLogger(DefaultExceptionMapper.class); @Override - public Response toResponse(Exception exception) { - log.debug("#toResponse - An error occurred: ", exception); + public Response toResponse(final Exception exception) { + LOGGER.error("An unhandled error has occurred", exception); return Response.status(HttpStatus.INTERNAL_SERVER_ERROR_500).entity(exception.getMessage()).build(); } } diff --git a/catalog-be/src/main/resources/config/error-configuration.yaml b/catalog-be/src/main/resources/config/error-configuration.yaml index 0830dda7b4..ee5f7fa836 100644 --- a/catalog-be/src/main/resources/config/error-configuration.yaml +++ b/catalog-be/src/main/resources/config/error-configuration.yaml @@ -2834,3 +2834,17 @@ errors: code: 404 message: "Data type '%1' was not found." messageId: "SVC4011" + + # %1 - The data type Uid + # %2 - The property name + DATA_TYPE_PROPERTY_ALREADY_EXISTS: + code: 409 + message: "Data type '%1' property '%2' already exists." + messageId: "SVC4012" + + # %1 - The operation that the error occurred + UNEXPECTED_ERROR: + code: 500 + message: "An unexpected error occurred while %1." + messageId: "SVC4013" + diff --git a/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml b/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml index d31d4a6203..ad40131f28 100644 --- a/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml +++ b/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml @@ -2820,4 +2820,24 @@ errors: CAPABILITY_NOT_FOUND_IN_COMPONENT: code: 400 message: "Capability '%1' not found in '%2' '%3'." - messageId: "SVC4186" \ No newline at end of file + messageId: "SVC4186" + + # %1 - The data type Uid + DATA_TYPE_NOT_FOUND: + code: 404 + message: "Data type '%1' was not found." + messageId: "SVC4011" + + # %1 - The data type Uid + # %2 - The property name + DATA_TYPE_PROPERTY_ALREADY_EXISTS: + code: 409 + message: "Data type '%1' property '%2' already exists." + messageId: "SVC4012" + + # %1 - The operation that the error occurred + UNEXPECTED_ERROR: + code: 500 + message: "An unexpected error occurred while %1." + messageId: "SVC4013" + -- cgit 1.2.3-korg