Search in sources :

Example 1 with UserId

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

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

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

the class GivenCommandContext method withRandomActor.

/**
 * Creates a new {@link CommandContext} instance with a randomly
 * generated {@linkplain UserId actor} and current timestamp as a creation date.
 *
 * @return a new {@code CommandContext} instance
 */
public static CommandContext withRandomActor() {
    final UserId userId = GivenUserId.newUuid();
    final Timestamp now = getCurrentTime();
    return withActorAndTime(userId, now);
}
Also used : UserId(io.spine.core.UserId) Timestamp(com.google.protobuf.Timestamp)

Example 4 with UserId

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

the class GivenUserIdShould method create_UserId_by_string.

@Test
public void create_UserId_by_string() {
    final String testIdString = "12345";
    final UserId userId = of(testIdString);
    final UserId expected = UserId.newBuilder().setValue(testIdString).build();
    assertEquals(expected, userId);
}
Also used : UserId(io.spine.core.UserId) Test(org.junit.Test)

Example 5 with UserId

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

the class CommandFactoryShould method create_command_context.

@Test
public void create_command_context() {
    final TenantId tenantId = GivenTenantId.newUuid();
    final UserId userId = GivenUserId.newUuid();
    final ZoneOffset zoneOffset = ZoneOffsets.ofHours(-3);
    final int targetVersion = 100500;
    final CommandContext commandContext = CommandFactory.createContext(tenantId, userId, zoneOffset, targetVersion);
    final ActorContext actorContext = commandContext.getActorContext();
    assertEquals(tenantId, actorContext.getTenantId());
    assertEquals(userId, actorContext.getActor());
    assertEquals(zoneOffset, actorContext.getZoneOffset());
    assertEquals(targetVersion, commandContext.getTargetVersion());
}
Also used : TenantId(io.spine.core.TenantId) GivenTenantId(io.spine.core.given.GivenTenantId) CommandContext(io.spine.core.CommandContext) UserId(io.spine.core.UserId) GivenUserId(io.spine.core.given.GivenUserId) ZoneOffset(io.spine.time.ZoneOffset) 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