Search in sources :

Example 26 with ConstraintViolation

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

the class EventValidator method validate.

@Override
public Optional<MessageInvalid> validate(EventEnvelope envelope) {
    checkNotNull(envelope);
    final Event event = envelope.getOuterObject();
    MessageInvalid result = null;
    final List<ConstraintViolation> violations = messageValidator.validate(event);
    if (!violations.isEmpty()) {
        result = onConstraintViolations(event, violations);
    }
    return Optional.fromNullable(result);
}
Also used : ConstraintViolation(io.spine.validate.ConstraintViolation) Event(io.spine.core.Event) MessageInvalid(io.spine.core.MessageInvalid)

Example 27 with ConstraintViolation

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

the class CommandValidator method isCommandValid.

private Optional<MessageInvalid> isCommandValid(CommandEnvelope envelope) {
    final Command command = envelope.getCommand();
    final List<ConstraintViolation> violations = inspect(envelope);
    InvalidCommandException exception = null;
    if (!violations.isEmpty()) {
        exception = onConstraintViolations(command, violations);
        commandBus.commandStore().storeWithError(command, exception);
    }
    return Optional.<MessageInvalid>fromNullable(exception);
}
Also used : Command(io.spine.core.Command) ConstraintViolation(io.spine.validate.ConstraintViolation) MessageInvalid(io.spine.core.MessageInvalid)

Aggregations

ConstraintViolation (io.spine.validate.ConstraintViolation)27 Test (org.junit.Test)18 Command (io.spine.core.Command)5 Command (io.spine.base.Command)4 Any (com.google.protobuf.Any)2 MessageInvalid (io.spine.core.MessageInvalid)2 CustomMessageRequiredStringFieldValue (io.spine.test.validate.msg.CustomMessageRequiredStringFieldValue)2 RequiredStringFieldValue (io.spine.test.validate.msg.RequiredStringFieldValue)2 Optional (com.google.common.base.Optional)1 ImmutableList (com.google.common.collect.ImmutableList)1 ByteString (com.google.protobuf.ByteString)1 Message (com.google.protobuf.Message)1 ProtocolMessageEnum (com.google.protobuf.ProtocolMessageEnum)1 CommandContext (io.spine.base.CommandContext)1 CommandId (io.spine.base.CommandId)1 Error (io.spine.base.Error)1 Identifiers.idToString (io.spine.base.Identifiers.idToString)1 Event (io.spine.core.Event)1 EnclosedMessageFieldValue (io.spine.test.validate.msg.EnclosedMessageFieldValue)1 MaxNumberFieldValue (io.spine.test.validate.msg.MaxNumberFieldValue)1