feat: Emit effects for assignments to program rule variables backed by a field [DHIS2-21730]#186
Draft
enricocolasante wants to merge 2 commits into
Draft
feat: Emit effects for assignments to program rule variables backed by a field [DHIS2-21730]#186enricocolasante wants to merge 2 commits into
enricocolasante wants to merge 2 commits into
Conversation
…y a field [DHIS2-21730]
ASSIGN actions targeting a program rule variable now emit a RuleEffect
when the variable is backed by a data element or tracked entity
attribute, with the backing field and attributeType injected into the
effect action so consumers can apply it like a direct field assignment.
Emission is matched to the evaluation context (data elements in the
event pass, attributes in the enrollment pass) so evaluateAll emits
each assignment exactly once. Calculated values keep their silent
value-map-only behavior, and rule chaining is unchanged.
The two ASSIGN modes are now dispatched through the new sealed
AssignTarget type (RuleAction.assignTarget()), which accepts both
#{variableName} and A{variableName} content notations and reports
malformed actions with actionable error messages instead of
"unexpected exception: null".
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
fb69d4a to
0627269
Compare
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Emit effects for assignments to program rule variables backed by a field DHIS2-21730
Why
ASSIGN actions targeting a program rule variable (via
content) were handled entirely inside the engine: the variable was updated in the value map and noRuleEffectwas emitted. When the variable was backed by a data element or tracked entity attribute, the assigned value was invisible to consumers and never applied to the underlying field.In addition, the two ASSIGN modes (assign to field vs. assign to variable) were dispatched implicitly on whether
fieldwas empty, so a misconfigured action — neitherfieldnorcontent, or a malformed variable reference — failed mid-evaluation withraised an unexpected exception: null.What
Variable assignments now emit effects for their backing field
RuleEffectwhen the variable is backed by a data element or tracked entity attribute. The backingfieldandattributeTypeare injected into a copy of the action, so the effect is self-contained and consumers can apply it exactly like a direct field assignment (e.g. dhis2-core readsruleAction.field()when buildingValidationEffect). The originalcontentis preserved on the action.attributeType, and ensuringevaluateAllemits each assignment exactly once instead of once per pass.fieldis the variable's own uid, not an assignable data element or attribute.Explicit ASSIGN target dispatch
AssignTarget(Variable(name)/Field(field)) andRuleAction.assignTarget(), which resolves the target of an ASSIGN action and throws a descriptiveIllegalArgumentExceptionfor malformed actions.#{variableName}andA{variableName}notations.RuleAction.ASSIGNandRuleAction.ERRORreplace magic strings; configuration errors are reported asraised an errorwith an actionable message instead ofraised an unexpected exception: null.Compatibility