cancel
Showing results for 
Search instead for 
Did you mean: 

Mandatory-enforce not overridable according to modelSchema.xsd

ipirat
Champ in-the-making
Champ in-the-making
I think, I came across something one could call a bug, or, at least unexpected behaviour:
When defining the mandatory attribute on a model property, one can use "enforced=true/false"
to control the enforcement of the "mandatory" constraint.

When overriding the mandatory attribute, you cant specify "enforced", as mandatory is "just" aboolean when overriding.



   <xs:complexType name="property">
      …
         <xs:element name="mandatory" maxOccurs="1" minOccurs="0" type="dd:mandatoryDef" />
      …
   </xs:complexType>

   <xs:complexType name="propertyOverride">
      …
         <xs:element name="mandatory" maxOccurs="1" minOccurs="0" type="xs:boolean" />
      …
   </xs:complexType>



I think, this should be overridable…



10 REPLIES 10

ipirat
Champ in-the-making
Champ in-the-making
PS: it seems, that the "enforced" value is at least inherited from parent type, so <strong>it is possible to work around it in most cases</strong>


e.g. the following example will enforce integrity check on foo:documentDate in the foo:child type,

    <types>
        <type name="foo:parent">
            …
            <properties>
                <property name="foo:documentDate">
                    <type>d:date</type>
                    <mandatory enforced="true">false</mandatory>
                    <multiple>false</multiple>
                </property>
            </properties>
        </type>
        <!– Rechnung –>
        <type name="foo:child">
            …
            <overrides>
                <property name="foo:documentDate">
                    <mandatory>true</mandatory>
                </property>
            </overrides>
        </type>
    </types>


this one will not enforce foo:documentDate on the type foo:child

    <types>
        <type name="foo:parent">
            …
            <properties>
                <property name="foo:documentDate">
                    <type>d:date</type>
                    <mandatory enforced="false">false</mandatory>
                    <multiple>false</multiple>
                </property>
            </properties>
        </type>
        <!– Rechnung –>
        <type name="foo:child">
            …
            <overrides>
                <property name="foo:documentDate">
                    <mandatory>true</mandatory>
                </property>
            </overrides>
        </type>
    </types>

kaynezhang
World-Class Innovator
World-Class Innovator
In my opinion even if it is a bug ,it is not too much of a problem.Here is the reason:
In your parent type you define <strong>mandatory is false </strong>but <strong>mandatory enforced is true</strong>,it is meaningless. once you set
 mandatory to false 
it would be useless to set
mandatory enforced to true
.So under normal circumstances we will not define our model like that



As why it happens as you pointed ,here is the reason:
When alfresco complile overrided property ,it will try to enforce both mandatory requirment and mandatory enforced requirment on the
overrided property no matter wether the mandatory comes from parent property definition or comes from overrided property. Doing so it will not take the risk that relax mandatory requirement.
That means for both mandatory and mandatory enforced attribute ,alfresco will set the attribute value to <strong>true </strong> if there is at lease one true in either parent property definition or overrided property
So in your first example parent type's mandatory enforced attribute
 enforced="true"
will be inherited by child type,plus child type 's own
 <mandatory>true</mandatory>
.combine the two give you

            <overrides>
                <property name="foo:documentDate">
                   <mandatory enforced="true">true</mandatory>
                </property>
            </overrides>

In your second example, combine parent type's settings and child type's sttings  give you

            <overrides>
                <property name="foo:documentDate">
                   <mandatory enforced="false">true</mandatory>
                </property>
            </overrides>



Although it is not a serious bug ,I guess it would be better if alfresco can give us a warning or add some test statements to deal with this problem.

kaynezhang
World-Class Innovator
World-Class Innovator
In my opinion even if it is a bug ,it is not too much of a problem.Here is the reason:
In your parent type you define <strong>mandatory is false </strong>but <strong>mandatory enforced is true</strong>,it is meaningless. once you set
 mandatory to false 
it would be useless to set
mandatory enforced to true
.So under normal circumstances we will not define our model like that



As why it happens as you pointed ,here is the reason:
When alfresco complile overrided property ,it will try to enforce both mandatory requirment and mandatory enforced requirment on the
overrided property no matter wether the mandatory comes from parent property definition or comes from overrided property. Doing so it will not take the risk that relax mandatory requirement.
That means for both mandatory and mandatory enforced attribute ,alfresco will set the attribute value to <strong>true </strong> if there is at lease one true in either parent property definition or overrided property
So in your first example parent type's mandatory enforced attribute
 enforced="true"
will be inherited by child type,plus child type 's own
 <mandatory>true</mandatory>
.combine the two give you

            <overrides>
                <property name="foo:documentDate">
                   <mandatory enforced="true">true</mandatory>
                </property>
            </overrides>

In your second example, combine parent type's settings and child type's sttings  give you

            <overrides>
                <property name="foo:documentDate">
                   <mandatory enforced="false">true</mandatory>
                </property>
            </overrides>



Although it is not a serious bug ,I guess it would be better if alfresco can give us a warning or add some test statements to deal with this problem.

ipirat
Champ in-the-making
Champ in-the-making
I think, my second post was a little misleading, so I just edited it: it was showing a workaround.

But, as you pointed out, it is "misleading" or at least "not clear" why I would define "enforcement" on a mandatory=false property (In fact: just so my overridden Property has correct enforcement)

And, it has a case, which cant be modeled:

parent: mandatory=false,
child1: mandatory=true/enforcement=true,
child2: mandatory=true/enforcement=false

(just a hypothetic example, though)


All-in-All: It would be much clearer to allow overriding enforcement on the mandatory tag.

kaynezhang
World-Class Innovator
World-Class Innovator
In alfresco all mandatory/enforcement will be inherited by overrided properties,so in child type you can only enforce ,not relax mandatory requirement.

It is legal to define like below,even if
enforcement=true 
is no use for parent type ,but it will be inherited by child type.

parent: mandatory=false, enforcement=true

So except necessary ,I think we should define parent type like this

parent: mandatory=false, enforcement=false
or parent: mandatory=true, enforcement=false


Then in child type ,we can set enforcement=true,or just use parent or default value(default value is false).

ipirat
Champ in-the-making
Champ in-the-making
<blockquote>Then in child type, we can set enforcement=true</blockquote>

and that's the Whole Point: we can't. The XSD will not allow adding "enforcement" attribute to "mandatory" tag!
(see the relevant portion of XSD in my original post)

kaynezhang
World-Class Innovator
World-Class Innovator
Yes,you are right propertyOverride dose not allow adding "enforced" attribute to "mandatory" tag in xsd !
But It seems "enforced" attribute is already considered in java class (M2PropertyOverride.java) and m2binding file,it is just ignored in modelSchema.xsd
You can submit a bug in jira,hope they will modify this xsd file and add "enforced" attribute to "mandatory" tag.

ipirat
Champ in-the-making
Champ in-the-making
Jira Issue submitted: https://issues.alfresco.com/jira/browse/ALF-20980

you can vote for it there Smiley Wink

kaynezhang
World-Class Innovator
World-Class Innovator
I have already voted.