Skip to content

Utility Classes

A collection of commonly used utility classes in Erupt development.

Getting the Logged-In User Context

Available in dataProxy and similar contexts. Custom endpoints require the token to be passed explicitly.

java
@Component
public class Test {

    @Autowired
    private EruptUserService eruptUserService;

    @Autowired
    private EruptContextService eruptContextService;

    public void test() {
        // Get the current logged-in user's ID
        Long uid = eruptUserService.getCurrentUid();

        // Get the current logged-in user object (EruptUser)
        EruptUser eruptUser = eruptUserService.getCurrentEruptUser();

        // Get basic user info without querying the database
        MetaUserinfo metaUserinfo = eruptUserService.getSimpleUserInfo();

        // Get the current request token
        String token = eruptContextService.getCurrentToken();

        // Get the current menu being accessed (with custom menu parameters, etc.)
        EruptMenu eruptMenu = eruptContextService.getCurrentEruptMenu();

        // Get the erupt name of the current request (MetaContext is an InheritableThreadLocal)
        String eruptName = MetaContext.getErupt().getName();

        // Resolve the context class (the class annotated with @Erupt) from that name
        Class<?> clazz = EruptCoreService.getErupt(eruptName).getClazz();
    }
}

Inside a DataProxy callback you can call DataProxyContext.currentClass() directly to get the current erupt class, without going through MetaContext.

Extending Base Entity Classes

java
@Erupt(name = "Show only the current user's data")
public class EruptClass extends LookerSelf {
    // TODO: field definitions
}

@Erupt(name = "Auto-manage creator, create time, updater, and update time fields")
public class EruptClass extends HyperModel {
    // TODO: field definitions
}

Base Model

Class nameDescription
BaseModelManages the database primary key with universal configuration, compatible with all mainstream databases

Data Audit (Foreign Key Association)

Class nameDescription
HyperModelAuto-manages creator, create time, updater, and update time fields
HyperModelVoAuto-manages audit fields and displays them on the page
HyperModelCreatorVoAuto-manages audit fields and displays creator and create time
HyperModelUpdateVoAuto-manages audit fields and displays updater and update time

Data Audit (No Foreign Key Association)

When using eruptDao.persist or eruptDao.merge in non-page operations, audit fields are automatically populated if the token is correctly passed (supported since 1.12.23+).

Class nameDescription
MetaModelAuto-manages creator, create time, updater, and update time fields (no user table FK)
MetaModelVoAuto-manages audit fields and displays them on the page (no user table FK)
MetaModelCreateVoAuto-manages audit fields and displays creator and create time (no user table FK)
MetaModelUpdateVoAuto-manages audit fields and displays updater and update time (no user table FK)
MetaModelCreateOnlyVoAuto-manages creator and create time, and displays updater and update time (no user table FK)

Permission Filtering

Multi-level nesting is not supported. If the class hierarchy is deeply nested, it is recommended to create a custom permission filter class modeled after the LookerXXX pattern.

Class nameDescription
LookerSelfShows only data created by the current user (admins see all data)
LookerOrgShows only data belonging to the current user's organization (admins see all data)
LookerPostLevelShows data from users in the same organization whose position weight is lower than the logged-in user's (admins see all data)

For other custom requirements, you can freely define your own logic via @PreDataProxy.

Error Messages & Dialog Notifications

Throw these exceptions in any method to produce the corresponding effect.

java
public void fun() {
    // Display error in a dialog
    throw new EruptApiErrorTip("Error message");

    // Display error as a toast message
    throw new EruptApiErrorTip("Error message", R.PromptWay.MESSAGE);

    // Display error as a notification
    throw new EruptApiErrorTip("Error message", R.PromptWay.NOTIFY);
}

JDBC Operations with Erupt Classes

See: EruptDao (JDBC)

Contributors

The avatar of contributor named as YuePeng YuePeng
The avatar of contributor named as Claude Opus 5 (1M context) Claude Opus 5 (1M context)

Changelog

Released under the Apache-2.0 License.