Example usage for org.springframework.web.servlet ModelAndView getModelMap

List of usage examples for org.springframework.web.servlet ModelAndView getModelMap

Introduction

In this page you can find the example usage for org.springframework.web.servlet ModelAndView getModelMap.

Prototype

public ModelMap getModelMap() 

Source Link

Document

Return the underlying ModelMap instance (never null ).

Usage

From source file:com.greenline.guahao.web.module.common.exception.PortalExceptionResolver.java

@Override
public ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception ex) {//from  w  w w  . java2 s.co m
    logger.error("url=" + (request.getServerName() + CommonUtils.getBeforeRepath(request)));
    // ?
    ModelAndView mv = super.doResolveException(request, response, handler, ex);
    mv.setViewName(domainFilter.getAuthorization(request).getErrorViewName(request, response));
    response.setStatus(HttpServletResponse.SC_OK);
    String servername = (String) request.getAttribute("servername");
    if (StringUtils.isNotBlank(servername)) {
        // ???url 0 1?
        String domain_showurl = (String) request.getAttribute("domain_showurl");
        if (StringUtils.isNotBlank(domain_showurl) && "0".equals(domain_showurl)) {
            String domainservername = request.getScheme() + "://" + servername
                    + CommonUtils.getServerPort(request);
            mv.getModelMap().put("guahaoServer", domainservername);
        }
    }
    return mv;
}

From source file:org.openmrs.module.radiology.web.controller.RadiologyOrderFormControllerTest.java

/**
 * @see RadiologyOrderFormController#getRadiologyOrderFormWithExistingRadiologyOrderByOrderId(Integer)
 *//*from ww  w  .  j  av  a2s. c  o m*/
@Test
@Verifies(value = "should populate model and view with existing radiology order matching given order id", method = "getRadiologyOrderFormWithExistingRadiologyOrderByOrderId(Integer)")
public void getRadiologyOrderFormWithExistingRadiologyOrderByOrderId_shouldPopulateModelAndViewWithExistingRadiologyOrderMatchingGivenOrderId()
        throws Exception {

    //given
    RadiologyOrder mockRadiologyOrder = RadiologyTestData.getMockRadiologyOrder1();

    when(radiologyService.getRadiologyOrderByOrderId(mockRadiologyOrder.getOrderId()))
            .thenReturn(mockRadiologyOrder);

    ModelAndView modelAndView = radiologyOrderFormController
            .getRadiologyOrderFormWithExistingRadiologyOrderByOrderId(mockRadiologyOrder);

    assertNotNull(modelAndView);
    assertThat(modelAndView.getViewName(), is("module/radiology/radiologyOrderForm"));

    assertThat(modelAndView.getModelMap(), hasKey("radiologyOrder"));
    RadiologyOrder order = (RadiologyOrder) modelAndView.getModelMap().get("radiologyOrder");
    assertThat(order, is(mockRadiologyOrder));
}

From source file:org.openmrs.module.radiology.web.controller.RadiologyOrderFormControllerTest.java

/**
 * @see RadiologyOrderFormController#getRadiologyOrderFormWithNewRadiologyOrderAndPrefilledPatient(Integer)
 *///  w w w. ja v  a2s.c om
@Test
@Verifies(value = "should populate model and view with new radiology order prefilled with given patient", method = "getRadiologyOrderFormWithNewRadiologyOrderAndPrefilledPatient(Integer)")
public void getRadiologyOrderFormWithNewRadiologyOrderAndPrefilledPatient_shouldPopulateModelAndViewWithNewRadiologyOrderPrefilledWithGivenPatient()
        throws Exception {

    //given
    Patient mockPatient = RadiologyTestData.getMockPatient1();

    ModelAndView modelAndView = radiologyOrderFormController
            .getRadiologyOrderFormWithNewRadiologyOrderAndPrefilledPatient(mockPatient);

    assertNotNull(modelAndView);
    assertThat(modelAndView.getViewName(), is("module/radiology/radiologyOrderForm"));

    assertThat(modelAndView.getModelMap(), hasKey("radiologyOrder"));
    RadiologyOrder order = (RadiologyOrder) modelAndView.getModelMap().get("radiologyOrder");
    assertNull(order.getOrderId());

    assertNotNull(order.getStudy());
    assertNull(order.getStudy().getStudyId());

    assertNotNull(order.getPatient());
    assertThat(order.getPatient(), is(mockPatient));

    assertThat(modelAndView.getModelMap(), hasKey("patientId"));
    Integer patientId = (Integer) modelAndView.getModelMap().get("patientId");
    assertThat(patientId, is(mockPatient.getPatientId()));
}

From source file:edu.usc.lunchnlearn.elasticsearch.interceptor.BreadCrumbInterceptor.java

private Crumb getCurrentCrumb(HttpServletRequest request, Map<String, Long> breadcrumbUrls,
        Map<Long, Crumb> breadcrumbs, ModelAndView modelAndView) {
    Crumb crumb = new Crumb();

    StringBuffer stringBuffer = request.getRequestURL();
    if (request.getQueryString() != null) {
        stringBuffer.append("?").append(request.getQueryString());
    }//from   w w w  .j  a  v  a 2s  .c om
    crumb.setUrl(stringBuffer.toString());

    //if the exact URL has already been requested, use that crumb instead of creating a new one.
    if (breadcrumbUrls.containsKey(crumb.getUrl())) {
        return breadcrumbs.get(breadcrumbUrls.get(crumb.getUrl()));
    }

    //set the display text of the breadcrumb
    crumb.setDisplayText("");

    if (modelAndView.getModelMap().containsAttribute("title")) {
        crumb.setDisplayText((String) modelAndView.getModelMap().get("title"));
    } else {
        for (String uri : uriDisplayTextMapping.keySet()) {
            if (crumb.getUrl().contains(uri)) {
                crumb.setDisplayText(uriDisplayTextMapping.get(uri));
                break;
            }
        }
    }

    //set the parent value
    if (request.getParameterMap().containsKey("x")) {
        if (StringUtils.isNumeric(request.getParameter("x"))) {
            crumb.setParentX(Long.parseLong(request.getParameter("x")));
        }
    }

    //set the time in millis for X
    crumb.setX(System.currentTimeMillis());

    return crumb;
}

From source file:com.tms.controller.customer.CustomerController.java

@RequestMapping("/update")
public ModelAndView updateCustomer(String id, HttpServletResponse response, HttpServletRequest request)
        throws Exception {
    ModelAndView view = new ModelAndView();
    Company customer = companyService.findById(id);
    view.getModel().put("customer", customer);

    String[] customerStatus = new String[CompanyStatus.values().length];
    int index = 0;
    for (CompanyStatus companyStatus : CompanyStatus.values()) {//?
        customerStatus[index] = companyStatus.name();
        index++;/*from w  w w.j  av a 2  s. c o  m*/
    }
    view.getModelMap().put("customerStatus", customerStatus);

    List<TimeZone> timeZones = timeZoneService.findAll();
    view.getModelMap().put("timeZones", timeZones);

    List<OutFaceType> outFaceTypes = outFaceTypeService.findAll();
    if (CollectionUtils.isNotEmpty(outFaceTypes)) {
        List<OutFaceType> outFaceTypeArrayList = new ArrayList<OutFaceType>();
        List<OutFaceType> otherOutFaceTypeArrayList = new ArrayList<OutFaceType>();
        for (OutFaceType outfaceType : outFaceTypes) {
            if (outfaceType.isOther()) {
                otherOutFaceTypeArrayList.add(outfaceType);
            } else {
                outFaceTypeArrayList.add(outfaceType);
            }
        }
        view.getModelMap().put("outFace", outFaceTypeArrayList);
        view.getModelMap().put("otherOutFace", otherOutFaceTypeArrayList);
    }

    List<ReportManagement> reportManagements = reportManagementService.findAll();
    view.getModelMap().put("reportManagements", reportManagements);

    List<Features> features = featuresService.findAll();
    view.getModelMap().put("features", features);

    if (customer.getOutFaceTypes() != null) {
        for (OutFaceType outfaceType : customer.getOutFaceTypes()) {
            if (outfaceType.isOther()) {
                view.getModelMap().put("otherOutFaceTypeId", outfaceType.getId());
            } else {
                view.getModelMap().put("outFaceTypeId", outfaceType.getId());
            }
        }
    }
    if (customer.getStatus() != null) {
        view.getModelMap().put("customerStatus", customer.getStatus().name());
    }

    view.setViewName("admin/customer/savecustomer");
    return view;
}

From source file:org.openmrs.module.radiology.web.controller.RadiologyOrderFormControllerTest.java

/**
 * @see RadiologyOrderFormController#postDiscontinueRadiologyOrder(HttpServletRequest,
 *      HttpServletResponse, Order, String, Date)
 *//*from   ww  w .j  a  v a 2  s  .  c  o m*/
@Test
@Verifies(value = "should not redirect if discontinuation failed in pacs", method = "postDiscontinueRadiologyOrder(HttpServletRequest, HttpServletResponse, Order, String, Date)")
public void postDiscontinueRadiologyOrder_shouldNotRedirectIfDiscontinuationFailedInPacs() throws Exception {
    //given
    RadiologyOrder mockRadiologyOrderToDiscontinue = RadiologyTestData.getMockRadiologyOrder1();
    mockRadiologyOrderToDiscontinue.getStudy().setMwlStatus(MwlStatus.DISCONTINUE_ERR);
    String discontinueReason = "Wrong Procedure";
    Date discontinueDate = new GregorianCalendar(2015, Calendar.JANUARY, 01).getTime();

    Order mockDiscontinuationOrder = new Order();
    mockDiscontinuationOrder.setOrderId(2);
    mockDiscontinuationOrder.setAction(Order.Action.DISCONTINUE);
    mockDiscontinuationOrder.setOrderer(mockRadiologyOrderToDiscontinue.getOrderer());
    mockDiscontinuationOrder.setOrderReasonNonCoded(discontinueReason);
    mockDiscontinuationOrder.setPreviousOrder(mockRadiologyOrderToDiscontinue);

    MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.addParameter("discontinueOrder", "discontinueOrder");
    MockHttpSession mockSession = new MockHttpSession();
    mockRequest.setSession(mockSession);

    when(radiologyService.getRadiologyOrderByOrderId(mockRadiologyOrderToDiscontinue.getOrderId()))
            .thenReturn(mockRadiologyOrderToDiscontinue);
    when(orderService.discontinueOrder(mockRadiologyOrderToDiscontinue, discontinueReason, discontinueDate,
            mockRadiologyOrderToDiscontinue.getOrderer(), mockRadiologyOrderToDiscontinue.getEncounter()))
                    .thenReturn(mockDiscontinuationOrder);

    ModelAndView modelAndView = radiologyOrderFormController.postDiscontinueRadiologyOrder(mockRequest, null,
            mockRadiologyOrderToDiscontinue, mockDiscontinuationOrder);

    assertNotNull(modelAndView);
    assertThat(modelAndView.getViewName(), is("module/radiology/radiologyOrderForm"));

    assertThat(modelAndView.getModelMap(), hasKey("order"));
    Order order = (Order) modelAndView.getModelMap().get("order");
    assertThat(order, is((Order) mockRadiologyOrderToDiscontinue));

    assertThat(modelAndView.getModelMap(), hasKey("radiologyOrder"));
    RadiologyOrder radiologyOrder = (RadiologyOrder) modelAndView.getModelMap().get("radiologyOrder");
    assertThat(radiologyOrder, is(mockRadiologyOrderToDiscontinue));

    assertNotNull(mockSession.getAttribute(WebConstants.OPENMRS_ERROR_ATTR));
    assertThat((String) mockSession.getAttribute(WebConstants.OPENMRS_ERROR_ATTR),
            is("radiology.failWorklist"));
}

From source file:org.openmrs.module.radiology.order.web.RadiologyOrderFormControllerTest.java

/**
 * @see RadiologyOrderFormController#getRadiologyOrderFormWithNewRadiologyOrder()
 * @verifies populate model and view with new radiology order
 *//*from w w w  .j  av a2 s  . c  om*/
@Test
public void getRadiologyOrderFormWithNewRadiologyOrder_shouldPopulateModelAndViewWithNewRadiologyOrder()
        throws Exception {

    ModelAndView modelAndView = radiologyOrderFormController.getRadiologyOrderFormWithNewRadiologyOrder();

    assertNotNull(modelAndView);
    assertThat(modelAndView.getViewName(), is(RadiologyOrderFormController.RADIOLOGY_ORDER_FORM_VIEW));

    assertThat(modelAndView.getModelMap(), hasKey("radiologyOrder"));
    RadiologyOrder order = (RadiologyOrder) modelAndView.getModelMap().get("radiologyOrder");
    assertNull(order.getOrderId());

    assertNotNull(order.getStudy());
    assertNull(order.getStudy().getStudyId());

    assertNull(order.getOrderer());
}

From source file:org.openmrs.module.radiology.web.controller.RadiologyOrderFormControllerTest.java

/**
 * @see RadiologyOrderFormController#postDiscontinueRadiologyOrder(HttpServletRequest,
 *      HttpServletResponse, Order, String, Date)
 *///from  w w w  .j  a va  2 s .  co  m
@Test
@Verifies(value = "should not redirect if discontinuation failed through date in the future", method = "postDiscontinueRadiologyOrder(HttpServletRequest, HttpServletResponse, Order, String, Date)")
public void postDiscontinueRadiologyOrder_shouldNotRedirectIfDiscontinuationFailedThroughDateInTheFuture()
        throws Exception {
    //given
    RadiologyOrder mockRadiologyOrderToDiscontinue = RadiologyTestData.getMockRadiologyOrder1();
    mockRadiologyOrderToDiscontinue.getStudy().setMwlStatus(MwlStatus.DISCONTINUE_OK);
    String discontinueReason = "Wrong Procedure";
    Date discontinueDate = new Date();
    APIException apiException = new APIException("Discontinue date cannot be in the future");

    Order mockDiscontinuationOrder = new Order();
    mockDiscontinuationOrder.setOrderId(2);
    mockDiscontinuationOrder.setAction(Order.Action.DISCONTINUE);
    mockDiscontinuationOrder.setOrderer(mockRadiologyOrderToDiscontinue.getOrderer());
    mockDiscontinuationOrder.setOrderReasonNonCoded(discontinueReason);
    mockDiscontinuationOrder.setDateActivated(discontinueDate);
    mockDiscontinuationOrder.setPreviousOrder(mockRadiologyOrderToDiscontinue);

    MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.addParameter("discontinueOrder", "discontinueOrder");
    MockHttpSession mockSession = new MockHttpSession();
    mockRequest.setSession(mockSession);

    when(radiologyService.getRadiologyOrderByOrderId(mockRadiologyOrderToDiscontinue.getOrderId()))
            .thenReturn(mockRadiologyOrderToDiscontinue);
    when(radiologyService.discontinueRadiologyOrder(mockRadiologyOrderToDiscontinue,
            mockDiscontinuationOrder.getOrderer(), mockDiscontinuationOrder.getDateActivated(),
            mockDiscontinuationOrder.getOrderReasonNonCoded())).thenThrow(apiException);

    assertThat(mockRadiologyOrderToDiscontinue.getAction(), is(Order.Action.NEW));
    ModelAndView modelAndView = radiologyOrderFormController.postDiscontinueRadiologyOrder(mockRequest, null,
            mockRadiologyOrderToDiscontinue, mockDiscontinuationOrder);

    assertNotNull(modelAndView);
    assertThat(modelAndView.getViewName(), is("module/radiology/radiologyOrderForm"));

    assertThat(modelAndView.getModelMap(), hasKey("order"));
    Order order = (Order) modelAndView.getModelMap().get("order");
    assertThat(order, is((Order) mockRadiologyOrderToDiscontinue));

    assertThat(modelAndView.getModelMap(), hasKey("radiologyOrder"));
    RadiologyOrder radiologyOrder = (RadiologyOrder) modelAndView.getModelMap().get("radiologyOrder");
    assertThat(radiologyOrder, is(mockRadiologyOrderToDiscontinue));

    assertNotNull(mockSession.getAttribute(WebConstants.OPENMRS_ERROR_ATTR));
    assertThat((String) mockSession.getAttribute(WebConstants.OPENMRS_ERROR_ATTR),
            is("Discontinue date cannot be in the future"));
}

From source file:org.openmrs.module.radiology.order.web.RadiologyOrderFormControllerTest.java

/**
 * @see RadiologyOrderFormController#saveRadiologyOrder(HttpServletRequest, RadiologyOrder, BindingResult)
 * @verifies not save given radiology order if it is not valid and not redirect
 */// w  ww  .  j a va  2 s.c o m
@Test
public void saveRadiologyOrder_shouldNotSaveGivenRadiologyOrderIfItIsNotValidAndNotRedirect() throws Exception {

    // given
    RadiologyOrder mockRadiologyOrder = RadiologyTestData.getMockRadiologyOrder1();

    MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.addParameter("saveOrder", "saveOrder");
    MockHttpSession mockSession = new MockHttpSession();
    mockRequest.setSession(mockSession);

    BindingResult orderErrors = mock(BindingResult.class);
    when(orderErrors.hasErrors()).thenReturn(true);

    ModelAndView modelAndView = radiologyOrderFormController.saveRadiologyOrder(mockRequest, mockRadiologyOrder,
            orderErrors);

    assertNotNull(modelAndView);
    assertThat(modelAndView.getViewName(), is(RadiologyOrderFormController.RADIOLOGY_ORDER_FORM_VIEW));

    assertThat(modelAndView.getModelMap(), hasKey("order"));
    Order order = (Order) modelAndView.getModelMap().get("order");
    assertThat(order, is(mockRadiologyOrder));

    assertThat(modelAndView.getModelMap(), hasKey("radiologyOrder"));
    RadiologyOrder radiologyOrder = (RadiologyOrder) modelAndView.getModelMap().get("radiologyOrder");
    assertThat(radiologyOrder, is(mockRadiologyOrder));
}

From source file:org.openmrs.module.radiology.order.web.RadiologyOrderFormControllerTest.java

/**
 * @see RadiologyOrderFormController#getRadiologyOrderFormWithExistingRadiologyOrder(Order)
 * @verifies populate model and view with existing radiology order if given order id matches a
 *           radiology order and no dicom viewer url if order is not completed
 *//*  w w w  .j  av  a2 s.  co m*/
@Test
public void getRadiologyOrderFormWithExistingRadiologyOrder_shouldPopulateModelAndViewWithExistingRadiologyOrderIfGivenOrderIdMatchesARadiologyOrderAndNoDicomViewerUrlIfOrderIsNotCompleted()
        throws Exception {

    // given
    RadiologyOrder mockRadiologyOrderInProgress = RadiologyTestData.getMockRadiologyOrder1();
    mockRadiologyOrderInProgress.getStudy().setPerformedStatus(PerformedProcedureStepStatus.IN_PROGRESS);

    ModelAndView modelAndView = radiologyOrderFormController
            .getRadiologyOrderFormWithExistingRadiologyOrder(mockRadiologyOrderInProgress);

    assertNotNull(modelAndView);
    assertThat(modelAndView.getViewName(), is(RadiologyOrderFormController.RADIOLOGY_ORDER_FORM_VIEW));

    assertThat(modelAndView.getModelMap(), hasKey("order"));
    RadiologyOrder order = (RadiologyOrder) modelAndView.getModelMap().get("order");
    assertThat(order, is(mockRadiologyOrderInProgress));

    assertThat(modelAndView.getModelMap(), hasKey("radiologyOrder"));
    RadiologyOrder radiologyOrder = (RadiologyOrder) modelAndView.getModelMap().get("radiologyOrder");
    assertThat(radiologyOrder, is(mockRadiologyOrderInProgress));

    assertThat(modelAndView.getModelMap(), not(hasKey("dicomViewerUrl")));
}