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 --- .../openecomp/sdc/be/servlets/DataTypeServlet.java | 28 +++++++++++++++++++++- .../servlets/exception/DefaultExceptionMapper.java | 9 +++---- 2 files changed, 32 insertions(+), 5 deletions(-) (limited to 'catalog-be/src/main/java') 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(); } } -- cgit 1.2.3-korg