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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations