Skip to content
  • Sylvain Thénault's avatar
    [hooks] Ensure we don't have several children with cardinality != 1 · 39d1d971e058
    Sylvain Thénault authored
    By trying to validate several profiles using Jing (in Asalae), it appears that
    it isn't possible to validate a profile where there are several elements with
    the same name with optional or/and multiple cardinality, e.g. with a profile
    telling we expect  1..n Document followed by 1 Document, a transfer with two
    documents won't be accepted, telling a required document is missing. This is
    much probably because the validator "eats" the two documents for the first rule,
    then it misses one to satisfy the second rule.
    
    In order to avoid generating such insatisfyable profiles, while not changing
    much the UI for now, we decided to add hook preventing usage of several sibling
    children with a cardinality != 1 during edition, and then at RNG profile
    generation time to put the one with cardinality != 1 as last children. That way
    profiles should always be validable.
    
    This patch introduces the hooks preventing insatisfyable profiles to be created.
    The next one will ensure the order of RNG export.
    
    Two hooks are added to check for unhandled case one for new watched relations
    and the other for update cardinalities.
    
    Added test cases for the 3 most prominent cases: archive unit, document and
    keywords, with more coverage in the first one and only simple check for the two
    others. Also, some test have to be updated to follow this change. Notice diff of
    exported RNG isn't nice to read but is actually only removal of a surrounding
    "oneOrMore" element.
    
    Related to #17098404
    39d1d971e058