moqui-jexl, a separate Moqui component with no Darpan code. moqui-jexl stores and runs scripts in a sandbox, reads their inputs, and schedules and delivers them. Darpan adds the tenant, three read sources over what audits keep, two deliveries, and the facade the app calls. Darpan’s own engine (darpan.script.*) is deleted.
The component
Entities
moqui-jexl’s entities are in thejexl.script package, not moqui.*, so entity filters apply to them.
entity/QueryEntities.xml adds companyUserGroupId (not null, indexed) to UserScript and UserScriptDeployment, and to UserScriptRun, which copies its deployment’s. The filters DARPAN_SCOPE_JEXL_SCRIPT, DARPAN_SCOPE_JEXL_DEPLOYMENT and DARPAN_SCOPE_JEXL_RUN put the three in DARPAN_ACTIVE_COMPANY_SCOPE. The tenant is set through moqui-jexl’s ownerFields on store: an existing row’s owner fields never change, and query.QueryHostServices.check#QueryOwnerFields refuses a value other than the caller’s active tenant. Every read in darpan.query.TenantQuerySupport also names the tenant.
The retired darpan.script.TenantScript and TenantScriptDeployment definitions and their DARPAN_SCOPE_TENANT_SCRIPT* filters stay only for the migration to read. They are to be dropped once TENANT_SCRIPTS_TO_QUERIES has run on every instance.
Darpan’s hooks
MoquiConf.xml sets these default properties:
moqui-jexl’s own checks run first at every run: the owner must exist, not be terminated or disabled, and hold
JEXL_SCRIPT_SCHEDULE. A temporary login lockout holds the run (HELD) instead.
Read sources
Each source implementsmoqui.jexl.ScriptServices.read#ScriptSource, is a jexl.script.ScriptSource row (data/QuerySeedData.xml), and is in JEXL_SOURCES, granted to DARPAN_USER. moqui-jexl ships its artifact groups and the JEXL_SCRIPT_RESULT template as type seed, which a Darpan deploy does not load, so data/MoquiJexlSeedData.xml carries the same rows as darpan-seed (MoquiJexlSeedDataMirrorTests keeps them identical).
A read runs as the owner in a fresh execution context with no active tenant.
darpan.query.QuerySourceScope takes the tenant from the saved query (userScriptId), or for an unsaved run from the ownerKey the facade passed (the active tenant), never from the read spec. It enters that tenant as the owner’s requested tenant, refused unless the owner is a current member, then reads with explicit tenant conditions. A dataset, run or audit of another tenant is READ_NOT_ALLOWED. QueryRows stops at maxRows + 1 (READ_TOO_LARGE) and when the lane interrupts the thread.
Deliveries
Both implementmoqui.jexl.ScriptServices.deliver#UserScriptDeploymentResult, are in JEXL_SCRIPT_SCHEDULE, run as the owner, and enter the query’s tenant the same way. A schedule and its query must share a tenant.
A query schedule’s chat delivery is the
SCRIPT route on the Notifications page (get#NotificationRoutes, set#NotificationRoute). Deleting a chat space that a schedule posts to is refused.
Facade
service/facade/TenantScriptFacadeServices.xml keeps its file name and serves the query methods (list#TenantQueries, save#TenantQuery, run#TenantQuery, list#TenantQuerySchedules, save#TenantQuerySchedule, run#TenantQuerySchedule, get#TenantQueryCatalog, create#TenantQueryProposal and the deletes). save#TenantQueryPins (3.4.3) keeps each user’s pinned queries per tenant in the user preference darpan.queries.pinnedIds.<tenantId> (a JSON list, parsed and normalised by ReconciliationDashboardPreferenceSupport as the dashboard pins are), and list#TenantQueries returns them as pinnedQueryIds, dropping any query that no longer exists; it needs view access only. Writing and running need tenant write access; schedules, and changing or deleting a query that has one, need isTenantAdmin (otherwise an editor’s save would make them the owner in moqui-jexl and the owner check would switch it off). A preview (run#TenantQuerySchedule with send false) runs the saved query as the calling tenant admin; moqui-jexl’s own preview is the owner’s only. A draft of a saved query runs as written. Darpan grants JEXL_SCRIPT_EDIT and JEXL_SCRIPT_SCHEDULE to DARPAN_USER and enforces the per-tenant rule in the facade. darpan-agent’s send#AgentQueryTurn runs the QUERY_AUTHOR role (prompt query-author.md, data like the other prompts) with tools get_query_catalog, propose_query and ask_human. See the service catalog.
Config transfer and config versions carry queries (SCRIPT kind, natural key scriptName), their schedules by position, and each schedule’s deliveries by position. A read’s savedRunId and a delivery’s chatSpaceId travel as refs, except a run the tenant does not have, which stays a plain id; owner, run state and delivery outcomes stay the target’s. Every schedule of a query an import or restore creates or changes arrives switched off with no next run, because import and restore need only edit access. TenantConfig.eecas.xml records a change to the three config entities, never UserScriptRun.
Migration from scripts
TENANT_SCRIPTS_TO_QUERIES (query.QueryHostServices.migrate#TenantScriptsToQueries, sequence 150, no dry run) runs from the migration registry:
- Each
TenantScriptbecomes aUserScriptwith idMIG_<tenantScriptId>: same tenant, name and body, profileQUERY, owner its last editor. A script that read a run result gets arunResultread of its deployment’s saved run (fieldsbucket,key), is switched off, and its description says to check it, because its input is now flat rows ininput.differences. - Each
TenantScriptDeploymentbecomes aUserScriptDeploymentwith idMIG_<tenantScriptDeploymentId>: same cron, the tenant’s zone, owner its last editor, switched off, with one chat delivery to its chat space. A deployment with no user to own it is not migrated and is named in the result. - It deletes the retired
scan_TenantScriptDeployments_5mjob with its runs and parameters. A seed load never deletes it, and its service is gone. - Old rows are kept. A second run skips rows whose
MIG_id exists.
Tests
darpan.query.*Tests: QueryHostSmokeTests, QuerySourcesSmokeTests, QueryDeliverySmokeTests, TenantQueryFacadeSmokeTests, QueryMigrationSmokeTests, QueryLoadAndDeliveryUnitTests, MoquiJexlSeedDataMirrorTests, with config transfer, config version and notification route cases. Test JVMs set jexl_hold_cpu_percent and jexl_hold_heap_percent to 101 and jexl_deployment_check_seconds to 0. darpan-agent’s ProposeQueryTests. moqui-jexl’s own suite runs with ./gradlew :runtime:component:moqui-jexl:test.