2

Am trying to create a new Map <String, List<String>> headErrors with selective elements from another Map <String, List<String>> invoiceErrorLines

invoiceErrorLines = ['1660277':['Line : 1 Invoice does not foot Reported', 'Line : 2 MATH ERROR'], 
 '1660278':['Line : 5 Invoice does not foot Reported', 'cl_id is a required field'], 
 '1660279':['Line : 7 could not parse date ', 'File Error : The file doesnt have delimiter'], 
 '1660280':['Line : 9 Invoice error']]
def regex = "^Line\\s(?:(\\d+)\\s)?\\s*:\\s+(\\d+)?.+"
def headErrors = invoiceErrorLines.each{ inv ->
 inv.value.findAll{it.contains('Invoice does not foot Reported') || !(it ==~ regex) }.groupBy{inv.key} 
}

New Map should contain invoice numbers as key and its corresponding error messages which doesnt match regex = "^Line\\s(?:(\\d+)\\s)?\\s*:\\s+(\\d+)?.+" but contains Invoice does not foot Reported

When I print headErrors am seeing the same map as invoiceErrorLines but am expecting the headErrors as below

headErrors = ['1660277':['Line : 1 Invoice does not foot Reported'], 
 '1660278':['Line : 5 Invoice does not foot Reported', 'cl_id is a required field'], 
 '1660279':['File Error : The file doesnt have delimiter'] 
 ]

Can someone help me with this?

asked Apr 7, 2015 at 18:29

1 Answer 1

3

With

def headErrors = invoiceErrorLines.collectEntries{ key, value ->
 value.findAll{ it.contains('Invoice does not foot Reported') || !(it ==~ regex) }.groupBy{ key }
}

it yields

[1660277:[Line : 1 Invoice does not foot Reported], 1660278:[Line : 5 Invoice does not foot Reported, cl_id is a required field], 1660279:[File Error : The file doesnt have delimiter]]
answered Apr 7, 2015 at 18:46

2 Comments

Thanks for the answer. I appreciate it. Can you also help me with this stackoverflow.com/questions/29570648/…
can you please help me solving this problem? stackoverflow.com/questions/47717505/…

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.