VoCustomerServiceImpl implements VoCustomerService { @Override public VoSearchResult<VoCustomerInfo> getFilteredCustomers(final VoSearchContext filter) throws Exception { final VoSearchResult<VoCustomerInfo> result = new VoSearchResult<>(); final List<VoCustomerInfo> results = new ArrayList<>(); result.setSearchContext(filter); result.setItems(results); final Map<String, List> all = filter.getParameters() != null ? new HashMap<>(filter.getParameters()) : new HashMap<>(); if (!federationFacade.isCurrentUserSystemAdmin()) { final Set<Long> shopIds = federationFacade.getAccessibleShopIdsByCurrentManager(); if (CollectionUtils.isEmpty(shopIds)) { return result; } all.put("shopIds", new ArrayList(shopIds)); } final SearchContext searchContext = new SearchContext( all, filter.getStart(), filter.getSize(), filter.getSortBy(), filter.isSortDesc(), "filter", "shopIds" ); final SearchResult<CustomerDTO> batch = dtoCustomerService.findCustomers(searchContext); results.addAll(voAssemblySupport.assembleVos(VoCustomerInfo.class, CustomerDTO.class, batch.getItems())); result.setTotal(batch.getTotal()); return result; } VoCustomerServiceImpl(final DtoCustomerService dtoCustomerService,
                                 final DtoAttributeService dtoAttributeService,
                                 final FederationFacade federationFacade,
                                 final VoAssemblySupport voAssemblySupport,
                                 final VoIOSupport voIOSupport); @Override VoSearchResult<VoCustomerInfo> getFilteredCustomers(final VoSearchContext filter); @Override VoCustomer getCustomerById(final long id); @Override VoCustomer updateCustomer(final VoCustomer vo); @Override VoCustomer createCustomer(final VoCustomer vo); @Override void removeCustomer(final long id); @Override List<VoAttrValueCustomer> getCustomerAttributes(final long customerId); @Override List<VoAttrValueCustomer> updateCustomerAttributes(final List<MutablePair<VoAttrValueCustomer, Boolean>> vo); @Override void resetPassword(final long customerId, final long shopId); void setSkipAttributesInView(List<String> attributes);  }
@Test public void testGetCustomers() throws Exception { VoSearchContext ctxNoFilter = new VoSearchContext(); ctxNoFilter.setSize(10); VoSearchResult<VoCustomerInfo> customerNoFilter = voCustomerService.getFilteredCustomers(ctxNoFilter); assertNotNull(customerNoFilter); assertTrue(customerNoFilter.getTotal() > 0); VoSearchContext ctxFind = new VoSearchContext(); ctxFind.setParameters(createSearchContextParams("filter", "reg@test.com")); ctxFind.setSize(10); VoSearchResult<VoCustomerInfo> customerFind = voCustomerService.getFilteredCustomers(ctxFind); assertNotNull(customerFind); assertTrue(customerFind.getTotal() > 0); assertEquals("reg@test.com", customerFind.getItems().get(0).getEmail()); assertNotNull(customerFind.getItems().get(0).getCustomerShops()); assertFalse(customerFind.getItems().get(0).getCustomerShops().isEmpty()); VoSearchContext ctxByEmailTagOrCompany = new VoSearchContext(); ctxByEmailTagOrCompany.setParameters(createSearchContextParams("filter", "#JJ")); ctxByEmailTagOrCompany.setSize(10); VoSearchResult<VoCustomerInfo> customerByEmailTagOrCompany = voCustomerService.getFilteredCustomers(ctxByEmailTagOrCompany); assertNotNull(customerByEmailTagOrCompany); assertTrue(customerByEmailTagOrCompany.getTotal() > 0); assertEquals("reg@test.com", customerByEmailTagOrCompany.getItems().get(0).getEmail()); VoSearchContext ctxByName = new VoSearchContext(); ctxByName.setParameters(createSearchContextParams("filter", "?John")); ctxByName.setSize(10); VoSearchResult<VoCustomerInfo> customerByName = voCustomerService.getFilteredCustomers(ctxByName); assertNotNull(customerByName); assertTrue(customerByName.getTotal() > 0); assertEquals("reg@test.com", customerByName.getItems().get(0).getEmail()); VoSearchContext ctxByAddress = new VoSearchContext(); ctxByAddress.setParameters(createSearchContextParams("filter", "@NW1 6XE")); ctxByAddress.setSize(10); VoSearchResult<VoCustomerInfo> customerByAddress = voCustomerService.getFilteredCustomers(ctxByAddress); assertNotNull(customerByAddress); assertTrue(customerByAddress.getTotal() > 0); assertEquals("reg@test.com", customerByAddress.getItems().get(0).getEmail()); VoSearchContext ctxByTypeOrPolicy = new VoSearchContext(); ctxByTypeOrPolicy.setParameters(createSearchContextParams("filter", "$TEST")); ctxByTypeOrPolicy.setSize(10); VoSearchResult<VoCustomerInfo> customerByTypeOrPolicy = voCustomerService.getFilteredCustomers(ctxByTypeOrPolicy); assertNotNull(customerByTypeOrPolicy); assertTrue(customerByTypeOrPolicy.getTotal() > 0); assertEquals("reg@test.com", customerByTypeOrPolicy.getItems().get(0).getEmail()); VoSearchContext ctxByByDate = new VoSearchContext(); ctxByByDate.setParameters(createSearchContextParams("filter", "2008-12<2009-01")); ctxByByDate.setSize(10); VoSearchResult<VoCustomerInfo> customerByDate = voCustomerService.getFilteredCustomers(ctxByByDate); assertNotNull(customerByDate); assertTrue(customerByDate.getTotal() > 0); assertEquals("reg@test.com", customerByDate.getItems().get(0).getEmail()); }