fork(2) download
  1. String response = """
  2. <Root>
  3.   <DateTime>02.01.2017 14:45:21</DateTime>
  4.   <ReferenceId>10</ReferenceId>
  5.   <ServiceName>Front Office WS</ServiceName>
  6.   <ResultCulture>ru-RU</ResultCulture>
  7.   <ResultCode>10</ResultCode>
  8.   <ResultDescription />
  9.   <UsageIdentity />
  10.   <Result>
  11.     <Root>
  12.       <IdentificationDocuments stitle="Documents" title="id documents">
  13.         <Document rank="Primary evaluation" stitle="Actual" type="Current">
  14.           <Name id="1" title="Document type" value="RNN" />
  15.           <DateOfRegistration title="Recording date" value="01.01.1900" />
  16.           <DateOfIssuance title="Date of issuance" value="07.08.2012" />
  17.           <DateOfExpiration title="Duration" value="-" />
  18.           <Number title="Number" value="211567849595" />
  19.           <IssuanceLocation title="Issued by" value="" />
  20.           <DateOfInserted title="Date of receipt of information" value="12.04.2006" />
  21.         </Document>
  22.         <Document rank="Primary evaluation" stitle="Actual" type="Current">
  23.           <Name id="1" title="Document type" value="RNN" />
  24.           <DateOfRegistration title="Recording date" value="01.01.1900" />
  25.           <DateOfIssuance title="Date of issuance" value="07.08.2002" />
  26.           <DateOfExpiration title="Duration" value="-" />
  27.           <Number title="Number" value="211567849595" />
  28.           <IssuanceLocation title="Issued by" value="" />
  29.           <DateOfInserted title="Date of receipt of information" value="12.04.2006" />
  30.         </Document>
  31.         <Document rank="Primary evaluation" stitle="Actual" type="Current">
  32.           <Name id="14" title="Document type" value="IIN" />
  33.           <DateOfRegistration title="Recording date" value="15.03.2010" />
  34.           <DateOfIssuance title="Date of issuance" value="-" />
  35.           <DateOfExpiration title="Duration" value="-" />
  36.           <Number title="Number" value="645125901764" />
  37.           <IssuanceLocation title="Issued by" value="" />
  38.           <DateOfInserted title="Date of receipt of information" value="31.08.2010" />
  39.         </Document>
  40.         <Document rank="Secondary evaluation" stitle="Actual" type="Current">
  41.           <Name id="7" title="Document type" value="ID card" />
  42.           <DateOfRegistration title="Recording date" value="20.02.1998" />
  43.           <DateOfIssuance title="Date of issuance" value="-" />
  44.           <DateOfExpiration title="Duration" value="-" />
  45.           <Number title="Number" value="008070236" />
  46.           <IssuanceLocation title="Issued by" value="" />
  47.           <DateOfInserted title="Date of receipt of information" value="12.04.2006" />
  48.         </Document>
  49.         <Document rank="Secondary evaluation" stitle="Actual" type="Current">
  50.           <Name id="7" title="Document type" value="ID card" />
  51.           <DateOfRegistration title="Recording date" value="20.02.1998" />
  52.           <DateOfIssuance title="Date of issuance" value="10.10.2010" />
  53.           <DateOfExpiration title="Duration" value="-" />
  54.           <Number title="Number" value="8057836" />
  55.           <IssuanceLocation title="Issued by" value="" />
  56.           <DateOfInserted title="Date of receipt of information" value="08.01.2007" />
  57.         </Document>
  58.         <Document rank="Secondary evaluation" stitle="Actual" type="Current">
  59.           <Name id="3" title="Document type" value="SIK" />
  60.           <DateOfRegistration title="Recording date" value="01.01.1900" />
  61.           <DateOfIssuance title="Date of issuance" value="01.01.1900" />
  62.           <DateOfExpiration title="Duration" value="-" />
  63.           <Number title="Number" value="E5G7J8846UR5R32U" />
  64.           <IssuanceLocation title="Issued by" value="" />
  65.           <DateOfInserted title="Date of receipt of information" value="03.06.2007" />
  66.         </Document>
  67.         <Document rank="Secondary evaluation" stitle="Actual" type="Current">
  68.           <Name id="7" title="Document type" value="ID card" />
  69.           <DateOfRegistration title="Recording date" value="20.02.1998" />
  70.           <DateOfIssuance title="Date of issuance" value="13.05.2015" />
  71.           <DateOfExpiration title="Duration" value="-" />
  72.           <Number title="Номер" value="ID008070236" />
  73.           <IssuanceLocation title="Issued by" value="" />
  74.           <DateOfInserted title="Date of receipt of information" value="15.08.2008" />
  75.         </Document>
  76.         <Document rank="Secondary evaluation" stitle="Actual" type="Current">
  77.           <Name id="7" title="Document type" value="ID card" />
  78.           <DateOfRegistration title="Recording date" value="11.02.2010" />
  79.           <DateOfIssuance title="Date of issuance" value="23.03.2016" />
  80.           <DateOfExpiration title="Duration" value="-" />
  81.           <Number title="Номер" value="045808572" />
  82.           <IssuanceLocation title="Issued by" value="" />
  83.           <DateOfInserted title="Date of receipt of information" value="18.03.2010" />
  84.         </Document>      
  85.       </IdentificationDocuments>
  86.     </Root>
  87.   </Result>
  88. </Root>"""
  89. def xml = new XmlSlurper().parseText(response)
  90. def docs = xml.'**'.findAll{it.name() == 'Document'}
  91. def map = (docs.collect{it.Name.@id.text()} as Set).collectEntries{id -> [(id as Integer): docs.findAll{it.Name.@id.text() == id && it.DateOfIssuance.@value.text() && it.DateOfIssuance.@value.text() != "-" }.collect{Date.parse('dd.MM.yyyy', it.DateOfIssuance.@value.text())}.max()?.format('dd.MM.yyyy')]}.sort{it.key}.findAll{it.value}
  92. map.collect { println "Max date of issuance for ${it.key} is ${it.value}" }
Success #stdin #stdout 1.26s 4456448KB
stdin
Standard input is empty
stdout
Max date of issuance for 1 is 07.08.2012
Max date of issuance for 3 is 01.01.1900
Max date of issuance for 7 is 23.03.2016