Search in sources :

Example 11 with MatchedExecutionHeaders

use of org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders in project kogito-apps by kiegroup.

the class AbstractTrustyServiceIT method searchExecutionsByPrefixTest.

@Test
public void searchExecutionsByPrefixTest() {
    String executionId = "da8ad1e9-a679-4ded-a6d5-53fd019e7002";
    long executionTimestamp = 1617270053L;
    Instant instant = Instant.ofEpochMilli(executionTimestamp);
    storeExecution(executionId, executionTimestamp);
    MatchedExecutionHeaders executionHeaders = trustyService.getExecutionHeaders(OffsetDateTime.ofInstant(instant.minusMillis(1), ZoneOffset.UTC), OffsetDateTime.ofInstant(instant.plusMillis(1), ZoneOffset.UTC), 10, 0, "da8ad1e9-a679");
    Assertions.assertEquals(1, executionHeaders.getExecutions().size());
}
Also used : MatchedExecutionHeaders(org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders) Instant(java.time.Instant) Test(org.junit.jupiter.api.Test)

Example 12 with MatchedExecutionHeaders

use of org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders in project kogito-apps by kiegroup.

the class AbstractTrustyServiceIT method givenTwoExecutionsWhenThePrefixIsUsedThenOnlyOneExecutionIsReturned.

@Test
public void givenTwoExecutionsWhenThePrefixIsUsedThenOnlyOneExecutionIsReturned() {
    storeExecution("myExecution", 1591692950000L);
    storeExecution("executionId2", 1591692958000L);
    OffsetDateTime from = OffsetDateTime.ofInstant(Instant.ofEpochMilli(1591692940000L), ZoneOffset.UTC);
    OffsetDateTime to = OffsetDateTime.ofInstant(Instant.ofEpochMilli(1591692959000L), ZoneOffset.UTC);
    MatchedExecutionHeaders result = trustyService.getExecutionHeaders(from, to, 100, 0, "my");
    Assertions.assertEquals(1, result.getExecutions().size());
    Assertions.assertEquals("myExecution", result.getExecutions().get(0).getExecutionId());
}
Also used : MatchedExecutionHeaders(org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders) OffsetDateTime(java.time.OffsetDateTime) Test(org.junit.jupiter.api.Test)

Example 13 with MatchedExecutionHeaders

use of org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders 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

MatchedExecutionHeaders (org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders)13 Test (org.junit.jupiter.api.Test)11 OffsetDateTime (java.time.OffsetDateTime)8 ArrayList (java.util.ArrayList)8 QuarkusTest (io.quarkus.test.junit.QuarkusTest)4 Decision (org.kie.kogito.trusty.storage.api.model.decision.Decision)4 List (java.util.List)3 Storage (org.kie.kogito.persistence.api.Storage)3 Query (org.kie.kogito.persistence.api.query.Query)3 ExecutionsResponse (org.kie.kogito.trusty.service.common.responses.ExecutionsResponse)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 Instant (java.time.Instant)1 DateTimeParseException (java.time.format.DateTimeParseException)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 AttributeFilter (org.kie.kogito.persistence.api.query.AttributeFilter)1 ExecutionHeaderResponse (org.kie.kogito.trusty.service.common.responses.ExecutionHeaderResponse)1 Execution (org.kie.kogito.trusty.storage.api.model.Execution)1