public List<DictionaryItem> getVacationTypes(List<Vacation> vacations) { List<DictionaryItem> result = new ArrayList<DictionaryItem>(); for (Vacation vacation : vacations) { if (!result.contains(vacation.getType())) { result.add(vacation.getType()); } } // отсортируем Collections.sort( result, new Comparator() { @Override public int compare(Object type1, Object type2) { Integer typeId1 = ((DictionaryItem) type1).getId(); Integer typeId2 = ((DictionaryItem) type2).getId(); return typeId1.compareTo(typeId2); } }); return result; }
public String getVacationListByRegionJSON( Date dateFrom, Date dateTo, List<Vacation> vacationList) { List<Region> regionList = regionService.getRegions(); List<Employee> employeeList = new ArrayList<Employee>(); for (Vacation vacation : vacationList) { Employee employee = vacation.getEmployee(); if (!(employeeList.contains(employee))) { employeeList.add(employee); } } final JsonArrayNodeBuilder result = anArrayBuilder(); // для каждого проекта смотрим сотрудников у которых есть отпуск for (Region region : regionList) { JsonArrayNodeBuilder employeeNode = anArrayBuilder(); boolean hasEmployees = false; for (Employee employee : employeeList) { if (employee.getRegion().getId().equals(region.getId())) { JsonArrayNodeBuilder vacationNode = createVacationsNode(employee, vacationList); hasEmployees = true; employeeNode.withElement( anObjectBuilder() .withField("employee", aStringBuilder(employee.getName())) .withField("vacations", vacationNode)); } } if (hasEmployees) { result.withElement( anObjectBuilder() .withField("region_id", aStringBuilder(region.getId().toString())) .withField("region_name", aStringBuilder(region.getName())) .withField("employeeList", employeeNode) .withField("holidays", getHolidayInRegion(dateFrom, dateTo, region))); } } return JsonUtil.format(result); }