Example usage for org.springframework.ui ModelMap ModelMap

List of usage examples for org.springframework.ui ModelMap ModelMap

Introduction

In this page you can find the example usage for org.springframework.ui ModelMap ModelMap.

Prototype

public ModelMap() 

Source Link

Document

Construct a new, empty ModelMap .

Usage

From source file:org.esupportail.dining.web.controllers.EditAdminController.java

@RequestMapping("/stats")
public ModelAndView renderStatsAdminView() throws Exception {

    ModelMap model = new ModelMap();

    /* Favorite Restaurants stats */

    ResultSet results = this.dc.executeQuery("SELECT RESTAURANTID FROM FAVORITERESTAURANT");

    HashMap<Integer, Integer> nbRestaurant = new HashMap<Integer, Integer>();

    while (results.next()) {
        int currentValue = nbRestaurant.get(results.getInt("RESTAURANTID")) == null ? 0
                : nbRestaurant.get(results.getInt("RESTAURANTID"));
        if (currentValue == 0) {
            nbRestaurant.put(results.getInt("RESTAURANTID"), 1);
        } else {/*  www.ja  v a 2  s . c  o m*/
            nbRestaurant.put(results.getInt("RESTAURANTID"), ++currentValue);
        }
    }

    HashMap<Integer, String> restaurantsName = new HashMap<Integer, String>();
    for (Restaurant r : this.feed.getFeed().getRestaurants()) {
        restaurantsName.put(r.getId(), r.getTitle());
    }

    /* Nutrition preferences stats */

    ResultSet resultsNutrit = this.dc
            .executeQuery("SELECT NUTRITIONCODE, COUNT(*) FROM NUTRITIONPREFERENCES GROUP BY NUTRITIONCODE");
    Map<Integer, Integer> prefCodeList = new HashMap<Integer, Integer>();

    while (resultsNutrit.next()) {
        prefCodeList.put(resultsNutrit.getInt(1), resultsNutrit.getInt(2));
    }

    model.put("prefCodeList", prefCodeList);
    model.put("stats", nbRestaurant);
    model.put("restaurantsName", restaurantsName);

    return new ModelAndView("stats", model);
}

From source file:game.kalaha.test.ModelControlTest.java

@Test
public void testRetrievePlayers() {
    ModelMap model = new ModelMap();
    controller.retrievePlayers(model);/* w w  w .ja v a 2s . c om*/
    assertEquals("Player id for player1 unexpected", 0, model.get("player1"));
    assertEquals("Player id for player2 unexpected", 1, model.get("player2"));
}

From source file:com.Voxce.Controllers.TrialsController.java

public ModelAndView ShowTrials(HttpServletRequest request, HttpServletResponse response) throws Exception {
    CurrentUser = (Users) request.getSession().getAttribute("CurrentUser");
    if (CurrentUser == null) {
        response.sendRedirect("login.htm");
    }//from  ww w.  j a va2  s  .  c  o  m

    List<ApprovalStatusType> approvalstatustypelist;

    try {
        int studyid = Integer.parseInt(request.getParameter("studyid"));
        currentstudy = studiesdao.getStudyDetail(studyid).get(0);

        approvalstatustypelist = approvalstatustypedao.listapprovals(currentstudy.getStudy_id());

        ModelMap modelMap = new ModelMap();
        modelMap.addAttribute("currentstudy", currentstudy);
        modelMap.addAttribute("approvalstatustypelist", approvalstatustypelist);
        if (request.getParameter("app_type_form") != null) {
            int form = Integer.parseInt(request.getParameter("app_type_form"));
            if (form == 1)
                modelMap.addAttribute("CurrentFormApprovalType", "View_Approval_Status_Type_div");
            else
                modelMap.addAttribute("CurrentFormApprovalType", "Create_Approval_Status_Type_div");
        } else
            modelMap.addAttribute("CurrentFormApprovalType", "View_Approval_Status_Type_div");
        return new ModelAndView("trials", modelMap);
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
        response.sendRedirect("login.htm");

    }
    return new ModelAndView("trials", new ModelMap());

}

From source file:org.ngrinder.perftest.controller.PerfTestControllerTest.java

@Test
public void testSavePerfTestCloneAndLeaveCommentAndStop() {
    String testName = "test1";
    PerfTest test = createPerfTest(testName, Status.READY, null);
    long preId = test.getId();

    PerfTest cloneTest = newPerfTest(testName, Status.READY, null);
    cloneTest.setId(test.getId()); // set cloned test's ID as previous test

    ModelMap model = new ModelMap();
    controller.saveOne(getTestUser(), cloneTest, true, model);
    assertThat(preId, not(cloneTest.getId()));

    // test leave comment
    controller.leaveComment(getTestUser(), cloneTest.getId(), "TestComment", "");
    model.clear();/* ww  w .  java2s  .  c  om*/
    controller.getOne(getTestUser(), cloneTest.getId(), model);
    PerfTest testInDB = (PerfTest) model.get(PARAM_TEST);
    assertThat(testInDB.getTestComment(), is("TestComment"));

    // test stop test
    cloneTest.setStatus(Status.TESTING);
    perfTestService.save(getTestUser(), cloneTest);
    controller.stop(getTestUser(), String.valueOf(cloneTest.getId()));
}

From source file:fragment.web.BillingControllerTest.java

@Before
public void init() throws Exception {
    map = new ModelMap();
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    prepareMock(true, bootstrapActivator);
    if (!isMockInstanceCreated) {

        Service ossService = serviceDAO.find(7l);
        ossService.setEnabled(true);/*  w ww.  j av a2 s. c  o  m*/
        Service cloudService = serviceDAO.find(6l);
        connectorManagementService.getAllServiceInstances(cloudService);

        isMockInstanceCreated = true;
    }
    asRoot();
}

From source file:br.com.edo.atmlist.controller.ATMControllerTest.java

/**
 * Test of logout method, of class ATMController.
 *///  www.  ja  va2s  .  c  om
@Test
public void testLogout() {
    System.out.println("logout");
    ModelMap model = new ModelMap();
    HttpSession session = new MockHttpSession();
    ATMController instance = new ATMController();
    String expResult = "redirect:login";
    String result = instance.logout(model, session);
    assertEquals(expResult, result);

}

From source file:org.ngrinder.user.controller.UserControllerTest.java

private void saveTestUser(String userId, String userName) {
    User newUser = new User();
    newUser.setUserId(userId);/*from  w  ww. jav  a 2s  . co  m*/
    newUser.setUserName(userName);
    newUser.setEmail("junoyoon@gmail.com");
    newUser.setCreatedUser(getTestUser());
    newUser.setCreatedDate(new Date());
    newUser.setRole(Role.USER);
    ModelMap model = new ModelMap();
    userController.save(getAdminUser(), newUser, model);
}

From source file:com.forexnepal.controller.HomeController.java

@RequestMapping(value = "/exchange_rates/bank/{byBankId}/{byDate}/{byTime}", method = RequestMethod.GET)
public @ResponseBody ModelMap ExchangeRatesByBankDateTime(@PathVariable(value = "byBankId") int byBankId,
        @PathVariable(value = "byDate") Date byDate, @PathVariable(value = "byTime") Time byTime) {
    ModelMap map = new ModelMap();
    //System.out.println(byCurrencyId + "" + byDate + "" + byTime);
    map.addAttribute("exchangeRatesByBankDateTime",
            exchangeRatesService.getByBankDateTime(byBankId, byDate, byTime));
    return map;// w  w w. ja v  a  2 s. co  m
}

From source file:fragment.web.AbstractProfilesControllerTest.java

/**
 * Author: vinayv Description: Test to edit Customer users profiles
 *///from  w  ww. j ava 2s. co m
@SuppressWarnings("unchecked")
@Test
public void testEditCustomerUserProfiles() {

    map = new ModelMap();
    Profile profile = profileService.getProfile(9L);
    String authorityNames = ",ROLE_USER";
    String result = profilesController.editProfile(map, "9", authorityNames);
    Assert.assertNotNull(result);
    Assert.assertEquals("profiles.show", result);
    List<ProfileAuthority> authorityList = profile.getAuthorityList();
    Assert.assertEquals(1, authorityList.size());
    List<ProfileForm> allProfileList = (List<ProfileForm>) map.get("allProfileList");
    Assert.assertNotNull(allProfileList);
    Assert.assertEquals(profileDAO.count(), allProfileList.size());
    List<Profile> globalProfileList = (List<Profile>) profileService.listAllProfilesOfClass(Scope.GLOBAL);
    List<ProfileForm> opsProfileList = (List<ProfileForm>) map.get("opsProfileList");
    Assert.assertEquals(globalProfileList.size(), opsProfileList.size());
    List<Profile> tenantProfileList = (List<Profile>) profileService.listAllProfilesOfClass(Scope.TENANT);
    List<ProfileForm> nonOpsProfileList = (List<ProfileForm>) map.get("nonOpsProfileList");
    Assert.assertEquals(tenantProfileList.size(), nonOpsProfileList.size());
}

From source file:com.github.bpark.BlogPostController.java

/**
 * Handles SpamExceptions./*w w  w .j a  v a 2  s  . com*/
 *
 * @param request the request.
 * @param response the response.
 * @param session the session.
 * @param e the SpamException.
 * @return the error page.
 */
@ExceptionHandler(SpamException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ModelAndView handleSpamException(HttpServletRequest request, HttpServletResponse response,
        HttpSession session, SpamException e) {
    ModelMap model = new ModelMap();
    return new ModelAndView("/spam", model);
}