execute method

Future execute(
  1. String? correlationId,
  2. String commandName,
  3. Parameters args
)

Executes a ICommand commandspecificed by its name.

  • correlationId (optional) transaction id 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

/// - [correlationId] (optional) transaction id 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(
    String? correlationId, String commandName, Parameters args) async {
  var cref = findCommand(commandName);

  if (cref == null) {
    throw BadRequestException(
            correlationId, 'CMD_NOT_FOUND', 'Request command does not exist')
        .withDetails('command', commandName);
  }

  correlationId ??= IdGenerator.nextShort();

  var results = cref.validate(args);
  ValidationException.throwExceptionIfNeeded(correlationId, results, false);
  return await cref.execute(correlationId, args);
}