skipcheck

TM1 Spring Boot starter · Docs · The client

Tm1AutoConfiguration

import io.skipcheck.tm1.spring.boot.autoconfigure.Tm1AutoConfiguration;

Auto-configures the TM1 client for each TM1 server the application names: a Tm1ConnectionDetails, a Tm1Session, a Tm1Client and, with the server's pool.enabled=true, a Tm1SessionPool. Sessions and pools are closed on shutdown.

Sessions are built on Boot's WebClient.Builder when there is one (so its customizers, codecs and observations apply) and report to the application's ObservationRegistry. The connector is Reactor Netty, built with Boot's connector builder so ssl.bundle works like any other Boot client's SSL bundle.

Set the tm1.* properties and inject the client:

// Its settings are tm1.address, tm1.user and tm1.password, in application.yml
@Service
static class SalesCubes {

    private final Tm1Client tm1;

    SalesCubes(Tm1Client tm1) {
        this.tm1 = tm1;
    }

    Flux<String> names() {
        return tm1.cubes().modelCubes(ODataQuery.none().select(Cube.NAME)).map(Cube::name);
    }

}

An application acting for many users gets each user's session from the pool:

// With tm1.pool.enabled=true, and a service account that may impersonate users
@Service
static class UserCubes {

    private final Tm1SessionPool pool;

    UserCubes(Tm1SessionPool pool) {
        this.pool = pool;
    }

    // The cubes the user may see. Get a session for each piece of work
    Flux<String> names(String user) {
        return Flux.defer(() -> Tm1Client.of(pool.session(Tm1Identity.impersonating(user)))
            .cubes()
            .modelCubes(ODataQuery.none().select(Cube.NAME))
            .map(Cube::name));
    }

}

Servers by name

Every server has a name. Each tm1.servers.&lt;name&gt;.* is one, with the same properties as tm1.*; and tm1.* is the server named default, the same as tm1.servers.default.*. Setting both tm1.* and tm1.servers.default.* is an error. Each server's beans are named after it, <name>Tm1ConnectionDetails, <name>Tm1Session, <name>Tm1Client and <name>Tm1SessionPool, and qualified by the name:

// With tm1.servers.planning.* and tm1.servers.reporting.*: a client for each
@Service
static class Reconciliation {

    private final Tm1Client planning;

    private final Tm1Client reporting;

    Reconciliation(@Qualifier("planning") Tm1Client planning, @Qualifier("reporting") Tm1Client reporting) {
        this.planning = planning;
        this.reporting = reporting;
    }

    // The cubes planning has and reporting doesn't
    Flux<String> notYetReported() {
        return cubes(reporting).collectList()
            .flatMapMany(reported -> cubes(planning).filter(cube -> !reported.contains(cube)));
    }

    private static Flux<String> cubes(Tm1Client tm1) {
        return tm1.cubes().modelCubes(ODataQuery.none().select(Cube.NAME)).map(Cube::name);
    }

}

The default server's beans are the default candidates, so a plain Tm1Client gets its client. Every other server's are not (defaultCandidate = false): Spring injects them only where a @Qualifier names the server. So with only named servers there's no plain Tm1Client, even when there's one; name it default for that. Spring Boot's bean conditions skip beans that aren't default candidates, too: a @ConditionalOnBean(Tm1Client.class) of your own matches the default server's client only.

Beans of your own

A bean of yours under one of a server's bean names takes the place of the starter's, for any server: planningTm1ConnectionDetails, say, for a login the properties can't describe. The starter gives it the server's qualifier and, for a server other than default, makes it no default candidate, as its own are. A bean named defaultTm1ConnectionDetails makes a default server even without tm1.*.

For the default server, a bean of one of these types under any other name also takes the place of the starter's, as long as it's a default candidate, since the default server's beans are the default candidates. That is how Spring Boot's connection details work: @ServiceConnection registers a Tm1ConnectionDetails under a name of its own, and it becomes the default server, tm1.* or not.

Also in the Javadoc.