Search in sources :

Example 1 with Parameters

use of org.eclipse.microprofile.openapi.annotations.parameters.Parameters 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 2 with Parameters

use of org.eclipse.microprofile.openapi.annotations.parameters.Parameters in project policies-ui-backend by RedHatInsights.

the class PolicyCrudService method getPoliciesForCustomer.

@Operation(summary = "Return all policies for a given account")
@GET
@Path("/")
@Parameters({ @Parameter(name = "offset", in = ParameterIn.QUERY, description = "Page number, starts 0, if not specified uses 0.", schema = @Schema(type = SchemaType.INTEGER)), @Parameter(name = "limit", in = ParameterIn.QUERY, description = "Number of items per page, if not specified uses 50. " + Pager.NO_LIMIT + " can be used to specify an unlimited page, when specified it ignores the offset", schema = @Schema(type = SchemaType.INTEGER)), @Parameter(name = "sortColumn", in = ParameterIn.QUERY, description = "Column to sort the results by", schema = @Schema(type = SchemaType.STRING, enumeration = { "name", "description", "is_enabled", "mtime" })), @Parameter(name = "sortDirection", in = ParameterIn.QUERY, description = "Sort direction used", schema = @Schema(type = SchemaType.STRING, enumeration = { "asc", "desc" })), @Parameter(name = "filter[name]", in = ParameterIn.QUERY, description = "Filtering policies by the name depending on the Filter operator used.", schema = @Schema(type = SchemaType.STRING)), @Parameter(name = "filter:op[name]", in = ParameterIn.QUERY, description = "Operations used with the filter", schema = @Schema(type = SchemaType.STRING, enumeration = { "equal", "like", "ilike", "not_equal" }, defaultValue = "equal")), @Parameter(name = "filter[description]", in = ParameterIn.QUERY, description = "Filtering policies by the description depending on the Filter operator used.", schema = @Schema(type = SchemaType.STRING)), @Parameter(name = "filter:op[description]", in = ParameterIn.QUERY, description = "Operations used with the filter", schema = @Schema(type = SchemaType.STRING, enumeration = { "equal", "like", "ilike", "not_equal" }, defaultValue = "equal")), @Parameter(name = "filter[is_enabled]", in = ParameterIn.QUERY, description = "Filtering policies by the is_enabled field." + "Defaults to true if no operand is given.", schema = @Schema(type = SchemaType.STRING, defaultValue = "true", enumeration = { "true", "false" })) })
@APIResponse(responseCode = "400", description = "Bad parameter for sorting was passed")
@APIResponse(responseCode = "404", description = "No policies found for customer")
@APIResponse(responseCode = "403", description = "Individual permissions missing to complete action")
@APIResponse(responseCode = "200", description = "Policies found", content = @Content(schema = @Schema(implementation = PagedResponseOfPolicy.class)), headers = @Header(name = "TotalCount", description = "Total number of items found", schema = @Schema(type = SchemaType.INTEGER)))
public Response getPoliciesForCustomer() {
    if (!user.canReadPolicies()) {
        return Response.status(Response.Status.FORBIDDEN).entity(new Msg(MISSING_PERMISSIONS_TO_RETRIEVE_POLICIES)).build();
    }
    Page<Policy> page;
    try {
        Pager pager = PagingUtils.extractPager(uriInfo);
        page = Policy.pagePoliciesForCustomer(entityManager, user.getAccount(), pager);
        for (Policy policy : page) {
            Long lastTriggerTime = policiesHistoryRepository.getLastTriggerTime(user.getAccount(), policy.id);
            if (lastTriggerTime != null) {
                policy.setLastTriggered(lastTriggerTime);
            }
        }
    } catch (IllegalArgumentException iae) {
        return Response.status(400, iae.getLocalizedMessage()).build();
    }
    return PagingUtils.responseBuilder(page).build();
}
Also used : Msg(com.redhat.cloud.policies.app.model.Msg) Policy(com.redhat.cloud.policies.app.model.Policy) Pager(com.redhat.cloud.policies.app.model.pager.Pager) Path(javax.ws.rs.Path) APIResponse(org.eclipse.microprofile.openapi.annotations.responses.APIResponse) Parameters(org.eclipse.microprofile.openapi.annotations.parameters.Parameters) GET(javax.ws.rs.GET) Operation(org.eclipse.microprofile.openapi.annotations.Operation)

Example 3 with Parameters

use of org.eclipse.microprofile.openapi.annotations.parameters.Parameters in project policies-ui-backend by RedHatInsights.

the class PolicyCrudService method getPolicyIdsForCustomer.

@Operation(summary = "Return all policy ids for a given account after applying the filters")
@GET
@Path("/ids")
@Parameters({ @Parameter(name = "filter[name]", in = ParameterIn.QUERY, description = "Filtering policies by the name depending on the Filter operator used.", schema = @Schema(type = SchemaType.STRING)), @Parameter(name = "filter:op[name]", in = ParameterIn.QUERY, description = "Operations used with the filter", schema = @Schema(type = SchemaType.STRING, enumeration = { "equal", "like", "ilike", "not_equal" }, defaultValue = "equal")), @Parameter(name = "filter[description]", in = ParameterIn.QUERY, description = "Filtering policies by the description depending on the Filter operator used.", schema = @Schema(type = SchemaType.STRING)), @Parameter(name = "filter:op[description]", in = ParameterIn.QUERY, description = "Operations used with the filter", schema = @Schema(type = SchemaType.STRING, enumeration = { "equal", "like", "ilike", "not_equal" }, defaultValue = "equal")), @Parameter(name = "filter[is_enabled]", in = ParameterIn.QUERY, description = "Filtering policies by the is_enabled field." + "Defaults to true if no operand is given.", schema = @Schema(type = SchemaType.STRING, defaultValue = "true", enumeration = { "true", "false" })) })
@APIResponse(responseCode = "400", description = "Bad parameter for sorting was passed")
@APIResponse(responseCode = "404", description = "No policies found for customer")
@APIResponse(responseCode = "403", description = "Individual permissions missing to complete action")
@APIResponse(responseCode = "200", description = "PolicyIds found", content = @Content(schema = @Schema(type = SchemaType.ARRAY, implementation = UUID.class)))
public Response getPolicyIdsForCustomer() {
    if (!user.canReadPolicies()) {
        return Response.status(Response.Status.FORBIDDEN).entity(new Msg(MISSING_PERMISSIONS_TO_RETRIEVE_POLICIES)).build();
    }
    List<UUID> uuids;
    try {
        Pager pager = PagingUtils.extractPager(uriInfo);
        uuids = Policy.getPolicyIdsForCustomer(entityManager, user.getAccount(), pager);
    } catch (IllegalArgumentException iae) {
        return Response.status(400, iae.getLocalizedMessage()).build();
    }
    return Response.ok(uuids).build();
}
Also used : Msg(com.redhat.cloud.policies.app.model.Msg) Pager(com.redhat.cloud.policies.app.model.pager.Pager) UUID(java.util.UUID) Path(javax.ws.rs.Path) APIResponse(org.eclipse.microprofile.openapi.annotations.responses.APIResponse) Parameters(org.eclipse.microprofile.openapi.annotations.parameters.Parameters) GET(javax.ws.rs.GET) Operation(org.eclipse.microprofile.openapi.annotations.Operation)

Example 4 with Parameters

use of org.eclipse.microprofile.openapi.annotations.parameters.Parameters 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 5 with Parameters

use of org.eclipse.microprofile.openapi.annotations.parameters.Parameters 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)

Aggregations

GET (javax.ws.rs.GET)7 Path (javax.ws.rs.Path)7 Operation (org.eclipse.microprofile.openapi.annotations.Operation)7 Parameters (org.eclipse.microprofile.openapi.annotations.parameters.Parameters)7 Produces (javax.ws.rs.Produces)4 Timed (org.eclipse.microprofile.metrics.annotation.Timed)4 APIResponses (org.eclipse.microprofile.openapi.annotations.responses.APIResponses)4 Msg (com.redhat.cloud.policies.app.model.Msg)3 Pager (com.redhat.cloud.policies.app.model.pager.Pager)3 BibliographicEntity (dk.dbc.search.solrdocstore.jpa.BibliographicEntity)3 APIResponse (org.eclipse.microprofile.openapi.annotations.responses.APIResponse)3 Policy (com.redhat.cloud.policies.app.model.Policy)2 LogWith (dk.dbc.log.LogWith)2 EnqueueCollector (dk.dbc.search.solrdocstore.enqueue.EnqueueCollector)2 AgencyClassifierItemKey (dk.dbc.search.solrdocstore.jpa.AgencyClassifierItemKey)2 ExistsResponse (dk.dbc.search.solrdocstore.response.ExistsResponse)2 StatusResponse (dk.dbc.search.solrdocstore.response.StatusResponse)2 SQLException (java.sql.SQLException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 AgencyItemKey (dk.dbc.search.solrdocstore.jpa.AgencyItemKey)1