Mixins

External Attribute Mixins

External mixins allow you to extend the attribute set of records in any part of the system by specifying only their ECOS type.

Requirements

Parent project version 2.21.0+ (for Java 17) or 1.49.0+ (for Java 8) is required for both the application with the data source and the application that defines the external mixins.

Description

To define new attributes, create a new bean in any microservice that implements the interface:

ru.citeck.ecos.records3.record.mixin.external.ExtAttMixinConfigurer

This interface has one method register, which accepts settings that allow adding any number of computed attributes.

Kotlin example:

@Component
class CustomExtMixinConfigurer : ExtAttMixinConfigurer {

    override fun configure(settings: ExtMixinConfig) {
        settings.setEcosType("contract") // тип ECOS к которому добавляется новый атрибут. Атрибут добавляется к указанному типу и к его наследникам.
            .addProvidedAtt("newExtAtt") // имя добавляемого атрибута
            .addRequiredAtts(mapOf("ref" to "?id")) // атрибуты, которые нужны для вычисления значения нашего атрибута
            .withHandler { // код по вычислению атрибута
                EntityRef.create("emodel","person", "admin") // возвращаем просто ссылку на другую сущность
            }
    }
}

Java example:

public class CustomExtMixinConfigurer implements ExtAttMixinConfigurer {

    @Override
    public void configure(@NotNull ExtMixinConfig config) throws Exception {

        Map<String, String> requiredAtts = new HashMap<>();

        config.setEcosType("contract") // тип ECOS к которому добавляется новый атрибут. Атрибут добавляется к указанному типу и к его наследникам.
            .addProvidedAtt("newExtAtt") // имя добавляемого атрибута
            .addRequiredAtts(requiredAtts) // атрибуты, которые нужны для вычисления значения нашего атрибута
            .withHandler(data -> { // код по вычислению атрибута
                return EntityRef.create("emodel", "person", "admin"); // возвращаем просто ссылку на другую сущность
            });
    }
}

Once the new attributes are defined for ECOS types, you can use the standard Records API to retrieve the values of these attributes.

For example, to load a new attribute in the browser, you can run the following script:

var rec = Records.get("emodel/contract@295ea260-df3e-493e-b27c-34b6c27e7fea"); // берем сущность с типом, на который мы добавили новый атрибут.
await rec.load("newExtAtt,", true); // загружаем значение нового атрибута