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

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

Introduction

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

Prototype

public Map<String, Object> getModel() 

Source Link

Document

Return the model map.

Usage

From source file:com.ge.predix.acs.commons.web.RestErrorHandlerTest.java

@Test
public void testException() {
    RestErrorHandler errorHandler = new RestErrorHandler();

    HttpServletRequest request = new MockHttpServletRequest();
    HttpServletResponse response = new MockHttpServletResponse();
    Exception e = new Exception("Descriptive Error Message");

    ModelAndView errorResponse = errorHandler.createApiErrorResponse(e, request, response);

    // The default error status code is 500
    Assert.assertEquals(response.getStatus(), HttpStatus.INTERNAL_SERVER_ERROR.value());

    // Not null error response containing an ErrorDetails model
    Assert.assertNotNull(errorResponse);
    Assert.assertNotNull(errorResponse.getModel().get("ErrorDetails"));

    // Default response payload error code and message
    assertRestApiErrorResponse(errorResponse, "FAILED", "Operation Failed");

}

From source file:fm.last.citrine.web.ChildTaskFormsControllerTest.java

@Test
public void testCancel() throws Exception {
    mockRequest.setParameter(Constants.PARAM_CANCEL, "true");
    TaskChildCandidatesDTO dto = new TaskChildCandidatesDTO();
    dto.setSelectedGroupName("testGroupName");
    ModelAndView modelAndView = childTasksFormController.processFormSubmission(mockRequest, mockResponse, dto,
            null);/* w  w w .j a v  a 2s.co m*/
    RedirectView view = (RedirectView) modelAndView.getView();
    assertEquals("tasks.do?selectedGroupName=testGroupName", view.getUrl());
    assertEquals(0, modelAndView.getModel().size());
}

From source file:org.zilverline.web.TestIndexController.java

public void testIndexController() throws Exception {
    assertTrue(applicationContext.containsBean("indexController"));
    assertTrue(applicationContext.containsBean("collectionMan"));

    IndexController ixC = (IndexController) applicationContext.getBean("indexController");
    CollectionManager colM = (CollectionManager) applicationContext.getBean("collectionMan");

    assertEquals(ixC.getCollectionManager(), colM);
    log.debug(ixC.getApplicationContext().getBeanDefinitionNames());

    CollectionManager colMan = (CollectionManager) applicationContext.getBean("collectionMan");

    log.debug("Index is at: " + colMan.getIndexBaseDir());
    // get the testdata collection
    FileSystemCollection col = (FileSystemCollection) colMan.getCollectionByName("testdata");

    assertNotNull(col);/*  w ww .  j  a  va  2 s.  c o m*/

    CollectionForm cf = new CollectionForm();

    cf.setNames(new String[] { col.getName() });

    // full index
    cf.setFullIndex(true);

    ModelAndView mv = ixC.onSubmit(cf);
    assertTrue(col.isIndexValid());
    while (col.isIndexingInProgress()) {
        Thread.sleep(100);
        // col.stopRequest();
        log.debug("zzz");
    }

    assertEquals("14 docs", 14, col.getNumberOfDocs());
    assertEquals("returned correct view name", mv.getViewName(), "collections");
    assertTrue(mv.getModel().containsKey("collections"));
}

From source file:ru.org.linux.user.ShowRemarkController.java

@RequestMapping("/people/{nick}/remarks")
public ModelAndView showRemarks(ServletRequest request, @PathVariable String nick,
        @RequestParam(value = "offset", defaultValue = "0") int offset,
        @RequestParam(value = "sort", defaultValue = "0") int sortorder) throws Exception {
    Template tmpl = Template.getTemplate(request);
    if (!tmpl.isSessionAuthorized() || !tmpl.getCurrentUser().getNick().equals(nick)) {
        throw new AccessViolationException("Not authorized");
    }//from   w w w  . j  ava 2 s. c o m

    int count = userDao.getRemarkCount(tmpl.getCurrentUser());

    ModelAndView mv = new ModelAndView("view-remarks");

    int limit = tmpl.getProf().getMessages();

    if (count > 0) {
        if (offset >= count) {
            throw new UserErrorException("Offset is too long");
        }
        if (offset < 0)
            offset = 0;

        if (sortorder != 1) {
            sortorder = 0;
            mv.getModel().put("sortorder", "");
        } else {
            mv.getModel().put("sortorder", "&amp;sort=1");
        }

        List<Remark> remarks = userDao.getRemarkList(tmpl.getCurrentUser(), offset, sortorder, limit);
        List<PreparedRemark> preparedRemarks = prepareService.prepareRemarkList(remarks);

        mv.getModel().put("remarks", preparedRemarks);
    } else {
        mv.getModel().put("remarks", ImmutableList.of());
    }
    mv.getModel().put("offset", offset);
    mv.getModel().put("limit", limit);
    mv.getModel().put("hasMore", (count > (offset + limit)));

    return mv;
}

From source file:com.github.fedorchuck.webstore.web.controllers.SystemInfoController.java

@RequestMapping(value = "", method = GET)
public ModelAndView index() {
    ModelAndView model = new ModelAndView("sysinfo");

    final double mb = 1024 * 1024;
    Runtime runtime = Runtime.getRuntime();
    long usedRam = runtime.totalMemory() - runtime.freeMemory();

    Map<String, Double> mem = new TreeMap<>();
    mem.put("Used memory", usedRam / mb);
    mem.put("Total memory", runtime.totalMemory() / mb);
    mem.put("Free memory", runtime.freeMemory() / mb);

    model.getModel().put("mem", mem);

    //model.addObject("userActions", new UserActions());

    return model;
}

From source file:com.healthcit.cacure.web.controller.FormListController.java

@Override
public boolean isModelEditable(ModelAndView mav) {
    // the whole of the forms listing is editable unless the module
    // in in APPROVED states

    // get moduleID from model
    Map<String, Object> map = mav.getModel();
    Object o = map.get(MODULE_ID_NAME);
    if (o != null && o instanceof Long) {
        BaseModule module = (BaseModule) moduleManager.getModule((Long) o);
        return moduleManager.isEditableInCurrentContext(module);
    }/*from   w  ww  .j ava  2 s .c o m*/
    return true;
}

From source file:fm.last.citrine.web.ChildTaskFormsControllerTest.java

@Test
public void testProcessFormSubmissionNoChildTasks() throws Exception {
    long taskId = 100;
    Task task = new Task("task100");
    task.setId(taskId);/* w w  w .  j  a va 2  s.c om*/
    when(mockTaskManager.get(taskId)).thenReturn(task);

    TaskChildCandidatesDTO dto = new TaskChildCandidatesDTO();
    dto.setTask(task);
    dto.setSelectedGroupName("testGroupName");
    BindException bindException = new BindException(dto, "bla");
    ModelAndView modelAndView = childTasksFormController.processFormSubmission(mockRequest, mockResponse, dto,
            bindException);
    RedirectView view = (RedirectView) modelAndView.getView();
    assertEquals("tasks.do?selectedGroupName=testGroupName", view.getUrl());
    assertEquals(0, modelAndView.getModel().size());
}

From source file:no.dusken.common.plugin.velocity.RenderPluginDirective.java

private void renderPlugin(InternalContextAdapter context, Writer writer, PluginContentMapping plugin) {
    Map<String, Object> currentContext = getCurrentContext(context);
    try {//from w  w  w  .  j  ava2  s  . c  om
        ModelAndView mav = plugin.handleContentMapping(currentContext);
        String view = mav.getViewName();
        if (!view.endsWith(".vm")) {
            view = view.concat(".vm");
        }
        Template template = velocityEngine.getTemplate(view);

        template.merge(addToContext(context, mav.getModel()), writer);
    } catch (Exception e) {
        log.error("Error when merging template", e);
    }
}

From source file:fm.last.citrine.web.ChildTaskFormsControllerTest.java

@Test
public void testProcessFormSubmissionCandidateChildTasksOnly() throws Exception {
    long taskId = 100;
    Task task = new Task("task100");
    task.setId(taskId);//from w  w w. j  a  v  a 2 s  . com
    when(mockTaskManager.get(taskId)).thenReturn(task);

    TaskChildCandidatesDTO dto = new TaskChildCandidatesDTO();
    dto.setTask(task);
    dto.setSelectedGroupName("testGroupName");

    long candidateTaskId = 200;
    Task candidateTask = new Task("task200");
    candidateTask.setId(candidateTaskId);
    when(mockTaskManager.get(candidateTaskId)).thenReturn(candidateTask);
    Set<Long> candidateTaskIds = new HashSet<Long>();
    candidateTaskIds.add(candidateTaskId);
    dto.setCandidateChildTaskIds(candidateTaskIds);

    BindException bindException = new BindException(dto, "bla");
    ModelAndView modelAndView = childTasksFormController.processFormSubmission(mockRequest, mockResponse, dto,
            bindException);
    RedirectView view = (RedirectView) modelAndView.getView();
    assertEquals("tasks.do?selectedGroupName=testGroupName", view.getUrl());
    assertEquals(0, modelAndView.getModel().size());

    Set<Task> childTasks = task.getChildTasks();
    assertEquals(1, childTasks.size());
    assertEquals(candidateTask, childTasks.iterator().next());
}