Search in sources :

Example 1 with CommandValidationError

use of io.spine.core.CommandValidationError in project core-java by SpineEventEngine.

the class CommandExpiredException method commandExpired.

/**
 * Creates an instance of the command expired error.
 */
static Error commandExpired(Command command) {
    final String format = "Scheduled command of type `%s` expired.";
    final CommandValidationError errorCode = CommandValidationError.EXPIRED;
    return createError(format, command, errorCode);
}
Also used : CommandValidationError(io.spine.core.CommandValidationError)

Example 2 with CommandValidationError

use of io.spine.core.CommandValidationError in project core-java by SpineEventEngine.

the class UnsupportedCommandException method unsupportedCommand.

/**
 * Creates an instance of unsupported command error.
 */
private static Error unsupportedCommand(Command command) {
    final String format = "Commands of the type `%s` are not supported.";
    final CommandValidationError errorCode = CommandValidationError.UNSUPPORTED_COMMAND;
    return createError(format, command, errorCode);
}
Also used : CommandValidationError(io.spine.core.CommandValidationError)

Example 3 with CommandValidationError

use of io.spine.core.CommandValidationError in project core-java by SpineEventEngine.

the class AbstractCommandBusTestSuite method checkCommandError.

static void checkCommandError(Ack sendingResult, CommandValidationError validationError, String errorType, Command cmd) {
    final Status status = sendingResult.getStatus();
    assertEquals(status.getStatusCase(), Status.StatusCase.ERROR);
    final CommandId commandId = cmd.getId();
    assertEquals(commandId, unpack(sendingResult.getMessageId()));
    final Error error = status.getError();
    assertEquals(errorType, error.getType());
    assertEquals(validationError.getNumber(), error.getCode());
    assertFalse(error.getMessage().isEmpty());
    if (validationError == INVALID_COMMAND) {
        assertFalse(error.getValidationError().getConstraintViolationList().isEmpty());
    }
}
Also used : Status(io.spine.core.Status) Error(io.spine.base.Error) CommandValidationError(io.spine.core.CommandValidationError) CommandId(io.spine.core.CommandId)

Example 4 with CommandValidationError

use of io.spine.core.CommandValidationError in project core-java by SpineEventEngine.

the class CommandException method createError.

protected static Error createError(String format, Command command, CommandValidationError errorCode) {
    final Message commandMessage = CommandEnvelope.of(command).getMessage();
    final String commandType = commandMessage.getDescriptorForType().getFullName();
    final String errMsg = format(format, commandType);
    final String descriptorName = CommandValidationError.getDescriptor().getFullName();
    final Error.Builder error = Error.newBuilder().setType(descriptorName).setMessage(errMsg).setCode(errorCode.getNumber()).putAllAttributes(commandTypeAttribute(commandMessage));
    return error.build();
}
Also used : Message(com.google.protobuf.Message) Error(io.spine.base.Error) CommandValidationError(io.spine.core.CommandValidationError)

Aggregations

CommandValidationError (io.spine.core.CommandValidationError)4 Error (io.spine.base.Error)2 Message (com.google.protobuf.Message)1 CommandId (io.spine.core.CommandId)1 Status (io.spine.core.Status)1