DistrictFacadeEjb implements DistrictFacade { @Override public Map<String, String> getRegionUuidsForDistricts(List<DistrictReferenceDto> districts) { if (districts.isEmpty()) { return new HashMap<>(); } CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class); Root<District> root = cq.from(District.class); Join<District, Region> regionJoin = root.join(District.REGION, JoinType.LEFT); Predicate filter = root.get(District.UUID).in(districts.stream().map(ReferenceDto::getUuid).collect(Collectors.toList())); cq.where(filter); cq.multiselect(root.get(District.UUID), regionJoin.get(Region.UUID)); return em.createQuery(cq).getResultList().stream().collect(Collectors.toMap(e -> (String) e[0], e -> (String) e[1])); }  @Override List<DistrictReferenceDto> getAllActiveAsReference(); @Override List<DistrictReferenceDto> getAllActiveByRegion(String regionUuid); @Override List<DistrictDto> getAllAfter(Date date); @Override List<DistrictIndexDto> getIndexList(DistrictCriteria criteria, Integer first, Integer max, List<SortProperty> sortProperties); @Override long count(DistrictCriteria criteria); @Override List<String> getAllUuids(); @Override int getCountByRegion(String regionUuid); @Override DistrictDto getDistrictByUuid(String uuid); @Override List<DistrictDto> getByUuids(List<String> uuids); @Override DistrictReferenceDto getDistrictReferenceByUuid(String uuid); @Override DistrictReferenceDto getDistrictReferenceById(long id); @Override Map<String, String> getRegionUuidsForDistricts(List<DistrictReferenceDto> districts); @Override void saveDistrict(DistrictDto dto); @Override List<DistrictReferenceDto> getByName(String name, RegionReferenceDto regionRef, boolean includeArchivedEntities); @Override List<String> getNamesByIds(List<Long> districtIds); @Override void archive(String districtUuid); @Override void dearchive(String districtUuid); @Override boolean isUsedInOtherInfrastructureData(Collection<String> districtUuids); @Override boolean hasArchivedParentInfrastructure(Collection<String> districtUuids); static DistrictReferenceDto toReferenceDto(District entity); DistrictDto toDto(District entity); DistrictIndexDto toIndexDto(District entity); @Override String getFullEpidCodeForDistrict(String districtUuid); String getFullEpidCodeForDistrict(District district);  }
@Test public void testGetRegionUuidsForDistricts() { Region r1 = creator.createRegion("r1"); Region r2 = creator.createRegion("r2"); District d1 = creator.createDistrict("d1", r1); District d2 = creator.createDistrict("d2", r2); District d3 = creator.createDistrict("d3", r2); Map<String, String> districtRegions = getDistrictFacade().getRegionUuidsForDistricts( Arrays.asList(new DistrictReferenceDto(d1.getUuid()), new DistrictReferenceDto(d2.getUuid()), new DistrictReferenceDto(d3.getUuid()))); assertThat(districtRegions.get(d1.getUuid()), is(r1.getUuid())); assertThat(districtRegions.get(d2.getUuid()), is(r2.getUuid())); assertThat(districtRegions.get(d3.getUuid()), is(r2.getUuid())); }