Imported from previous forum
I am trying to find a way to do conditional validation and I can’t seem to find a way to describe it correctly.
For example.
I have an optional field, let’s call it ABC.
If the field is entered it can only attain values that are dependent on value entered in another field let’s call it DEF where ABC has to be less then DEF.
While individual rules are fairly easy to come up with DEF > ABC can only be evaluated if both values are entered and not null.
Is there a way to do this?
You can test whether a parameter is null or not provided by the user by using the EX (exists) or NX (does not exist) operators. The most common example is with optional StartTime and EndTime parameters.
Here’s the logic: If (StartTime != null) and (EndTime != null) then StartTime < EndTime must be true.
Which is equivalent to: (StartTime == null) OR (EndTime == null) OR (StartTime < EndTime)
In FIXatdl:
<val:StrategyEdit errorMessage=“Start time must be less than end time.”>
<val:Edit logicOperator=“OR”>
<val:Edit field=“StartTime” operator=“NX”/>
<val:Edit field=“EndTime” operator=“NX”/>
<val:Edit field=“StartTime” field2=“EndTime” operator=“LT”/>
</val:Edit>
</val:StrategyEdit>
The only caveat is that the validation engine must enforce short-circuit evaluation which is required by the specification. For example, if EndTime were null, the validator would never evaluate whether StartTime < EndTime because it is not necessary.
-Greg
You can test whether a parameter is null or not provided by the user by using the EX (exists) or NX (does not exist) operators. The most common example is with optional StartTime and EndTime parameters.
Here’s the logic: If (StartTime != null) and (EndTime != null) then StartTime < EndTime must be true.
Which is equivalent to: (StartTime == null) OR (EndTime == null) OR (StartTime < EndTime)In FIXatdl:
<val:StrategyEdit errorMessage=“Start time must be less than end time.”>
<val:Edit logicOperator=“OR”>
<val:Edit field=“StartTime” operator=“NX”/>
<val:Edit field=“EndTime” operator=“NX”/>
<val:Edit field=“StartTime” field2=“EndTime” operator=“LT”/>
</val:Edit>
</val:StrategyEdit>The only caveat is that the validation engine must enforce short-circuit evaluation which is required by the specification. For example, if EndTime were null, the validator would never evaluate whether StartTime < EndTime because it is not necessary.
-Greg
That requires the validation engine to stop evaluation, which atdl4j doesn’t appear to do. And also another assumption which I am yet to validate:
Does “Not Defined” == “NULL”?
We use atld4j and our brokers typically provide one of the following:
<val:StrategyEdit errorMessage=“Start time must be less than end time.”>
<val:Edit logicOperator=“OR”>
<val:Edit field=“StartTime” operator=“NX”/>
<val:Edit field=“EndTime” operator=“NX”/>
<val:Edit field=“EndTime” operator=“GT” field2=“StartTime”/>
</val:Edit>
</val:StrategyEdit>
<val:StrategyEdit errorMessage=“Start time must be less than end time.”>
<val:Edit logicOperator=“OR”>
<val:Edit field=“StartTime” operator=“NX”/>
<val:Edit field=“EndTime” operator=“NX”/>
<val:Edit field=“StartTime” field2=“EndTime” operator=“LT”/>
</val:Edit>
</val:StrategyEdit>
You can test whether a parameter is null or not provided by the user by using the EX (exists) or NX (does not exist) operators. The most common example is with optional StartTime and EndTime parameters.
Here’s the logic: If (StartTime != null) and (EndTime != null) then StartTime < EndTime must be true.
Which is equivalent to: (StartTime == null) OR (EndTime == null) OR (StartTime < EndTime)In FIXatdl:
<val:StrategyEdit errorMessage=“Start time must be less than end time.”>
<val:Edit logicOperator=“OR”>
<val:Edit field=“StartTime” operator=“NX”/>
<val:Edit field=“EndTime” operator=“NX”/>
<val:Edit field=“StartTime” field2=“EndTime” operator=“LT”/>
</val:Edit>
</val:StrategyEdit>The only caveat is that the validation engine must enforce short-circuit evaluation which is required by the specification. For example, if EndTime were null, the validator would never evaluate whether StartTime < EndTime because it is not necessary.
-Greg
That requires the validation engine to stop evaluation, which atdl4j doesn’t appear to do. And also another assumption which I am yet to validate:
Does “Not Defined” == “NULL”?
We use atld4j and our brokers typically provide one of the following:
<val:StrategyEdit errorMessage=“Start time must be less than end time.”>
<val:Edit logicOperator=“OR”>
<val:Edit field=“StartTime” operator=“NX”/>
<val:Edit field=“EndTime” operator=“NX”/>
<val:Edit field=“EndTime” operator=“GT” field2=“StartTime”/>
</val:Edit>
</val:StrategyEdit><val:StrategyEdit errorMessage=“Start time must be less than end time.”>
<val:Edit logicOperator=“OR”>
<val:Edit field=“StartTime” operator=“NX”/>
<val:Edit field=“EndTime” operator=“NX”/>
<val:Edit field=“StartTime” field2=“EndTime” operator=“LT”/>
</val:Edit>
</val:StrategyEdit>You can test whether a parameter is null or not provided by the user by using the EX (exists) or NX (does not exist) operators. The most common example is with optional StartTime and EndTime parameters.
Here’s the logic: If (StartTime != null) and (EndTime != null) then StartTime < EndTime must be true.
Which is equivalent to: (StartTime == null) OR (EndTime == null) OR (StartTime < EndTime)In FIXatdl:
<val:StrategyEdit errorMessage=“Start time must be less than end time.”>
<val:Edit logicOperator=“OR”>
<val:Edit field=“StartTime” operator=“NX”/>
<val:Edit field=“EndTime” operator=“NX”/>
<val:Edit field=“StartTime” field2=“EndTime” operator=“LT”/>
</val:Edit>
</val:StrategyEdit>The only caveat is that the validation engine must enforce short-circuit evaluation which is required by the specification. For example, if EndTime were null, the validator would never evaluate whether StartTime < EndTime because it is not necessary.
-Greg
That requires the validation engine to stop evaluation, which atdl4j doesn’t appear to do. And also another assumption which I am yet to validate:
Does “Not Defined” == “NULL”?
This works. Except in our case EndTime not being defined is a valid state. Which makes the rule as you specify fail. What I would like to have is to have the rule evaluated only if EndTime value exists.
This works. Except in our case EndTime not being defined is a valid state. Which makes the rule as you specify fail. What I would like to have is to have the rule evaluated only if EndTime value exists.
I am bit confused. The StrategyEdit cited is specific to a given . Are you saying that the issue is that a given Strategy does not have an EndTime parameter defined (vs. not set with a value)? If so, then simply do not reference that parameter within the StrategyEdit.
This works. Except in our case EndTime not being defined is a valid state. Which makes the rule as you specify fail. What I would like to have is to have the rule evaluated only if EndTime value exists.
I am bit confused. The StrategyEdit cited is specific to a given . Are you saying that the issue is that a given Strategy does not have an EndTime parameter defined (vs. not set with a value)? If so, then simply do not reference that parameter within the StrategyEdit.
Sorry for the confusion. The parameter EndTime is defined for the Strategy but may not have a value set.
I see you want to apply some execution flow control.
E.g.:
If (EndTime has a value) then use EndTime in some boolean expression.
Now I may not know a modens from a polens, but we achieve the same result using boolean expressions and short-circuit evaluation.
By doing so we avoid situations where the validating engine executes code such as:
if ( pointer && pointer->someMethod() )
without short-circuit logic, it would crash on dereferencing a NULL pointer, but with short-circuit logic, it works fine.
So this is why FIXatdl asjes that the renderers/validators use short-circuit evaluation. It allows you to check for the existence of a value and then, only if the value exists, access the value.
-Greg
I see you want to apply some execution flow control.
E.g.:
If (EndTime has a value) then use EndTime in some boolean expression.Now I may not know a modens from a polens, but we achieve the same result using boolean expressions and short-circuit evaluation.
By doing so we avoid situations where the validating engine executes code such as:if ( pointer && pointer->someMethod() )
without short-circuit logic, it would crash on dereferencing a NULL pointer, but with short-circuit logic, it works fine.
So this is why FIXatdl asjes that the renderers/validators use short-circuit evaluation. It allows you to check for the existence of a value and then, only if the value exists, access the value.
-Greg
OK. I think I got it.