Search in sources :

Example 1 with APIResponses

use of org.eclipse.microprofile.openapi.annotations.responses.APIResponses in project solr-document-store by DBCDK.

the class ResourceBean method addResource.

@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Path("add")
@Operation(operationId = "add-resource", summary = "Adds a resource to an item", description = "This operation sets the resource and connect" + " it to a number of manifestations item, if possible.")
@APIResponses({ @APIResponse(name = "Success", responseCode = "200", description = "Resource has been added", ref = StatusResponse.NAME) })
@RequestBody(ref = BibliographicResourceSchemaAnnotated.NAME)
public Response addResource(String jsonContent) throws JSONBException {
    try (LogWith logWith = track(UUID.randomUUID().toString())) {
        AddResourceRequest request = jsonbContext.unmarshall(jsonContent, AddResourceRequest.class);
        // Add resource
        BibliographicResourceEntity resource = request.asBibliographicResource();
        log.debug("POST resource: {}", resource);
        return storeResource(resource);
    }
}
Also used : LogWith(dk.dbc.log.LogWith) BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) AddResourceRequest(dk.dbc.search.solrdocstore.request.AddResourceRequest) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Operation(org.eclipse.microprofile.openapi.annotations.Operation) RequestBody(org.eclipse.microprofile.openapi.annotations.parameters.RequestBody)

Example 2 with APIResponses

use of org.eclipse.microprofile.openapi.annotations.responses.APIResponses in project solr-document-store by DBCDK.

the class QueueBean method queueWork.

@GET
@Produces({ MediaType.APPLICATION_JSON })
@Path("work/{ workId : work:\\d+ }")
@Timed
@Operation(summary = "Queue a manifestation", description = "This operation puts a work and its manifestations on queue.")
@APIResponses({ @APIResponse(name = "Success", responseCode = "200", description = "The work was found, and put onto the queue", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(ref = StatusResponse.NAME))), @APIResponse(name = "Not Found", responseCode = "404", description = "There's no such work", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(ref = StatusResponse.NAME))) })
@Parameters({ @Parameter(name = "workId", description = "The (corepo-)id of the work", required = true), @Parameter(name = "trackingId", description = "For tracking the request", required = false) })
public Response queueWork(@PathParam("workId") String workId, @QueryParam("trackingId") String trackingId) {
    if (trackingId == null || trackingId.isEmpty())
        trackingId = UUID.randomUUID().toString();
    try (LogWith logWith = LogWith.track(trackingId).pid(workId)) {
        List<BibliographicEntity> biblEntitys = BibliographicEntity.fetchByWork(entityManager, workId);
        if (biblEntitys.isEmpty()) {
            return Response.status(Response.Status.NOT_FOUND).entity(new StatusResponse("No such work")).build();
        }
        EnqueueCollector enqueueCollector = enqueueSupplier.getEnqueueCollector();
        biblEntitys.forEach(biblEntity -> enqueueCollector.add(biblEntity, QueueType.ENDPOINT, QueueType.WORKENDPOINT));
        enqueueCollector.commit();
        return Response.ok(new StatusResponse()).build();
    } catch (SQLException ex) {
        log.error("Error queueing: {}: {}", workId, ex.getMessage());
        log.debug("Error queueing: {}: ", workId, ex);
        return Response.serverError().entity(new StatusResponse(ex.getMessage())).build();
    }
}
Also used : LogWith(dk.dbc.log.LogWith) SQLException(java.sql.SQLException) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) StatusResponse(dk.dbc.search.solrdocstore.response.StatusResponse) EnqueueCollector(dk.dbc.search.solrdocstore.enqueue.EnqueueCollector) Path(javax.ws.rs.Path) Parameters(org.eclipse.microprofile.openapi.annotations.parameters.Parameters) Produces(javax.ws.rs.Produces) Timed(org.eclipse.microprofile.metrics.annotation.Timed) GET(javax.ws.rs.GET) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Operation(org.eclipse.microprofile.openapi.annotations.Operation)

Example 3 with APIResponses

use of org.eclipse.microprofile.openapi.annotations.responses.APIResponses in project narayana by jbosstm.

the class Coordinator method getLRAInfo.

@GET
@Path("{LraId}")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Obtain the information about an LRA as a JSON structure")
@APIResponses({ @APIResponse(responseCode = "200", description = "The LRA exists and the information is packed as JSON in the content body.", content = @Content(schema = @Schema(implementation = LRAData.class)), headers = { @Header(ref = LRAConstants.NARAYANA_LRA_API_VERSION_HEADER_NAME) }), @APIResponse(responseCode = "404", description = "The coordinator has no knowledge of this LRA", content = @Content(schema = @Schema(implementation = String.class))), @APIResponse(responseCode = "417", description = "The requested version provided in HTTP Header is not supported by this end point", content = @Content(schema = @Schema(implementation = String.class))) })
public Response getLRAInfo(@Parameter(name = "LraId", description = "The unique identifier of the LRA", required = true) @PathParam("LraId") String lraId, @Parameter(ref = LRAConstants.NARAYANA_LRA_API_VERSION_HEADER_NAME) @HeaderParam(LRAConstants.NARAYANA_LRA_API_VERSION_HEADER_NAME) @DefaultValue(CURRENT_API_VERSION_STRING) String version) {
    URI lraIdURI = toURI(lraId);
    LRAData lraData = lraService.getLRA(lraIdURI);
    return Response.status(OK).entity(lraData).header(NARAYANA_LRA_API_VERSION_HEADER_NAME, version).build();
}
Also used : URI(java.net.URI) LRAData(io.narayana.lra.LRAData) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Operation(org.eclipse.microprofile.openapi.annotations.Operation)

Example 4 with APIResponses

use of org.eclipse.microprofile.openapi.annotations.responses.APIResponses in project narayana by jbosstm.

the class Coordinator method getLRAStatus.

@GET
@Path("{LraId}/status")
@Produces(MediaType.TEXT_PLAIN)
@Operation(summary = "Obtain the status of an LRA as a string")
@APIResponses({ @APIResponse(responseCode = "200", description = "The LRA exists. The status is reported in the content body.", content = @Content(schema = @Schema(implementation = String.class)), headers = { @Header(ref = LRAConstants.NARAYANA_LRA_API_VERSION_HEADER_NAME) }), @APIResponse(responseCode = "404", description = "The coordinator has no knowledge of this LRA", content = @Content(schema = @Schema(implementation = String.class))), @APIResponse(responseCode = "417", description = "The requested version provided in HTTP Header is not supported by this end point", content = @Content(schema = @Schema(implementation = String.class))) })
public Response getLRAStatus(@Parameter(name = "LraId", description = "The unique identifier of the LRA." + "Expecting to be a valid URL where the participant can be contacted at. If not in URL format it will be considered " + "to be an id which will be declared to exist at URL where coordinator is deployed at.", required = true) @PathParam("LraId") String lraId, @Parameter(ref = LRAConstants.NARAYANA_LRA_API_VERSION_HEADER_NAME) @HeaderParam(LRAConstants.NARAYANA_LRA_API_VERSION_HEADER_NAME) @DefaultValue(CURRENT_API_VERSION_STRING) String version) throws NotFoundException {
    // throws NotFoundException -> response 404
    LongRunningAction transaction = lraService.getTransaction(toURI(lraId));
    LRAStatus status = transaction.getLRAStatus();
    if (status == null) {
        status = LRAStatus.Active;
    }
    return Response.ok().entity(status.name()).header(NARAYANA_LRA_API_VERSION_HEADER_NAME, version).build();
}
Also used : LRAStatus(org.eclipse.microprofile.lra.annotation.LRAStatus) LongRunningAction(io.narayana.lra.coordinator.domain.model.LongRunningAction) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Operation(org.eclipse.microprofile.openapi.annotations.Operation)

Example 5 with APIResponses

use of org.eclipse.microprofile.openapi.annotations.responses.APIResponses in project narayana by jbosstm.

the class Coordinator method getAllLRAs.

@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Returns all LRAs", description = "Gets both active and recovering LRAs")
@APIResponses({ @APIResponse(responseCode = "200", description = "The LRAData json array which is known to coordinator", content = @Content(schema = @Schema(type = SchemaType.ARRAY, implementation = LRAData.class)), headers = { @Header(ref = LRAConstants.NARAYANA_LRA_API_VERSION_HEADER_NAME) }), @APIResponse(responseCode = "400", description = "Provided Status is not recognized as a valid LRA status value", content = @Content(schema = @Schema(implementation = String.class)), headers = { @Header(ref = LRAConstants.NARAYANA_LRA_API_VERSION_HEADER_NAME) }), @APIResponse(responseCode = "417", description = "The requested version provided in HTTP Header is not supported by this end point", content = @Content(schema = @Schema(implementation = String.class))) })
public Response getAllLRAs(@Parameter(name = STATUS_PARAM_NAME, description = "Filter the returned LRAs to only those in the give state (see CompensatorStatus)") @QueryParam(STATUS_PARAM_NAME) @DefaultValue("") String state, @Parameter(ref = LRAConstants.NARAYANA_LRA_API_VERSION_HEADER_NAME) @HeaderParam(LRAConstants.NARAYANA_LRA_API_VERSION_HEADER_NAME) @DefaultValue(CURRENT_API_VERSION_STRING) String version) {
    LRAStatus requestedLRAStatus = null;
    if (!state.isEmpty()) {
        try {
            requestedLRAStatus = LRAStatus.valueOf(state);
        } catch (IllegalArgumentException e) {
            String errorMsg = "Status " + state + " is not a valid LRAStatus value";
            LRALogger.logger.debugf(errorMsg);
            throw new WebApplicationException(errorMsg, e, Response.status(BAD_REQUEST).header(NARAYANA_LRA_API_VERSION_HEADER_NAME, version).entity(errorMsg).build());
        }
    }
    List<LRAData> lras = lraService.getAll(requestedLRAStatus);
    return Response.ok().entity(lras).header(NARAYANA_LRA_API_VERSION_HEADER_NAME, version).build();
}
Also used : LRAStatus(org.eclipse.microprofile.lra.annotation.LRAStatus) WebApplicationException(javax.ws.rs.WebApplicationException) LRAData(io.narayana.lra.LRAData) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Operation(org.eclipse.microprofile.openapi.annotations.Operation)

Aggregations

APIResponses (org.eclipse.microprofile.openapi.annotations.responses.APIResponses)28 Operation (org.eclipse.microprofile.openapi.annotations.Operation)27 Path (javax.ws.rs.Path)25 Produces (javax.ws.rs.Produces)22 GET (javax.ws.rs.GET)15 ProcessInstanceNotFoundException (io.automatiko.engine.api.workflow.ProcessInstanceNotFoundException)8 POST (javax.ws.rs.POST)8 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)7 APIResponse (org.eclipse.microprofile.openapi.annotations.responses.APIResponse)7 AbstractProcessInstance (io.automatiko.engine.workflow.AbstractProcessInstance)6 Optional (java.util.Optional)6 DELETE (javax.ws.rs.DELETE)6 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)6 LogWith (dk.dbc.log.LogWith)5 JsonExportedProcessInstance (io.automatiko.engine.addons.process.management.model.JsonExportedProcessInstance)5 ArchivedProcessInstance (io.automatiko.engine.api.workflow.ArchivedProcessInstance)5 ProcessImageNotFoundException (io.automatiko.engine.api.workflow.ProcessImageNotFoundException)5 URI (java.net.URI)5 Consumes (javax.ws.rs.Consumes)5 WebApplicationException (javax.ws.rs.WebApplicationException)5