use of io.spine.base.CommandContext in project core-java by SpineEventEngine.
the class CommandTestUtil method checkRecord.
static void checkRecord(CommandRecord record, Command cmd, CommandStatus statusExpected) {
final CommandContext context = cmd.getContext();
final CommandId commandId = cmd.getId();
final CreateProject message = unpack(cmd.getMessage());
assertEquals(cmd.getMessage(), record.getCommand().getMessage());
assertTrue(record.getTimestamp().getSeconds() > 0);
assertEquals(message.getClass().getSimpleName(), record.getCommandType());
assertEquals(commandId, record.getCommandId());
assertEquals(statusExpected, record.getStatus().getCode());
assertEquals(context, record.getCommand().getContext());
switch(statusExpected) {
case RECEIVED:
case OK:
case SCHEDULED:
assertTrue(isDefault(record.getStatus().getError()));
assertTrue(isDefault(record.getStatus().getFailure()));
break;
case ERROR:
assertTrue(isNotDefault(record.getStatus().getError()));
break;
case FAILURE:
assertTrue(isNotDefault(record.getStatus().getFailure()));
break;
case UNDEFINED:
case UNRECOGNIZED:
break;
}
}
use of io.spine.base.CommandContext in project core-java by SpineEventEngine.
the class Validator method validate.
/**
* Validates a command checking that its required fields are valid and
* validates a command message according to Spine custom protobuf options.
*
* @param envelope a command to validate
* @return constraint violations found
*/
List<ConstraintViolation> validate(CommandEnvelope envelope) {
final ImmutableList.Builder<ConstraintViolation> result = ImmutableList.builder();
final Message message = envelope.getMessage();
final CommandContext context = envelope.getCommandContext();
final CommandId id = envelope.getCommandId();
validateCommandId(id, result);
validateMessage(message, result);
validateContext(context, result);
validateTargetId(message, result);
return result.build();
}
use of io.spine.base.CommandContext in project core-java by SpineEventEngine.
the class ProcessManagerRepository method dispatchCommand.
/**
* Dispatches the command to a corresponding process manager.
*
* <p>If there is no stored process manager with such an ID,
* a new process manager is created and stored after it handles the passed command.
*
* @param envelope a request to dispatch
* @see CommandHandlingEntity#dispatchCommand(CommandEnvelope)
*/
@Override
public void dispatchCommand(CommandEnvelope envelope) {
final Message commandMessage = envelope.getMessage();
final CommandContext context = envelope.getCommandContext();
final CommandClass commandClass = envelope.getMessageClass();
checkCommandClass(commandClass);
final I id = getIdFromCommandMessage.apply(commandMessage, context);
final P manager = findOrCreate(id);
final ProcManTransaction<?, ?, ?> tx = beginTransactionFor(manager);
final List<Event> events = manager.dispatchCommand(envelope);
store(manager);
tx.commit();
postEvents(events);
}
use of io.spine.base.CommandContext in project core-java by SpineEventEngine.
the class TestEventFactory method newInstance.
public static TestEventFactory newInstance(Any producerId, TestActorRequestFactory requestFactory) {
checkNotNull(requestFactory);
final CommandContext commandContext = requestFactory.createCommandContext();
final CommandId commandId = requestFactory.createCommandId();
final Builder builder = EventFactory.newBuilder().setProducerId(producerId).setCommandContext(commandContext).setCommandId(commandId);
final TestEventFactory result = new TestEventFactory(builder);
return result;
}
use of io.spine.base.CommandContext in project core-java by SpineEventEngine.
the class TimeTests method adjustTimestamp.
/**
* Adjusts a timestamp in the context of the passed command.
*
* @return new command instance with the modified timestamp
*/
public static Command adjustTimestamp(Command command, Timestamp timestamp) {
final CommandContext context = command.getContext();
final ActorContext.Builder withTime = context.getActorContext().toBuilder().setTimestamp(timestamp);
final Command.Builder commandBuilder = command.toBuilder().setContext(context.toBuilder().setActorContext(withTime));
return commandBuilder.build();
}
Aggregations