@Test public void testUpdate() throws IOException, Exception { when(recoveryService.update(any(List.class), any(BindingResult.class), any(RequestInfo.class))) .thenReturn(getUpdateRecoverys()); mockMvc.perform(post("/recoverys/_update?tenantId=default") .content(resources.readRequest("recovery/recovery_update_valid_request.json")) .contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().is(201)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(content().json(resources .readResponse("recovery/recovery_update_valid_response.json"))); }
@PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public RecoveryResponse update(@RequestBody RecoveryRequest recoveryRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } recoveryRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); RecoveryResponse recoveryResponse = new RecoveryResponse(); recoveryResponse.setResponseInfo(getResponseInfo(recoveryRequest.getRequestInfo())); List<Recovery> recoverys = new ArrayList<>(); Recovery recovery; List<RecoveryContract> recoveryContracts = new ArrayList<>(); RecoveryContract contract; for (RecoveryContract recoveryContract : recoveryRequest.getRecoverys()) { recovery = new Recovery(); model.map(recoveryContract, recovery); recoveryContract.setLastModifiedBy(recoveryRequest.getRequestInfo().getUserInfo()); recoveryContract.setLastModifiedDate(new Date()); recoverys.add(recovery); } recoverys = recoveryService.update(recoverys, errors, recoveryRequest.getRequestInfo()); for (Recovery recoveryObj : recoverys) { contract = new RecoveryContract(); model.map(recoveryObj, contract); recoveryObj.setLastModifiedDate(new Date()); recoveryContracts.add(contract); } recoveryResponse.setRecoverys(recoveryContracts); return recoveryResponse; }
RecoveryController { @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public RecoveryResponse update(@RequestBody RecoveryRequest recoveryRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } recoveryRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); RecoveryResponse recoveryResponse = new RecoveryResponse(); recoveryResponse.setResponseInfo(getResponseInfo(recoveryRequest.getRequestInfo())); List<Recovery> recoverys = new ArrayList<>(); Recovery recovery; List<RecoveryContract> recoveryContracts = new ArrayList<>(); RecoveryContract contract; for (RecoveryContract recoveryContract : recoveryRequest.getRecoverys()) { recovery = new Recovery(); model.map(recoveryContract, recovery); recoveryContract.setLastModifiedBy(recoveryRequest.getRequestInfo().getUserInfo()); recoveryContract.setLastModifiedDate(new Date()); recoverys.add(recovery); } recoverys = recoveryService.update(recoverys, errors, recoveryRequest.getRequestInfo()); for (Recovery recoveryObj : recoverys) { contract = new RecoveryContract(); model.map(recoveryObj, contract); recoveryObj.setLastModifiedDate(new Date()); recoveryContracts.add(contract); } recoveryResponse.setRecoverys(recoveryContracts); return recoveryResponse; } }
RecoveryController { @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public RecoveryResponse update(@RequestBody RecoveryRequest recoveryRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } recoveryRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); RecoveryResponse recoveryResponse = new RecoveryResponse(); recoveryResponse.setResponseInfo(getResponseInfo(recoveryRequest.getRequestInfo())); List<Recovery> recoverys = new ArrayList<>(); Recovery recovery; List<RecoveryContract> recoveryContracts = new ArrayList<>(); RecoveryContract contract; for (RecoveryContract recoveryContract : recoveryRequest.getRecoverys()) { recovery = new Recovery(); model.map(recoveryContract, recovery); recoveryContract.setLastModifiedBy(recoveryRequest.getRequestInfo().getUserInfo()); recoveryContract.setLastModifiedDate(new Date()); recoverys.add(recovery); } recoverys = recoveryService.update(recoverys, errors, recoveryRequest.getRequestInfo()); for (Recovery recoveryObj : recoverys) { contract = new RecoveryContract(); model.map(recoveryObj, contract); recoveryObj.setLastModifiedDate(new Date()); recoveryContracts.add(contract); } recoveryResponse.setRecoverys(recoveryContracts); return recoveryResponse; }  }
RecoveryController { @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public RecoveryResponse update(@RequestBody RecoveryRequest recoveryRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } recoveryRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); RecoveryResponse recoveryResponse = new RecoveryResponse(); recoveryResponse.setResponseInfo(getResponseInfo(recoveryRequest.getRequestInfo())); List<Recovery> recoverys = new ArrayList<>(); Recovery recovery; List<RecoveryContract> recoveryContracts = new ArrayList<>(); RecoveryContract contract; for (RecoveryContract recoveryContract : recoveryRequest.getRecoverys()) { recovery = new Recovery(); model.map(recoveryContract, recovery); recoveryContract.setLastModifiedBy(recoveryRequest.getRequestInfo().getUserInfo()); recoveryContract.setLastModifiedDate(new Date()); recoverys.add(recovery); } recoverys = recoveryService.update(recoverys, errors, recoveryRequest.getRequestInfo()); for (Recovery recoveryObj : recoverys) { contract = new RecoveryContract(); model.map(recoveryObj, contract); recoveryObj.setLastModifiedDate(new Date()); recoveryContracts.add(contract); } recoveryResponse.setRecoverys(recoveryContracts); return recoveryResponse; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) RecoveryResponse create(@RequestBody RecoveryRequest recoveryRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) RecoveryResponse update(@RequestBody RecoveryRequest recoveryRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) RecoveryResponse search(@ModelAttribute RecoverySearchContract recoverySearchContract, @RequestBody RequestInfo requestInfo,
                                   BindingResult errors,@RequestParam String tenantId); }
RecoveryController { @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public RecoveryResponse update(@RequestBody RecoveryRequest recoveryRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } recoveryRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); RecoveryResponse recoveryResponse = new RecoveryResponse(); recoveryResponse.setResponseInfo(getResponseInfo(recoveryRequest.getRequestInfo())); List<Recovery> recoverys = new ArrayList<>(); Recovery recovery; List<RecoveryContract> recoveryContracts = new ArrayList<>(); RecoveryContract contract; for (RecoveryContract recoveryContract : recoveryRequest.getRecoverys()) { recovery = new Recovery(); model.map(recoveryContract, recovery); recoveryContract.setLastModifiedBy(recoveryRequest.getRequestInfo().getUserInfo()); recoveryContract.setLastModifiedDate(new Date()); recoverys.add(recovery); } recoverys = recoveryService.update(recoverys, errors, recoveryRequest.getRequestInfo()); for (Recovery recoveryObj : recoverys) { contract = new RecoveryContract(); model.map(recoveryObj, contract); recoveryObj.setLastModifiedDate(new Date()); recoveryContracts.add(contract); } recoveryResponse.setRecoverys(recoveryContracts); return recoveryResponse; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) RecoveryResponse create(@RequestBody RecoveryRequest recoveryRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) RecoveryResponse update(@RequestBody RecoveryRequest recoveryRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) RecoveryResponse search(@ModelAttribute RecoverySearchContract recoverySearchContract, @RequestBody RequestInfo requestInfo,
                                   BindingResult errors,@RequestParam String tenantId);  }