VoFulfilmentServiceImpl implements VoFulfilmentService { @Override public VoSearchResult<VoInventory> getFilteredInventory(final VoSearchContext filter) throws Exception { final VoSearchResult<VoInventory> result = new VoSearchResult<>(); final List<VoInventory> results = new ArrayList<>(); result.setSearchContext(filter); result.setItems(results); final long centreId = FilterSearchUtils.getIdFilter(filter.getParameters().get("centreId")); if (!federationFacade.isManageable(centreId, WarehouseDTO.class)) { return result; } final SearchContext searchContext = new SearchContext( filter.getParameters(), filter.getStart(), filter.getSize(), filter.getSortBy(), filter.isSortDesc(), "filter", "centreId" ); final SearchResult<InventoryDTO> batch = dtoInventoryService.findInventory(searchContext); if (!batch.getItems().isEmpty()) { results.addAll(voAssemblySupport.assembleVos(VoInventory.class, InventoryDTO.class, batch.getItems())); } result.setTotal(batch.getTotal()); return result; } VoFulfilmentServiceImpl(final DtoWarehouseService dtoWarehouseService,
                                   final DtoInventoryService dtoInventoryService,
                                   final FederationFacade federationFacade,
                                   final VoAssemblySupport voAssemblySupport); @Override VoSearchResult<VoFulfilmentCentreInfo> getFilteredFulfilmentCentres(final VoSearchContext filter); @Override List<VoShopFulfilmentCentre> getShopFulfilmentCentres(final long shopId); @Override void fillShopSummaryDetails(final VoShopSummary summary, final long shopId, final String lang); @Override VoFulfilmentCentre getFulfilmentCentreById(final long id); @Override VoFulfilmentCentre createFulfilmentCentre(final VoFulfilmentCentre vo); @Override VoFulfilmentCentre createShopFulfilmentCentre(final VoFulfilmentCentreInfo vo, final long shopId); @Override VoFulfilmentCentre updateFulfilmentCentre(final VoFulfilmentCentre vo); @Override List<VoShopFulfilmentCentre> updateShopFulfilmentCentres(final List<VoShopFulfilmentCentre> vo); @Override void removeFulfilmentCentre(final long id); @Override VoSearchResult<VoInventory> getFilteredInventory(final VoSearchContext filter); @Override VoInventory getInventoryById(final long id); @Override VoInventory updateInventory(final VoInventory vo); @Override VoInventory createInventory(final VoInventory vo); @Override void removeInventory(final long id);  }
@Test public void testGetInventory() throws Exception { VoSearchContext ctxFindNone = new VoSearchContext(); ctxFindNone.setParameters(createSearchContextParams( "filter", "XXXXX", "centreId", 3L )); ctxFindNone.setSize(10); final List<VoInventory> invNone = voFulfilmentService.getFilteredInventory(ctxFindNone).getItems(); assertNotNull(invNone); assertTrue(invNone.isEmpty()); VoSearchContext ctxFindName = new VoSearchContext(); ctxFindName.setParameters(createSearchContextParams( "filter", "Ben", "centreId", 2L )); ctxFindName.setSize(10); final List<VoInventory> invByName = voFulfilmentService.getFilteredInventory(ctxFindName).getItems(); assertNotNull(invByName); assertFalse(invByName.isEmpty()); assertTrue(invByName.get(0).getSkuCode().contains("BENDER")); VoSearchContext ctxFindCode = new VoSearchContext(); ctxFindCode.setParameters(createSearchContextParams( "filter", "!BENDER-ua", "centreId", 2L )); ctxFindCode.setSize(10); final List<VoInventory> invByCode = voFulfilmentService.getFilteredInventory(ctxFindCode).getItems(); assertNotNull(invByCode); assertFalse(invByCode.isEmpty()); assertEquals("BENDER-ua", invByCode.get(0).getSkuCode()); VoSearchContext ctxFindReserved = new VoSearchContext(); ctxFindReserved.setParameters(createSearchContextParams( "filter", "+1", "centreId", 2L )); ctxFindReserved.setSize(10); final List<VoInventory> invReserved = voFulfilmentService.getFilteredInventory(ctxFindReserved).getItems(); assertNotNull(invReserved); assertFalse(invReserved.isEmpty()); assertEquals("PRODUCT6", invReserved.get(0).getSkuCode()); assertTrue(BigDecimal.ZERO.compareTo(invReserved.get(0).getReserved()) < 0); VoSearchContext ctxFindDate = new VoSearchContext(); ctxFindDate.setParameters(createSearchContextParams( "filter", "2010-01-01<", "centreId", 2L )); ctxFindDate.setSize(10); final List<VoInventory> invAvailable = voFulfilmentService.getFilteredInventory(ctxFindDate).getItems(); assertNotNull(invAvailable); assertFalse(invAvailable.isEmpty()); }