[REST] allow running rules with context (#3160)

Signed-off-by: Jan N. Klug <github@klug.nrw>
pull/3211/head
J-N-K 2022-12-11 00:01:46 +01:00 committed by GitHub
parent 5e6770749e
commit 6479e4f818
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -312,19 +312,20 @@ public class RuleResource implements RESTResource {
@POST
@RolesAllowed({ Role.USER, Role.ADMIN })
@Path("/{ruleUID}/runnow")
@Consumes(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_JSON)
@Operation(operationId = "runRuleNow", summary = "Executes actions of the rule.", responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Rule corresponding to the given UID does not found.") })
public Response runNow(@PathParam("ruleUID") @Parameter(description = "ruleUID") String ruleUID)
public Response runNow(@PathParam("ruleUID") @Parameter(description = "ruleUID") String ruleUID,
@Nullable @Parameter(description = "the context for running this rule") Map<String, Object> context)
throws IOException {
Rule rule = ruleRegistry.get(ruleUID);
if (rule == null) {
logger.info("Received HTTP PUT request for run now at '{}' for the unknown rule '{}'.", uriInfo.getPath(),
logger.info("Received HTTP POST request for run now at '{}' for the unknown rule '{}'.", uriInfo.getPath(),
ruleUID);
return Response.status(Status.NOT_FOUND).build();
} else {
ruleManager.runNow(ruleUID);
ruleManager.runNow(ruleUID, false, context);
return Response.ok().build();
}
}