execute method
- IContext? context,
- String commandName,
- Parameters args
Executes a ICommand command
specificed by its name.
context
(optional) a context to trace execution through call chain.commandName
the name of that command that is to be executed.args
the parameters (arguments) to pass to the command for execution.- Returns execution result. If an exception is raised, then it will be throw the exeption (for example: a ValidationException can be thrown). See ICommand See Parameters
Implementation
/// - [context] (optional) a context to trace execution through call chain.
/// - [commandName] the name of that command that is to be executed.
/// - [args] the parameters (arguments) to pass to the command for execution.
/// - Returns execution result. If an exception is raised, then
/// it will be throw the exeption (for example: a ValidationException can be thrown).
/// See [ICommand]
/// See [Parameters]
Future<dynamic> execute(
IContext? context, String commandName, Parameters args) async {
var cref = findCommand(commandName);
var trace_id = context != null ? ContextResolver.getTraceId(context) : null;
if (cref == null) {
throw BadRequestException(
trace_id, 'CMD_NOT_FOUND', 'Request command does not exist')
.withDetails('command', commandName);
}
if (trace_id == null || trace_id.isEmpty) {
trace_id = IdGenerator.nextShort();
}
var results = cref.validate(args);
ValidationException.throwExceptionIfNeeded(trace_id, results, false);
return await cref.execute(context ?? Context.fromTraceId(trace_id), args);
}