@Test public void shouldGetEquipmentList() throws Exception { Pagination page=new Pagination(1,2); Equipment equipment = makeAnEquipment(); EquipmentType equipmentType=new EquipmentType(); equipmentType.setColdChain(false); when(service.getEquipmentsCountByType(1L)).thenReturn(2); when(service.getByType(1L,page)).thenReturn(asList(equipment)); when(equipmentTypeService.getTypeById(1L)).thenReturn(equipmentType); ResponseEntity<OpenLmisResponse> response = controller.getList(1L,1,"2"); assertThat(asList(equipment), is(response.getBody().getData().get("equipments"))); }
@RequestMapping(method = RequestMethod.GET, value = "list") @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_SETTINGS') or @permissionEvaluator.hasPermission(principal,'SERVICE_VENDOR_RIGHT')") public ResponseEntity<OpenLmisResponse> getList(@RequestParam("equipmentTypeId") Long equipmentTypeId, @RequestParam(value = "page", defaultValue = "1") Integer page, @Value("${search.page.size}") String limit ){ Pagination pagination = new Pagination(page, parseInt(limit)); EquipmentType equipmentType=equipmentTypeService.getTypeById(equipmentTypeId); if(equipmentType.isColdChain()) { List<ColdChainEquipment> equipments=service.getAllCCE(equipmentTypeId,pagination); pagination.setTotalRecords(service.getCCECountByType(equipmentTypeId)); ResponseEntity<OpenLmisResponse> response = OpenLmisResponse.response(EQUIPMENTS,equipments); response.getBody().addData("pagination", pagination); return response; } else{ List<Equipment> equipments=service.getByType(equipmentTypeId, pagination); pagination.setTotalRecords(service.getEquipmentsCountByType(equipmentTypeId)); ResponseEntity<OpenLmisResponse> response = OpenLmisResponse.response(EQUIPMENTS,equipments); response.getBody().addData("pagination", pagination); return response; } }
EquipmentController extends BaseController { @RequestMapping(method = RequestMethod.GET, value = "list") @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_SETTINGS') or @permissionEvaluator.hasPermission(principal,'SERVICE_VENDOR_RIGHT')") public ResponseEntity<OpenLmisResponse> getList(@RequestParam("equipmentTypeId") Long equipmentTypeId, @RequestParam(value = "page", defaultValue = "1") Integer page, @Value("${search.page.size}") String limit ){ Pagination pagination = new Pagination(page, parseInt(limit)); EquipmentType equipmentType=equipmentTypeService.getTypeById(equipmentTypeId); if(equipmentType.isColdChain()) { List<ColdChainEquipment> equipments=service.getAllCCE(equipmentTypeId,pagination); pagination.setTotalRecords(service.getCCECountByType(equipmentTypeId)); ResponseEntity<OpenLmisResponse> response = OpenLmisResponse.response(EQUIPMENTS,equipments); response.getBody().addData("pagination", pagination); return response; } else{ List<Equipment> equipments=service.getByType(equipmentTypeId, pagination); pagination.setTotalRecords(service.getEquipmentsCountByType(equipmentTypeId)); ResponseEntity<OpenLmisResponse> response = OpenLmisResponse.response(EQUIPMENTS,equipments); response.getBody().addData("pagination", pagination); return response; } } }
EquipmentController extends BaseController { @RequestMapping(method = RequestMethod.GET, value = "list") @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_SETTINGS') or @permissionEvaluator.hasPermission(principal,'SERVICE_VENDOR_RIGHT')") public ResponseEntity<OpenLmisResponse> getList(@RequestParam("equipmentTypeId") Long equipmentTypeId, @RequestParam(value = "page", defaultValue = "1") Integer page, @Value("${search.page.size}") String limit ){ Pagination pagination = new Pagination(page, parseInt(limit)); EquipmentType equipmentType=equipmentTypeService.getTypeById(equipmentTypeId); if(equipmentType.isColdChain()) { List<ColdChainEquipment> equipments=service.getAllCCE(equipmentTypeId,pagination); pagination.setTotalRecords(service.getCCECountByType(equipmentTypeId)); ResponseEntity<OpenLmisResponse> response = OpenLmisResponse.response(EQUIPMENTS,equipments); response.getBody().addData("pagination", pagination); return response; } else{ List<Equipment> equipments=service.getByType(equipmentTypeId, pagination); pagination.setTotalRecords(service.getEquipmentsCountByType(equipmentTypeId)); ResponseEntity<OpenLmisResponse> response = OpenLmisResponse.response(EQUIPMENTS,equipments); response.getBody().addData("pagination", pagination); return response; } }  }
EquipmentController extends BaseController { @RequestMapping(method = RequestMethod.GET, value = "list") @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_SETTINGS') or @permissionEvaluator.hasPermission(principal,'SERVICE_VENDOR_RIGHT')") public ResponseEntity<OpenLmisResponse> getList(@RequestParam("equipmentTypeId") Long equipmentTypeId, @RequestParam(value = "page", defaultValue = "1") Integer page, @Value("${search.page.size}") String limit ){ Pagination pagination = new Pagination(page, parseInt(limit)); EquipmentType equipmentType=equipmentTypeService.getTypeById(equipmentTypeId); if(equipmentType.isColdChain()) { List<ColdChainEquipment> equipments=service.getAllCCE(equipmentTypeId,pagination); pagination.setTotalRecords(service.getCCECountByType(equipmentTypeId)); ResponseEntity<OpenLmisResponse> response = OpenLmisResponse.response(EQUIPMENTS,equipments); response.getBody().addData("pagination", pagination); return response; } else{ List<Equipment> equipments=service.getByType(equipmentTypeId, pagination); pagination.setTotalRecords(service.getEquipmentsCountByType(equipmentTypeId)); ResponseEntity<OpenLmisResponse> response = OpenLmisResponse.response(EQUIPMENTS,equipments); response.getBody().addData("pagination", pagination); return response; } }  @RequestMapping(method = RequestMethod.GET, value = "id") @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_SETTINGS')") ResponseEntity<OpenLmisResponse> getEquipmentById(@RequestParam("id") Long id); @RequestMapping(method = RequestMethod.GET, value = "type-and-id") @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_SETTINGS')") ResponseEntity<OpenLmisResponse> getEquipmentByTypeAndId(@RequestParam("id") Long id, @RequestParam("equipmentTypeId") Long equipmentTypeId); @RequestMapping(method = RequestMethod.GET, value = "list") @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_SETTINGS') or @permissionEvaluator.hasPermission(principal,'SERVICE_VENDOR_RIGHT')") ResponseEntity<OpenLmisResponse> getList(@RequestParam("equipmentTypeId") Long equipmentTypeId,
                                                  @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                  @Value("${search.page.size}") String limit
                                                  ); @RequestMapping(method = RequestMethod.GET, value = "list-by-type") @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_SETTINGS')" + " or @permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_INVENTORY')" + " or @permissionEvaluator.hasPermission(principal,'SERVICE_VENDOR_RIGHT')") ResponseEntity<OpenLmisResponse> getListByType(@RequestParam("equipmentTypeId") Long equipmentTypeId); @RequestMapping(method = RequestMethod.GET, value = "typesByProgram/{programId}", headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_SETTINGS')" + " or @permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_INVENTORY')") ResponseEntity<OpenLmisResponse> getTypesByProgram(@PathVariable(value="programId") Long programId); @RequestMapping(method = RequestMethod.POST, value = "save", headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_SETTINGS')") @Transactional ResponseEntity<OpenLmisResponse> save( @RequestBody Equipment equipment, HttpServletRequest request); @RequestMapping(value="remove/{equipmentTypeId}/{id}") @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_SETTINGS')") @Transactional ResponseEntity<OpenLmisResponse> remove(@PathVariable(value = "equipmentTypeId") Long equipmentTypeId,@PathVariable(value = "id") Long id); }
EquipmentController extends BaseController { @RequestMapping(method = RequestMethod.GET, value = "list") @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_SETTINGS') or @permissionEvaluator.hasPermission(principal,'SERVICE_VENDOR_RIGHT')") public ResponseEntity<OpenLmisResponse> getList(@RequestParam("equipmentTypeId") Long equipmentTypeId, @RequestParam(value = "page", defaultValue = "1") Integer page, @Value("${search.page.size}") String limit ){ Pagination pagination = new Pagination(page, parseInt(limit)); EquipmentType equipmentType=equipmentTypeService.getTypeById(equipmentTypeId); if(equipmentType.isColdChain()) { List<ColdChainEquipment> equipments=service.getAllCCE(equipmentTypeId,pagination); pagination.setTotalRecords(service.getCCECountByType(equipmentTypeId)); ResponseEntity<OpenLmisResponse> response = OpenLmisResponse.response(EQUIPMENTS,equipments); response.getBody().addData("pagination", pagination); return response; } else{ List<Equipment> equipments=service.getByType(equipmentTypeId, pagination); pagination.setTotalRecords(service.getEquipmentsCountByType(equipmentTypeId)); ResponseEntity<OpenLmisResponse> response = OpenLmisResponse.response(EQUIPMENTS,equipments); response.getBody().addData("pagination", pagination); return response; } }  @RequestMapping(method = RequestMethod.GET, value = "id") @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_SETTINGS')") ResponseEntity<OpenLmisResponse> getEquipmentById(@RequestParam("id") Long id); @RequestMapping(method = RequestMethod.GET, value = "type-and-id") @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_SETTINGS')") ResponseEntity<OpenLmisResponse> getEquipmentByTypeAndId(@RequestParam("id") Long id, @RequestParam("equipmentTypeId") Long equipmentTypeId); @RequestMapping(method = RequestMethod.GET, value = "list") @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_SETTINGS') or @permissionEvaluator.hasPermission(principal,'SERVICE_VENDOR_RIGHT')") ResponseEntity<OpenLmisResponse> getList(@RequestParam("equipmentTypeId") Long equipmentTypeId,
                                                  @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                  @Value("${search.page.size}") String limit
                                                  ); @RequestMapping(method = RequestMethod.GET, value = "list-by-type") @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_SETTINGS')" + " or @permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_INVENTORY')" + " or @permissionEvaluator.hasPermission(principal,'SERVICE_VENDOR_RIGHT')") ResponseEntity<OpenLmisResponse> getListByType(@RequestParam("equipmentTypeId") Long equipmentTypeId); @RequestMapping(method = RequestMethod.GET, value = "typesByProgram/{programId}", headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_SETTINGS')" + " or @permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_INVENTORY')") ResponseEntity<OpenLmisResponse> getTypesByProgram(@PathVariable(value="programId") Long programId); @RequestMapping(method = RequestMethod.POST, value = "save", headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_SETTINGS')") @Transactional ResponseEntity<OpenLmisResponse> save( @RequestBody Equipment equipment, HttpServletRequest request); @RequestMapping(value="remove/{equipmentTypeId}/{id}") @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_SETTINGS')") @Transactional ResponseEntity<OpenLmisResponse> remove(@PathVariable(value = "equipmentTypeId") Long equipmentTypeId,@PathVariable(value = "id") Long id); static final String EQUIPMENT; static final String EQUIPMENTS; }