Skip to content

fix: FilterMappingQualifier for a list with CollectionMappingQualifier failing - #46

Open
artacho-xitaso wants to merge 3 commits into
devfrom
fix/filter-mapping-before-collection-mapping
Open

fix: FilterMappingQualifier for a list with CollectionMappingQualifier failing#46
artacho-xitaso wants to merge 3 commits into
devfrom
fix/filter-mapping-before-collection-mapping

Conversation

@artacho-xitaso

Copy link
Copy Markdown
Contributor

MR: FilterMappingQualifier for a list with CollectionMappingQualifier failing

Branch: fix/filter-mapping-before-collection-mappingdev


Summary

A blueprint where an optional (ZeroToOne) SubmodelElementList wraps a mandatory (OneToMany) CollectionMappingInfo
collection and gates the list with a FilterMappingInfo (e.g. $count(marking) > 0) threw during generation when the payload
had no items, instead of omitting the list. Root cause: DuplicateCollections ran before FilterElements and threw on the
mandatory-but-empty inner collection before the filter could drop its optional parent. This MR runs FilterElements before
and after DuplicateCollections so structural filters prune the branch first.


Changes

MnestixCore/AASGenerator/SubmodelDataToInstanceMapper/DataMapper.cs

  • Added a second FilterElements step before DuplicateCollections in the pipeline (now: Filter → Duplicate → Filter).
    Pre-pass handles structural filters so an optional wrapper is dropped before duplication can throw on empty data; post-pass
    keeps handling per-item filters.

MnestixCore/AASGenerator/SubmodelDataToInstanceMapper/Steps/FilterElementsStep.cs

  • Skip any filter expression containing [*]. A per-item filter cannot be evaluated as a single boolean before the collection
    is duplicated/indexed, so evaluating it pre-duplication would resolve the whole array and give a meaningless verdict.
    Skipping makes the same step safe to run in both pipeline positions (self-routes on [*]).

wiki/Rules-Engine-Architecture.md

  • Updated pipeline step list (10 → 11 steps): FilterElements (pre-duplication) at step 4, DuplicateCollections at 5,
    FilterElements (post-duplication) at 6; renumbered the rest. Documented the reason for the pre-pass and the [*]-skip,
    incl. the note that [*][i] rewrite for filter qualifiers is not yet implemented (per-item filters currently always
    skipped).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts the Submodel data-to-instance mapping pipeline to prevent generation failures when an optional wrapper element is gated by a filter but contains a mandatory (OneToMany) collection mapping that would otherwise throw on empty payloads.

Changes:

  • Run FilterElements both before and after DuplicateCollections to allow structural pruning prior to duplication.
  • Add logic to skip evaluating filter expressions containing [*] (wildcard) in FilterElementsStep.
  • Add fixture-based tests covering: optional wrapper omitted, optional wrapper kept, and wildcard filter expression skipped; update architecture documentation.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
wiki/Rules-Engine-Architecture.md Updates documented pipeline step ordering/count and explains the added filter pass.
MnestixCore/AASGenerator/SubmodelDataToInstanceMapper/Steps/FilterElementsStep.cs Skips evaluation of wildcard ([*]) filter expressions.
MnestixCore/AASGenerator/SubmodelDataToInstanceMapper/DataMapper.cs Inserts a pre-duplication FilterElements step.
Core.Tests/AasGenerator/AasGeneratorTests.cs Adds three regression tests for the new pipeline behavior.
Core.Tests/AasGenerator/TestJsons/InputFilterWildcardExpressionSkipped/TemplateSubmodel.json New fixture: template with wildcard filter expression.
Core.Tests/AasGenerator/TestJsons/InputFilterWildcardExpressionSkipped/Data.json New fixture: data payload for wildcard filter case.
Core.Tests/AasGenerator/TestJsons/InputFilterWildcardExpressionSkipped/ExpectedResult.json New fixture: expected output for wildcard filter case.
Core.Tests/AasGenerator/TestJsons/InputFilterOmitsOptionalCollection/TemplateSubmodel.json New fixture: optional wrapper + mandatory inner collection gated by filter.
Core.Tests/AasGenerator/TestJsons/InputFilterOmitsOptionalCollection/Data.json New fixture: empty payload for the gated collection.
Core.Tests/AasGenerator/TestJsons/InputFilterOmitsOptionalCollection/ExpectedResult.json New fixture: expected output omitting the optional wrapper.
Core.Tests/AasGenerator/TestJsons/InputFilterKeepsOptionalCollection/TemplateSubmodel.json New fixture: same blueprint as omit-case.
Core.Tests/AasGenerator/TestJsons/InputFilterKeepsOptionalCollection/Data.json New fixture: payload containing items so filter passes.
Core.Tests/AasGenerator/TestJsons/InputFilterKeepsOptionalCollection/ExpectedResult.json New fixture: expected output keeping and duplicating the collection.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread MnestixCore/AASGenerator/SubmodelDataToInstanceMapper/DataMapper.cs
Comment thread wiki/Rules-Engine-Architecture.md Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants