DtoCarrierSlaServiceImpl extends AbstractDtoServiceImpl<CarrierSlaDTO, CarrierSlaDTOImpl, CarrierSla> implements DtoCarrierSlaService { @Override public SearchResult<CarrierSlaDTO> findCarrierSlas(final SearchContext filter) throws UnmappedInterfaceException, UnableToCreateInstanceException { final Map<String, List> params = filter.reduceParameters("filter", "carrierIds"); final String textFilter = FilterSearchUtils.getStringFilter(params.get("filter")); final List carrierIds = params.containsKey("carrierIds") ? (List) params.get("carrierIds").stream().map(id -> NumberUtils.toLong(String.valueOf(id))).collect(Collectors.toList()) : null; final int pageSize = filter.getSize(); final int startIndex = filter.getStart() * pageSize; final CarrierSlaService carrierSlaService = (CarrierSlaService) service; if (carrierIds != null) { final Map<String, List> currentFilter = new HashMap<>(); if (StringUtils.isNotBlank(textFilter)) { final Pair<String, String> code = ComplexSearchUtils.checkSpecialSearch(textFilter, CODE); if (code != null) { if ("!".equals(code.getFirst())) { currentFilter.put("guid", Collections.singletonList(SearchContext.MatchMode.EQ.toParam(code.getSecond()))); } } else { SearchContext.JoinMode.OR.setMode(currentFilter); currentFilter.put("guid", Collections.singletonList(textFilter)); currentFilter.put("name", Collections.singletonList(textFilter)); currentFilter.put("description", Collections.singletonList(textFilter)); currentFilter.put("carrier.guid", Collections.singletonList(textFilter)); currentFilter.put("carrier.name", Collections.singletonList(textFilter)); } } currentFilter.put("carrierIds", carrierIds); final int count = carrierSlaService.findCarrierSlaCount(currentFilter); if (count > startIndex) { final List<CarrierSlaDTO> entities = new ArrayList<>(); final List<CarrierSla> carrierSlas = carrierSlaService.findCarrierSlas(startIndex, pageSize, filter.getSortBy(), filter.isSortDesc(), currentFilter); fillDTOs(carrierSlas, entities); return new SearchResult<>(filter, entities, count); } } return new SearchResult<>(filter, Collections.emptyList(), 0); } DtoCarrierSlaServiceImpl(final DtoFactory dtoFactory,
                                 final GenericService<CarrierSla> carrierSlaGenericService,
                                 final AdaptersRepository AdaptersRepository); @Override List<CarrierSlaDTO> findByCarrier(final long carrierId); @Override SearchResult<CarrierSlaDTO> findCarrierSlas(final SearchContext filter); @Override List<CarrierSlaDTO> findBy(final String filter, final int page, final int pageSize); @Override Class<CarrierSlaDTO> getDtoIFace(); @Override Class<CarrierSlaDTOImpl> getDtoImpl(); @Override Class<CarrierSla> getEntityIFace();  }
@Test public void testFindCarrierSlas() throws Exception { final List<Long> carrierIdsNone = Collections.singletonList(9999L); final List<Long> carrierIds = Arrays.asList(1L, 2L, 3L); SearchContext ctx; SearchResult<CarrierSlaDTO> rez; ctx = createSearchContext("guid", false, 0, 10, "filter", "1_CARRIER", "carrierIds", carrierIds ); rez = dtoService.findCarrierSlas(ctx); assertEquals(3, rez.getTotal()); assertEquals(3, rez.getItems().size()); assertEquals(1L, rez.getItems().get(0).getCarrierId()); assertEquals(1L, rez.getItems().get(1).getCarrierId()); assertEquals(1L, rez.getItems().get(2).getCarrierId()); ctx = createSearchContext("guid", false, 0, 10, "carrierIds", carrierIdsNone ); rez = dtoService.findCarrierSlas(ctx); assertEquals(0, rez.getTotal()); ctx = createSearchContext("guid", false, 0, 10, "carrierIds", carrierIds ); rez = dtoService.findCarrierSlas(ctx); assertEquals(4, rez.getTotal()); assertEquals(4, rez.getItems().size()); assertEquals("1_CARRIERSLA", rez.getItems().get(0).getCode()); assertEquals("2_CARRIERSLA", rez.getItems().get(1).getCode()); assertEquals("3_CARRIERSLA", rez.getItems().get(2).getCode()); }