AnsweredAssumed Answered

How to sort records by two fields and perform certain validations

Question asked by rohit_tiwari on May 4, 2018
Latest reply on May 8, 2018 by leif.jacobsen@dagrofa.dk

I have a certain requirement to perform validation on Json data, please see below:

 

 

1. SORT ALL RECORDS by EmployeeId and Time in ascending order : I see groovy scripts available to sort by one filed, how to do it by two fields?

 

2.ONLY CONSIDER RECORDS WHEN THE FOLLOWING CONDITIONS ARE MET:

 

1) If the eventType = “ON”, and the immediate following record for the same EmployeeId with eventType = “OFF” AND (Status not= “DOT” or not= “DOT Break”)

2) If the eventType = “OFF”, and the (Status not= “DOT” or not= “DOT Break”)

 

Example 1:

Record 1: ACCEPT

{

"EmployeeId": "130630",

"Time": "2018-04-24 03:29",

"EventType": "ON",

"Status": ""

},

 

Record 2: ACCEPT

{

"EmployeeId": "123456",

"Time": "2018-04-24 16:30",

"EventType": "OFF",

"Status": ""

},

 

Example 2:

Record 1: IGNORE

{

"EmployeeId": "123456",

"Time": "2018-04-24 03:29",

"EventType": "ON",

"Status": ""

},

 

Record 2: IGNORE

{

"EmployeeId": "123456",

"Time": "2018-04-24 16:30",

"EventType": "OFF",

"Status": "DOT"

},

 

Example 3:

 

Record 1: ACCEPT

{

"EmployeeId": "123456",

"Time": "2018-04-24 03:29",

"EventType": "ON",

"Status": ""

},

 

Record 2: ACCEPT

{

"EmployeeId": "123456",

"Time": "2018-04-24 16:30",

"EventType": "OFF",

"Status": "Break"

},

 

Example 4:

 

Record 1: IGNORE

{

"EmployeeId": "123456",

"Time": "2018-04-24 03:29",

"EventType": "ON",

"Status": ""

},

 

THERE IS NO immediate following record for the same EmployeeId with eventType = “OFF” AND (Status not= “DOT” or not= “DOT Break”) FOUND

 

Example 5:

 

Record 1: ACCEPT

{

"EmployeeId": "123456",

"Time": "2018-04-24 03:29",

"EventType": "OFF",

"Status": ""

},

 

Example 6:

 

Record 1: IGNORE

{

"EmployeeId": "123456",

"Time": "2018-04-24 03:29",

"EventType": "OFF",

"Status": "DOT Break"

},

 

Please let me know the pointers to achieve these validations.

 

Thanks,

Rohit

Outcomes