Example usage for org.springframework.ui Model asMap

List of usage examples for org.springframework.ui Model asMap

Introduction

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

Prototype

Map<String, Object> asMap();

Source Link

Document

Return the current set of model attributes as a Map.

Usage

From source file:fr.univrouen.poste.web.membre.PosteAPourvoirController.java

@RequestMapping(value = "/{id}/addFile", method = RequestMethod.POST, produces = "text/html")
@PreAuthorize("hasPermission(#id, 'manageposte')")
public String addFile(@PathVariable("id") Long id, @Valid PosteAPourvoirFile posteFile,
        BindingResult bindingResult, Model uiModel, HttpServletRequest request) throws IOException {
    if (bindingResult.hasErrors()) {
        logger.warn(bindingResult.getAllErrors());
        return "redirect:/posteapourvoirs/" + id.toString();
    }/*from   www  . java  2  s .c o  m*/
    uiModel.asMap().clear();

    PosteAPourvoir poste = PosteAPourvoir.findPosteAPourvoir(id);

    // upload file
    MultipartFile file = posteFile.getFile();

    // sometimes file is null here, but I don't know how to reproduce this issue ... maybe that can occur only with some specifics browsers ?
    if (file != null) {
        String filename = file.getOriginalFilename();

        boolean filenameAlreadyUsed = false;
        for (PosteAPourvoirFile pcFile : poste.getPosteFiles()) {
            if (pcFile.getFilename().equals(filename)) {
                filenameAlreadyUsed = true;
                break;
            }
        }

        if (filenameAlreadyUsed) {
            uiModel.addAttribute("filename_already_used", filename);
            logger.warn("Upload Restriction sur '" + filename
                    + "' un fichier de mme nom existe dj pour le poste " + poste.getNumEmploi());
        } else {

            Long fileSize = file.getSize();

            if (fileSize != 0) {
                String contentType = file.getContentType();
                // cf https://github.com/EsupPortail/esup-dematec/issues/8 - workaround pour viter mimetype erron comme application/text-plain:formatted
                contentType = contentType.replaceAll(":.*", "");

                logger.info("Try to upload file '" + filename + "' with size=" + fileSize + " and contentType="
                        + contentType);

                InputStream inputStream = file.getInputStream();
                //byte[] bytes = IOUtils.toByteArray(inputStream);

                posteFile.setFilename(filename);
                posteFile.setFileSize(fileSize);
                posteFile.setContentType(contentType);
                logger.info("Upload and set file in DB with filesize = " + fileSize);
                posteFile.getBigFile().setBinaryFileStream(inputStream, fileSize);
                posteFile.getBigFile().persist();

                Calendar cal = Calendar.getInstance();
                Date currentTime = cal.getTime();
                posteFile.setSendTime(currentTime);

                poste.getPosteFiles().add(posteFile);
                poste.persist();

                logService.logActionPosteFile(LogService.UPLOAD_ACTION, poste, posteFile, request, currentTime);
            }
        }
    } else {
        String userId = SecurityContextHolder.getContext().getAuthentication().getName();
        String ip = request.getRemoteAddr();
        String userAgent = request.getHeader("User-Agent");
        logger.warn(userId + "[" + ip + "] tried to add a 'null file' ... his userAgent is : " + userAgent);
    }

    return "redirect:/posteapourvoirs/" + id.toString();
}

From source file:org.kew.rmf.matchconf.web.CustomConfigController.java

@RequestMapping(value = "/{configType}_configs", method = RequestMethod.POST, produces = "text/html")
public String create(@PathVariable("configType") String configType, @Valid Configuration configuration,
        BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
    configuration.setClassName(ConfigSwitch.TYPE_CLASS_MAP.get(configType));
    this.customValidation(configuration, bindingResult);
    if (bindingResult.hasErrors()) {
        populateEditForm(uiModel, configuration);
        return configType + "_configs/create";
    }//from w  w w .  j  ava 2s  .co m
    uiModel.asMap().clear();
    configuration.persist();
    return String.format("redirect:/%s_configs/", configType)
            + encodeUrlPathSegment(configuration.getName(), httpServletRequest);
}

From source file:uk.ac.ebi.emma.controller.GeneManagementListControllerTest.java

/**
 * Test of showFilter method, of class GeneManagementListController.
 *//*from w  w  w  . j  av  a  2s .  co  m*/
@Test
public void testShowFilter() {
    System.out.println("showFilter");
    String gene_key = "123";
    String geneName = "test gene name";
    String geneSymbol = "test gene symbol";
    String chromosome = "test chromosome";
    String mgiReference = "test mgi reference";
    Model model = new BindingAwareModelMap();
    GeneManagementListController instance = new GeneManagementListController();
    String expResult = "geneManagementList";
    String result = instance.showFilter(gene_key, geneName, geneSymbol, chromosome, mgiReference, model);
    assertEquals(expResult, result);

    Map modelMap = model.asMap();
    // Check filter.
    Filter filter = (Filter) modelMap.get("filter");
    assertEquals(gene_key, filter.getGene_key());
    assertEquals(geneName, filter.getGeneName());
    assertEquals(geneSymbol, filter.getGeneSymbol());
    assertEquals(chromosome, filter.getChromosome());
    assertEquals(mgiReference, filter.getGeneMgiReference());

    // Check showResultsForm.
    boolean showResultsForm = (boolean) modelMap.get("showResultsForm");
    assertFalse(showResultsForm);
}

From source file:uk.ac.ebi.emma.controller.GeneManagementListControllerTest.java

/**
 * Test of go method, of class GeneManagementListController.
 *//*from  w w w.j  ava  2  s. c  o  m*/
@Test
public void testGo() {
    System.out.println("go");
    String gene_key = "123";
    String geneName = "test gene name";
    String geneSymbol = "test gene symbol";
    String chromosome = "test chromosome";
    String mgiReference = "test mgi reference";
    Model model = new BindingAwareModelMap();
    GeneManagementListController instance = new GeneManagementListController();
    String expResult = "geneManagementList";
    String result = instance.go(gene_key, geneName, geneSymbol, chromosome, mgiReference, model);
    assertEquals(expResult, result);

    Map modelMap = model.asMap();

    // Check filter.
    Filter filter = (Filter) modelMap.get("filter");
    assertEquals(gene_key, filter.getGene_key());
    assertEquals(geneName, filter.getGeneName());
    assertEquals(geneSymbol, filter.getGeneSymbol());
    assertEquals(chromosome, filter.getChromosome());
    assertEquals(mgiReference, filter.getGeneMgiReference());

    // Check filteredGenesList.
    List<Gene> filteredGenesList = (List<Gene>) modelMap.get("filteredGenesList");
    assertTrue(filteredGenesList.size() >= 0);

    // Check showResultsForm.
    boolean showResultsForm = (boolean) modelMap.get("showResultsForm");
    assertTrue(showResultsForm);

    // Check resultsCount.
    int resultsCount = (int) modelMap.get("resultsCount");
    assertEquals(filteredGenesList.size(), resultsCount);
}

From source file:org.duracloud.account.app.controller.AccountGroupsController.java

private void addGroupsObjectsToModel(AccountService as, List<DuracloudGroup> groups, Model model)
        throws Exception {
    addUserToModel(model);/*w  w  w  .  jav a 2 s . c  om*/
    model.addAttribute(ACCOUNT_INFO_KEY, as.retrieveAccountInfo());
    model.addAttribute("accountId", as.getAccountId());
    if (!model.asMap().containsKey(GROUPS_FORM_KEY)) {
        model.addAttribute(GROUPS_FORM_KEY, new GroupsForm());
    }
    addGroupsToModel(model, groups);
}

From source file:com.utbm.formation.controller.ListCourseSessionController.java

/**
 * Filtre la liste des sessions en fonction des paramtres fournit
 * @param itemid les filtres//from   w w  w  .  j a  va  2  s  . c o m
 * @param model la listes des sessions
 * @return la listes des sessions filtrs
 * @throws ParseException 
 */
@RequestMapping(value = "", method = POST)
public ModelAndView listCourseFilter(@Valid BeanCourseFilter itemid, Model model) throws ParseException {

    Iterable<Course_session> listSession = courseSessionService.getCourseSessionFilter(itemid);
    Iterable<Course> listCourse = courseService.getAllCourses();
    Iterable<Location_course> listLocation = locationService.getAllLocation();

    model.addAttribute("listCourse", listCourse);
    model.addAttribute("listLocation", listLocation);
    model.addAttribute("listCourseSession", listSession);
    return new ModelAndView("listCourse", model.asMap());
}

From source file:uk.ac.ebi.emma.controller.GeneManagementDetailControllerTest.java

/**
 * Test of edit method, of class GeneManagementDetailController.
 *///w  w w  . j a  v a2 s . c  o m
@Test
public void testEditGene() {
    System.out.println("edit");
    int id_gene = 0;
    String filterGeneKey = "0";
    String filterGeneName = "test gene name";
    String filterGeneSymbol = "test gene symbol";
    String filterChromosome = "test chromosome";
    String filterMGIReference = "test mgi reference";
    Model model = new BindingAwareModelMap();

    GeneManagementDetailController instance = new GeneManagementDetailController();
    String expResult = "geneManagementDetail";
    String result = instance.edit(id_gene, filterGeneKey, filterGeneName, filterGeneSymbol, filterChromosome,
            filterMGIReference, model);
    assertEquals(expResult, result); // Verify function return.

    Map modelMap = model.asMap();
    // Check filter.
    Filter filter = (Filter) modelMap.get("filter");
    assertEquals(filterGeneKey, filter.getGene_key());
    assertEquals(filterGeneName, filter.getGeneName());
    assertEquals(filterGeneSymbol, filter.getGeneSymbol());
    assertEquals(filterChromosome, filter.getChromosome());
    assertEquals(filterMGIReference, filter.getGeneMgiReference());

    Gene gene = (Gene) modelMap.get("gene");
    // The gene's components are null, so there is no more checking that can be done.
}

From source file:uk.ac.ebi.emma.controller.AlleleManagementDetailController.java

/**
 * 'Edit/New Allele' icon implementation
 * /*ww  w . j ava2  s. c o m*/
 * @param allele_key the allele ID being edited (a value of 0 indicates a new
 * @param filterAlleleKey
 * @param filterAlleleName
 * @param filterAlleleSymbol
 * @param filterAlleleMgiReference
 * @param filterGeneKey
 * @param filterGeneName
 * @param filterGeneSymbol
 *                allele is to be added).
 * @param model the model
 * @return the view to show
 */
@RequestMapping(value = "/edit", method = RequestMethod.GET)
public String edit(

        @RequestParam(value = "hid_allele_key", required = false) Integer allele_key,
        @RequestParam(value = "filterAlleleKey", required = false) String filterAlleleKey,
        @RequestParam(value = "filterAlleleName", required = false) String filterAlleleName,
        @RequestParam(value = "filterAlleleSymbol", required = false) String filterAlleleSymbol,
        @RequestParam(value = "filterAlleleMgiReference", required = false) String filterAlleleMgiReference,
        @RequestParam(value = "filterGeneKey", required = false) String filterGeneKey,
        @RequestParam(value = "filterGeneName", required = false) String filterGeneName,
        @RequestParam(value = "filterGeneSymbol", required = false) String filterGeneSymbol, Model model) {
    String loggedInUser = SecurityContextHolder.getContext().getAuthentication().getName();
    model.addAttribute("loggedInUser", loggedInUser);

    Allele allele = allelesManager.getAllele(allele_key);
    if (allele == null) {
        allele = new Allele();
    }

    model.addAttribute("allele", allele);

    Map modelMap = model.asMap();
    Filter filter = (Filter) modelMap.get("filter");
    filterAlleleKey = filter.getAllele_key();
    filterAlleleName = filter.getAlleleName();
    filterAlleleSymbol = filter.getAlleleSymbol();
    filterAlleleMgiReference = filter.getAlleleMgiReference();
    filterGeneKey = filter.getGene_key();
    filterGeneName = filter.getGeneName();
    filterGeneSymbol = filter.getGeneSymbol();
    model.addAttribute("filter", filter);

    return "alleleManagementDetail";
}

From source file:org.kew.rmf.matchconf.web.CustomWiredTransformerController.java

@RequestMapping(value = "/{configType}_configs/{configName}/wires/{wireName}/{transformerType}_transformers", method = RequestMethod.POST, produces = "text/html")
public String create(@PathVariable("configType") String configType,
        @PathVariable("configName") String configName, @PathVariable("wireName") String wireName,
        @PathVariable("transformerType") String transformerType, @Valid WiredTransformer wiredTransformer,
        BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) throws Exception {
    if (!T_TYPES.contains(transformerType))
        throw new Exception(String.format("The transformer type has to be of %s", T_TYPES));
    if (bindingResult.hasErrors()) {
        populateEditForm(uiModel, configType, configName, wiredTransformer);
        return "wiredtransformers/create";
    }//from  w w  w  .ja  v a  2 s  . c om
    uiModel.asMap().clear();
    wiredTransformer.persist();
    Wire wire = Configuration.findConfigurationsByNameEquals(configName).getSingleResult()
            .getWireForName(wireName);
    new GetterSetter<List<WiredTransformer>>().getattr(wire, transformerType + "Transformers")
            .add(wiredTransformer);
    wire.merge();
    return String.format("redirect:/%s_configs/%s/wires/%s/%s_transformers/%s", configType, configName,
            wireName, transformerType, wiredTransformer.getName());
}

From source file:org.fenixedu.academic.thesis.ui.controller.ThesisProposalsController.java

protected ModelAndView error(ThesisProposalBean proposalBean, Model model) {
    model.addAttribute("configurations", service.getCurrentThesisProposalsConfigurations());
    model.addAttribute("participantTypeList", service.getThesisProposalParticipantTypes());
    model.addAttribute("command", proposalBean);
    return new ModelAndView("proposals/create", model.asMap());
}