Search in sources :

Example 21 with Link

use of io.swagger.v3.oas.models.links.Link in project atlasmap by atlasmap.

the class AtlasService method validateMappingRequest.

/**
 * Validates the mapping file.
 * @param mapping mapping
 * @param mappingDefinitionId mapping definition ID
 * @param uriInfo URI info
 * @return {@link Validations} validation result
 */
@PUT
@Path("/mapping/validate/{mappingDefinitionId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Validate Mapping", description = "Validate mapping file")
@RequestBody(description = "Mapping file content", content = @Content(schema = @Schema(implementation = AtlasMapping.class)))
@ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = Validations.class)), description = "Return a validation result"))
public Response validateMappingRequest(InputStream mapping, @Parameter(description = "Mapping ID") @PathParam("mappingDefinitionId") Integer mappingDefinitionId, @Context UriInfo uriInfo) {
    try {
        AtlasMapping atlasMapping = fromJson(mapping, AtlasMapping.class);
        LOG.debug("Validate mappings: {}", atlasMapping.getName());
        return validateMapping(mappingDefinitionId, atlasMapping, uriInfo);
    } catch (AtlasException | IOException e) {
        throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) AtlasException(io.atlasmap.api.AtlasException) 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)

Example 22 with Link

use of io.swagger.v3.oas.models.links.Link in project atlasmap by atlasmap.

the class AtlasService method listMappings.

/**
 * Retrieves a list of mapping file name saved with specified mapping definition ID.
 * @param uriInfo URI info
 * @param filter filter
 * @param mappingDefinitionId mapping definition ID
 * @return A list of mapping file name in {@link StringMap}
 */
@GET
@Path("/mappings/{mappingDefinitionId}")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "List Mappings", description = "Retrieves a list of mapping file name saved with specified mappingDefinitionId")
@ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = StringMap.class)), description = "Return a list of a pair of mapping file name and content"))
public Response listMappings(@Context UriInfo uriInfo, @QueryParam("filter") final String filter, @Parameter(description = "Mapping Definition ID") @PathParam("mappingDefinitionId") Integer mappingDefinitionId) {
    StringMap sMap = new StringMap();
    LOG.debug("listMappings with filter '{}'", filter);
    ADMArchiveHandler handler = loadExplodedMappingDirectory(mappingDefinitionId);
    AtlasMapping map = handler.getMappingDefinition();
    if (map == null) {
        return Response.ok().entity(toJson(sMap)).build();
    }
    StringMapEntry mapEntry = new StringMapEntry();
    mapEntry.setName(map.getName());
    UriBuilder builder = uriInfo.getBaseUriBuilder().path("v2").path("atlas").path("mapping").path(map.getName());
    mapEntry.setValue(builder.build().toString());
    sMap.getStringMapEntry().add(mapEntry);
    byte[] serialized = toJson(sMap);
    if (LOG.isDebugEnabled()) {
        LOG.debug(new String(serialized));
    }
    return Response.ok().entity(serialized).build();
}
Also used : StringMap(io.atlasmap.v2.StringMap) AtlasMapping(io.atlasmap.v2.AtlasMapping) StringMapEntry(io.atlasmap.v2.StringMapEntry) ADMArchiveHandler(io.atlasmap.core.ADMArchiveHandler) UriBuilder(javax.ws.rs.core.UriBuilder) 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 23 with Link

use of io.swagger.v3.oas.models.links.Link in project atlasmap by atlasmap.

the class AtlasService method processMappingRequest.

/**
 * Processes mapping by feeding input data.
 * @param request request
 * @param uriInfo URI info
 * @return {@link ProcessMappingResponse} which holds the result of the mappings
 */
@PUT
@Path("/mapping/process")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Process Mapping", description = "Process Mapping by feeding input data")
@RequestBody(description = "Mapping file content", content = @Content(schema = @Schema(implementation = AtlasMapping.class)))
@ApiResponses({ @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = ProcessMappingResponse.class)), description = "Return a mapping result"), @ApiResponse(responseCode = "204", description = "Skipped empty mapping execution") })
public Response processMappingRequest(InputStream request, @Context UriInfo uriInfo) {
    ProcessMappingRequest pmr = fromJson(request, ProcessMappingRequest.class);
    if (pmr.getAtlasMapping() != null) {
        throw new WebApplicationException("Whole mapping execution is not yet supported");
    }
    Mapping mapping = pmr.getMapping();
    if (mapping == null) {
        return Response.noContent().build();
    }
    Audits audits = null;
    try {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Preview request: {}", new String(toJson(mapping)));
        }
        audits = previewContext.processPreview(mapping);
    } catch (AtlasException e) {
        throw new WebApplicationException("Unable to process mapping preview", e);
    }
    ProcessMappingResponse response = new ProcessMappingResponse();
    response.setMapping(mapping);
    if (audits != null) {
        response.setAudits(audits);
    }
    byte[] serialized = toJson(response);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Preview outcome: {}", new String(serialized));
    }
    return Response.ok().entity(serialized).build();
}
Also used : Audits(io.atlasmap.v2.Audits) WebApplicationException(javax.ws.rs.WebApplicationException) ProcessMappingResponse(io.atlasmap.v2.ProcessMappingResponse) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) AtlasException(io.atlasmap.api.AtlasException) ProcessMappingRequest(io.atlasmap.v2.ProcessMappingRequest) 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)

Example 24 with Link

use of io.swagger.v3.oas.models.links.Link in project atlasmap by atlasmap.

the class AtlasService method listFieldActions.

/**
 * Retrieves a list of available field action.
 * @param uriInfo URI info
 * @return {@link ActionDetails} serialized to JSON
 */
@GET
@Path("/fieldActions")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "List FieldActions", description = "Retrieves a list of available field action")
@ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = ActionDetails.class)), description = "Return a list of field action detail"))
public Response listFieldActions(@Context UriInfo uriInfo) {
    ActionDetails details = new ActionDetails();
    if (atlasContextFactory == null || atlasContextFactory.getFieldActionService() == null) {
        return Response.ok().entity(toJson(details)).build();
    }
    details.getActionDetail().addAll(atlasContextFactory.getFieldActionService().listActionDetails());
    byte[] serialized = toJson(details);
    if (LOG.isDebugEnabled()) {
        LOG.debug(new String(serialized));
    }
    return Response.ok().entity(serialized).build();
}
Also used : ActionDetails(io.atlasmap.v2.ActionDetails) 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 25 with Link

use of io.swagger.v3.oas.models.links.Link in project atlasmap by atlasmap.

the class JsonService method inspect.

/**
 * Inspect a JSON schema or instance and return a Document object.
 * @param requestIn request
 * @return {@link JsonInspectionResponse}
 */
@POST
@Path("/inspect")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Inspect JSON", description = "Inspect a JSON schema or instance and return a Document object")
@RequestBody(description = "JsonInspectionRequest object", content = @Content(schema = @Schema(implementation = JsonInspectionRequest.class)))
@ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = JsonInspectionResponse.class)), description = "Return a Document object represented by JsonDocument"))
public Response inspect(InputStream requestIn) {
    JsonInspectionRequest request = fromJson(requestIn, JsonInspectionRequest.class);
    long startTime = System.currentTimeMillis();
    JsonInspectionResponse response = new JsonInspectionResponse();
    JsonDocument d = null;
    try {
        if (request.getType() == null || request.getJsonData() == null) {
            response.setErrorMessage("Json data and Instance or Schema inspection type must be specified in request");
        } else {
            JsonInspectionService s = new JsonInspectionService();
            String jsonData = cleanJsonData(request.getJsonData());
            if (!validJsonData(jsonData)) {
                response.setErrorMessage("Invalid json payload specified");
            } else {
                switch(request.getType()) {
                    case INSTANCE:
                        d = s.inspectJsonDocument(jsonData);
                        break;
                    case SCHEMA:
                        d = s.inspectJsonSchema(jsonData);
                        break;
                    default:
                        response.setErrorMessage("Unsupported inspection type: " + request.getType());
                        break;
                }
            }
        }
    } catch (Exception e) {
        LOG.error("Error inspecting json: " + e.getMessage(), e);
        response.setErrorMessage(e.getMessage());
    } finally {
        response.setExecutionTime(System.currentTimeMillis() - startTime);
    }
    AtlasUtil.excludeNotRequestedFields(d, request.getInspectPaths());
    response.setJsonDocument(d);
    return Response.ok().entity(toJson(response)).build();
}
Also used : JsonInspectionService(io.atlasmap.json.inspect.JsonInspectionService) JsonInspectionResponse(io.atlasmap.json.v2.JsonInspectionResponse) JsonInspectionRequest(io.atlasmap.json.v2.JsonInspectionRequest) JsonDocument(io.atlasmap.json.v2.JsonDocument) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) WebApplicationException(javax.ws.rs.WebApplicationException) 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)

Aggregations

Link (io.swagger.v3.oas.models.links.Link)18 OpenAPI (io.swagger.v3.oas.models.OpenAPI)14 Test (org.testng.annotations.Test)14 Operation (io.swagger.v3.oas.annotations.Operation)12 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)12 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)8 Schema (io.swagger.v3.oas.models.media.Schema)7 Path (javax.ws.rs.Path)7 Produces (javax.ws.rs.Produces)7 Components (io.swagger.v3.oas.models.Components)6 MediaType (io.swagger.v3.oas.models.media.MediaType)6 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)6 RefFormat (io.swagger.v3.parser.models.RefFormat)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 RequestBody (io.swagger.v3.oas.annotations.parameters.RequestBody)5 Operation (io.swagger.v3.oas.models.Operation)5 PathItem (io.swagger.v3.oas.models.PathItem)5 Example (io.swagger.v3.oas.models.examples.Example)5 StringSchema (io.swagger.v3.oas.models.media.StringSchema)5 Parameter (io.swagger.v3.oas.models.parameters.Parameter)5