Search in sources :

Example 6 with UserId

use of io.spine.core.UserId 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 7 with UserId

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

the class TaskAggregate method on.

@React
Pair<AggUserNotified, Optional<AggUserNotified>> on(AggTaskAssigned event) {
    final AggTaskId taskId = event.getTaskId();
    final UserId previousAssignee = event.getPreviousAssignee();
    final AggUserNotified previousAssigneeNotified = userNotifiedOrNull(taskId, previousAssignee);
    final UserId newAssignee = event.getNewAssignee();
    final AggUserNotified newAssigneeNotified = userNotified(taskId, newAssignee);
    return Pair.withNullable(newAssigneeNotified, previousAssigneeNotified);
}
Also used : UserId(io.spine.core.UserId) AggUserNotified(io.spine.test.aggregate.event.AggUserNotified) AggTaskId(io.spine.test.aggregate.task.AggTaskId) React(io.spine.core.React)

Example 8 with UserId

use of io.spine.core.UserId 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)

Example 9 with UserId

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

the class GivenCommandContextShould method create_with_actor_and_time.

@Test
public void create_with_actor_and_time() {
    final UserId actorId = newUuid();
    final Timestamp when = add(getCurrentTime(), fromMinutes(42));
    final CommandContext context = GivenCommandContext.withActorAndTime(actorId, when);
    checkValid(context);
    final ActorContext actualActorContext = context.getActorContext();
    assertEquals(actorId, actualActorContext.getActor());
    assertEquals(when, actualActorContext.getTimestamp());
}
Also used : CommandContext(io.spine.core.CommandContext) UserId(io.spine.core.UserId) Timestamp(com.google.protobuf.Timestamp) ActorContext(io.spine.core.ActorContext) Test(org.junit.Test)

Aggregations

UserId (io.spine.core.UserId)9 AggTaskAssigned (io.spine.test.aggregate.event.AggTaskAssigned)4 AggTaskId (io.spine.test.aggregate.task.AggTaskId)4 Assign (io.spine.server.command.Assign)3 Test (org.junit.Test)3 Timestamp (com.google.protobuf.Timestamp)2 ActorContext (io.spine.core.ActorContext)2 CommandContext (io.spine.core.CommandContext)2 React (io.spine.core.React)1 TenantId (io.spine.core.TenantId)1 GivenTenantId (io.spine.core.given.GivenTenantId)1 GivenUserId (io.spine.core.given.GivenUserId)1 AggTaskCreated (io.spine.test.aggregate.event.AggTaskCreated)1 AggUserNotified (io.spine.test.aggregate.event.AggUserNotified)1 AggCannotReassignUnassignedTask (io.spine.test.aggregate.rejection.AggCannotReassignUnassignedTask)1 ZoneOffset (io.spine.time.ZoneOffset)1 Nullable (javax.annotation.Nullable)1