Search in sources :

Example 1 with AggTaskAssigned

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;
}
Also used : UserId(io.spine.core.UserId) AggTaskAssigned(io.spine.test.aggregate.event.AggTaskAssigned) Nullable(javax.annotation.Nullable)

Example 2 with AggTaskAssigned

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;
}
Also used : UserId(io.spine.core.UserId) AggTaskAssigned(io.spine.test.aggregate.event.AggTaskAssigned) AggTaskId(io.spine.test.aggregate.task.AggTaskId) Assign(io.spine.server.command.Assign)

Example 3 with AggTaskAssigned

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;
}
Also used : UserId(io.spine.core.UserId) AggTaskAssigned(io.spine.test.aggregate.event.AggTaskAssigned) AggCannotReassignUnassignedTask(io.spine.test.aggregate.rejection.AggCannotReassignUnassignedTask) AggTaskId(io.spine.test.aggregate.task.AggTaskId) Assign(io.spine.server.command.Assign)

Example 4 with AggTaskAssigned

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);
}
Also used : AggTaskCreated(io.spine.test.aggregate.event.AggTaskCreated) UserId(io.spine.core.UserId) AggTaskAssigned(io.spine.test.aggregate.event.AggTaskAssigned) AggTaskId(io.spine.test.aggregate.task.AggTaskId) Assign(io.spine.server.command.Assign)

Aggregations

UserId (io.spine.core.UserId)4 AggTaskAssigned (io.spine.test.aggregate.event.AggTaskAssigned)4 Assign (io.spine.server.command.Assign)3 AggTaskId (io.spine.test.aggregate.task.AggTaskId)3 AggTaskCreated (io.spine.test.aggregate.event.AggTaskCreated)1 AggCannotReassignUnassignedTask (io.spine.test.aggregate.rejection.AggCannotReassignUnassignedTask)1 Nullable (javax.annotation.Nullable)1