List of usage examples for org.springframework.web.servlet ModelAndView getModelMap
public ModelMap getModelMap()
From source file:com.devnexus.ting.web.controller.admin.RegistrationController.java
@RequestMapping(value = "/s/admin/{eventKey}/groupRegistration", method = RequestMethod.POST) public ModelAndView downloadGroupRegistration(ModelAndView model, HttpServletRequest request, @PathVariable(value = "eventKey") String eventKey, @Valid RegisterForm form, BindingResult result) throws FileNotFoundException, IOException, InvalidFormatException { EventSignup signUp = eventSignupRepository.getByEventKey(eventKey); model.getModelMap().addAttribute("event", signUp.getEvent()); model.getModelMap().addAttribute("registerForm", form); if (!result.hasErrors()) { Workbook workbook = WorkbookFactory .create(getClass().getResourceAsStream("/forms/registration_form.xlsx")); Sheet formSheet = workbook.getSheetAt(0); Sheet ticketTypeSheet = workbook.createSheet("ticket_types"); Row contactNameRow = formSheet.getRow(0); Row contactEmailRow = formSheet.getRow(1); Row contactPhoneRow = formSheet.getRow(2); Row registrationReferenceRow = formSheet.getRow(3); String[] ticketTypes = formatTicketTypes(signUp); addTicketTypesToSheet(ticketTypes, ticketTypeSheet); contactNameRow.createCell(1).setCellValue(form.getContactName()); contactEmailRow.createCell(1).setCellValue(form.getContactEmailAddress()); contactPhoneRow.createCell(1).setCellValue(form.getContactPhoneNumber()); registrationReferenceRow.createCell(1).setCellValue(UUID.randomUUID().toString()); createTicketTypeDropDown(formSheet, ticketTypeSheet, ticketTypes); model.setView(new BulkRegistrationFormView(workbook, form.getContactName().replace(" ", "_") + "RegistrationFile.xlsx")); } else {//from w w w .j a v a 2 s.co m model.setViewName("/admin/group-registration"); } return model; }
From source file:org.openmrs.module.radiology.web.controller.RadiologyObsFormControllerTest.java
/** * @see RadiologyObsFormController#getNewObs(RadiologyOrder) * @verifies populate model and view with new obs given a valid radiology order *///w ww .ja v a2 s . co m @Test public void getNewObs_shouldPopulateModelAndViewWithNewObsGivenAValidRadiologyOrder() throws Exception { ModelAndView modelAndView = radiologyObsFormController.getNewObs(mockRadiologyOrder); assertThat(modelAndView, is(notNullValue())); assertThat(modelAndView.getViewName(), is("module/radiology/radiologyObsForm")); assertThat(modelAndView.getModelMap(), hasKey("obs")); Obs obs = (Obs) modelAndView.getModelMap().get("obs"); assertThat(obs.getOrder(), is(notNullValue())); assertThat((RadiologyOrder) obs.getOrder(), is(mockRadiologyOrder)); assertThat(obs.getPerson(), is((Person) mockRadiologyOrder.getPatient())); }
From source file:org.openmrs.module.radiology.web.controller.RadiologyObsFormControllerTest.java
/** * @see RadiologyObsFormController#getObs(RadiologyOrder,Obs) * @verifies populate model and view with obs for given obs and given valid radiology order *//*from w w w .jav a2 s . c o m*/ @Test public void getObs_shouldPopulateModelAndViewWithObsForGivenObsAndGivenValidRadiologyOrder() throws Exception { ModelAndView modelAndView = radiologyObsFormController.getObs(mockRadiologyOrder, mockObs); assertThat(modelAndView, is(notNullValue())); assertThat(modelAndView.getViewName(), is("module/radiology/radiologyObsForm")); assertThat(modelAndView.getModelMap(), hasKey("obs")); Obs obs = (Obs) modelAndView.getModelMap().get("obs"); assertThat(obs, is(mockObs)); }
From source file:org.openmrs.module.radiology.web.controller.RadiologyObsFormControllerTest.java
/** * @see RadiologyObsFormController#saveObs(HttpServletRequest,HttpServletResponse,String,RadiologyOrder,Obs,BindingResult) * @verifies return populated model and view for invalid obs *//* w w w . j a v a 2s .c om*/ @Test public void saveObs_shouldReturnPopulatedModelAndViewForInvalidObs() throws Exception { //given mockRequest.addParameter("saveObs", "saveObs"); when(obsErrors.hasErrors()).thenReturn(true); when(obsService.saveObs(mockObs, "Test Edit Reason")).thenReturn(RadiologyTestData.getEditedMockObs()); ModelAndView modelAndView = radiologyObsFormController.saveObs(mockRequest, null, "Test Edit Reason", mockRadiologyOrder, mockObs, obsErrors); assertThat(modelAndView.getViewName(), is("module/radiology/radiologyObsForm")); assertThat(modelAndView, is(notNullValue())); assertThat(modelAndView.getModelMap(), hasKey("obs")); Obs obs = (Obs) modelAndView.getModelMap().get("obs"); assertThat(obs, is(mockObs)); }
From source file:org.openmrs.module.radiology.order.web.RadiologyOrderFormControllerTest.java
/** * @see RadiologyOrderFormController#radiologyReportNeedsToBeCreated(ModelAndView,Order) * @verifies return false if radiology order is not completed *///from w ww.j a v a2s . c om @Test public void radiologyReportNeedsToBeCreated_shouldReturnFalseIfRadiologyOrderIsNotCompleted() throws Exception { // given ModelAndView modelAndView = new ModelAndView(RadiologyOrderFormController.RADIOLOGY_ORDER_FORM_VIEW); RadiologyOrder incompleteRadiologyOrder = RadiologyTestData.getMockRadiologyOrder1(); incompleteRadiologyOrder.getStudy().setPerformedStatus(PerformedProcedureStepStatus.IN_PROGRESS); final boolean result = (Boolean) radiologyReportNeedsToBeCreatedMethod.invoke(radiologyOrderFormController, new Object[] { modelAndView, incompleteRadiologyOrder }); assertFalse(result); assertThat(modelAndView.getModelMap(), hasKey("radiologyReportNeedsToBeCreated")); assertFalse((Boolean) modelAndView.getModelMap().get("radiologyReportNeedsToBeCreated")); }
From source file:org.openmrs.module.radiology.web.controller.RadiologyObsFormControllerTest.java
/** * @see RadiologyObsFormController#saveComplexObs(MultipartHttpServletRequest,HttpServletResponse,String,RadiologyOrder,Obs,BindingResult) * @verifies return populated model and view for invalid complex obs *//*from w w w . j a v a 2s . c o m*/ @Test public void saveComplexObs_shouldReturnPopulatedModelAndViewForInvalidComplexObs() throws Exception { when(obsErrors.hasErrors()).thenReturn(true); when(obsService.saveObs(mockObs, "Test Edit Reason")).thenReturn(RadiologyTestData.getEditedMockObs()); ModelAndView modelAndView = radiologyObsFormController.saveComplexObs( mockMultipartHttpServletRequestRequest, null, "Test Edit Reason", mockRadiologyOrder, mockObs, obsErrors); assertThat(modelAndView, is(notNullValue())); assertThat(modelAndView.getViewName(), is("module/radiology/radiologyObsForm")); assertThat(modelAndView.getModelMap(), hasKey("obs")); Obs obs = (Obs) modelAndView.getModelMap().get("obs"); assertThat(obs, is(mockObs)); }
From source file:com.revolsys.ui.web.rest.interceptor.WebAnnotationMethodHandlerAdapter.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public ModelAndView getModelAndView(final Method handlerMethod, final Class<?> handlerType, final Object returnValue, final ExtendedModelMap implicitModel, final ServletWebRequest webRequest) throws Exception { boolean responseArgumentUsed = false; final ResponseStatus responseStatusAnn = AnnotationUtils.findAnnotation(handlerMethod, ResponseStatus.class); if (responseStatusAnn != null) { final HttpStatus responseStatus = responseStatusAnn.value(); // to be picked up by the RedirectView webRequest.getRequest().setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, responseStatus); webRequest.getResponse().setStatus(responseStatus.value()); responseArgumentUsed = true;/*from w w w .ja v a 2s. c o m*/ } // Invoke custom resolvers if present... if (WebAnnotationMethodHandlerAdapter.this.customModelAndViewResolvers != null) { for (final ModelAndViewResolver mavResolver : WebAnnotationMethodHandlerAdapter.this.customModelAndViewResolvers) { final ModelAndView mav = mavResolver.resolveModelAndView(handlerMethod, handlerType, returnValue, implicitModel, webRequest); if (mav != ModelAndViewResolver.UNRESOLVED) { return mav; } } } if (returnValue != null && AnnotationUtils.findAnnotation(handlerMethod, ResponseBody.class) != null) { final View view = handleResponseBody(returnValue, webRequest); return new ModelAndView(view).addAllObjects(implicitModel); } if (returnValue instanceof ModelAndView) { final ModelAndView mav = (ModelAndView) returnValue; mav.getModelMap().mergeAttributes(implicitModel); return mav; } else if (returnValue instanceof Model) { return new ModelAndView().addAllObjects(implicitModel).addAllObjects(((Model) returnValue).asMap()); } else if (returnValue instanceof View) { return new ModelAndView((View) returnValue).addAllObjects(implicitModel); } else if (AnnotationUtils.findAnnotation(handlerMethod, ModelAttribute.class) != null) { addReturnValueAsModelAttribute(handlerMethod, handlerType, returnValue, implicitModel); return new ModelAndView().addAllObjects(implicitModel); } else if (returnValue instanceof Map) { return new ModelAndView().addAllObjects(implicitModel).addAllObjects((Map) returnValue); } else if (returnValue instanceof String) { return new ModelAndView((String) returnValue).addAllObjects(implicitModel); } else if (returnValue == null) { // Either returned null or was 'void' return. if (responseArgumentUsed || webRequest.isNotModified()) { return null; } else { // Assuming view name translation... return new ModelAndView().addAllObjects(implicitModel); } } else if (!BeanUtils.isSimpleProperty(returnValue.getClass())) { // Assume a single model attribute... addReturnValueAsModelAttribute(handlerMethod, handlerType, returnValue, implicitModel); return new ModelAndView().addAllObjects(implicitModel); } else { throw new IllegalArgumentException("Invalid handler method return value: " + returnValue); } }
From source file:org.openmrs.module.radiology.web.controller.RadiologyObsFormControllerTest.java
/** * @see RadiologyObsFormController#saveObs(HttpServletRequest,HttpServletResponse,String,RadiologyOrder,Obs,BindingResult) * @verifies populate model and view with obs for occuring Exception *//* www . j a v a 2 s . c om*/ @Test public void saveObs_shouldPopulateModelAndViewWithObsForOccuringException() throws Exception { //given mockRequest.addParameter("saveObs", "saveObs"); APIException apiException = new APIException("Test Exception Handling"); when(obsService.saveObs(mockObs, "Test Edit Reason")).thenThrow(apiException); ModelAndView modelAndView = radiologyObsFormController.saveObs(mockRequest, null, "Test Edit Reason", mockRadiologyOrder, mockObs, obsErrors); assertThat((String) mockSession.getAttribute(WebConstants.OPENMRS_ERROR_ATTR), is("Test Exception Handling")); assertThat(modelAndView.getViewName(), is("module/radiology/radiologyObsForm")); assertThat(modelAndView, is(notNullValue())); assertThat(modelAndView.getModelMap(), hasKey("obs")); Obs obs = (Obs) modelAndView.getModelMap().get("obs"); assertThat(obs, is(mockObs)); }
From source file:com.devnexus.ting.web.controller.admin.RegistrationController.java
@RequestMapping(value = "/s/admin/{eventKey}/uploadRegistration", method = RequestMethod.POST) public ModelAndView uploadGroupRegistration(ModelAndView model, HttpServletRequest request, @PathVariable(value = "eventKey") String eventKey, @Valid @ModelAttribute("registerForm") UploadGroupRegistrationForm uploadForm, BindingResult bindingResult) throws FileNotFoundException, IOException, InvalidFormatException { EventSignup signUp = eventSignupRepository.getByEventKey(eventKey); model.getModelMap().addAttribute("event", signUp.getEvent()); if (bindingResult.hasErrors()) { model.getModelMap().addAttribute("registerForm", uploadForm); model.setViewName("/admin/upload-registration"); } else {/*from w w w . j av a2s .c om*/ boolean hasErrors = false; try { Workbook wb = WorkbookFactory.create(uploadForm.getRegistrationFile().getInputStream()); Sheet sheet = wb.getSheetAt(0); Cell contactNameCell = sheet.getRow(0).getCell(1, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); Cell contactEmailCell = sheet.getRow(1).getCell(1, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); Cell contactPhoneCell = sheet.getRow(2).getCell(1, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); Cell registrationReferenceCell = sheet.getRow(3).getCell(1, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); if (contactNameCell.getStringCellValue().isEmpty()) { hasErrors = true; bindingResult.addError(new ObjectError("registrationFile", "Contact Name Empty")); } if (contactEmailCell.getStringCellValue().isEmpty()) { hasErrors = true; bindingResult.addError(new ObjectError("registrationFile", "Contact Email Empty")); } if (contactPhoneCell.getStringCellValue().isEmpty()) { hasErrors = true; bindingResult.addError(new ObjectError("registrationFile", "Contact Phone Empty")); } if (registrationReferenceCell.getStringCellValue().isEmpty()) { hasErrors = true; bindingResult.addError(new ObjectError("registrationFile", "Registration Reference Empty")); } if (!hasErrors) { RegistrationDetails details = new RegistrationDetails(); details.setContactEmailAddress(contactEmailCell.getStringCellValue()); details.setContactName(contactNameCell.getStringCellValue()); details.setContactPhoneNumber(contactPhoneCell.getStringCellValue()); details.setRegistrationFormKey(registrationReferenceCell.getStringCellValue()); details.setEvent(signUp.getEvent()); details.setFinalCost(BigDecimal.ZERO); details.setInvoice("Invoiced"); details.setPaymentState(RegistrationDetails.PaymentState.PAID); int attendeeRowIndex = 7; Row attendeeRow = sheet.getRow(attendeeRowIndex); while (attendeeRow != null) { attendeeRow = sheet.getRow(attendeeRowIndex); if (attendeeRow != null) { Cell firstName = attendeeRow.getCell(0, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); Cell lastName = attendeeRow.getCell(1, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); Cell emailAddress = attendeeRow.getCell(2, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); Cell city = attendeeRow.getCell(3, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); Cell state = attendeeRow.getCell(4, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); Cell country = attendeeRow.getCell(5, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); Cell ticketType = attendeeRow.getCell(6, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); Cell company = attendeeRow.getCell(7, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); Cell jobTitle = attendeeRow.getCell(8, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); Cell tshirtSize = attendeeRow.getCell(9, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); Cell vegetarian = attendeeRow.getCell(10, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); Cell sponsorMessages = attendeeRow.getCell(11, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); if (firstName.getStringCellValue().isEmpty()) { break; } if (lastName.getStringCellValue().isEmpty()) { bindingResult.addError(new ObjectError("registrationFile", " row " + (attendeeRowIndex + 1) + " missing information : lastName")); hasErrors = true; break; } if (emailAddress.getStringCellValue().isEmpty()) { bindingResult.addError(new ObjectError("registrationFile", " row " + (attendeeRowIndex + 1) + " missing information : emailAddress")); hasErrors = true; break; } if (city.getStringCellValue().isEmpty()) { bindingResult.addError(new ObjectError("registrationFile", " row " + (attendeeRowIndex + 1) + " missing information : city")); hasErrors = true; break; } if (state.getStringCellValue().isEmpty()) { bindingResult.addError(new ObjectError("registrationFile", " row " + (attendeeRowIndex + 1) + " missing information : state ")); hasErrors = true; break; } if (country.getStringCellValue().isEmpty()) { bindingResult.addError(new ObjectError("registrationFile", " row " + (attendeeRowIndex + 1) + " missing information : country")); hasErrors = true; break; } if (company.getStringCellValue().isEmpty()) { bindingResult.addError(new ObjectError("registrationFile", " row " + (attendeeRowIndex + 1) + " missing information : company")); hasErrors = true; break; } if (jobTitle.getStringCellValue().isEmpty()) { bindingResult.addError(new ObjectError("registrationFile", " row " + (attendeeRowIndex + 1) + " missing information : jobTitle")); hasErrors = true; break; } if (ticketType.getStringCellValue().isEmpty()) { bindingResult.addError(new ObjectError("registrationFile", " row " + (attendeeRowIndex + 1) + " missing information: ticket type")); hasErrors = true; break; } if (tshirtSize.getStringCellValue().isEmpty()) { bindingResult.addError(new ObjectError("registrationFile", " row " + (attendeeRowIndex + 1) + " missing information: t shirt ")); hasErrors = true; break; } if (vegetarian.getStringCellValue().isEmpty() || !(vegetarian.getStringCellValue().equalsIgnoreCase("no") || vegetarian.getStringCellValue().equalsIgnoreCase("yes"))) { bindingResult.addError( new ObjectError("registrationFile", " row " + (attendeeRowIndex + 1) + " missing information. Vegetarian option should be yes or no ")); hasErrors = true; break; } if (sponsorMessages.getStringCellValue().isEmpty() || !(sponsorMessages.getStringCellValue().equalsIgnoreCase("no") || sponsorMessages.getStringCellValue().equalsIgnoreCase("yes"))) { bindingResult.addError( new ObjectError("registrationFile", " row " + (attendeeRowIndex + 1) + " missing information. Sponsor message should be yes or no ")); hasErrors = true; break; } TicketOrderDetail detail = new TicketOrderDetail(); detail.setCity(city.getStringCellValue()); detail.setCompany(company.getStringCellValue()); detail.setCouponCode(""); detail.setCountry(country.getStringCellValue()); detail.setEmailAddress(emailAddress.getStringCellValue()); detail.setFirstName(firstName.getStringCellValue()); detail.setJobTitle(jobTitle.getStringCellValue()); detail.setLastName(lastName.getStringCellValue()); detail.setSponsorMayContact( sponsorMessages.getStringCellValue().equalsIgnoreCase("no") ? "false" : "true"); detail.setState(state.getStringCellValue()); detail.setTicketGroup( Long.parseLong(ticketType.getStringCellValue().split("-\\|-")[1].trim())); detail.setLabel(businessService.getTicketGroup(detail.getTicketGroup()).getLabel()); detail.settShirtSize(tshirtSize.getStringCellValue()); detail.setVegetarian( vegetarian.getStringCellValue().equalsIgnoreCase("no") ? "false" : "true"); detail.setRegistration(details); details.getOrderDetails().add(detail); attendeeRowIndex++; } } if (uploadForm.getOverrideRegistration()) { try { RegistrationDetails tempRegistration = businessService .getRegistrationForm(registrationReferenceCell.getStringCellValue()); tempRegistration.getOrderDetails().forEach((oldDetail) -> { oldDetail.setRegistration(null); }); tempRegistration.getOrderDetails().clear(); tempRegistration.getOrderDetails().addAll(details.getOrderDetails()); tempRegistration.getOrderDetails().forEach((detail) -> { detail.setRegistration(tempRegistration); }); details = tempRegistration; businessService.updateRegistration(details, uploadForm.getSendEmail()); } catch (EmptyResultDataAccessException ignore) { businessService.updateRegistration(details, uploadForm.getSendEmail()); } } else { try { RegistrationDetails tempRegistration = businessService .getRegistrationForm(registrationReferenceCell.getStringCellValue()); hasErrors = true; bindingResult.addError(new ObjectError("registrationFile", "Registration with this key exists, please check \"Replace Registrations\".")); } catch (EmptyResultDataAccessException ignore) { businessService.updateRegistration(details, uploadForm.getSendEmail()); } } } } catch (Exception ex) { hasErrors = true; Logger.getAnonymousLogger().log(Level.SEVERE, ex.getMessage(), ex); bindingResult.addError(new ObjectError("registrationFile", ex.getMessage())); } if (hasErrors) { model.setViewName("/admin/upload-registration"); } else { model.setViewName("/admin/index"); } } return model; }
From source file:org.openmrs.module.radiology.web.controller.RadiologyObsFormControllerTest.java
/** * @see RadiologyObsFormController#saveComplexObs(MultipartHttpServletRequest,HttpServletResponse,String,RadiologyOrder,Obs,BindingResult) * @verifies populate model and view with obs for occuring Exception */// w w w .j a v a2s. co m @Test public void saveComplexObs_shouldPopulateModelAndViewWithObsForOccuringException() throws Exception { APIException apiException = new APIException("Test Exception Handling"); when(obsService.saveObs(mockObs, "Test Edit Reason")).thenThrow(apiException); ModelAndView modelAndView = radiologyObsFormController.saveComplexObs( mockMultipartHttpServletRequestRequest, null, "Test Edit Reason", mockRadiologyOrder, mockObs, obsErrors); assertThat((String) mockSession.getAttribute(WebConstants.OPENMRS_ERROR_ATTR), is("Test Exception Handling")); assertThat(modelAndView, is(notNullValue())); assertThat(modelAndView.getViewName(), is("module/radiology/radiologyObsForm")); assertThat(modelAndView.getModelMap(), hasKey("obs")); Obs obs = (Obs) modelAndView.getModelMap().get("obs"); assertThat(obs, is(mockObs)); }