LogoLogo
timvero.comMaven Repository
  • timveroOS SDK guide
  • timveroOS how-to
  • timveroOS admin-side setup
  • Campaigns in timveroOS
    • 7.11
      • Business Context
      • Introduction
      • Core Concept
        • Entity Diagram
        • Lifecycle Diagram
        • Expression
      • Design and Development of the Campaign Model
        • Campaign model
        • Campaign repository
        • Campaign forms
        • Campaign сontroller
        • UI elements
        • Campaign actions
      • Design and Development of the CampaignExecution Model
        • CampaignExecution model
        • CampaignExecution repository
        • CampaignExecution controller
        • UI elements
      • Expression
      • Services
        • CampaignService
        • CampaignExecutionService
      • Campaign Processing
        • Producer
        • Consumer
      • Post-processing
        • Checker
Powered by GitBook
On this page
  • 🎯 Purpose
  • βš™οΈ Using the JavaScript/Python Engine
  • πŸ” Security
  • πŸ§ͺ Expression Example
  • πŸ“Œ Code Usage Example

Was this helpful?

  1. Campaigns in timveroOS
  2. 7.11

Expression

🎯 Purpose

An Expression is used to filter clients participating in a campaign. It is a script written in JavaScript or Python that evaluates a specific client's data and returns true or false. Only clients for whom the result is true will be included in the campaign execution.


βš™οΈ Using the JavaScript/Python Engine

The timveroOS platform supports script execution in both JavaScript and Python via the ScriptManager component.

The CampaignExecutionService compiles the expression with:

Script script = scriptManager.compile(expression);

And evaluates it for each client with:

Object evaluationResult = script.eval(Map.of("client", client));

πŸ’‘ The script runs in a sandboxed environment with no access to unsafe resources. Compilation or runtime errors are wrapped in a ScriptException and logged.


πŸ” Security

Scripts are executed with strict limitations:

  • Restricted classes

  • Execution timeouts

  • No external system access

Any error (e.g., NullPointerException, syntax error) is captured in an ExceptionEntity and shown in the UI as EXCEPTION_OCCURRED.


πŸ§ͺ Expression Example

client.age > 25 && client.income > 3000 && client.country == "UK"

This expression selects clients who are:

  • Older than 25

  • Have an income over 3000

  • Live in the United Kingdom


πŸ“Œ Code Usage Example

private Optional<Client> evaluateClient(Script script, UUID clientId) throws ScriptException {
    Client client = clientRepository.getReferenceById(clientId);
    Object result = script.eval(Map.of("client", client));
    return Boolean.TRUE.equals(result) ? Optional.of(client) : Optional.empty();
}
PreviousUI elementsNextServices

Last updated 1 month ago

Was this helpful?