List of usage examples for org.springframework.ui Model asMap
Map<String, Object> asMap();
From source file:org.opentravel.pubs.controllers.AdminController.java
@RequestMapping({ "/DoUploadCodeList.html", "/DoUploadCodeList.htm" }) public String doUploadCodeListPage(HttpSession session, Model model, RedirectAttributes redirectAttrs, @ModelAttribute("codeListForm") CodeListForm codeListForm, @RequestParam(value = "archiveFile", required = false) MultipartFile archiveFile) { String targetPage = "uploadCodeList"; try {// w w w.jav a2s . co m if (codeListForm.isProcessForm()) { CodeList codeList = new CodeList(); try { codeList.setReleaseDate(CodeList.labelFormat.parse(codeListForm.getReleaseDateLabel())); if (!archiveFile.isEmpty()) { DAOFactoryManager.getFactory().newCodeListDAO().publishCodeList(codeList, archiveFile.getInputStream()); model.asMap().clear(); redirectAttrs.addAttribute("releaseDate", codeList.getReleaseDateLabel()); targetPage = "redirect:/admin/ViewCodeList.html"; } else { ValidationResults vResults = ModelValidator.validate(codeList); // An archive file must be provided on initial creation of a publication vResults.add(codeList, "archiveFilename", "Archive File is Required"); if (vResults.hasViolations()) { throw new ValidationException(vResults); } } } catch (ParseException e) { ValidationResults vResult = new ValidationResults(); vResult.add(codeList, "releaseDate", "Invalid release date"); addValidationErrors(vResult, model); } catch (ValidationException e) { addValidationErrors(e, model); } catch (Throwable t) { log.error("An error occurred while publishing the code list: ", t); setErrorMessage(t.getMessage(), model); } } } catch (Throwable t) { log.error("Error during publication controller processing.", t); setErrorMessage(DEFAULT_ERROR_MESSAGE, model); } return applyCommonValues(model, targetPage); }
From source file:net.triptech.buildulator.web.ProjectController.java
/** * Creates the project.//from w w w. j ava 2 s .c o m * * @param definitionForm the definition form * @param bindingResult the binding result * @param uiModel the ui model * @param request the http servlet request * @return the string */ @RequestMapping(method = RequestMethod.POST) public String create(@Valid Project project, @RequestParam(value = "templateId", required = false) Long templateId, BindingResult bindingResult, Model uiModel, HttpServletRequest request) { Person user = getUser(request); if (bindingResult.hasErrors()) { uiModel.addAttribute("project", project); FlashScope.appendMessage(getMessage("buildulator_object_validation", Project.class), request); return "projects/create"; } uiModel.asMap().clear(); if (user == null) { String sessionId = request.getSession().getId(); // Set the session id as the owner project.setSession(sessionId); // Store the existing session id in case the user logs in request.getSession().setAttribute("PreviousSessionId", sessionId); } else { // Set the logged in person as the owner project.setPerson(user); } // Check the privileges for the template functionality if (project.isTemplate() || project.isComparable()) { if (!Project.canViewOrEditTemplatesOrComparables(user)) { project.setTemplate(false); project.setComparable(false); } } if (templateId != null && templateId > 0) { // Try loading the template and assigning the operating energy data // to the new project. try { Project template = Project.findProject(templateId); if (template != null && template.isTemplate()) { // Set the operating energy data for the new project project.setDataField(Project.OPERATING_ENERGY, template.getDataField(Project.OPERATING_ENERGY)); } } catch (Exception e) { logger.error("Error loading template (" + templateId + "): " + e.getMessage()); } } project.persist(); project.flush(); FlashScope.appendMessage(getMessage("buildulator_create_complete", Project.class), request); return "redirect:/projects/" + encodeUrlPathSegment(project.getId().toString(), request); }
From source file:org.opentravel.pubs.controllers.PublicationController.java
@RequestMapping({ "/downloads/cl/{releaseDate}/{filename:.+}" }) public String downloadCodeList(Model model, HttpSession session, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttrs, @PathVariable("releaseDate") String releaseDateStr, @PathVariable("filename") String filename) { String targetPath = null;//w w w.ja v a2 s . c o m try { Registrant registrant = getCurrentRegistrant(session); if (registrant == null) { model.asMap().clear(); redirectAttrs.addAttribute("releaseDate", releaseDateStr); redirectAttrs.addAttribute("filename", filename); targetPath = "redirect:/specifications/cl/DownloadRegister.html"; } else { targetPath = doCodeListDownload(model, session, registrant, request, response, redirectAttrs, releaseDateStr, filename); } } catch (Throwable t) { log.error("Error during publication controller processing.", t); setErrorMessage(DEFAULT_ERROR_MESSAGE, model); } return applyCommonValues(model, targetPath); }
From source file:org.opentravel.pubs.controllers.AdminController.java
@RequestMapping({ "/ChangeAdminCredentials.html", "/ChangeAdminCredentials.htm" }) public String changeCredentialsPage(HttpSession session, Model model, @RequestParam(value = "processUpdate", required = false) boolean processUpdate, @RequestParam(value = "userId", required = false) String userId, @RequestParam(value = "password", required = false) String password) { String targetPage = "changeCredentials"; try {//from ww w .j a v a 2 s . com AdminDAO aDao = DAOFactoryManager.getFactory().newAdminDAO(); boolean success = false; if (processUpdate) { try { AdminCredentials credentials = new AdminCredentials(); credentials.setUserId(StringUtils.trimString(userId)); credentials.setPassword(StringUtils.trimString(password)); aDao.updateAdminCredentials(credentials); success = true; model.asMap().clear(); targetPage = "redirect:/admin/index.html"; } catch (ValidationException e) { addValidationErrors(e, model); } } else if (userId == null) { userId = aDao.getAdminCredentials().getUserId(); } if (!success) { model.addAttribute("userId", userId); model.addAttribute("password", password); } } catch (Throwable t) { log.error("Error during publication controller processing.", t); setErrorMessage(DEFAULT_ERROR_MESSAGE, model); } return applyCommonValues(model, targetPage); }
From source file:org.opentravel.pubs.controllers.PublicationController.java
@RequestMapping({ "/downloads/{pubName}/{pubType}/{filename:.+}" }) public String downloadPublication(Model model, HttpSession session, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttrs, @PathVariable("pubName") String pubName, @PathVariable("pubType") String type, @PathVariable("filename") String filename) { String targetPath = null;/* ww w . j a v a 2 s . co m*/ try { Registrant registrant = getCurrentRegistrant(session); if (registrant == null) { model.asMap().clear(); redirectAttrs.addAttribute("pubName", pubName); redirectAttrs.addAttribute("pubType", type); redirectAttrs.addAttribute("filename", filename); targetPath = "redirect:/specifications/DownloadRegister.html"; } else { targetPath = doPublicationDownload(model, session, registrant, request, response, redirectAttrs, pubName, type, filename); } } catch (Throwable t) { log.error("Error during publication controller processing.", t); setErrorMessage(DEFAULT_ERROR_MESSAGE, model); } return applyCommonValues(model, targetPath); }
From source file:org.fenixedu.academic.thesis.ui.controller.AdminThesisProposalsController.java
@RequestMapping(value = "/createProposal", method = RequestMethod.POST) public ModelAndView createThesisProposals(@ModelAttribute ThesisProposalBean proposalBean, @RequestParam String participantsJson, @RequestParam String externalsJson, @RequestParam Set<ThesisProposalsConfiguration> thesisProposalsConfigurations, Model model, @RequestParam(required = false) ThesisProposalsConfiguration configuration) { try {/*from w w w . j av a 2 s . c o m*/ if (thesisProposalsConfigurations == null || thesisProposalsConfigurations.isEmpty()) { throw new UnexistentConfigurationException(); } ThesisProposalsConfiguration base = thesisProposalsConfigurations.iterator().next(); for (ThesisProposalsConfiguration config : thesisProposalsConfigurations) { if (!base.isEquivalent(config)) { throw new UnequivalentThesisConfigurationsException(base, config); } } proposalBean.setThesisProposalsConfigurations(thesisProposalsConfigurations); service.createThesisProposal(proposalBean, participantsJson, externalsJson); } catch (ThesisProposalException exception) { model.addAttribute("error", exception.getClass().getSimpleName()); model.addAttribute("configurations", service.getCurrentThesisProposalsConfigurations()); model.addAttribute("participantTypeList", service.getThesisProposalParticipantTypes()); model.addAttribute("command", proposalBean); model.addAttribute("action", "admin-proposals/createProposal"); return new ModelAndView("proposals/create", model.asMap()); } return new ModelAndView("redirect:/admin-proposals" + (configuration != null ? "?configuration=" + configuration.getExternalId() : "")); }
From source file:org.duracloud.account.app.controller.UserController.java
@Transactional @RequestMapping(value = { CHANGE_PASSWORD_MAPPING }, method = RequestMethod.POST) public ModelAndView changePassword(@PathVariable String username, @ModelAttribute(CHANGE_PASSWORD_FORM_KEY) @Valid ChangePasswordForm form, BindingResult result, Model model) throws Exception { DuracloudUser user = this.userService.loadDuracloudUserByUsername(username); // check for errors if (!result.hasErrors()) { log.info("changing user password for {}", username); Long id = user.getId();//from w w w .j av a 2 s . c o m try { this.userService.changePassword(id, form.getOldPassword(), false, form.getPassword()); return new ModelAndView(formatUserRedirect(username)); } catch (InvalidPasswordException e) { result.addError( new FieldError(CHANGE_PASSWORD_FORM_KEY, "oldPassword", "The old password is not correct")); } } log.debug("password form has errors for {}: returning...", username); addUserToModel(user, model); UserProfileEditForm editForm = new UserProfileEditForm(); editForm.setFirstName(user.getFirstName()); editForm.setLastName(user.getLastName()); editForm.setEmail(user.getEmail()); editForm.setSecurityQuestion(user.getSecurityQuestion()); editForm.setSecurityAnswer(user.getSecurityAnswer()); model.addAttribute(USER_PROFILE_FORM_KEY, editForm); return new ModelAndView(USER_EDIT_VIEW, model.asMap()); }
From source file:net.triptech.buildulator.web.ProjectController.java
/** * Update the project.//from w w w . j ava 2 s.c o m * * @param project the project * @param bindingResult the binding result * @param uiModel the ui model * @param request the http servlet request * @param response the response * @return the string */ @RequestMapping(method = RequestMethod.PUT) public String update(@Valid Project project, BindingResult bindingResult, Model uiModel, HttpServletRequest request, final HttpServletResponse response) { String page = "resourceNotFound"; Project existingProject = Project.findProject(project.getId()); if (checkProjectPermission(existingProject, request)) { if (bindingResult.hasErrors()) { uiModel.addAttribute("project", project); FlashScope.appendMessage(getMessage("metahive_object_validation", Project.class), request); page = "projects/edit"; } else { existingProject.update(project); existingProject.persist(); existingProject.flush(); uiModel.asMap().clear(); FlashScope.appendMessage(getMessage("buildulator_edit_complete", Project.class), request); page = "redirect:/projects/" + encodeUrlPathSegment(existingProject.getId().toString(), request); } } else { response.setStatus(HttpServletResponse.SC_NOT_FOUND); } return page; }
From source file:org.opentravel.pubs.controllers.AdminController.java
@RequestMapping({ "/DoUploadSpecification.html", "/DoUploadSpecification.htm" }) public String doUploadSpecificationPage(HttpSession session, Model model, RedirectAttributes redirectAttrs, @ModelAttribute("specificationForm") SpecificationForm specificationForm, @RequestParam(value = "archiveFile", required = false) MultipartFile archiveFile) { String targetPage = "uploadSpecification"; try {/*w ww . j ava2s.c o m*/ if (specificationForm.isProcessForm()) { PublicationType publicationType = resolvePublicationType(specificationForm.getSpecType()); PublicationState publicationState = (specificationForm.getPubState() == null) ? null : PublicationState.valueOf(specificationForm.getPubState()); Publication publication = new PublicationBuilder() .setName(StringUtils.trimString(specificationForm.getName())).setType(publicationType) .setState(publicationState).build(); try { if (!archiveFile.isEmpty()) { DAOFactoryManager.getFactory().newPublicationDAO().publishSpecification(publication, archiveFile.getInputStream()); model.asMap().clear(); redirectAttrs.addAttribute("publication", publication.getName()); redirectAttrs.addAttribute("specType", publication.getType()); targetPage = "redirect:/admin/ViewSpecification.html"; } else { ValidationResults vResults = ModelValidator.validate(publication); // An archive file must be provided on initial creation of a publication vResults.add(publication, "archiveFilename", "Archive File is Required"); if (vResults.hasViolations()) { throw new ValidationException(vResults); } } } catch (ValidationException e) { addValidationErrors(e, model); } catch (Throwable t) { log.error("An error occurred while publishing the spec: ", t); setErrorMessage(t.getMessage(), model); } } } catch (Throwable t) { log.error("Error during publication controller processing.", t); setErrorMessage(DEFAULT_ERROR_MESSAGE, model); } return applyCommonValues(model, targetPage); }
From source file:org.opentravel.pubs.controllers.AdminController.java
@RequestMapping({ "/DoUpdateCodeList.html", "/DoUpdateCodeList.htm" }) public String doUpdateCodeListPage(HttpSession session, Model model, RedirectAttributes redirectAttrs, @ModelAttribute("codeListForm") CodeListForm codeListForm, @RequestParam(value = "archiveFile", required = false) MultipartFile archiveFile) { String targetPage = "updateSpecification"; try {/* w w w .j av a 2 s . c om*/ if (codeListForm.isProcessForm()) { CodeListDAO cDao = DAOFactoryManager.getFactory().newCodeListDAO(); CodeList codeList = cDao.getCodeList(codeListForm.getCodeListId()); try { codeList.setReleaseDate(CodeList.labelFormat.parse(codeListForm.getReleaseDateLabel())); ValidationResults vResults = ModelValidator.validate(codeList); // Before we try to update the contents of the spefication, validate the // publication object to see if there are any errors. if (vResults.hasViolations()) { throw new ValidationException(vResults); } if (!archiveFile.isEmpty()) { cDao.updateCodeList(codeList, archiveFile.getInputStream()); } model.asMap().clear(); redirectAttrs.addAttribute("releaseDate", codeList.getReleaseDateLabel()); targetPage = "redirect:/admin/ViewCodeList.html"; } catch (ParseException e) { ValidationResults vResult = new ValidationResults(); vResult.add(codeList, "releaseDate", "Invalid release date"); addValidationErrors(vResult, model); } catch (ValidationException e) { addValidationErrors(e, model); } catch (Throwable t) { log.error("An error occurred while updating the spec: ", t); setErrorMessage(t.getMessage(), model); } } } catch (Throwable t) { log.error("Error during publication controller processing.", t); setErrorMessage(DEFAULT_ERROR_MESSAGE, model); } return applyCommonValues(model, targetPage); }