use of io.spine.test.aggregate.event.AggTaskAssigned in project core-java by SpineEventEngine.
the class TaskAggregate method taskAssignedOrNull.
/**
* Creates a new {@link AggTaskAssigned} event message with provided values. If the
* {@linkplain UserId assignee} is a default empty instance returns {@code null}.
*/
@Nullable
private static AggTaskAssigned taskAssignedOrNull(AggTaskId id, UserId assignee) {
final UserId emptyUserId = UserId.getDefaultInstance();
if (assignee.equals(emptyUserId)) {
return null;
}
final AggTaskAssigned event = AggTaskAssigned.newBuilder().setTaskId(id).setNewAssignee(assignee).build();
return event;
}
use of io.spine.test.aggregate.event.AggTaskAssigned in project core-java by SpineEventEngine.
the class TaskAggregate method handle.
@Assign
AggTaskAssigned handle(AggAssignTask command) {
final AggTaskId id = command.getTaskId();
final UserId newAssignee = command.getAssignee();
final UserId previousAssignee = getState().getAssignee();
final AggTaskAssigned event = taskAssigned(id, previousAssignee, newAssignee);
return event;
}
use of io.spine.test.aggregate.event.AggTaskAssigned in project core-java by SpineEventEngine.
the class TaskAggregate method handle.
@Assign
AggTaskAssigned handle(AggReassignTask command) throws AggCannotReassignUnassignedTask {
final AggTaskId id = command.getTaskId();
final UserId newAssignee = command.getAssignee();
final UserId previousAssignee = getState().getAssignee();
if (previousAssignee.equals(EMPTY_USER_ID)) {
throw new AggCannotReassignUnassignedTask(id, previousAssignee);
}
final AggTaskAssigned event = taskAssigned(id, previousAssignee, newAssignee);
return event;
}
use of io.spine.test.aggregate.event.AggTaskAssigned in project core-java by SpineEventEngine.
the class TaskAggregate method handle.
/**
* A command handler that returns a pair with an optional second element.
*
* <p>{@link AggTaskAssigned} is present when the command contains an
* {@linkplain AggCreateTask#getAssignee() assignee}.
*/
@Assign
Pair<AggTaskCreated, Optional<AggTaskAssigned>> handle(AggCreateTask command) {
final AggTaskId id = command.getTaskId();
final AggTaskCreated createdEvent = taskCreated(id);
final UserId assignee = command.getAssignee();
final AggTaskAssigned assignedEvent = taskAssignedOrNull(id, assignee);
return Pair.withNullable(createdEvent, assignedEvent);
}
Aggregations