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());
}
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());
}
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();
}
Aggregations