28
28
import com .fasterxml .jackson .databind .ObjectMapper ;
29
29
import com .fasterxml .jackson .databind .node .ArrayNode ;
30
30
31
+
31
32
/**
32
33
* This class represents the mechanism to fetch the rule conditions from the
33
34
* Subscription Object and match it with the aggregatedObject to check if it is
@@ -49,67 +50,55 @@ public class RunSubscription {
49
50
* This method matches every condition specified in the subscription Object
50
51
* and if all conditions are matched then only the aggregatedObject is
51
52
* eligible for notification via e-mail or REST POST.
53
+ *
54
+ * (AND between conditions in requirements, "OR" between requirements with conditions)
52
55
*
53
56
* @param aggregatedObject
54
57
* @param requirement
55
58
* @param subscriptionJson
56
59
* @return boolean
57
60
*/
58
- public boolean runSubscriptionOnObject ( String aggregatedObject , ArrayNode fulfilledRequirements ,
59
- JsonNode subscriptionJson ) {
60
- Iterator < JsonNode > requirementIterator = fulfilledRequirements . elements ();
61
+
62
+ public boolean runSubscriptionOnObject ( String aggregatedObject , Iterator < JsonNode > requirementIterator ,
63
+ JsonNode subscriptionJson ) {
61
64
boolean conditionFulfilled = false ;
65
+ int count_condition_fulfillment = 0 ;
66
+ int count_conditions = 0 ;
67
+
68
+
62
69
while (requirementIterator .hasNext ()) {
63
70
JsonNode requirement = requirementIterator .next ();
64
71
log .info ("The fulfilled requirement which will condition checked is : " + requirement .toString ());
65
72
ArrayNode conditions = (ArrayNode ) requirement .get ("conditions" );
73
+
74
+ count_condition_fulfillment = 0 ;
75
+ count_conditions = conditions .size ();
76
+
66
77
log .info ("Conditions of the subscription : " + conditions .toString ());
67
78
Iterator <JsonNode > conditionIterator = conditions .elements ();
68
- // boolean conditionFulfilled = false;
69
79
while (conditionIterator .hasNext ()) {
70
80
String rule = conditionIterator .next ().get ("jmespath" ).toString ().replaceAll ("^\" |\" $" , "" );
71
81
String new_Rule = rule .replace ("'" , "\" " );
72
82
log .info ("Rule : " + rule );
73
83
log .info ("New Rule after replacing single quote : " + new_Rule );
74
84
JsonNode result = jmespath .runRuleOnEvent (rule , aggregatedObject );
75
85
log .info ("Result : " + result .toString ());
76
- if (result .toString () != null ) {
77
- conditionFulfilled = true ;
86
+ int test = result .toString ().length ();
87
+ if (result .toString () != null && result .toString () != "false" && !result .toString ().equals ("[]" )){
88
+ count_condition_fulfillment ++;
78
89
}
79
90
}
80
- }
81
- log .info ("The final value of conditionFulfilled is : " + conditionFulfilled );
82
- return conditionFulfilled ;
83
91
84
- }
92
+ if ( count_conditions != 0 && count_condition_fulfillment == count_conditions ){
85
93
86
- /**
87
- * This method check if the subscription requirement type and the
88
- * aggregatedObject TemplateName are same.
89
- *
90
- * @param requirementIterator
91
- * @param aggregatedObject
92
- * @return JsonNode
93
- */
94
- public ArrayNode checkRequirementType (Iterator <JsonNode > requirementIterator , String aggregatedObject ) {
95
- ArrayNode fulfilledRequirements = new ObjectMapper ().createArrayNode ();
96
- ;
97
- JsonNode requirement = null ;
98
- JsonNode aggregatedJson = null ;
99
- boolean condition = false ;
100
- try {
101
- aggregatedJson = new ObjectMapper ().readTree (aggregatedObject );
102
- log .info ("AggregatedJson : " + aggregatedJson .toString ());
103
- } catch (Exception e ) {
104
- log .error (e .getMessage (), e );
105
- }
106
- while (requirementIterator .hasNext ()) {
107
- requirement = requirementIterator .next ();
108
- log .info ("Requirements : " + requirement .toString ());
109
- fulfilledRequirements .add (requirement );
94
+ conditionFulfilled = true ;
95
+ }
110
96
}
111
97
112
- return fulfilledRequirements ;
98
+ log .info ("The final value of conditionFulfilled is : " + conditionFulfilled );
99
+
100
+ return conditionFulfilled ;
101
+
113
102
}
114
103
115
104
}
0 commit comments