@Test public void shouldReturnNullWhenLotsOnHandIsNull() { Long facilityId = 1L; String productCode = "2"; Integer numEntries = 100; when(stockCardRepository.getStockCardByFacilityAndProduct(any(Long.class), any(String.class))).thenReturn(dummyCard); setupPermissionCalls(Collections.singletonList(new Right("VIEW_STOCK_ON_HAND", RightType.REQUISITION))); boolean includeEmptyLots = false; ResponseEntity response = controller.getStockCard(facilityId, productCode, numEntries, includeEmptyLots, request); StockCard stockCard = (StockCard)response.getBody(); assertNull(stockCard.getLotsOnHand()); includeEmptyLots = true; response = controller.getStockCard(facilityId, productCode, numEntries, includeEmptyLots, request); stockCard = (StockCard)response.getBody(); assertNull(stockCard.getLotsOnHand()); }
@RequestMapping(value = "facilities/{facilityId}/products/{productCode}/stockCard", method = GET, headers = ACCEPT_JSON) @ApiOperation(value = "Get information about the stock card for the specified facility and product.", notes = "Gets stock card information, by facility and product." + "<p>If no view permissions are found for this stock card, will return 403 Forbidden." + "<p>" + "<p>Path parameters (required):" + "<ul>" + "<li><strong>facilityId</strong> (Long) - facility for the stock card.</li>" + "<li><strong>productCode</strong> (String) - product for the stock card.</li>" + "</ul>" + "<p>" + "<p>Request parameters:" + "<ul>" + "<li><strong>entries</strong> (Integer, optional, default = 1) - Number of stock card entries to " + "get in the result.</li>" + "</ul>") public ResponseEntity getStockCard(@PathVariable Long facilityId, @PathVariable String productCode, @RequestParam(value = "entries", defaultValue = "1")Integer entries, @RequestParam(value = "includeEmptyLots", required = false, defaultValue = "false") boolean includeEmptyLots, HttpServletRequest request) { Long userId = loggedInUserId(request); List<Right> rights = roleRightsService.getRightsForUserFacilityAndProductCode(userId, facilityId, productCode); if (!any(rights, with("VIEW_STOCK_ON_HAND"))) { return OpenLmisResponse.error(messageService.message("error.permission.stock.card.view"), HttpStatus.FORBIDDEN); } StockCard stockCard = stockCardRepository.getStockCardByFacilityAndProduct(facilityId, productCode); if (stockCard != null) { filterEntries(stockCard, entries, includeEmptyLots); return OpenLmisResponse.response(stockCard); } else { return OpenLmisResponse.error("The specified stock card does not exist." , HttpStatus.NOT_FOUND); } }
StockCardController extends BaseController { @RequestMapping(value = "facilities/{facilityId}/products/{productCode}/stockCard", method = GET, headers = ACCEPT_JSON) @ApiOperation(value = "Get information about the stock card for the specified facility and product.", notes = "Gets stock card information, by facility and product." + "<p>If no view permissions are found for this stock card, will return 403 Forbidden." + "<p>" + "<p>Path parameters (required):" + "<ul>" + "<li><strong>facilityId</strong> (Long) - facility for the stock card.</li>" + "<li><strong>productCode</strong> (String) - product for the stock card.</li>" + "</ul>" + "<p>" + "<p>Request parameters:" + "<ul>" + "<li><strong>entries</strong> (Integer, optional, default = 1) - Number of stock card entries to " + "get in the result.</li>" + "</ul>") public ResponseEntity getStockCard(@PathVariable Long facilityId, @PathVariable String productCode, @RequestParam(value = "entries", defaultValue = "1")Integer entries, @RequestParam(value = "includeEmptyLots", required = false, defaultValue = "false") boolean includeEmptyLots, HttpServletRequest request) { Long userId = loggedInUserId(request); List<Right> rights = roleRightsService.getRightsForUserFacilityAndProductCode(userId, facilityId, productCode); if (!any(rights, with("VIEW_STOCK_ON_HAND"))) { return OpenLmisResponse.error(messageService.message("error.permission.stock.card.view"), HttpStatus.FORBIDDEN); } StockCard stockCard = stockCardRepository.getStockCardByFacilityAndProduct(facilityId, productCode); if (stockCard != null) { filterEntries(stockCard, entries, includeEmptyLots); return OpenLmisResponse.response(stockCard); } else { return OpenLmisResponse.error("The specified stock card does not exist." , HttpStatus.NOT_FOUND); } } }
StockCardController extends BaseController { @RequestMapping(value = "facilities/{facilityId}/products/{productCode}/stockCard", method = GET, headers = ACCEPT_JSON) @ApiOperation(value = "Get information about the stock card for the specified facility and product.", notes = "Gets stock card information, by facility and product." + "<p>If no view permissions are found for this stock card, will return 403 Forbidden." + "<p>" + "<p>Path parameters (required):" + "<ul>" + "<li><strong>facilityId</strong> (Long) - facility for the stock card.</li>" + "<li><strong>productCode</strong> (String) - product for the stock card.</li>" + "</ul>" + "<p>" + "<p>Request parameters:" + "<ul>" + "<li><strong>entries</strong> (Integer, optional, default = 1) - Number of stock card entries to " + "get in the result.</li>" + "</ul>") public ResponseEntity getStockCard(@PathVariable Long facilityId, @PathVariable String productCode, @RequestParam(value = "entries", defaultValue = "1")Integer entries, @RequestParam(value = "includeEmptyLots", required = false, defaultValue = "false") boolean includeEmptyLots, HttpServletRequest request) { Long userId = loggedInUserId(request); List<Right> rights = roleRightsService.getRightsForUserFacilityAndProductCode(userId, facilityId, productCode); if (!any(rights, with("VIEW_STOCK_ON_HAND"))) { return OpenLmisResponse.error(messageService.message("error.permission.stock.card.view"), HttpStatus.FORBIDDEN); } StockCard stockCard = stockCardRepository.getStockCardByFacilityAndProduct(facilityId, productCode); if (stockCard != null) { filterEntries(stockCard, entries, includeEmptyLots); return OpenLmisResponse.response(stockCard); } else { return OpenLmisResponse.error("The specified stock card does not exist." , HttpStatus.NOT_FOUND); } } StockCardController(MessageService messageService,
                        FacilityRepository facilityRepository,
                        ProductService productService,
                        StockAdjustmentReasonRepository stockAdjustmentReasonRepository,
                        StockCardRepository stockCardRepository,
                        LotRepository lotRepository,
                        ProgramProductService programProductService,
                        ProgramService programService,
                        RoleRightsService roleRightsService,
                        StockCardService service); }
StockCardController extends BaseController { @RequestMapping(value = "facilities/{facilityId}/products/{productCode}/stockCard", method = GET, headers = ACCEPT_JSON) @ApiOperation(value = "Get information about the stock card for the specified facility and product.", notes = "Gets stock card information, by facility and product." + "<p>If no view permissions are found for this stock card, will return 403 Forbidden." + "<p>" + "<p>Path parameters (required):" + "<ul>" + "<li><strong>facilityId</strong> (Long) - facility for the stock card.</li>" + "<li><strong>productCode</strong> (String) - product for the stock card.</li>" + "</ul>" + "<p>" + "<p>Request parameters:" + "<ul>" + "<li><strong>entries</strong> (Integer, optional, default = 1) - Number of stock card entries to " + "get in the result.</li>" + "</ul>") public ResponseEntity getStockCard(@PathVariable Long facilityId, @PathVariable String productCode, @RequestParam(value = "entries", defaultValue = "1")Integer entries, @RequestParam(value = "includeEmptyLots", required = false, defaultValue = "false") boolean includeEmptyLots, HttpServletRequest request) { Long userId = loggedInUserId(request); List<Right> rights = roleRightsService.getRightsForUserFacilityAndProductCode(userId, facilityId, productCode); if (!any(rights, with("VIEW_STOCK_ON_HAND"))) { return OpenLmisResponse.error(messageService.message("error.permission.stock.card.view"), HttpStatus.FORBIDDEN); } StockCard stockCard = stockCardRepository.getStockCardByFacilityAndProduct(facilityId, productCode); if (stockCard != null) { filterEntries(stockCard, entries, includeEmptyLots); return OpenLmisResponse.response(stockCard); } else { return OpenLmisResponse.error("The specified stock card does not exist." , HttpStatus.NOT_FOUND); } } StockCardController(MessageService messageService,
                        FacilityRepository facilityRepository,
                        ProductService productService,
                        StockAdjustmentReasonRepository stockAdjustmentReasonRepository,
                        StockCardRepository stockCardRepository,
                        LotRepository lotRepository,
                        ProgramProductService programProductService,
                        ProgramService programService,
                        RoleRightsService roleRightsService,
                        StockCardService service); @RequestMapping(value = "facilities/{facilityId}/products/{productCode}/stockCard", method = GET, headers = ACCEPT_JSON) @ApiOperation(value = "Get information about the stock card for the specified facility and product.", notes = "Gets stock card information, by facility and product." + "<p>If no view permissions are found for this stock card, will return 403 Forbidden." + "<p>" + "<p>Path parameters (required):" + "<ul>" + "<li><strong>facilityId</strong> (Long) - facility for the stock card.</li>" + "<li><strong>productCode</strong> (String) - product for the stock card.</li>" + "</ul>" + "<p>" + "<p>Request parameters:" + "<ul>" + "<li><strong>entries</strong> (Integer, optional, default = 1) - Number of stock card entries to " + "get in the result.</li>" + "</ul>") ResponseEntity getStockCard(@PathVariable Long facilityId,
                                       @PathVariable String productCode,
                                       @RequestParam(value = "entries", defaultValue = "1")Integer entries,
                                       @RequestParam(value = "includeEmptyLots", required = false, defaultValue = "false") boolean includeEmptyLots,
                                       HttpServletRequest request); @RequestMapping(value = "facilities/{facilityId}/stockCards/{stockCardId}", method = GET, headers = ACCEPT_JSON) @ApiOperation(value = "Get information about the specified stock card for the specified facility.", notes = "Gets stock card information, by facility and stock card id." + "<p>If facility does not have specified stock card id, will return 404 Not Found." + "<p>If no view permissions are found for this stock card, will return 403 Forbidden." + "<p>" + "<p>Path parameters (required):" + "<ul>" + "<li><strong>facilityId</strong> (Long) - facility for the stock card.</li>" + "<li><strong>stockCardId</strong> (Long) - the specified stock card.</li>" + "</ul>" + "<p>" + "<p>Request parameters:" + "<ul>" + "<li><strong>entries</strong> (Integer, optional, default = 1) - Number of stock card entries to " + "get in the result.</li>" + "</ul>") ResponseEntity getStockCardById(@PathVariable Long facilityId, @PathVariable Long stockCardId,
                                           @RequestParam(value = "entries", defaultValue = "1")Integer entries,
                                           @RequestParam(value = "includeEmptyLots", required = false, defaultValue = "false") boolean includeEmptyLots,
                                           HttpServletRequest request); @RequestMapping(value = "facilities/{facilityId}/stockCards", method = GET, headers = ACCEPT_JSON) @ApiOperation(value = "Get information about all stock cards for the specified facility.", notes = "Gets all stock card information, by facility." + "<p>If no stock cards exist, will return 404 Not Found." + "<p>If no view permissions are found for any existing stock card, will return an empty list." + "<p>" + "<p>Path parameters (required):" + "<ul>" + "<li><strong>facilityId</strong> (Long) - facility for the stock cards.</li>" + "</ul>" + "<p>" + "<p>Request parameters:" + "<ul>" + "<li><strong>entries</strong> (Integer, optional, default = 1) - Number of stock card entries to " + "get in the result.</li>" + "<li><strong>countOnly</strong> (Boolean, optional, default = false) - Get only the count of " + "stock cards.</li>" + "</ul>") ResponseEntity getStockCards(@PathVariable Long facilityId,
                                        @RequestParam(value = "entries", defaultValue = "1") Integer entries,
                                        @RequestParam(value = "countOnly", defaultValue = "false") Boolean countOnly,
                                        @RequestParam(value = "includeEmptyLots", required = false, defaultValue = "false") boolean includeEmptyLots,
                                        HttpServletRequest request); @RequestMapping(value = "facilities/{facilityId}/stockCards", method = POST, headers = ACCEPT_JSON) @ApiOperation(value="Update stock cards at a facility.", notes = "Updates stock cards at a facility. This is done by providing a list of stock events." + "<p>Path parameters (required):" + "<ul>" + "<li><strong>facilityId</strong> (Long) - facility for the stock cards in which to update.</li>" + "</ul>" + "<p>" + "<p>Body parameters (required):" + "<ul>" + "<li>" + "<strong>stock events</strong> (Array of stock event objects) - a list of stock events to " + "process for update." + "<p>" + "<p>Stock event properties" + "<ul>" + "<li><strong>type</strong> (String, required) - type code of stock event (choices are ISSUE, " + "RECEIPT, ADJUSTMENT).</li>" + "<li><strong>facilityId</strong> (Long, required for ISSUE/RECEIPT types) - facility id where" + "stock is going to/coming from.</li>" + "<li><strong>productCode</strong> (String, required) - product code of the stock being " + "processed.</li>" + "<li><strong>quantity</strong> (Long, required) - quantity of stock being processed. Specify as a " + "positive number. For ISSUE, this amount is decremented, for RECEIPT, this amount is incremented, " + "for ADJUSTMENT, it depends on the adjustment reason.</li>" + "<li><strong>reasonName</strong> (String, required for ADJUSTMENT types) - reason code for the " + "adjustment.</li>" + "<li><strong>lotId</strong> (Long, optional) - lot id of a particular lot that will be processed. " + "This and lot are optional; if lotId is specified, lot is ignored.</li>" + "<li><strong>lot</strong> (Object, optional) - lot object of a particular lot that will be " + "processed. If lot with the specified code, manufacturerName, and expirationDate do not exist, a " + "lot will be created.</li>" + "<li><strong>customProps</strong> (Object, optional) - an object of custom properties (keys and " + "values) to specify custom fields for the stock event." + "</ul>" + "</li>" + "</ul>" + "<p>" + "<p>Example stock event list JSON:" + "<pre><code>" + "[\n" + " {\n" + " \"type\": \"ADJUSTMENT\",\n" + " \"productCode\": \"V001\",\n" + " \"quantity\": 50,\n" + " \"reasonName\": \"TRANSFER_IN\",\n" + " \"lotId\": 1\n" + " },\n" + " {\n" + " \"type\": \"ISSUE\",\n" + " \"facilityId\": 19077,\n" + " \"productCode\": \"V001\",\n" + " \"quantity\": 50,\n" + " \"customProps\": {\n" + " \"occurred\": \"2015-10-01\"\n" + " }\n" + " },\n" + " {\n" + " \"type\": \"RECEIPT\",\n" + " \"facilityId\": 19074,\n" + " \"productCode\": \"V001\",\n" + " \"quantity\": 50,\n" + " \"lot\": {\n" + " \"lotCode\": \"C1\",\n" + " \"manufacturerName\": \"Manufacturer 3\",\n" + " \"expirationDate\": \"2016-07-01\"\n" + " },\n" + " \"customProps\": {\n" + " \"vvmStatus\": \"1\"\n" + " }\n" + " }\n" + "]\n" + "</code></pre>") @Transactional ResponseEntity processStock(@PathVariable long facilityId,
                                       @RequestBody(required = true) List<StockEvent> events,
                                       HttpServletRequest request); }
StockCardController extends BaseController { @RequestMapping(value = "facilities/{facilityId}/products/{productCode}/stockCard", method = GET, headers = ACCEPT_JSON) @ApiOperation(value = "Get information about the stock card for the specified facility and product.", notes = "Gets stock card information, by facility and product." + "<p>If no view permissions are found for this stock card, will return 403 Forbidden." + "<p>" + "<p>Path parameters (required):" + "<ul>" + "<li><strong>facilityId</strong> (Long) - facility for the stock card.</li>" + "<li><strong>productCode</strong> (String) - product for the stock card.</li>" + "</ul>" + "<p>" + "<p>Request parameters:" + "<ul>" + "<li><strong>entries</strong> (Integer, optional, default = 1) - Number of stock card entries to " + "get in the result.</li>" + "</ul>") public ResponseEntity getStockCard(@PathVariable Long facilityId, @PathVariable String productCode, @RequestParam(value = "entries", defaultValue = "1")Integer entries, @RequestParam(value = "includeEmptyLots", required = false, defaultValue = "false") boolean includeEmptyLots, HttpServletRequest request) { Long userId = loggedInUserId(request); List<Right> rights = roleRightsService.getRightsForUserFacilityAndProductCode(userId, facilityId, productCode); if (!any(rights, with("VIEW_STOCK_ON_HAND"))) { return OpenLmisResponse.error(messageService.message("error.permission.stock.card.view"), HttpStatus.FORBIDDEN); } StockCard stockCard = stockCardRepository.getStockCardByFacilityAndProduct(facilityId, productCode); if (stockCard != null) { filterEntries(stockCard, entries, includeEmptyLots); return OpenLmisResponse.response(stockCard); } else { return OpenLmisResponse.error("The specified stock card does not exist." , HttpStatus.NOT_FOUND); } } StockCardController(MessageService messageService,
                        FacilityRepository facilityRepository,
                        ProductService productService,
                        StockAdjustmentReasonRepository stockAdjustmentReasonRepository,
                        StockCardRepository stockCardRepository,
                        LotRepository lotRepository,
                        ProgramProductService programProductService,
                        ProgramService programService,
                        RoleRightsService roleRightsService,
                        StockCardService service); @RequestMapping(value = "facilities/{facilityId}/products/{productCode}/stockCard", method = GET, headers = ACCEPT_JSON) @ApiOperation(value = "Get information about the stock card for the specified facility and product.", notes = "Gets stock card information, by facility and product." + "<p>If no view permissions are found for this stock card, will return 403 Forbidden." + "<p>" + "<p>Path parameters (required):" + "<ul>" + "<li><strong>facilityId</strong> (Long) - facility for the stock card.</li>" + "<li><strong>productCode</strong> (String) - product for the stock card.</li>" + "</ul>" + "<p>" + "<p>Request parameters:" + "<ul>" + "<li><strong>entries</strong> (Integer, optional, default = 1) - Number of stock card entries to " + "get in the result.</li>" + "</ul>") ResponseEntity getStockCard(@PathVariable Long facilityId,
                                       @PathVariable String productCode,
                                       @RequestParam(value = "entries", defaultValue = "1")Integer entries,
                                       @RequestParam(value = "includeEmptyLots", required = false, defaultValue = "false") boolean includeEmptyLots,
                                       HttpServletRequest request); @RequestMapping(value = "facilities/{facilityId}/stockCards/{stockCardId}", method = GET, headers = ACCEPT_JSON) @ApiOperation(value = "Get information about the specified stock card for the specified facility.", notes = "Gets stock card information, by facility and stock card id." + "<p>If facility does not have specified stock card id, will return 404 Not Found." + "<p>If no view permissions are found for this stock card, will return 403 Forbidden." + "<p>" + "<p>Path parameters (required):" + "<ul>" + "<li><strong>facilityId</strong> (Long) - facility for the stock card.</li>" + "<li><strong>stockCardId</strong> (Long) - the specified stock card.</li>" + "</ul>" + "<p>" + "<p>Request parameters:" + "<ul>" + "<li><strong>entries</strong> (Integer, optional, default = 1) - Number of stock card entries to " + "get in the result.</li>" + "</ul>") ResponseEntity getStockCardById(@PathVariable Long facilityId, @PathVariable Long stockCardId,
                                           @RequestParam(value = "entries", defaultValue = "1")Integer entries,
                                           @RequestParam(value = "includeEmptyLots", required = false, defaultValue = "false") boolean includeEmptyLots,
                                           HttpServletRequest request); @RequestMapping(value = "facilities/{facilityId}/stockCards", method = GET, headers = ACCEPT_JSON) @ApiOperation(value = "Get information about all stock cards for the specified facility.", notes = "Gets all stock card information, by facility." + "<p>If no stock cards exist, will return 404 Not Found." + "<p>If no view permissions are found for any existing stock card, will return an empty list." + "<p>" + "<p>Path parameters (required):" + "<ul>" + "<li><strong>facilityId</strong> (Long) - facility for the stock cards.</li>" + "</ul>" + "<p>" + "<p>Request parameters:" + "<ul>" + "<li><strong>entries</strong> (Integer, optional, default = 1) - Number of stock card entries to " + "get in the result.</li>" + "<li><strong>countOnly</strong> (Boolean, optional, default = false) - Get only the count of " + "stock cards.</li>" + "</ul>") ResponseEntity getStockCards(@PathVariable Long facilityId,
                                        @RequestParam(value = "entries", defaultValue = "1") Integer entries,
                                        @RequestParam(value = "countOnly", defaultValue = "false") Boolean countOnly,
                                        @RequestParam(value = "includeEmptyLots", required = false, defaultValue = "false") boolean includeEmptyLots,
                                        HttpServletRequest request); @RequestMapping(value = "facilities/{facilityId}/stockCards", method = POST, headers = ACCEPT_JSON) @ApiOperation(value="Update stock cards at a facility.", notes = "Updates stock cards at a facility. This is done by providing a list of stock events." + "<p>Path parameters (required):" + "<ul>" + "<li><strong>facilityId</strong> (Long) - facility for the stock cards in which to update.</li>" + "</ul>" + "<p>" + "<p>Body parameters (required):" + "<ul>" + "<li>" + "<strong>stock events</strong> (Array of stock event objects) - a list of stock events to " + "process for update." + "<p>" + "<p>Stock event properties" + "<ul>" + "<li><strong>type</strong> (String, required) - type code of stock event (choices are ISSUE, " + "RECEIPT, ADJUSTMENT).</li>" + "<li><strong>facilityId</strong> (Long, required for ISSUE/RECEIPT types) - facility id where" + "stock is going to/coming from.</li>" + "<li><strong>productCode</strong> (String, required) - product code of the stock being " + "processed.</li>" + "<li><strong>quantity</strong> (Long, required) - quantity of stock being processed. Specify as a " + "positive number. For ISSUE, this amount is decremented, for RECEIPT, this amount is incremented, " + "for ADJUSTMENT, it depends on the adjustment reason.</li>" + "<li><strong>reasonName</strong> (String, required for ADJUSTMENT types) - reason code for the " + "adjustment.</li>" + "<li><strong>lotId</strong> (Long, optional) - lot id of a particular lot that will be processed. " + "This and lot are optional; if lotId is specified, lot is ignored.</li>" + "<li><strong>lot</strong> (Object, optional) - lot object of a particular lot that will be " + "processed. If lot with the specified code, manufacturerName, and expirationDate do not exist, a " + "lot will be created.</li>" + "<li><strong>customProps</strong> (Object, optional) - an object of custom properties (keys and " + "values) to specify custom fields for the stock event." + "</ul>" + "</li>" + "</ul>" + "<p>" + "<p>Example stock event list JSON:" + "<pre><code>" + "[\n" + " {\n" + " \"type\": \"ADJUSTMENT\",\n" + " \"productCode\": \"V001\",\n" + " \"quantity\": 50,\n" + " \"reasonName\": \"TRANSFER_IN\",\n" + " \"lotId\": 1\n" + " },\n" + " {\n" + " \"type\": \"ISSUE\",\n" + " \"facilityId\": 19077,\n" + " \"productCode\": \"V001\",\n" + " \"quantity\": 50,\n" + " \"customProps\": {\n" + " \"occurred\": \"2015-10-01\"\n" + " }\n" + " },\n" + " {\n" + " \"type\": \"RECEIPT\",\n" + " \"facilityId\": 19074,\n" + " \"productCode\": \"V001\",\n" + " \"quantity\": 50,\n" + " \"lot\": {\n" + " \"lotCode\": \"C1\",\n" + " \"manufacturerName\": \"Manufacturer 3\",\n" + " \"expirationDate\": \"2016-07-01\"\n" + " },\n" + " \"customProps\": {\n" + " \"vvmStatus\": \"1\"\n" + " }\n" + " }\n" + "]\n" + "</code></pre>") @Transactional ResponseEntity processStock(@PathVariable long facilityId,
                                       @RequestBody(required = true) List<StockEvent> events,
                                       HttpServletRequest request);  }