Groovy web console

subscribe to the feed Subscribe
to this
site
ClosuresWithMultiStmts (via #groovywebconsole)
tweet this snippet Tweet
this
script

ClosuresWithMultiStmts

Published 3 months ago by Anand Patil with tags find collect replace key
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def audits = [  [
    "id": 4892725,
    "contractId": 30,
    "parentKey": "30",
    "key": "58",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892724,
    "contractId": 30,
    "parentKey": "30",
    "key": "59",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892726,
    "contractId": 30,
    "parentKey": "30",
    "key": "60",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892727,
    "contractId": 30,
    "parentKey": "30",
    "key": "61",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892728,
    "contractId": 30,
    "parentKey": "30",
    "key": "62",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892729,
    "contractId": 30,
    "parentKey": "30",
    "key": "63",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892730,
    "contractId": 30,
    "parentKey": "30",
    "key": "64",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892731,
    "contractId": 30,
    "parentKey": "30",
    "key": "65",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892732,
    "contractId": 30,
    "parentKey": "30",
    "key": "66",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892733,
    "contractId": 30,
    "parentKey": "30",
    "key": "67",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892734,
    "contractId": 30,
    "parentKey": "30",
    "key": "68",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892735,
    "contractId": 30,
    "parentKey": "30",
    "key": "69",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892736,
    "contractId": 30,
    "parentKey": "30",
    "key": "70",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892737,
    "contractId": 30,
    "parentKey": "30",
    "key": "71",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892739,
    "contractId": 30,
    "parentKey": "30",
    "key": "72",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892738,
    "contractId": 30,
    "parentKey": "30",
    "key": "73",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892740,
    "contractId": 30,
    "parentKey": "30",
    "key": "74",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892741,
    "contractId": 30,
    "parentKey": "30",
    "key": "75",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892742,
    "contractId": 30,
    "parentKey": "30",
    "key": "76",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892743,
    "contractId": 30,
    "parentKey": "30",
    "key": "77",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892744,
    "contractId": 30,
    "parentKey": "30",
    "key": "78",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892745,
    "contractId": 30,
    "parentKey": "30",
    "key": "79",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892746,
    "contractId": 30,
    "parentKey": "30",
    "key": "80",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892747,
    "contractId": 30,
    "parentKey": "30",
    "key": "81",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892748,
    "contractId": 30,
    "parentKey": "30",
    "key": "82",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892749,
    "contractId": 30,
    "parentKey": "30",
    "key": "83",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892723,
    "contractId": 30,
    "parentKey": "30",
    "key": "5",
    "tableName": "mt_dispatch",
    "changeType": "U"
  ],
  [
    "id": 4892702,
    "contractId": 30,
    "parentKey": "6",
    "key": "318381",
    "tableName": "mt_progress",
    "changeType": "I"
  ],
  [
    "id": 4892703,
    "contractId": 30,
    "parentKey": "6",
    "key": "318382",
    "tableName": "mt_progress",
    "changeType": "I"
  ],
  [
    "id": 4892704,
    "contractId": 30,
    "parentKey": "6",
    "key": "318383",
    "tableName": "mt_progress",
    "changeType": "I"
  ],
  [
    "id": 4892705,
    "contractId": 30,
    "parentKey": "6",
    "key": "318384",
    "tableName": "mt_progress",
    "changeType": "I"
  ],
  [
    "id": 4892706,
    "contractId": 30,
    "parentKey": "6",
    "key": "318385",
    "tableName": "mt_progress2",
    "changeType": "I"
  ],
  [
    "id": 4892707,
    "contractId": 30,
    "parentKey": "6",
    "key": "318386",
    "tableName": "mt_progress2",
    "changeType": "I"
  ]
]

def dispatchesDetails = [  [
    "id": "c1a740bd-f2b2-4f1d-8c30-a904a816d694",
    "dispatchId": 5,
    "contractId": 30,
    "contractDescription": "SAP Banks Peninsula ",
    "roadId": 0,
    "roadName": null,
    "locationSummary": null,
    "progressSummary": "1 progress note (18/05/2017)",
    "assetTypeId": 108,
    "assetTypeDescription": "Street Maintenance                      ",
    "callTypeId": "C",
    "callTypeDescription": "Council",
    "callStatusDescription": "Entered",
    "callStatusId": "E",
    "contractFormattedDescription": "SAP Banks Peninsula  - 30/5",
    "faultId": "EDR",
    "faultDescription": "Clear Detritus",
    "dispatchFaultDescription": "Clear Detritus",
    "priorityId": "A",
    "priorityDescription": "Appraise",
    "assignedToId": null,
    "assignedStaffName": null,
    "rework": false,
    "risk": false,
    "dayWork": false,
    "externalRef": "1",
    "jobManagerContractor": null,
    "jobManagerContractorName": null,
    "jobManagerClient": null,
    "jobManagerClientName": null,
    "houseNumber": null,
    "eventNumber": "10",
    "description": "POSTMAN",
    "feature": null,
    "side": "C",
    "sideDescription": "Centre",
    "offset": null,
    "start": null,
    "end": null,
    "length": null,
    "width": null,
    "depth": null,
    "quantity": 0,
    "units": null,
    "unitDescription": null,
    "programme": null,
    "programmeCategory": null,
    "dataEntryQuantity": "O",
    "dataEntryWidth": "O",
    "dataEntryLength": "O",
    "dataEntryDepth": "O",
    "allowCustomUnit": true,
    "useUnitMeters": true,
    "useUnitMeters2": true,
    "useUnitMeters3": true,
    "isUserModifiedQuantity": false,
    "isUserModifiedUnit": false,
    "dispatchGroup1": null,
    "group1Description": null,
    "dispatchGroup2": null,
    "group2Description": null,
    "dispatchGroup3": null,
    "group3Description": null,
    "dispatchGroup4": null,
    "group4Description": null,
    "dispatchGroup5": null,
    "group5Description": null,
    "dispatchClaimGroup1": null,
    "claimGroup1Description1": null,
    "dispatchClaimGroup2": null,
    "claimGroup1Description2": null,
    "costGroupDescription": null,
    "costGroup": null,
    "maintenanceCostFaultDescription": null,
    "maintenanceCostFault": null,
    "activityDescription": null,
    "activity": null,
    "inspectionDescription": null,
    "inspection": null,
    "templateJob": null,
    "templateJobDescription": null,
    "addedOn": "2017-05-17T13:16:00",
    "changedOn": "2017-05-26T22:49:00"
  ],
  [
    "id": "9c156f30-84c8-4eb0-b9de-8c20ee4a9f32",
    "dispatchId": 58,
    "contractId": 30,
    "contractDescription": "SAP Banks Peninsula ",
    "roadId": 0,
    "roadName": null,
    "locationSummary": null,
    "progressSummary": "",
    "assetTypeId": 108,
    "assetTypeDescription": "Street Maintenance                      ",
    "callTypeId": "C",
    "callTypeDescription": "Council",
    "callStatusDescription": "Entered",
    "callStatusId": "E",
    "contractFormattedDescription": "SAP Banks Peninsula  - 30/58",
    "faultId": "EDR",
    "faultDescription": "Clear Detritus",
    "dispatchFaultDescription": "Clear Detritus",
    "priorityId": "A",
    "priorityDescription": "Appraise",
    "assignedToId": null,
    "assignedStaffName": null,
    "rework": false,
    "risk": false,
    "dayWork": false,
    "externalRef": "777",
    "jobManagerContractor": null,
    "jobManagerContractorName": null,
    "jobManagerClient": null,
    "jobManagerClientName": null,
    "houseNumber": null,
    "eventNumber": null,
    "description": "dispatch notes",
    "feature": null,
    "side": "C",
    "sideDescription": "Centre",
    "offset": null,
    "start": null,
    "end": null,
    "length": null,
    "width": null,
    "depth": null,
    "quantity": 0,
    "units": null,
    "unitDescription": null,
    "programme": null,
    "programmeCategory": null,
    "dataEntryQuantity": "O",
    "dataEntryWidth": "O",
    "dataEntryLength": "O",
    "dataEntryDepth": "O",
    "allowCustomUnit": true,
    "useUnitMeters": true,
    "useUnitMeters2": true,
    "useUnitMeters3": true,
    "isUserModifiedQuantity": false,
    "isUserModifiedUnit": false,
    "dispatchGroup1": null,
    "group1Description": null,
    "dispatchGroup2": null,
    "group2Description": null,
    "dispatchGroup3": null,
    "group3Description": null,
    "dispatchGroup4": null,
    "group4Description": null,
    "dispatchGroup5": null,
    "group5Description": null,
    "dispatchClaimGroup1": null,
    "claimGroup1Description1": null,
    "dispatchClaimGroup2": null,
    "claimGroup1Description2": null,
    "costGroupDescription": null,
    "costGroup": null,
    "maintenanceCostFaultDescription": null,
    "maintenanceCostFault": null,
    "activityDescription": null,
    "activity": null,
    "inspectionDescription": null,
    "inspection": null,
    "templateJob": null,
    "templateJobDescription": null,
    "addedOn": "2017-05-31T15:41:00",
    "changedOn": "2017-05-31T15:41:00"
  ],
  [
    "id": "a0687893-b9a5-4382-a982-2c54fbee86f7",
    "dispatchId": 59,
    "contractId": 30,
    "contractDescription": "SAP Banks Peninsula ",
    "roadId": 0,
    "roadName": null,
    "locationSummary": null,
    "progressSummary": "",
    "assetTypeId": 108,
    "assetTypeDescription": "Street Maintenance                      ",
    "callTypeId": "C",
    "callTypeDescription": "Council",
    "callStatusDescription": "Entered",
    "callStatusId": "E",
    "contractFormattedDescription": "SAP Banks Peninsula  - 30/59",
    "faultId": "EDR",
    "faultDescription": "Clear Detritus",
    "dispatchFaultDescription": "Clear Detritus",
    "priorityId": "A",
    "priorityDescription": "Appraise",
    "assignedToId": null,
    "assignedStaffName": null,
    "rework": false,
    "risk": false,
    "dayWork": false,
    "externalRef": "777",
    "jobManagerContractor": null,
    "jobManagerContractorName": null,
    "jobManagerClient": null,
    "jobManagerClientName": null,
    "houseNumber": null,
    "eventNumber": null,
    "description": "dispatch notes",
    "feature": null,
    "side": "C",
    "sideDescription": "Centre",
    "offset": null,
    "start": null,
    "end": null,
    "length": null,
    "width": null,
    "depth": null,
    "quantity": 0,
    "units": null,
    "unitDescription": null,
    "programme": null,
    "programmeCategory": null,
    "dataEntryQuantity": "O",
    "dataEntryWidth": "O",
    "dataEntryLength": "O",
    "dataEntryDepth": "O",
    "allowCustomUnit": true,
    "useUnitMeters": true,
    "useUnitMeters2": true,
    "useUnitMeters3": true,
    "isUserModifiedQuantity": false,
    "isUserModifiedUnit": false,
    "dispatchGroup1": null,
    "group1Description": null,
    "dispatchGroup2": null,
    "group2Description": null,
    "dispatchGroup3": null,
    "group3Description": null,
    "dispatchGroup4": null,
    "group4Description": null,
    "dispatchGroup5": null,
    "group5Description": null,
    "dispatchClaimGroup1": null,
    "claimGroup1Description1": null,
    "dispatchClaimGroup2": null,
    "claimGroup1Description2": null,
    "costGroupDescription": null,
    "costGroup": null,
    "maintenanceCostFaultDescription": null,
    "maintenanceCostFault": null,
    "activityDescription": null,
    "activity": null,
    "inspectionDescription": null,
    "inspection": null,
    "templateJob": null,
    "templateJobDescription": null,
    "addedOn": "2017-05-31T15:41:00",
    "changedOn": "2017-05-31T15:41:00"
  ],
  [
    "id": "32ee6c6c-6bc2-461f-9ecc-9f9d186ffba8",
    "dispatchId": 60,
    "contractId": 30,
    "contractDescription": "SAP Banks Peninsula ",
    "roadId": 0,
    "roadName": null,
    "locationSummary": null,
    "progressSummary": "",
    "assetTypeId": 108,
    "assetTypeDescription": "Street Maintenance                      ",
    "callTypeId": "C",
    "callTypeDescription": "Council",
    "callStatusDescription": "Entered",
    "callStatusId": "E",
    "contractFormattedDescription": "SAP Banks Peninsula  - 30/60",
    "faultId": "EDR",
    "faultDescription": "Clear Detritus",
    "dispatchFaultDescription": "Clear Detritus",
    "priorityId": "A",
    "priorityDescription": "Appraise",
    "assignedToId": null,
    "assignedStaffName": null,
    "rework": false,
    "risk": false,
    "dayWork": false,
    "externalRef": "777",
    "jobManagerContractor": null,
    "jobManagerContractorName": null,
    "jobManagerClient": null,
    "jobManagerClientName": null,
    "houseNumber": null,
    "eventNumber": null,
    "description": "dispatch notes",
    "feature": null,
    "side": "C",
    "sideDescription": "Centre",
    "offset": null,
    "start": null,
    "end": null,
    "length": null,
    "width": null,
    "depth": null,
    "quantity": 0,
    "units": null,
    "unitDescription": null,
    "programme": null,
    "programmeCategory": null,
    "dataEntryQuantity": "O",
    "dataEntryWidth": "O",
    "dataEntryLength": "O",
    "dataEntryDepth": "O",
    "allowCustomUnit": true,
    "useUnitMeters": true,
    "useUnitMeters2": true,
    "useUnitMeters3": true,
    "isUserModifiedQuantity": false,
    "isUserModifiedUnit": false,
    "dispatchGroup1": null,
    "group1Description": null,
    "dispatchGroup2": null,
    "group2Description": null,
    "dispatchGroup3": null,
    "group3Description": null,
    "dispatchGroup4": null,
    "group4Description": null,
    "dispatchGroup5": null,
    "group5Description": null,
    "dispatchClaimGroup1": null,
    "claimGroup1Description1": null,
    "dispatchClaimGroup2": null,
    "claimGroup1Description2": null,
    "costGroupDescription": null,
    "costGroup": null,
    "maintenanceCostFaultDescription": null,
    "maintenanceCostFault": null,
    "activityDescription": null,
    "activity": null,
    "inspectionDescription": null,
    "inspection": null,
    "templateJob": null,
    "templateJobDescription": null,
    "addedOn": "2017-05-31T15:44:00",
    "changedOn": "2017-05-31T15:44:00"
  ]
]

//def dispatches = audits.findAll{it.tableName == 'mt_progress2'}.collect{it.subMap(["contractId","key"])}.each{it.put("dispatchId",it.remove("key"))}

//dispatchesDetails.find{it.dispatchId == }

println audits.each{def parentIt = it
                    def valueFound = dispatchesDetails.find{it.dispatchId == parentIt.key.toInteger() && it.contractId == parentIt.contractId}    
                        it.put("details",valueFound)
                    }

//println dispatches//.collectdispatches[0].remove("key"))}
//dispatches.each{it.put("dispatchId",it.remove("key"))}