Search in sources :

Example 36 with CommandEnvelope

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

the class DuplicateCommandException method of.

/**
 * Creates an exception for a duplicate command.
 *
 * @param command the duplicate command
 * @return a newly constructed instance
 */
public static DuplicateCommandException of(Command command) {
    final CommandEnvelope envelope = CommandEnvelope.of(command);
    final Message commandMessage = envelope.getMessage();
    final String errorMessage = aggregateErrorMessage(envelope);
    final Error error = error(commandMessage, errorMessage);
    return new DuplicateCommandException(errorMessage, command, error);
}
Also used : Message(com.google.protobuf.Message) CommandEnvelope(io.spine.core.CommandEnvelope) Error(io.spine.base.Error) CommandValidationError(io.spine.core.CommandValidationError)

Example 37 with CommandEnvelope

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

the class InvalidCommandException method onInapplicableTenantId.

public static InvalidCommandException onInapplicableTenantId(Command command) {
    final CommandEnvelope cmd = CommandEnvelope.of(command);
    final TypeName typeName = TypeName.of(cmd.getMessage());
    final String errMsg = format("The command (class: %s, type: %s, id: %s) was posted to single-tenant " + "CommandBus, but has tenant_id: %s attribute set in the command context.", cmd.getMessageClass(), typeName, cmd.getId(), cmd.getTenantId());
    final Error error = inapplicableTenantError(cmd.getMessage(), errMsg);
    return new InvalidCommandException(errMsg, command, error);
}
Also used : TypeName(io.spine.type.TypeName) CommandEnvelope(io.spine.core.CommandEnvelope) Error(io.spine.base.Error) CommandValidationError(io.spine.core.CommandValidationError)

Example 38 with CommandEnvelope

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

the class InvalidCommandException method onMissingTenantId.

/**
 * Creates an exception for a command with missing {@code tenant_id} attribute in
 * the {@code CommandContext}, which is required in a multitenant application.
 */
public static InvalidCommandException onMissingTenantId(Command command) {
    final CommandEnvelope envelope = CommandEnvelope.of(command);
    final Message commandMessage = envelope.getMessage();
    final String errMsg = format("The command (class: `%s`, type: `%s`, id: `%s`) is posted to " + "multitenant Command Bus, but has no `tenant_id` attribute in the context.", CommandClass.of(commandMessage).value().getName(), TypeName.of(commandMessage), Identifier.toString(envelope.getId()));
    final Error error = unknownTenantError(commandMessage, errMsg);
    return new InvalidCommandException(errMsg, command, error);
}
Also used : Message(com.google.protobuf.Message) CommandEnvelope(io.spine.core.CommandEnvelope) Error(io.spine.base.Error) CommandValidationError(io.spine.core.CommandValidationError)

Example 39 with CommandEnvelope

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

the class Rescheduler method onScheduledCommandExpired.

/**
 * Sets the status of the expired command to error.
 *
 * <p>We cannot post such a command because there is no handler or dispatcher registered yet.
 * Or, posting such a command may be undesirable from the business logic point of view.
 *
 * @param command the expired command
 * @see CommandExpiredException
 */
private void onScheduledCommandExpired(Command command) {
    final CommandEnvelope commandEnvelope = CommandEnvelope.of(command);
    final Message msg = commandEnvelope.getMessage();
    final CommandId id = commandEnvelope.getId();
    final Error error = CommandExpiredException.commandExpired(command);
    commandStore().setToError(commandEnvelope, error);
    log().errorExpiredCommand(msg, id);
}
Also used : Message(com.google.protobuf.Message) CommandEnvelope(io.spine.core.CommandEnvelope) Error(io.spine.base.Error) CommandId(io.spine.core.CommandId)

Example 40 with CommandEnvelope

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

the class TestEventFactory method newInstance.

public static TestEventFactory newInstance(Any producerId, TestActorRequestFactory requestFactory) {
    checkNotNull(requestFactory);
    final CommandEnvelope cmd = requestFactory.generateEnvelope();
    return new TestEventFactory(cmd, producerId, 1);
}
Also used : CommandEnvelope(io.spine.core.CommandEnvelope)

Aggregations

CommandEnvelope (io.spine.core.CommandEnvelope)40 Test (org.junit.Test)25 Command (io.spine.core.Command)11 Message (com.google.protobuf.Message)7 Error (io.spine.base.Error)5 TestActorRequestFactory (io.spine.client.TestActorRequestFactory)4 StringValue (com.google.protobuf.StringValue)3 CommandValidationError (io.spine.core.CommandValidationError)3 Event (io.spine.core.Event)3 BoundedContext (io.spine.server.BoundedContext)3 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)3 CommandId (io.spine.core.CommandId)2 Commands.getMessage (io.spine.core.Commands.getMessage)2 TypeConverter.toMessage (io.spine.protobuf.TypeConverter.toMessage)2 CommandBus (io.spine.server.commandbus.CommandBus)2 HandlerMethodFailedException (io.spine.server.model.HandlerMethodFailedException)2 AggCreateProject (io.spine.test.aggregate.command.AggCreateProject)2 ProjectId (io.spine.test.procman.ProjectId)2 TypeName (io.spine.type.TypeName)2 Set (java.util.Set)2