Remove ControlBusController.getCommandsForBean
The extra REST API to get commands for specific bean does not make sense. Exactly same data can be extracted from the JSON returned by the `getCommands` REST API
This commit is contained in:
@@ -82,33 +82,6 @@ public class ControlBusController implements BeanFactoryAware, InitializingBean
|
||||
.toList();
|
||||
}
|
||||
|
||||
@GetMapping(name = "getCommandsForBean", path = "/{beanName}")
|
||||
public ControlBusBean getCommandsForBean(@PathVariable String beanName) {
|
||||
Map<ControlBusCommandRegistry.CommandMethod, String> commandsForBean =
|
||||
this.controlBusCommandRegistry.getCommands()
|
||||
.get(beanName);
|
||||
|
||||
return createControlBusBean(beanName, commandsForBean);
|
||||
}
|
||||
|
||||
private ControlBusBean createControlBusBean(String beanName,
|
||||
Map<ControlBusCommandRegistry.CommandMethod, String> commandsForBean) {
|
||||
|
||||
List<ControlBusCommand> commands =
|
||||
commandsForBean.keySet()
|
||||
.stream()
|
||||
.map(this::converControlBusCommand)
|
||||
.toList();
|
||||
|
||||
return new ControlBusBean(beanName, commands);
|
||||
}
|
||||
|
||||
private ControlBusCommand converControlBusCommand(ControlBusCommandRegistry.CommandMethod commandMethod) {
|
||||
return new ControlBusCommand(commandMethod.getBeanName() + '.' + commandMethod.getMethodName(),
|
||||
commandMethod.getDescription(),
|
||||
Arrays.asList(commandMethod.getParameterTypes()));
|
||||
}
|
||||
|
||||
@PostMapping(name = "invokeCommand", path = "/{command}")
|
||||
public Object invokeCommand(@PathVariable String command,
|
||||
@RequestBody(required = false) List<CommandArgument> arguments) {
|
||||
@@ -133,6 +106,24 @@ public class ControlBusController implements BeanFactoryAware, InitializingBean
|
||||
return commandExpression.getValue(this.evaluationContext, parameterValues);
|
||||
}
|
||||
|
||||
private static ControlBusBean createControlBusBean(String beanName,
|
||||
Map<ControlBusCommandRegistry.CommandMethod, String> commandsForBean) {
|
||||
|
||||
List<ControlBusCommand> commands =
|
||||
commandsForBean.keySet()
|
||||
.stream()
|
||||
.map(ControlBusController::converControlBusCommand)
|
||||
.toList();
|
||||
|
||||
return new ControlBusBean(beanName, commands);
|
||||
}
|
||||
|
||||
private static ControlBusCommand converControlBusCommand(ControlBusCommandRegistry.CommandMethod commandMethod) {
|
||||
return new ControlBusCommand(commandMethod.getBeanName() + '.' + commandMethod.getMethodName(),
|
||||
commandMethod.getDescription(),
|
||||
Arrays.asList(commandMethod.getParameterTypes()));
|
||||
}
|
||||
|
||||
public record ControlBusBean(String beanName, List<ControlBusCommand> commands) {
|
||||
|
||||
}
|
||||
|
||||
@@ -83,18 +83,6 @@ public class ControlBusControllerTests {
|
||||
.andExpect(content().string(Matchers.containsString("The overloaded operation with two arguments")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void commandsForBean() throws Exception {
|
||||
this.mockMvc.perform(get("/control-bus/testManagementComponent")
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||
.andExpect(handler().handlerType(ControlBusController.class))
|
||||
.andExpect(handler().methodName("getCommandsForBean"))
|
||||
.andExpect(content().string(Matchers.containsString("testManagementComponent.operation")))
|
||||
.andExpect(content().string(Matchers.containsString("testManagementComponent.operation2")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void controlBusCommandIsPerformedOverRestCall() throws Exception {
|
||||
this.mockMvc.perform(post("/control-bus/testManagementComponent.operation")
|
||||
|
||||
@@ -69,8 +69,6 @@ The `/control-bus` GET request returns all the control bus commands for the appl
|
||||
Essentially, a JSON-serialized list of `ControlBusController.ControlBusBean` instances.
|
||||
Each entry is a bean with a list of control bus eligible methods (see `ControlBusMethodFilter` for more information) with their parameter types and description from the `@ManagedOperation` or `@ManagedAttribute` (falls back to method name otherwise).
|
||||
|
||||
The GET method of this REST controller for `/control-bus/\{beanName}` returns commands for specific bean.
|
||||
|
||||
The POST method to `/control-bus/{beanName.methodName}` invokes the command.
|
||||
The body of the request may contain a list of values and their types for command to execute.
|
||||
For example, the `operation` command with `int` argument for the class:
|
||||
|
||||
Reference in New Issue
Block a user