-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(dpf-18714): inNextMinutes operator #835
Conversation
packages/@o3r/rules-engine/src/engine/operator/operators/date-based.operators.ts
Show resolved
Hide resolved
packages/@o3r/rules-engine/src/engine/operator/operators/date-based.operators.ts
Outdated
Show resolved
Hide resolved
packages/@o3r/rules-engine/src/engine/operator/operators/date-based.operators.ts
Outdated
Show resolved
Hide resolved
9b5ff69
to
f37ddb4
Compare
f37ddb4
to
ccdcda0
Compare
ccdcda0
to
29b6a71
Compare
316b732
to
4ed8707
Compare
packages/@o3r/rules-engine/src/engine/operator/facts/current-time/current-time.facts.ts
Outdated
Show resolved
Hide resolved
packages/@o3r/rules-engine/src/engine/operator/operator.helpers.ts
Outdated
Show resolved
Hide resolved
packages/@o3r/rules-engine/src/engine/operator/operator.interface.ts
Outdated
Show resolved
Hide resolved
packages/@o3r/rules-engine/src/engine/operator/operators/date-based.operators.spec.ts
Outdated
Show resolved
Hide resolved
packages/@o3r/rules-engine/src/engine/operator/operators/date-based.operators.spec.ts
Outdated
Show resolved
Hide resolved
4ed8707
to
ccf2ae4
Compare
packages/@o3r/rules-engine/src/engine/operator/operators/date-based.operators.ts
Outdated
Show resolved
Hide resolved
3f33473
to
011dc8b
Compare
packages/@o3r/rules-engine/src/engine/operator/operators/date-based.operators.ts
Outdated
Show resolved
Hide resolved
@kpanot which JSON Schema are you referring to? The ruleset one hasn't been modified in this PR. |
c8f106c
to
7642364
Compare
3f2b2d8
to
47784fb
Compare
...3r/rules-engine/builders/rules-engine-extractor/helpers/rules-engine.extractor.interfaces.ts
Outdated
Show resolved
Hide resolved
packages/@o3r/rules-engine/builders/rules-engine-extractor/helpers/rules-engine.extractor.ts
Outdated
Show resolved
Hide resolved
packages/@o3r/rules-engine/src/engine/operator/operator.interface.ts
Outdated
Show resolved
Hide resolved
packages/@o3r/rules-engine/src/engine/operator/operators/date-based.operators.ts
Show resolved
Hide resolved
const rulesWithContext: Rule[] = []; | ||
const rulesWithoutContext: Rule[] = []; | ||
const inputFactsForRule: Record<string, string[]> = {}; | ||
const exploreObject = (currentObj: any, ruleInputFacts: Set<string>) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure to understand the purpose of this part :S.
Why do you need it as you already have the list of facts available for the ruleset?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal is to compute the list of input facts and no longer take into account the value of the inputFacts
coming from the CMS.
We have even removed them from the showcase app ruleset https://github.com/AmadeusITGroup/otter/pull/835/files#diff-1c83c4284e0d72e53c44790c5bdd50daedb84c30b8e703c4e0552ecf2ab870ae
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, then the field should be flagged as deprecated
in the JSON schema.
The function may needs also a better name, comments ans proper input typings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concerning the types for the input, we support nested rules and the method will iterate on many types of Objects or Arrays.
Here's an example of a nested rule:
{
'id': '6e8t54h6s4e-6erth46sre8th4-d46t8s13t5j2',
'name': 'the second rule',
'inputRuntimeFacts': ['UI_FACT_2'],
'inputFacts': ['cart'],
'outputRuntimeFacts': [],
'rootElement': {
'elementType': 'RULE_BLOCK',
'blockType': 'IF_ELSE',
'condition': {
'any': [
{
'lhs': {
'type': 'RUNTIME_FACT',
'value': 'UI_FACT_2'
},
'operator': 'equals',
'rhs': {
'type': 'LITERAL',
'value': false
}
}
]
},
'successElements': [
{
'elementType': 'ACTION',
'actionType': 'UPDATE_LOCALISATION',
'key': 'my.loc.key2.success',
'value': 'my.loc.value2.success'
},
{
'elementType': 'ACTION',
'actionType': 'UPDATE_LOCALISATION',
'key': 'my.loc.key3.success',
'value': 'my.loc.value3.success'
},
{
'elementType': 'RULE_BLOCK',
'blockType': 'IF_ELSE',
'condition': {
'any': [
{
'lhs': {
'type': 'FACT',
'value': 'cart',
'path': '$.xmasHampers[0].hamperItems[1].id'
},
'operator': 'equals',
'rhs': {
'type': 'LITERAL',
'value': 'foieGras'
}
}
]
},
'successElements': [
{
'elementType': 'ACTION',
'actionType': 'UPDATE_LOCALISATION',
'key': 'my.loc.key4.success',
'value': 'my.loc.value4.success'
}
],
'failureElements': [
{
'elementType': 'ACTION',
'actionType': 'UPDATE_LOCALISATION',
'key': 'my.loc.key5.failure',
'value': 'my.loc.value5.failure'
}
]
},
{
'elementType': 'ACTION',
'actionType': 'UPDATE_LOCALISATION',
'key': 'my.loc.key6.success',
'value': 'my.loc.value6.success'
}
],
'failureElements': [
{
'elementType': 'ACTION',
'actionType': 'SET_FACT',
'fact': 'UI_FACT_2',
'value': false
}
]
}
}
The method will find the cart
fact in a successElements
array.
f130333
to
6b143ea
Compare
packages/@o3r/rules-engine/src/engine/operator/operator.interface.ts
Outdated
Show resolved
Hide resolved
6b143ea
to
90006c8
Compare
* @param currentObject The current object being explored. | ||
* @param ruleInputFacts A set to store the identified input facts for the rule. | ||
*/ | ||
const collectRuleInputFacts = (currentObject: any, ruleInputFacts: Set<string>) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currentObject
should be properly typed.
(this function can also be a private field to not be redefined at each execution)
19060e4
to
93f68ac
Compare
@@ -277,6 +277,14 @@ export class RulesEngineExtractor { | |||
nbValues: 1 | |||
} | |||
}; | |||
if (declaration.initializer && ts.isObjectLiteralExpression(declaration.initializer)) { | |||
declaration.initializer.properties.forEach((property: any) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
: any
should be avoid, how do you guaranty that property.name
exists otherwise?
* @param currentObject The current object being explored. | ||
* @param ruleInputFacts A set to store the identified input facts for the rule. | ||
*/ | ||
private collectRuleInputFacts(currentObject: any, ruleInputFacts: Set<string>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid : any
5c11621
to
eb4c10c
Compare
eb4c10c
to
227f851
Compare
if (!operatorFactValues) { | ||
throw new Error('No operatorFactValues. Unable to retrieve the current time.'); | ||
} | ||
if (typeof operatorFactValues.o3rCurrentTime !== 'number') { | ||
throw new Error('o3rCurrentTime value is not a number'); | ||
} | ||
const currentTimeValue = operatorFactValues.o3rCurrentTime; | ||
const now = new Date(currentTimeValue); | ||
const leftDate = new Date(leftDateInput); | ||
const targetDate = new Date(new Date(currentTimeValue).setMinutes(now.getMinutes() + +minutes)); | ||
return leftDate >= now && leftDate > targetDate; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!operatorFactValues) { | |
throw new Error('No operatorFactValues. Unable to retrieve the current time.'); | |
} | |
if (typeof operatorFactValues.o3rCurrentTime !== 'number') { | |
throw new Error('o3rCurrentTime value is not a number'); | |
} | |
const currentTimeValue = operatorFactValues.o3rCurrentTime; | |
const now = new Date(currentTimeValue); | |
const leftDate = new Date(leftDateInput); | |
const targetDate = new Date(new Date(currentTimeValue).setMinutes(now.getMinutes() + +minutes)); | |
return leftDate >= now && leftDate > targetDate; | |
return !dateInNextMinutes.evaluator(leftDateInput, minutes, operatorFactValues); |
?
Proposed change
Computing the input facts takes: