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;
}
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;
}
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();
}
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;
}
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());
}
Aggregations