Search in sources :

Example 16 with APIResponses

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

the class ExistenceBean method holdingExists.

@Timed
@GET
@Path("holdingsitem/{agencyId : \\d+}:{bibliographicRecordId : .+}")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Check if a agency has a 'live' holdings for a bibliographic item", description = "This operation checks for a given agency/item," + " and returns if a holding is retrievable for it.")
@APIResponses({ @APIResponse(name = "Success", responseCode = "200", description = "A holding for the given agency/item has been checked", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(ref = ExistsResponse.NAME))) })
@Parameters({ @Parameter(name = "agencyId", description = "The agency that should own the record", required = true), @Parameter(name = "bibliographicRecordId", description = "The id of the record", required = true) })
public ExistsResponse holdingExists(@PathParam("agencyId") Integer agencyId, @PathParam("bibliographicRecordId") String bibliographicRecordId) {
    log.info("Checking existence of holdings item {}:{}", agencyId, bibliographicRecordId);
    ExistsResponse response = new ExistsResponse();
    HoldingsItemEntity entity = entityManager.find(HoldingsItemEntity.class, new AgencyItemKey(agencyId, bibliographicRecordId));
    response.exists = entity != null;
    return response;
}
Also used : AgencyItemKey(dk.dbc.search.solrdocstore.jpa.AgencyItemKey) HoldingsItemEntity(dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity) ExistsResponse(dk.dbc.search.solrdocstore.response.ExistsResponse) 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 17 with APIResponses

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

the class ExistenceBean method bibliographicExists.

@Timed
@GET
@Path("bibliographicitem/{agencyId : \\d+}-{classifier : \\w+}:{bibliographicRecordId : .+}")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Check if a manifestation-id has a 'live' record", description = "This operation checks for a given identifier," + " and returns if a document is retrievable for it.")
@APIResponses({ @APIResponse(name = "Success", responseCode = "200", description = "An item for the given manifestation-id has been checked", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(ref = ExistsResponse.NAME))) })
@Parameters({ @Parameter(name = "agencyId", description = "The agency that should own the record", required = true), @Parameter(name = "classifier", description = "The classifier of the records (usually basis or katalog)", required = true), @Parameter(name = "bibliographicRecordId", description = "The id of the record", required = true) })
public ExistsResponse bibliographicExists(@PathParam("agencyId") Integer agencyId, @PathParam("classifier") String classifier, @PathParam("bibliographicRecordId") String bibliographicRecordId) {
    log.info("Checking existence of bibliographic item {}-{}:{}", agencyId, classifier, bibliographicRecordId);
    ExistsResponse response = new ExistsResponse();
    BibliographicEntity entity = entityManager.find(BibliographicEntity.class, new AgencyClassifierItemKey(agencyId, classifier, bibliographicRecordId));
    if (entity == null) {
        response.exists = false;
    } else {
        response.exists = !entity.isDeleted();
    }
    return response;
}
Also used : BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) AgencyClassifierItemKey(dk.dbc.search.solrdocstore.jpa.AgencyClassifierItemKey) ExistsResponse(dk.dbc.search.solrdocstore.response.ExistsResponse) 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 18 with APIResponses

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

the class ResourceBean method putResource.

@PUT
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Path("{fieldName}/{agencyId}:{bibliographicRecordId}")
@Operation(operationId = "add/update-resource", summary = "Adds/updates/removes a resource to/from an item", description = "This operation sets/removes the resource and connected" + " manifestations item, are queued.")
@APIResponses({ @APIResponse(name = "Success", responseCode = "200", description = "Resource has been added", ref = StatusResponse.NAME) })
@RequestBody(ref = BibliographicResourceSchemaAnnotated.NAME)
public Response putResource(String jsonContent, @PathParam("fieldName") String fieldName, @PathParam("agencyId") Integer agencyId, @PathParam("bibliographicRecordId") String bibliographicRecordId, @QueryParam("trackingId") String trackingId) throws JSONBException {
    if (trackingId == null || trackingId.isEmpty())
        trackingId = UUID.randomUUID().toString();
    try (LogWith logWith = track(trackingId)) {
        ResourceRestRequest request = jsonbContext.unmarshall(jsonContent, ResourceRestRequest.class);
        BibliographicResourceEntity resource = new BibliographicResourceEntity(agencyId, bibliographicRecordId, fieldName, request.getHas());
        log.debug("PUT resource: {}", resource);
        return storeResource(resource);
    }
}
Also used : LogWith(dk.dbc.log.LogWith) ResourceRestRequest(dk.dbc.search.solrdocstore.request.ResourceRestRequest) BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) Path(javax.ws.rs.Path) 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) PUT(javax.ws.rs.PUT) RequestBody(org.eclipse.microprofile.openapi.annotations.parameters.RequestBody)

Example 19 with APIResponses

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

the class ResourceBean method deleteResource.

@DELETE
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Path("{fieldName}/{agencyId}:{bibliographicRecordId}")
@Operation(operationId = "delete-resource", summary = "Removes a resource to an item", description = "This operation removed the resource and queues old connected" + " manifestations item, if any.")
@APIResponses({ @APIResponse(name = "Success", responseCode = "200", description = "Resource has been added", ref = StatusResponse.NAME) })
@RequestBody(ref = BibliographicResourceSchemaAnnotated.NAME)
public Response deleteResource(@PathParam("fieldName") String fieldName, @PathParam("agencyId") Integer agencyId, @PathParam("bibliographicRecordId") String bibliographicRecordId, @QueryParam("trackingId") String trackingId) throws JSONBException {
    if (trackingId == null || trackingId.isEmpty())
        trackingId = UUID.randomUUID().toString();
    try (LogWith logWith = track(trackingId)) {
        BibliographicResourceEntity resource = new BibliographicResourceEntity(agencyId, bibliographicRecordId, fieldName, false);
        log.debug("DELETE resource: {}", resource);
        return storeResource(resource);
    }
}
Also used : LogWith(dk.dbc.log.LogWith) BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) 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 20 with APIResponses

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

the class QueueBean method queueManifestation.

@GET
@Produces({ MediaType.APPLICATION_JSON })
@Path("manifestation/{ agencyId : \\d+}-{ classifier : \\w+ }:{ bibliographicRecordId : .+}")
@Operation(summary = "Queue a manifestation", description = "This operation puts a manifestation," + " and optionally (if it isn't deleted) its work on queue.")
@APIResponses({ @APIResponse(name = "Success", responseCode = "200", description = "The manifestation 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 manifestation", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(ref = StatusResponse.NAME))) })
@Parameters({ @Parameter(name = "agencyId", description = "The agency that owns the record", required = true), @Parameter(name = "classifier", description = "The classifier of the records (usually basis or katalog)", required = true), @Parameter(name = "bibliographicRecordId", description = "The id of the record", required = true), @Parameter(name = "trackingId", description = "For tracking the request", required = false) })
@Timed
public Response queueManifestation(@PathParam("agencyId") Integer agencyId, @PathParam("classifier") String classifier, @PathParam("bibliographicRecordId") String bibliographicRecordId, @QueryParam("trackingId") String trackingId) {
    if (trackingId == null || trackingId.isEmpty())
        trackingId = UUID.randomUUID().toString();
    String pid = agencyId + "-" + classifier + ":" + bibliographicRecordId;
    try (LogWith logWith = LogWith.track(trackingId).pid(pid)) {
        AgencyClassifierItemKey bibliographicKey = new AgencyClassifierItemKey(agencyId, classifier, bibliographicRecordId);
        BibliographicEntity biblEntity = entityManager.find(BibliographicEntity.class, bibliographicKey);
        if (biblEntity == null) {
            return Response.status(Response.Status.NOT_FOUND).entity(new StatusResponse("No such manifestation")).build();
        }
        EnqueueCollector enqueueCollector = enqueueSupplier.getEnqueueCollector();
        if (biblEntity.isDeleted()) {
            enqueueCollector.add(biblEntity, QueueType.ENDPOINT);
        } else {
            enqueueCollector.add(biblEntity, QueueType.ENDPOINT, QueueType.WORKENDPOINT);
        }
        enqueueCollector.commit();
        return Response.ok(new StatusResponse()).build();
    } catch (SQLException ex) {
        log.error("Error queueing: {}: {}", pid, ex.getMessage());
        log.debug("Error queueing: {}: ", pid, 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) AgencyClassifierItemKey(dk.dbc.search.solrdocstore.jpa.AgencyClassifierItemKey) 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)

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