Search in sources :

Example 6 with ApiResponses

use of io.swagger.v3.oas.models.responses.ApiResponses in project atlasmap by atlasmap.

the class AtlasService method getMappingRequest.

/**
 * Retrieve a mapping file saved on the server.
 * @param mappingFormat file type
 * @param mappingDefinitionId mapping definition ID
 * @return file
 */
@GET
@Path("/mapping/{mappingFormat}/{mappingDefinitionId}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_OCTET_STREAM })
@Operation(summary = "Get Mapping", description = "Retrieve a mapping file saved on the server")
@ApiResponses({ @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = AtlasMapping.class)), description = "Return a mapping file content"), @ApiResponse(responseCode = "204", description = "Mapping file was not found"), @ApiResponse(responseCode = "500", description = "Mapping file access error") })
public Response getMappingRequest(@Parameter(description = "Mapping Format") @PathParam("mappingFormat") MappingFileType mappingFormat, @Parameter(description = "Mapping ID") @PathParam("mappingDefinitionId") Integer mappingDefinitionId) {
    LOG.debug("getMappingRequest: {} '{}'", mappingFormat, mappingDefinitionId);
    ADMArchiveHandler admHandler = loadExplodedMappingDirectory(mappingDefinitionId);
    switch(mappingFormat) {
        case JSON:
            byte[] serialized = null;
            try {
                serialized = admHandler.getMappingDefinitionBytes();
            } catch (Exception e) {
                LOG.error("Error retrieving mapping definition file for ID:" + mappingDefinitionId, e);
                throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
            }
            if (LOG.isDebugEnabled() && serialized != null) {
                LOG.debug(new String(serialized));
            }
            if (serialized == null) {
                LOG.debug("Mapping definition not found for ID:{}", mappingDefinitionId);
                return Response.noContent().build();
            }
            return Response.ok().entity(serialized).build();
        case GZ:
            try {
                if (admHandler.getGzippedADMDigestBytes() == null) {
                    LOG.debug("ADM Digest file not found for ID:{}", mappingDefinitionId);
                    return Response.noContent().build();
                }
                return Response.ok().entity(admHandler.getGzippedADMDigestBytes()).build();
            } catch (Exception e) {
                LOG.error("Error getting compressed ADM digest file.\n" + e.getMessage(), e);
                throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
            }
        case ZIP:
            try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
                admHandler.setIgnoreLibrary(false);
                admHandler.setLibraryDirectory(Paths.get(this.libFolder));
                admHandler.export(out);
                return Response.ok().entity(out.toByteArray()).build();
            } catch (Exception e) {
                LOG.error("Error getting ADM archive file.\n" + e.getMessage(), e);
                throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
            }
        default:
            throw new WebApplicationException("Unrecognized mapping format: " + mappingFormat, Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ADMArchiveHandler(io.atlasmap.core.ADMArchiveHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) WebApplicationException(javax.ws.rs.WebApplicationException) AtlasException(io.atlasmap.api.AtlasException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 7 with ApiResponses

use of io.swagger.v3.oas.models.responses.ApiResponses in project atlasmap by atlasmap.

the class AtlasService method resetAllMappings.

/**
 * Removes all mapping files and catalogs saved on the server.
 * @return empty response
 */
@DELETE
@Path("/mapping/RESET/ALL")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Remove All Mappings", description = "Remove all mapping files and catalogs saved on the server")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "All mapping files were removed successfully"), @ApiResponse(responseCode = "204", description = "Unable to remove all mapping files") })
public Response resetAllMappings() {
    LOG.debug("resetAllMappings");
    java.nio.file.Path mappingFolderPath = Paths.get(mappingFolder);
    File mappingFolderPathFile = mappingFolderPath.toFile();
    if (mappingFolderPathFile == null || !mappingFolderPathFile.exists()) {
        return Response.ok().build();
    }
    AtlasUtil.deleteDirectoryContents(mappingFolderPathFile);
    return Response.ok().build();
}
Also used : File(java.io.File) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 8 with ApiResponses

use of io.swagger.v3.oas.models.responses.ApiResponses in project atlasmap by atlasmap.

the class AtlasService method listMappingBuilderClasses.

/**
 * List mapping builder classes which defines custom mapping logic.
 * @param uriInfo URI info
 * @return class names
 */
@GET
@Path("/mappingBuilders")
@Operation(summary = "List mapping builder classes", description = "List mapping builder classes which defines custom mapping logic")
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(type = "ArrayList<String>")), description = "Return a list of loadable class names"))
public Response listMappingBuilderClasses(@Context UriInfo uriInfo) {
    ArrayList<String> classNames;
    try {
        classNames = libraryLoader.getSubTypesOf(AtlasMappingBuilder.class, false);
    } catch (Exception e) {
        if (LOG.isDebugEnabled()) {
            LOG.error("Library class retrieval error.", e);
        }
        throw new WebApplicationException("Error retrieving class names from uploaded JARs.");
    }
    byte[] serialized = toJson(classNames);
    if (LOG.isDebugEnabled()) {
        LOG.debug(new String(serialized));
    }
    return Response.ok().entity(serialized).build();
}
Also used : AtlasMappingBuilder(io.atlasmap.api.AtlasMappingBuilder) WebApplicationException(javax.ws.rs.WebApplicationException) WebApplicationException(javax.ws.rs.WebApplicationException) AtlasException(io.atlasmap.api.AtlasException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 9 with ApiResponses

use of io.swagger.v3.oas.models.responses.ApiResponses in project atlasmap by atlasmap.

the class AtlasService method updateMappingRequest.

/**
 * Updates existing mapping file on the server.
 * @param mapping mapping
 * @param mappingDefinitionId mapping definition ID
 * @param uriInfo URI info
 * @return empty response
 */
@POST
@Path("/mapping/{mappingDefinitionId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Update Mapping", description = "Update existing mapping file on the server")
@RequestBody(description = "Mapping file content", content = @Content(schema = @Schema(implementation = AtlasMapping.class)))
@ApiResponses(@ApiResponse(responseCode = "200", description = "Succeeded"))
public Response updateMappingRequest(InputStream mapping, @Parameter(description = "Mapping Definition ID") @PathParam("mappingDefinitionId") Integer mappingDefinitionId, @Context UriInfo uriInfo) {
    ADMArchiveHandler handler = loadExplodedMappingDirectory(mappingDefinitionId);
    UriBuilder builder = uriInfo.getAbsolutePathBuilder();
    try {
        handler.setMappingDefinitionBytes(mapping);
        handler.persist();
        builder.path(handler.getMappingDefinition().getName());
    } catch (AtlasException e) {
        LOG.error("Error saving Mapping Definition file.\n" + e.getMessage(), e);
        throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
    }
    return Response.ok().location(builder.build()).build();
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ADMArchiveHandler(io.atlasmap.core.ADMArchiveHandler) UriBuilder(javax.ws.rs.core.UriBuilder) AtlasException(io.atlasmap.api.AtlasException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses) RequestBody(io.swagger.v3.oas.annotations.parameters.RequestBody)

Example 10 with ApiResponses

use of io.swagger.v3.oas.models.responses.ApiResponses in project atlasmap by atlasmap.

the class AtlasService method createMappingRequest.

/**
 * Saves a file on the server.
 * @param mapping request payload
 * @param mappingFormat file type
 * @param mappingDefinitionId mapping definition ID
 * @param uriInfo URI info
 * @return empty response
 */
@PUT
@Path("/mapping/{mappingFormat}/{mappingDefinitionId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_OCTET_STREAM })
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Create Mapping", description = "Save a mapping file on the server")
@RequestBody(description = "Mapping file content", content = @Content(schema = @Schema(implementation = AtlasMapping.class)))
@ApiResponses({ @ApiResponse(responseCode = "200", description = "Succeeded"), @ApiResponse(responseCode = "500", description = "Mapping file save error") })
public Response createMappingRequest(InputStream mapping, @Parameter(description = "Mapping Format") @PathParam("mappingFormat") MappingFileType mappingFormat, @Parameter(description = "Mapping ID") @PathParam("mappingDefinitionId") Integer mappingDefinitionId, @Context UriInfo uriInfo) {
    LOG.debug("createMappingRequest (save) with format '{}'", mappingFormat);
    UriBuilder builder = uriInfo.getAbsolutePathBuilder();
    ADMArchiveHandler admHandler = loadExplodedMappingDirectory(mappingDefinitionId);
    switch(mappingFormat) {
        case JSON:
            try {
                admHandler.setMappingDefinitionBytes(mapping);
                admHandler.persist();
                if (admHandler.getMappingDefinition() != null) {
                    builder.path(admHandler.getMappingDefinition().getName());
                }
            } catch (AtlasException e) {
                LOG.error("Error saving Mapping Definition file.\n" + e.getMessage(), e);
                throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
            }
            return Response.ok().location(builder.build()).build();
        case GZ:
            LOG.debug("  saveGzippedADMDigestRequest '{}' - ID: {}", admHandler.getGzippedADMDigestFileName(), mappingDefinitionId);
            try {
                admHandler.setGzippedADMDigest(mapping);
                admHandler.persist();
            } catch (AtlasException e) {
                LOG.error("Error saving gzipped ADM digest file.\n" + e.getMessage(), e);
                throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
            }
            builder.path(admHandler.getGzippedADMDigestFileName());
            return Response.ok().location(builder.build()).build();
        case ZIP:
            LOG.debug("  importADMArchiveRequest - ID:'{}'", mappingDefinitionId);
            try {
                admHandler.setIgnoreLibrary(false);
                admHandler.setLibraryDirectory(Paths.get(libFolder));
                admHandler.load(mapping);
                this.libraryLoader.reload();
                admHandler.persist();
                LOG.debug("  importADMArchiveRequest complete - ID:'{}'", mappingDefinitionId);
            } catch (Exception e) {
                LOG.error("Error importing ADM archive.\n" + e.getMessage(), e);
                throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
            }
            builder.path("atlasmap-" + mappingDefinitionId + ".adm");
            return Response.ok().location(builder.build()).build();
        case XML:
            throw new WebApplicationException("XML mapping format is no longer supported. Please use JSON format instead.");
        default:
            throw new WebApplicationException("Unrecognized mapping format: " + mappingFormat, Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ADMArchiveHandler(io.atlasmap.core.ADMArchiveHandler) UriBuilder(javax.ws.rs.core.UriBuilder) AtlasException(io.atlasmap.api.AtlasException) WebApplicationException(javax.ws.rs.WebApplicationException) AtlasException(io.atlasmap.api.AtlasException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Operation(io.swagger.v3.oas.annotations.Operation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses) RequestBody(io.swagger.v3.oas.annotations.parameters.RequestBody)

Aggregations

Operation (io.swagger.v3.oas.annotations.Operation)99 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)99 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)48 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)47 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)47 Operation (io.swagger.v3.oas.models.Operation)39 PathItem (io.swagger.v3.oas.models.PathItem)35 OpenAPI (io.swagger.v3.oas.models.OpenAPI)34 Test (org.testng.annotations.Test)31 ArrayList (java.util.ArrayList)23 Schema (io.swagger.v3.oas.models.media.Schema)22 Content (io.swagger.v3.oas.models.media.Content)21 StringSchema (io.swagger.v3.oas.models.media.StringSchema)21 MediaType (io.swagger.v3.oas.models.media.MediaType)20 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)19 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)17 Path (javax.ws.rs.Path)17 Produces (javax.ws.rs.Produces)17 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)16 Components (io.swagger.v3.oas.models.Components)10