> ## Documentation Index
> Fetch the complete documentation index at: https://docs.activeviam.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Atoti Limits Java integration

> “How to connect an Atoti Server instance to a running Atoti Limits server using the Java auto-configuration module, including the compatibility matrix, setup steps, and troubleshooting guidance”

## Overview

The Atoti Limits Java auto-configuration module connects an Atoti Server instance (the “Connected Server”) to a running Atoti Limits server. It uses [Spring Auto-configuration](https://docs.spring.io/spring-boot/reference/using/auto-configuration.) to bootstrap the required services and send a connection request to Atoti Limits.

This module enables Atoti Limits to manage limits on data served by Atoti Server. Once connected, Atoti Limits can evaluate limits against the measures and hierarchies exposed by the Connected Server.

> [!NOTE]
>
> Atoti Limits does not require the connected server to be an ActiveViam Business Solution, it
> can be any instance of Atoti Server.

The auto-configuration resides in the `limits-auto-config-*` modules. These modules are responsible for bootstrapping the Connected Server with any services required by Atoti Limits and for sending a connection request to Atoti Limits with required information.

## Compatibility matrix

This table lists the versions of Atoti Server compatible with each Atoti Limits
version. If you are using a solution, please check the
underlying version of Atoti Server to see if your version of the solution is compatible.

| Atoti Limits version | Atoti Server version |
| - | - |
| 6.2.2+ | 6.1.x, 6.2.x |
| 6.2.0-6.2.1 | 6.0.x, 6.0.x-sb3, 6.1.x, 6.2.x |
| 6.1.25+ | 6.1.x, 6.2.x |
| 6.1.20-6.1.24 | 6.0.x, 6.0.x-sb3, 6.1.x, 6.2.x |
| 4.2 | 6.0.x, 6.0.x-sb3, 6.1.x |
| 4.1 | 6.0.x, 6.0.x-sb3, 6.1.x |

## Prerequisites

1. The Atoti server(s) you wish to connect to must contain a slicing date hierarchy. This hierarchy
   will be used by Atoti Limits when evaluating limits.
2. User and role configurations must be consistent between Atoti Limits and the connected
   Atoti server(s) in order to guarantee proper access control. We recommend placing your security
   configurations in a single module and referencing that module in both Atoti Limits and the
   Atoti server.

## How does the connection process work?

From a high-level view, the connection process works as follows:

1. Once Atoti Limits starts, it sits idle until it receives a connection request from the
   Connected Server.
2. When the Connected Server starts, it pings Atoti Limits to check if it is available to
   receive a connection request.
3. After both Atoti Limits and the Connected Server are started, the Connected Server will
   start some services and gather information to send a connection request to Atoti Limits.

> [!NOTE]
>
> The order in which the servers are started is irrelevant.

4. The connection request contains information about the Connected Server that Atoti Limits
   requires to connect.
5. Atoti Limits connects to the Connected Server and is now ready to manage limits.
6. During the lifetime of the application, Atoti Limits will manage all of the Connected
   Servers that it is connected to.

## How to integrate a Connected Server with Atoti Limits

Follow these steps to integrate a Connected Server with Atoti Limits.

### Step 1: Import the auto-configuration dependency in the Connected Server

The `limits-auto-config-*` Maven dependency must be added to the Connected Server project. The correct artifact depends on the version of Atoti Server in use.

Add the following dependency to the project `pom.xml` file:

```xml theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
<dependency>
  <groupId>com.activeviam.modules.limits</groupId>
  <artifactId>limits-auto-config-{VERSION}</artifactId>
  <version>{ATOTI-LIMITS-MODULE-VERSION}</version>
</dependency>
```

The following table lists each artifact and its compatible Java versions:

| Atoti Server version | Auto-config artifact | Compatible Java versions |
| - | - | - |
| 6.1.X | limits-auto-config-61 | 21 |
| 6.2.X | limits-auto-config-62 | 25 |

### Step 2: Configure the auto-configuration properties in the Connected Server

The auto-configuration module requires a set of properties to establish the connection. Configure these properties in the `application.yml` file on the **Connected Server**.

The full list of properties is available in the [Auto-configuration properties section](https://docs.activeviam.com/atoti-intelligence/workflows/limits/6.2/user-ref/properties/config-properties/limits-integration-common.md).

> [!NOTE]
>
> Not all properties are required, but they are all listed in the event that your Connected Server is
> unable to derive the properties automatically.

### How to secure the auto-configuration REST endpoints

The auto-configuration module adds several REST endpoints to the Connected Server, for example to receive
connection requests and limit change events from Atoti Limits. Spring Security requires a filter chain for
them. Either the application declares one itself, or it lets the auto-configuration module register one.

Setting `limits.autoconfiguration.security.enabled` to `true` on the **Connected Server** registers a dedicated
Spring Security filter chain for these endpoints, built with the Connected Server's
`MachineToMachineSecurityDsl` like the Atoti Server ones. It handles JWT and HTTP Basic authentication, CORS
and CSRF the same way. Every request to these endpoints must be authenticated; no particular role is required.
`OPTIONS` requests (CORS preflight) are always permitted.

This property is `false` by default, so an application that does not set it keeps its existing security
configuration unchanged.

```yaml theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
limits:
  autoconfiguration:
    security:
      enabled: true
```

> [!NOTE]
>
> This chain requires a `MachineToMachineSecurityDsl` bean, which the Atoti Server Spring Boot starter
> (`atoti-server-starter`, Atoti Server 6.1 and later) provides. It is skipped on Connected Servers where that
> class is not on the classpath.

The chain covers the following endpoints:

| Endpoint | Purpose |
| - | - |
| `/limits/autoconfig/**` | Connection management and connection status |
| `/activeviam/limits/rest/v2/**` | Limit retrieval for the KPI drawer and the MDX data export used by Atoti Limits to evaluate limits |
| `/activeviam/inter-server-event-listener/rest/v1/**` | Limit change events pushed by Atoti Limits |
| `/services/rest/v1/levelPath/**` | Parent-child level path resolution used by Atoti Limits |

The Atoti Limits service principal, set by `limits.autoconfiguration.service-principal`, authenticates the
calls Atoti Limits makes to the Connected Server. UI users authenticate their own calls to the KPI drawer
endpoint.

### Step 3: Configure the inter-server-event-service properties in Atoti Limits

The Atoti Limits server needs to know where to find the Connected Server. Set the following configuration properties in the `application.yml` file on the **Atoti Limits server**.

```yaml theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
activeviam:
  apps:
    inter-server-event-service:
      issuer:
        target-servers:
          - name: <Connected Server>
            url: <Connected Server URL>
```

where:

* `<Connected Server>` is the name of the Connected Server and should be the same as the value (defined or auto-configured) of `limits.autoconfiguration.server-name` in the connected server.
* `<Connected Server URL>` is the URL of the Connected Server and should be the same as the value (defined or auto-configured) of `limits.autoconfiguration.atoti-base-url` in the connected server.

### Step 4: Start the servers

The order in which the servers start does not matter.

#### Start the Limits server

Start the Limits server using the [installation instructions](https://docs.activeviam.com/atoti-intelligence/workflows/limits/6.2/dev/getting-started.md#installing-the-starter-project).
Limits will wait for a connection from the Atoti Server.

#### Start the Connected Server

Start the Connected Server as normal. This should trigger a connection request.

## Troubleshooting

If the connection is unsuccessful, enable `debug` logging for further investigation.

> [!NOTE]
>
> Ensure that within the ActivePivotConfig of your connected solution, the contextValueManager
> method is not setting the ActivePivotContentService to null.
>
> If the ActivePivotContentService is
> null, KPIs will not appear in the UI, even if they are present in the content server.
>
> Sometimes this can be fixed by setting the property `contentServer.context-values.ignore`
> to `false`.
