public static JSONArray generateAllCategoriesJSON() { JSONArray jsonArray = new JSONArray(); List<ChartSearchCategoryDisplayName> allDisplayNames = chartSearchService.getAllCategoryDisplayNames(); List<CategoryFilter> allCats = chartSearchService.getAllCategoryFilters(); for (CategoryFilter cat : allCats) { JSONObject json = new JSONObject(); String name = cat.getCategoryName(); String description = cat.getCategoryDescription(); String displayName = ""; String uuid = cat.getCategoryUuid(); for (ChartSearchCategoryDisplayName catName : allDisplayNames) { if (Context.getAuthenticatedUser() .getUserId() .equals(catName.getPreference().getPreferenceOwner().getUserId()) && catName.getCategoryFilter().getCategoryName().equals(name)) { displayName = catName.getDisplayName(); uuid = catName.getUuid(); } } json.put("name", name); json.put("uuid", uuid); json.put("displayName", displayName); json.put("description", description); jsonArray.add(json); } return jsonArray; }