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:fragment.web.AbstractManageResourceControllerTest.java

/**
 * @author vinayv//  w w  w.  ja  v  a2  s. c o  m
 * @description : Test to get the Resource Views for a Tenant for Service Instance which was not enabled
 */
@Test
public void testResourceViewsFromSPUserForTenantWithNoCloudAccount() {
    try {
        request = new MockHttpServletRequest();
        User user = userDAO.find(3L);
        asUser(user);
        setlistResourceViews();
        map = new ModelMap();
        Tenant tenant = tenantdao.find(2L);
        ServiceInstance instance = serviceInstanceDao.find(11L);
        request.setAttribute("isSurrogatedTenant", Boolean.TRUE);
        controller.getResourceViews(tenant, tenant.getParam(), instance.getUuid(), map, request);
    } catch (Exception e) {
        Assert.assertEquals("message.no.cloud.account", e.getMessage());
    }
}

From source file:org.esupportail.portlet.filemanager.portlet.PortletControllerAjax.java

/**
 * Return the correct details view based on the requested file(s)
 *//*  w  w w .  j  a  v  a  2 s  .  co m*/
@ResourceMapping("detailsArea")
public ModelAndView detailsArea(FormCommand command, ResourceRequest request, ResourceResponse response) {
    ModelMap model = new ModelMap();

    if (command == null || pathEncodingUtils.decodeDirs(command.getDirs()) == null) {
        return new ModelAndView("details_empty", model);
    }

    // See if we go to the multiple files/folder view or not
    if (pathEncodingUtils.decodeDirs(command.getDirs()).size() == 1) {
        String path = pathEncodingUtils.decodeDirs(command.getDirs()).get(0);
        this.serverAccess.updateUserParameters(path, userParameters);

        // get resource with folder details (if it's a folder ...)
        JsTreeFile resource = this.serverAccess.get(path, userParameters, true, true);
        pathEncodingUtils.encodeDir(resource);

        // Based on the resource type, direct to appropriate details view
        if ("folder".equals(resource.getType()) || "drive".equals(resource.getType())) {
            Quota quota = this.serverAccess.getQuota(path, userParameters);
            if (quota != null)
                model.put("quota", quota);
            model.put("file", resource);
            return new ModelAndView("details_folder", model);
        } else if ("file".equals(resource.getType())) {
            model.put("file", resource);
            ResourceUtils.Type fileType = resourceUtils.getType(resource.getTitle());
            if (fileType == Type.AUDIO && !resource.isOverSizeLimit()) {
                return new ModelAndView("details_sound", model);
            } else if (fileType == Type.IMAGE && !resource.isOverSizeLimit()) {
                return new ModelAndView("details_image", model);
            } else {
                // generic file page
                return new ModelAndView("details_file", model);
            }
        }
    } else if (pathEncodingUtils.decodeDirs(command.getDirs()).size() > 1) {
        // Add data for multiple files details view
        model.put("numselected", pathEncodingUtils.decodeDirs(command.getDirs()).size());

        // Find the resources which are files and add them to the
        // image_paths array
        List<String> image_paths = new ArrayList<String>();

        for (String filePath : pathEncodingUtils.decodeDirs(command.getDirs())) {
            JsTreeFile resource = this.serverAccess.get(filePath, userParameters, false, true);
            org.esupportail.portlet.filemanager.services.ResourceUtils.Type fileType = resourceUtils
                    .getType(resource.getTitle());
            if (fileType == Type.IMAGE && !resource.isOverSizeLimit()) {
                image_paths.add(pathEncodingUtils.encodeDir(filePath));
            }
        }
        model.put("image_paths", image_paths);
        return new ModelAndView("details_files", model);
    }

    // Unknown resource type
    return new ModelAndView("details_empty", model);

}

From source file:se.vgregion.portal.iframe.controller.CSViewControllerTest.java

@Test
@Ignore//from w w w .j a  va  2s . c om
public void testShowProxyForm_AuthFormScreenNameOnly() throws ReadOnlyException, URISyntaxException {
    PortletPreferences prefs = new MockPortletPreferences();
    initPortletPreferences(prefs);
    prefs.setValue("site-key", "test-site-key");
    prefs.setValue("screenNameOnly", "true");

    ResourceRequest mockReq = new MockResourceRequest();
    ResourceRequest req = (ResourceRequest) initPortletRequest(mockReq);

    ModelMap model = new ModelMap();

    String result = controller.showProxyForm(prefs, req, model, null);

    assertEquals("proxyLoginForm", result);

    PortletConfig portletConfig = (PortletConfig) model.get("portletConfig");
    assertNotNull(portletConfig);

    UserSiteCredential siteCredential = (UserSiteCredential) model.get("siteCredential");
    assertNotNull(siteCredential);
    assertEquals("test-user", siteCredential.getUid());
    assertEquals("test-site-key", siteCredential.getSiteKey());
    assertEquals("test-user", siteCredential.getSiteUser());
    assertEquals("test-site-password", siteCredential.getSitePassword());
}

From source file:fragment.web.AbstractConnectorControllerTest.java

@Test
public void testShowCloudServicesForRoot() throws Exception {
    try {//from w ww  .  jav  a  2 s  .c o  m
        map = new ModelMap();
        Tenant tenant = tenantDAO.find(1L);
        setValidServiceAndServiceInstance();
        String viewService = controller.showCloudServices(tenant.getUuid(), null, null, map, request);
        Assert.assertEquals("redirect:/portal/home", viewService);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail();
    }
}

From source file:se.vgregion.portal.iframe.controller.CSViewControllerTest.java

@Test
public void testShowProxyForm_NoAuthForm() throws ReadOnlyException, URISyntaxException {
    PortletPreferences prefs = new MockPortletPreferences();
    initPortletPreferences(prefs);//from  w  w  w .j a va 2s.c  om
    prefs.setValue("auth", "false");

    ResourceRequest mockReq = new MockResourceRequest();
    ResourceRequest req = (ResourceRequest) initPortletRequest(mockReq);

    ModelMap model = new ModelMap();

    String result = controller.showProxyForm(prefs, req, model, null);

    assertEquals("view", result);
}

From source file:fragment.web.SanityTestSuit.java

/**
 * Description: Test to create a channel and add bundles to the newly created channel
 * /*from   w w w. ja  v  a2 s .co  m*/
 * @author vinayv
 */
@SuppressWarnings("unchecked")
@Test
public void testChannelCreationAndAddingBundles() throws JSONException {

    String[] currencyValueList = { "USD", "EUR", "GBP" };
    int beforeChannelCount = channelDAO.count();
    Channel obtainedChannel = channelController.createChannel(WebTestUtils.createChannelForm("SanityChannel",
            "SanityChannel", "SanityChannel", null, "en_US", "Asia/Kolkata", currencyValueList, map, response),
            null, map, response);
    Assert.assertNotNull(obtainedChannel);
    int afterChannelCount = channelDAO.count();
    Assert.assertEquals(beforeChannelCount + 1, afterChannelCount);
    ModelMap map1 = new ModelMap();
    String selectedProductBundles = "[2]";
    String result = channelController.attachProductBundles(obtainedChannel.getId().toString(),
            selectedProductBundles, map1);
    Assert.assertNotNull(result);
    Assert.assertEquals("success", result);
    String listBundlesResult = channelController.listbundles(obtainedChannel.getId().toString(), map1);
    Assert.assertNotNull(listBundlesResult);
    Assert.assertEquals("productbundle.add", listBundlesResult);
    List<ProductBundleRevision> productbundles = (List<ProductBundleRevision>) map1.get("productBundles");
    for (ProductBundleRevision productbundleRevision : productbundles) {
        ProductBundle productBundle = productbundleRevision.getProductBundle();
        Assert.assertTrue(productBundle.getId() != 2L);
    }
}

From source file:se.vgregion.portal.iframe.controller.CSViewControllerTest.java

@Test
@Ignore//from w w w .  jav a  2 s .  c  o m
public void testShowProxyForm_AuthNoForm() throws ReadOnlyException, URISyntaxException {
    PortletPreferences prefs = new MockPortletPreferences();
    initPortletPreferences(prefs);
    prefs.setValue("auth-type", "basic");

    ResourceRequest mockReq = new MockResourceRequest();
    ResourceRequest req = (ResourceRequest) initPortletRequest(mockReq);

    ModelMap model = new ModelMap();

    String result = controller.showProxyForm(prefs, req, model, null);

    assertEquals("view", result);
}

From source file:info.raack.appliancelabeler.web.MainController.java

@RequestMapping(value = "/energy/graph", method = RequestMethod.GET)
public ModelAndView showEnergyGraph(HttpServletRequest request, HttpServletResponse response) {
    EnergyMonitor energyMonitor = getCurrentEnergyMonitor(request, response);

    ModelMap model = new ModelMap();
    model.put("lastMeasurementDate", new Date());
    model.put("lastTimeIncludedInTraining",
            applianceDetectionEngine.getLastTimeIncludedInTraining(energyMonitor));
    model.put("retrainingInterval", applianceDetectionEngine.getRetrainingIntervalInHours() + "");

    if (energyMonitor != null) {
        Date lastTime = database.getLastMeasurementTimeForEnergyMonitor(energyMonitor);

        model.put("lastMeasurementDate", lastTime);
    }//from   ww w .  j a v a  2 s  .c  om
    return templateProvider.showPageInTemplate(1, "meter", model);
}

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

public ModelAndView ShowTrainingUser(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    CurrentUser = (Users) request.getSession().getAttribute("CurrentUser");
    if (CurrentUser == null) {
        response.sendRedirect("login.htm");
    }/*from   w w w. j  a  v a 2s.  com*/

    List<ApprovalStatusType> approvalstatustypelist;

    List<Training> traininglist;

    List<TrainingUser> traininguserlist;
    List<Users> userslist;

    List<Sites> siteslist;

    List<ProtocolVersion> versionlist;
    List<Countries> countrieslist;

    countrieslist = countriesDAO.listCountry();

    try {

        int studyid = Integer.parseInt(request.getParameter("studyid"));

        List<studies> li = studiesdao.getStudyDetail(studyid);
        currentstudy = li.get(0);

        approvalstatustypelist = approvalstatustypedao.listapprovals(currentstudy.getStudy_id());
        traininglist = trainingdao.listtrainings(currentstudy.getStudy_id());
        traininguserlist = traininguserdao.listtraininguser(currentstudy.getStudy_id());
        versionlist = traininguserdao.listprotocolversions(currentstudy.getStudy_id());
        userslist = userdao.listusers(CurrentUser);

        siteslist = sitedao.SitesList(CurrentUser);
        CurrentUser = (Users) request.getSession().getAttribute("CurrentUser");
        ModelMap modelMap = new ModelMap();
        modelMap.addAttribute("currentstudy", currentstudy);
        modelMap.addAttribute("approvalstatustypelist", approvalstatustypelist);
        modelMap.addAttribute("traininglist", traininglist);
        modelMap.addAttribute("countrieslist", countrieslist);
        modelMap.addAttribute("traininguserlist", traininguserlist);
        modelMap.addAttribute("siteslist", siteslist);
        modelMap.addAttribute("userslist", userslist);
        modelMap.addAttribute("versionlist", versionlist);
        int form = Integer.parseInt(request.getParameter("train_user_form"));
        if (form == 1)
            modelMap.addAttribute("CurrentFormTrainingUser", "View_Training_User_div");
        else
            modelMap.addAttribute("CurrentFormTrainingUser", "Create_Training_User_div");

        return new ModelAndView("training_user", modelMap);
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
        response.sendRedirect("login.htm");
    }
    return new ModelAndView("training_user", new ModelMap());
}

From source file:se.vgregion.portal.iframe.controller.CSViewControllerTest.java

@Test
public void testShowProxyForm_NoAuthNoForm() throws ReadOnlyException, URISyntaxException {
    PortletPreferences prefs = new MockPortletPreferences();
    initPortletPreferences(prefs);/*from  www . j  a v a  2  s .  com*/
    prefs.setValue("auth", "false");
    prefs.setValue("auth-type", "basic");

    ResourceRequest mockReq = new MockResourceRequest();
    ResourceRequest req = (ResourceRequest) initPortletRequest(mockReq);

    ModelMap model = new ModelMap();

    String result = controller.showProxyForm(prefs, req, model, null);

    assertEquals("view", result);
}