Customizing the Tuple Publishers

This section describes how to create custom tuple publishers in Atoti Limits. Atoti Limits comes with three interfaces to implement, each of which facilitate loading different sets of CSV files. For more information on loading CSV files, see the Atoti Server documentation.

Interface Default Target Stores Default CSV file Default Implementation
IAsOfDateTuplePublisher AsOfDate as_of_date.csv DefaultAsOfDateTuplePublisher
ILimitTuplePublisher LimitStructures, Limits limit_structures*.csv,limits_approve*.csv DefaultLimitTuplePublisher
IIncidentTuplePublisher Incidents incident.csv DefaultIncidentTuplePublisher

Interfaces

Each of the interfaces extends the ITuplePublisher<I> interface. The type is purposely generic, allowing overriding implementations to publish data from different data sources (IE: cloud sources).

    @Override
    void publish(IStoreMessage<? extends I, ?> message, List<Object[]> tuples);

    @Override
    Collection<String> getTargetStores();

Default getTargetStores() implementation

We provide a default implementation of the getTargetStores() method, which can be overridden.

// IAsOfDateTuplePublisher
@Override
default Collection<String> getTargetStores() {
    return Set.of(AS_OF_DATE_STORE_NAME);
}
// ILimitTuplePublisher
@Override
default Collection<String> getTargetStores() {
    return Set.of(
    LIMIT_STRUCTURE_STORE_NAME,
    LIMITS_STORE_NAME,
    LIMITS_SCOPE_STORE_NAME,
    SCOPE_LOCATION_STORE_NAME,
    SCOPE_LEVEL_MEMBERS_STORE_NAME,
    SCOPE_KEYS_STORE_NAME,
    SCOPE_VALUES_STORE_NAME);
}
// IIncidentTuplePublisher
@Override
default Collection<String> getTargetStores() {
    return Set.of(INCIDENTS_STORE_NAME);
}

1. Create the Spring Bean

To implement a custom tuple publisher, create a class that extends the appropriate interface and begin by overriding the publish(IStoreMessage<? extends IFileInfo<Path>, ?> message, List<Object[]> tuples) method. The getTargetStores() method can be overridden as well, but a default has been provided in the interface. Here is an example of a custom AsOfDateTuplePublisher:

import java.util.ArrayList;
import java.util.Collections;

@Primary
@Component
public class CustomAsOfDateTuplePublisher implements IAsOfDateTuplePublisher<IFileInfo<Path>> {

    // CustomAsOfDateTuplePublisher Constructor
    public CustomAsOfDateTuplePublisher() {
    }

    @Override
    public void publish(IStoreMessage<? extends IFileInfo<Path>, ?> message, List<Object[]> tuples) {
        List<Object[]> asOfDateTuples = new ArrayList<>();
        
        // Custom publishing logic ...

        datastore.getTransactionManager().addAll(AS_OF_DATE_STORE_NAME, asOfDateTuples);
    }

    @Override
    public Collection<String> getTargetStores() {
        return Set.of(AS_OF_DATE_STORE_NAME);
    }
}

note

Note the inclusion of the @Primary annotation, which tells Spring to use CustomAsOfDateTuplePublisher instead of DefaultAsOfDateTuplePublisher.

2. Import the Spring Bean

Once the bean is created, import it into the project. See Importing Spring Beans into the Project on how to do this. Once done, Spring will use the custom bean when loading data into the datastore.