Filing map in groovy without using list

45 Views Asked by At

I'am trying to fill up my HashMap with objects witchout using List<Order>, I know that .with and it is used like foreach, but at first I have to put index [0]. How to proper fill those map?

Map<String, Object> orders = new HashMap<>()
        try {
            context.apiClient.getDAO(pl.bonita.integrator.OrderDAO.class).findByArchived(IsArchived, startIndex, maxRows)[0].with {
                Map<String, Object> order = new HashMap<>()
                if (!it) {
                    response = "No case with id ${processId}"
                }
                order.put("CaseId", it.getCaseId())
                order.put("AssignedName", it.assignedName)
                orders.put(it.getCaseId().toString(), order)
            }
        } catch (Exception e) {
            response = "Exception: " + e.getMessage()
        }
0

There are 0 best solutions below