Search in sources :

Example 6 with TenantId

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

the class Commands method getTenantId.

/**
     * Obtains a tenant ID from the command.
     */
public static TenantId getTenantId(Command command) {
    checkNotNull(command);
    final TenantId result = command.getContext().getActorContext().getTenantId();
    return result;
}
Also used : TenantId(io.spine.users.TenantId)

Example 7 with TenantId

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

the class ValidationFilter method isTenantIdValid.

private boolean isTenantIdValid(CommandEnvelope envelope, StreamObserver<Response> responseObserver) {
    final TenantId tenantId = envelope.getTenantId();
    final boolean tenantSpecified = !isDefault(tenantId);
    final Command command = envelope.getCommand();
    if (commandBus.isMultitenant()) {
        if (!tenantSpecified) {
            reportMissingTenantId(command, responseObserver);
            return false;
        }
    } else {
        if (tenantSpecified) {
            reportTenantIdInapplicable(command, responseObserver);
            return false;
        }
    }
    return true;
}
Also used : TenantId(io.spine.users.TenantId) Command(io.spine.base.Command)

Example 8 with TenantId

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

the class Stand method subscribe.

/**
     * Subscribes for all further changes of an entity state, which satisfies the {@link Topic}.
     *
     * <p>Once this instance of {@code Stand} receives an update of an entity
     * with the given {@code TypeUrl}, all such callbacks are executed.
     *
     * @param topic an instance {@link Topic}, defining the entity and criteria,
     *              which changes should be propagated to the {@code callback}
     */
public void subscribe(final Topic topic, final StreamObserver<Subscription> responseObserver) {
    topicValidator.validate(topic, responseObserver);
    final TenantId tenantId = topic.getContext().getTenantId();
    final TenantAwareOperation op = new TenantAwareOperation(tenantId) {

        @Override
        public void run() {
            final Subscription subscription = subscriptionRegistry.add(topic);
            responseObserver.onNext(subscription);
            responseObserver.onCompleted();
        }
    };
    op.execute();
}
Also used : TenantId(io.spine.users.TenantId) Subscription(io.spine.client.Subscription) TenantAwareOperation(io.spine.server.tenant.TenantAwareOperation)

Example 9 with TenantId

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

the class SubscriptionValidator method checkInRegistry.

private boolean checkInRegistry(Subscription request) {
    final TenantId tenantId = request.getTopic().getContext().getTenantId();
    final Boolean result = new TenantAwareFunction<Subscription, Boolean>(tenantId) {

        @Override
        public Boolean apply(@Nullable Subscription input) {
            checkNotNull(input);
            final boolean result = registry.containsId(input.getId());
            return result;
        }
    }.execute(request);
    checkNotNull(result);
    return result;
}
Also used : TenantId(io.spine.users.TenantId) Subscription(io.spine.client.Subscription)

Example 10 with TenantId

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

the class CurrentTenantShould method clear_set_value.

@Test
public void clear_set_value() {
    final TenantId value = newTenantId(getClass());
    CurrentTenant.set(value);
    CurrentTenant.clear();
    assertFalse(CurrentTenant.get().isPresent());
}
Also used : TenantId(io.spine.users.TenantId) Tests.newTenantId(io.spine.test.Tests.newTenantId) Test(org.junit.Test)

Aggregations

TenantId (io.spine.users.TenantId)24 Test (org.junit.Test)14 Command (io.spine.base.Command)6 TenantAwareOperation (io.spine.server.tenant.TenantAwareOperation)4 CommandId (io.spine.base.CommandId)3 ActorRequestFactory (io.spine.client.ActorRequestFactory)2 Subscription (io.spine.client.Subscription)2 Tests.newTenantId (io.spine.test.Tests.newTenantId)2 Nullable (javax.annotation.Nullable)2 Any (com.google.protobuf.Any)1 Message (com.google.protobuf.Message)1 ActorContext (io.spine.base.ActorContext)1 CommandContext (io.spine.base.CommandContext)1 Commands.getMessage (io.spine.base.Commands.getMessage)1 Version (io.spine.base.Version)1 StringChange (io.spine.change.StringChange)1 Query (io.spine.client.Query)1 QueryResponse (io.spine.client.QueryResponse)1 CommandMessage.createProjectMessage (io.spine.server.commandbus.Given.CommandMessage.createProjectMessage)1 EntityStateEnvelope (io.spine.server.entity.EntityStateEnvelope)1