Search in sources :

Example 1 with ExecutionHeaderResponse

use of org.kie.kogito.trusty.service.common.responses.ExecutionHeaderResponse in project kogito-apps by kiegroup.

the class ExecutionsApiV1 method getExecutions.

/**
 * Gets all the headers of the executions that were evaluated within a specified time range.
 *
 * @param from The start datetime.
 * @param to The end datetime.
 * @param limit The maximum (non-negative) number of items to be returned.
 * @param offset The non-negative pagination offset.
 * @param prefix The executionId prefix to be matched in the search.
 * @return The execution headers that satisfy the time range, pagination and prefix conditions.
 */
@GET
@APIResponses(value = { @APIResponse(description = "Returns the execution headers.", responseCode = "200", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(type = SchemaType.OBJECT, implementation = ExecutionsResponse.class))), @APIResponse(description = "Bad Request", responseCode = "400", content = @Content(mediaType = MediaType.TEXT_PLAIN)) })
@Operation(summary = "Gets the execution headers", description = "Gets the execution headers.")
@Produces(MediaType.APPLICATION_JSON)
public Response getExecutions(@Parameter(name = "from", description = "Start datetime for the lookup. Date in the format \"yyyy-MM-dd'T'HH:mm:ssZ\"", required = false, schema = @Schema(implementation = String.class)) @DefaultValue("yesterday") @QueryParam("from") String from, @Parameter(name = "to", description = "End datetime for the lookup. Date in the format \"yyyy-MM-dd'T'HH:mm:ssZ\"", required = false, schema = @Schema(implementation = String.class)) @DefaultValue("now") @QueryParam("to") String to, @Parameter(name = "limit", description = "Maximum number of results to return.", required = false, schema = @Schema(implementation = Integer.class)) @DefaultValue("100") @QueryParam("limit") int limit, @Parameter(name = "offset", description = "Offset for the pagination.", required = false, schema = @Schema(implementation = Integer.class)) @DefaultValue("0") @QueryParam("offset") int offset, @Parameter(name = "search", description = "Execution ID prefix to be matched", required = false, schema = @Schema(implementation = String.class)) @DefaultValue("") @QueryParam("search") String prefix) {
    if (limit < 0 || offset < 0) {
        return Response.status(Response.Status.BAD_REQUEST.getStatusCode(), "Pagination parameters can not have negative values.").build();
    }
    OffsetDateTime fromDate;
    OffsetDateTime toDate;
    try {
        fromDate = parseParameterDate(from, true);
        toDate = parseParameterDate(to, false);
    } catch (DateTimeParseException e) {
        LOGGER.warn("Invalid date", e);
        return Response.status(Response.Status.BAD_REQUEST.getStatusCode(), "Date format should be yyyy-MM-dd'T'HH:mm:ssZ").build();
    }
    MatchedExecutionHeaders result = trustyService.getExecutionHeaders(fromDate, toDate, limit, offset, prefix);
    List<ExecutionHeaderResponse> headersResponses = new ArrayList<>();
    result.getExecutions().forEach(x -> headersResponses.add(ResponseUtils.executionHeaderResponseFrom(x)));
    return Response.ok(new ExecutionsResponse(result.getAvailableResults(), limit, offset, headersResponses)).build();
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) ExecutionHeaderResponse(org.kie.kogito.trusty.service.common.responses.ExecutionHeaderResponse) MatchedExecutionHeaders(org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders) OffsetDateTime(java.time.OffsetDateTime) ExecutionsResponse(org.kie.kogito.trusty.service.common.responses.ExecutionsResponse) ArrayList(java.util.ArrayList) 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

OffsetDateTime (java.time.OffsetDateTime)1 DateTimeParseException (java.time.format.DateTimeParseException)1 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 Operation (org.eclipse.microprofile.openapi.annotations.Operation)1 APIResponses (org.eclipse.microprofile.openapi.annotations.responses.APIResponses)1 MatchedExecutionHeaders (org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders)1 ExecutionHeaderResponse (org.kie.kogito.trusty.service.common.responses.ExecutionHeaderResponse)1 ExecutionsResponse (org.kie.kogito.trusty.service.common.responses.ExecutionsResponse)1