@RequestMapping(value = "api/{idString}/exprs", method = RequestMethod.GET) public @ResponseBody List<ExprDTO> getAllExprs(@PathVariable("idString") String idString) { // Get all collections List<Collection> collections = collectionRepository.findAllByOwner(idString); // Get all exprs List<Long> exprIds = new ArrayList<Long>(); for (Collection collection : collections) { exprIds.add(collection.getExprId()); } List<Expr> exprs = exprRepository.findAllByIdIn(exprIds); // Put collections into exprs List<ExprDTO> exprDTOs = new ArrayList<ExprDTO>(); Map<Long, ExprDTO> exprDTOMap = new HashMap<Long, ExprDTO>(); for (Expr expr : exprs) { ExprDTO exprDTO = new ExprDTO(expr); exprDTOs.add(exprDTO); exprDTOMap.put(exprDTO.getId(), exprDTO); } for (Collection collection : collections) { if (collection.getContent().length() > 0) { exprDTOMap.get(collection.getExprId()).tags.add(collection.getContent()); } } return exprDTOs; }