@Test public void shouldSaveCCEChanges() throws Exception { EquipmentType equipmentType=makeAnEquipmentType(); ColdChainEquipment coldChainEquipment=makeAnColdChainEquipment(); coldChainEquipment.setEquipmentType(equipmentType); when(equipmentTypeService.getTypeById(coldChainEquipment.getEquipmentTypeId())).thenReturn(equipmentType); doNothing().when(service).saveColdChainEquipment(any(ColdChainEquipment.class)); doNothing().when(service).updateColdChainEquipment(any(ColdChainEquipment.class)); ResponseEntity<OpenLmisResponse> coldChainResponse = controller.save(coldChainEquipment, request); assertThat(coldChainEquipment, is( coldChainResponse.getBody().getData().get("equipment"))); assertThat(coldChainResponse.getBody().getSuccessMsg(), is(notNullValue())); }
@RequestMapping(method = RequestMethod.POST, value = "save", headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_SETTINGS')") @Transactional public ResponseEntity<OpenLmisResponse> save( @RequestBody Equipment equipment, HttpServletRequest request){ ResponseEntity<OpenLmisResponse> response; Long userId = loggedInUserId(request); equipment.setCreatedBy(userId); equipment.setModifiedBy(userId); EquipmentType equipmentType=equipmentTypeService.getTypeById(equipment.getEquipmentTypeId()); equipment.setEquipmentType(equipmentType); ColdChainEquipment coldChainEquipment; try{ if(equipment.getId()==null) { if(equipmentType.isColdChain()) { service.saveEquipment(equipment); coldChainEquipment = (ColdChainEquipment) equipment; service.saveColdChainEquipment(coldChainEquipment); } else { service.saveEquipment(equipment); } } else{ if(equipmentType.isColdChain()) { service.updateEquipment(equipment); coldChainEquipment = (ColdChainEquipment) equipment; service.updateColdChainEquipment(coldChainEquipment); } else { service.updateEquipment(equipment); } } }catch(DuplicateKeyException exp){ return OpenLmisResponse.error("Duplicate Code Exists in DB.", HttpStatus.BAD_REQUEST); } response = OpenLmisResponse.success(messageService.message("message.equipment.list.saved")); response.getBody().addData(EQUIPMENT, equipment); return response; }
EquipmentController extends BaseController { @RequestMapping(method = RequestMethod.POST, value = "save", headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_SETTINGS')") @Transactional public ResponseEntity<OpenLmisResponse> save( @RequestBody Equipment equipment, HttpServletRequest request){ ResponseEntity<OpenLmisResponse> response; Long userId = loggedInUserId(request); equipment.setCreatedBy(userId); equipment.setModifiedBy(userId); EquipmentType equipmentType=equipmentTypeService.getTypeById(equipment.getEquipmentTypeId()); equipment.setEquipmentType(equipmentType); ColdChainEquipment coldChainEquipment; try{ if(equipment.getId()==null) { if(equipmentType.isColdChain()) { service.saveEquipment(equipment); coldChainEquipment = (ColdChainEquipment) equipment; service.saveColdChainEquipment(coldChainEquipment); } else { service.saveEquipment(equipment); } } else{ if(equipmentType.isColdChain()) { service.updateEquipment(equipment); coldChainEquipment = (ColdChainEquipment) equipment; service.updateColdChainEquipment(coldChainEquipment); } else { service.updateEquipment(equipment); } } }catch(DuplicateKeyException exp){ return OpenLmisResponse.error("Duplicate Code Exists in DB.", HttpStatus.BAD_REQUEST); } response = OpenLmisResponse.success(messageService.message("message.equipment.list.saved")); response.getBody().addData(EQUIPMENT, equipment); return response; } }
EquipmentController extends BaseController { @RequestMapping(method = RequestMethod.POST, value = "save", headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_SETTINGS')") @Transactional public ResponseEntity<OpenLmisResponse> save( @RequestBody Equipment equipment, HttpServletRequest request){ ResponseEntity<OpenLmisResponse> response; Long userId = loggedInUserId(request); equipment.setCreatedBy(userId); equipment.setModifiedBy(userId); EquipmentType equipmentType=equipmentTypeService.getTypeById(equipment.getEquipmentTypeId()); equipment.setEquipmentType(equipmentType); ColdChainEquipment coldChainEquipment; try{ if(equipment.getId()==null) { if(equipmentType.isColdChain()) { service.saveEquipment(equipment); coldChainEquipment = (ColdChainEquipment) equipment; service.saveColdChainEquipment(coldChainEquipment); } else { service.saveEquipment(equipment); } } else{ if(equipmentType.isColdChain()) { service.updateEquipment(equipment); coldChainEquipment = (ColdChainEquipment) equipment; service.updateColdChainEquipment(coldChainEquipment); } else { service.updateEquipment(equipment); } } }catch(DuplicateKeyException exp){ return OpenLmisResponse.error("Duplicate Code Exists in DB.", HttpStatus.BAD_REQUEST); } response = OpenLmisResponse.success(messageService.message("message.equipment.list.saved")); response.getBody().addData(EQUIPMENT, equipment); return response; }  }
EquipmentController extends BaseController { @RequestMapping(method = RequestMethod.POST, value = "save", headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_SETTINGS')") @Transactional public ResponseEntity<OpenLmisResponse> save( @RequestBody Equipment equipment, HttpServletRequest request){ ResponseEntity<OpenLmisResponse> response; Long userId = loggedInUserId(request); equipment.setCreatedBy(userId); equipment.setModifiedBy(userId); EquipmentType equipmentType=equipmentTypeService.getTypeById(equipment.getEquipmentTypeId()); equipment.setEquipmentType(equipmentType); ColdChainEquipment coldChainEquipment; try{ if(equipment.getId()==null) { if(equipmentType.isColdChain()) { service.saveEquipment(equipment); coldChainEquipment = (ColdChainEquipment) equipment; service.saveColdChainEquipment(coldChainEquipment); } else { service.saveEquipment(equipment); } } else{ if(equipmentType.isColdChain()) { service.updateEquipment(equipment); coldChainEquipment = (ColdChainEquipment) equipment; service.updateColdChainEquipment(coldChainEquipment); } else { service.updateEquipment(equipment); } } }catch(DuplicateKeyException exp){ return OpenLmisResponse.error("Duplicate Code Exists in DB.", HttpStatus.BAD_REQUEST); } response = OpenLmisResponse.success(messageService.message("message.equipment.list.saved")); response.getBody().addData(EQUIPMENT, equipment); 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.POST, value = "save", headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_SETTINGS')") @Transactional public ResponseEntity<OpenLmisResponse> save( @RequestBody Equipment equipment, HttpServletRequest request){ ResponseEntity<OpenLmisResponse> response; Long userId = loggedInUserId(request); equipment.setCreatedBy(userId); equipment.setModifiedBy(userId); EquipmentType equipmentType=equipmentTypeService.getTypeById(equipment.getEquipmentTypeId()); equipment.setEquipmentType(equipmentType); ColdChainEquipment coldChainEquipment; try{ if(equipment.getId()==null) { if(equipmentType.isColdChain()) { service.saveEquipment(equipment); coldChainEquipment = (ColdChainEquipment) equipment; service.saveColdChainEquipment(coldChainEquipment); } else { service.saveEquipment(equipment); } } else{ if(equipmentType.isColdChain()) { service.updateEquipment(equipment); coldChainEquipment = (ColdChainEquipment) equipment; service.updateColdChainEquipment(coldChainEquipment); } else { service.updateEquipment(equipment); } } }catch(DuplicateKeyException exp){ return OpenLmisResponse.error("Duplicate Code Exists in DB.", HttpStatus.BAD_REQUEST); } response = OpenLmisResponse.success(messageService.message("message.equipment.list.saved")); response.getBody().addData(EQUIPMENT, equipment); 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; }