@Test public void testEditLegalRepresentative() throws Exception { mockMvc.perform( post( "/patients/connectionMain/editLegalRepresenttive/" + (long) 10).param("firstName", "albert") .param("lastName", "smith") .param("birthDate", "01/01/2001")) .andExpect(status().isOk()) .andExpect( header().string("content-type", "application/json;charset=UTF-8")); mockMvc.perform( post( "/patients/connectionMain/editLegalRepresenttive/" + (long) 10).param("firstName", "albert") .param("lastName", "smith") .param("administrativeGenderCode", "M") .param("birthDate", "01/01/2001") .param("email", "willsmith@example.com")).andExpect( redirectedUrl("/patients/connectionMain.html")); }
@RequestMapping(value = "connectionMain/editLegalRepresenttive/{legalRepId}", method = RequestMethod.POST) public ModelAndView editLegalRepresentative( @Valid LegalRepresentativeDto newLegalRepresentativeDto, BindingResult result, @PathVariable("legalRepId") Long legalRepId, HttpServletResponse response, Model model) throws ParseException, SpiritClientNotAvailableException { fieldValidator.validate(newLegalRepresentativeDto, result); if (result.hasErrors()) { MappingJackson2JsonView view = new MappingJackson2JsonView(); Map<String, String> map = new HashMap<String, String>(); List<FieldError> errors = result.getFieldErrors(); for (FieldError error : errors) { for (String errorCode : error.getCodes()) { try { String errorMessage = messageProperties.getMessage( errorCode, null, null); String[] a = errorCode.split("\\."); map.put(a[a.length - 1], errorMessage); } catch (NoSuchMessageException e) { continue; } } } view.setAttributesMap(map); ModelAndView mav = new ModelAndView(); mav.setView(view); return mav; } AuthenticatedUser currentUser = userContext.getCurrentUser(); PatientProfileDto legalRepDto = patientLegalRepresentativeAssociationService .getPatientDtoFromLegalRepresentativeDto(newLegalRepresentativeDto); PatientLegalRepresentativeAssociationDto associationDto = patientLegalRepresentativeAssociationService .getAssociationDtoFromLegalRepresentativeDto(newLegalRepresentativeDto); legalRepDto.setId(legalRepId); try { patientService.updatePatient(legalRepDto); } catch (AuthenticationFailedException e) { logger.warn("Exception when updating patient profile"); } associationDto.setPatientId(patientService .findPatientProfileByUsername(currentUser.getUsername()) .getId()); associationDto.setLegalRepresentativeId(legalRepId); patientLegalRepresentativeAssociationService .updatePatientLegalRepresentativeAssociationDto(associationDto); return new ModelAndView("redirect:/patients/connectionMain.html"); }
LegalRepresentativeController { @RequestMapping(value = "connectionMain/editLegalRepresenttive/{legalRepId}", method = RequestMethod.POST) public ModelAndView editLegalRepresentative( @Valid LegalRepresentativeDto newLegalRepresentativeDto, BindingResult result, @PathVariable("legalRepId") Long legalRepId, HttpServletResponse response, Model model) throws ParseException, SpiritClientNotAvailableException { fieldValidator.validate(newLegalRepresentativeDto, result); if (result.hasErrors()) { MappingJackson2JsonView view = new MappingJackson2JsonView(); Map<String, String> map = new HashMap<String, String>(); List<FieldError> errors = result.getFieldErrors(); for (FieldError error : errors) { for (String errorCode : error.getCodes()) { try { String errorMessage = messageProperties.getMessage( errorCode, null, null); String[] a = errorCode.split("\\."); map.put(a[a.length - 1], errorMessage); } catch (NoSuchMessageException e) { continue; } } } view.setAttributesMap(map); ModelAndView mav = new ModelAndView(); mav.setView(view); return mav; } AuthenticatedUser currentUser = userContext.getCurrentUser(); PatientProfileDto legalRepDto = patientLegalRepresentativeAssociationService .getPatientDtoFromLegalRepresentativeDto(newLegalRepresentativeDto); PatientLegalRepresentativeAssociationDto associationDto = patientLegalRepresentativeAssociationService .getAssociationDtoFromLegalRepresentativeDto(newLegalRepresentativeDto); legalRepDto.setId(legalRepId); try { patientService.updatePatient(legalRepDto); } catch (AuthenticationFailedException e) { logger.warn("Exception when updating patient profile"); } associationDto.setPatientId(patientService .findPatientProfileByUsername(currentUser.getUsername()) .getId()); associationDto.setLegalRepresentativeId(legalRepId); patientLegalRepresentativeAssociationService .updatePatientLegalRepresentativeAssociationDto(associationDto); return new ModelAndView("redirect:/patients/connectionMain.html"); } }
LegalRepresentativeController { @RequestMapping(value = "connectionMain/editLegalRepresenttive/{legalRepId}", method = RequestMethod.POST) public ModelAndView editLegalRepresentative( @Valid LegalRepresentativeDto newLegalRepresentativeDto, BindingResult result, @PathVariable("legalRepId") Long legalRepId, HttpServletResponse response, Model model) throws ParseException, SpiritClientNotAvailableException { fieldValidator.validate(newLegalRepresentativeDto, result); if (result.hasErrors()) { MappingJackson2JsonView view = new MappingJackson2JsonView(); Map<String, String> map = new HashMap<String, String>(); List<FieldError> errors = result.getFieldErrors(); for (FieldError error : errors) { for (String errorCode : error.getCodes()) { try { String errorMessage = messageProperties.getMessage( errorCode, null, null); String[] a = errorCode.split("\\."); map.put(a[a.length - 1], errorMessage); } catch (NoSuchMessageException e) { continue; } } } view.setAttributesMap(map); ModelAndView mav = new ModelAndView(); mav.setView(view); return mav; } AuthenticatedUser currentUser = userContext.getCurrentUser(); PatientProfileDto legalRepDto = patientLegalRepresentativeAssociationService .getPatientDtoFromLegalRepresentativeDto(newLegalRepresentativeDto); PatientLegalRepresentativeAssociationDto associationDto = patientLegalRepresentativeAssociationService .getAssociationDtoFromLegalRepresentativeDto(newLegalRepresentativeDto); legalRepDto.setId(legalRepId); try { patientService.updatePatient(legalRepDto); } catch (AuthenticationFailedException e) { logger.warn("Exception when updating patient profile"); } associationDto.setPatientId(patientService .findPatientProfileByUsername(currentUser.getUsername()) .getId()); associationDto.setLegalRepresentativeId(legalRepId); patientLegalRepresentativeAssociationService .updatePatientLegalRepresentativeAssociationDto(associationDto); return new ModelAndView("redirect:/patients/connectionMain.html"); }  }
LegalRepresentativeController { @RequestMapping(value = "connectionMain/editLegalRepresenttive/{legalRepId}", method = RequestMethod.POST) public ModelAndView editLegalRepresentative( @Valid LegalRepresentativeDto newLegalRepresentativeDto, BindingResult result, @PathVariable("legalRepId") Long legalRepId, HttpServletResponse response, Model model) throws ParseException, SpiritClientNotAvailableException { fieldValidator.validate(newLegalRepresentativeDto, result); if (result.hasErrors()) { MappingJackson2JsonView view = new MappingJackson2JsonView(); Map<String, String> map = new HashMap<String, String>(); List<FieldError> errors = result.getFieldErrors(); for (FieldError error : errors) { for (String errorCode : error.getCodes()) { try { String errorMessage = messageProperties.getMessage( errorCode, null, null); String[] a = errorCode.split("\\."); map.put(a[a.length - 1], errorMessage); } catch (NoSuchMessageException e) { continue; } } } view.setAttributesMap(map); ModelAndView mav = new ModelAndView(); mav.setView(view); return mav; } AuthenticatedUser currentUser = userContext.getCurrentUser(); PatientProfileDto legalRepDto = patientLegalRepresentativeAssociationService .getPatientDtoFromLegalRepresentativeDto(newLegalRepresentativeDto); PatientLegalRepresentativeAssociationDto associationDto = patientLegalRepresentativeAssociationService .getAssociationDtoFromLegalRepresentativeDto(newLegalRepresentativeDto); legalRepDto.setId(legalRepId); try { patientService.updatePatient(legalRepDto); } catch (AuthenticationFailedException e) { logger.warn("Exception when updating patient profile"); } associationDto.setPatientId(patientService .findPatientProfileByUsername(currentUser.getUsername()) .getId()); associationDto.setLegalRepresentativeId(legalRepId); patientLegalRepresentativeAssociationService .updatePatientLegalRepresentativeAssociationDto(associationDto); return new ModelAndView("redirect:/patients/connectionMain.html"); }  @RequestMapping(value = "connectionMain.html", method = RequestMethod.POST) ModelAndView addLegalRepresentative(
			@Valid LegalRepresentativeDto newLegalRepresentativeDto,
			BindingResult result, HttpServletResponse response, Model model); @RequestMapping(value = "connectionMain/editLegalRepresenttive/{legalRepId}", method = RequestMethod.POST) ModelAndView editLegalRepresentative(
			@Valid LegalRepresentativeDto newLegalRepresentativeDto,
			BindingResult result, @PathVariable("legalRepId") Long legalRepId,
			HttpServletResponse response, Model model); @RequestMapping("connectionMain/deleteLegalRep/{legalRepId}") String deleteLegalRep(@PathVariable("legalRepId") Long legalRepId); }
LegalRepresentativeController { @RequestMapping(value = "connectionMain/editLegalRepresenttive/{legalRepId}", method = RequestMethod.POST) public ModelAndView editLegalRepresentative( @Valid LegalRepresentativeDto newLegalRepresentativeDto, BindingResult result, @PathVariable("legalRepId") Long legalRepId, HttpServletResponse response, Model model) throws ParseException, SpiritClientNotAvailableException { fieldValidator.validate(newLegalRepresentativeDto, result); if (result.hasErrors()) { MappingJackson2JsonView view = new MappingJackson2JsonView(); Map<String, String> map = new HashMap<String, String>(); List<FieldError> errors = result.getFieldErrors(); for (FieldError error : errors) { for (String errorCode : error.getCodes()) { try { String errorMessage = messageProperties.getMessage( errorCode, null, null); String[] a = errorCode.split("\\."); map.put(a[a.length - 1], errorMessage); } catch (NoSuchMessageException e) { continue; } } } view.setAttributesMap(map); ModelAndView mav = new ModelAndView(); mav.setView(view); return mav; } AuthenticatedUser currentUser = userContext.getCurrentUser(); PatientProfileDto legalRepDto = patientLegalRepresentativeAssociationService .getPatientDtoFromLegalRepresentativeDto(newLegalRepresentativeDto); PatientLegalRepresentativeAssociationDto associationDto = patientLegalRepresentativeAssociationService .getAssociationDtoFromLegalRepresentativeDto(newLegalRepresentativeDto); legalRepDto.setId(legalRepId); try { patientService.updatePatient(legalRepDto); } catch (AuthenticationFailedException e) { logger.warn("Exception when updating patient profile"); } associationDto.setPatientId(patientService .findPatientProfileByUsername(currentUser.getUsername()) .getId()); associationDto.setLegalRepresentativeId(legalRepId); patientLegalRepresentativeAssociationService .updatePatientLegalRepresentativeAssociationDto(associationDto); return new ModelAndView("redirect:/patients/connectionMain.html"); }  @RequestMapping(value = "connectionMain.html", method = RequestMethod.POST) ModelAndView addLegalRepresentative(
			@Valid LegalRepresentativeDto newLegalRepresentativeDto,
			BindingResult result, HttpServletResponse response, Model model); @RequestMapping(value = "connectionMain/editLegalRepresenttive/{legalRepId}", method = RequestMethod.POST) ModelAndView editLegalRepresentative(
			@Valid LegalRepresentativeDto newLegalRepresentativeDto,
			BindingResult result, @PathVariable("legalRepId") Long legalRepId,
			HttpServletResponse response, Model model); @RequestMapping("connectionMain/deleteLegalRep/{legalRepId}") String deleteLegalRep(@PathVariable("legalRepId") Long legalRepId);  }