List of usage examples for org.springframework.ui Model asMap
Map<String, Object> asMap();
From source file:org.sparkcommerce.openadmin.web.controller.entity.AdminBasicEntityController.java
/** * Shows the appropriate modal dialog to view the selected collection item. This will display the modal as readonly * * @param request/*from w ww. j av a 2 s . co m*/ * @param response * @param model * @param pathVars * @param id * @param collectionField * @param collectionItemId * @return the return view path * @throws Exception */ @RequestMapping(value = "/{id}/{collectionField:.*}/{collectionItemId}/view", method = RequestMethod.GET) public String showViewCollectionItem(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id, @PathVariable(value = "collectionField") String collectionField, @PathVariable(value = "collectionItemId") String collectionItemId) throws Exception { String returnPath = showViewUpdateCollection(request, model, pathVars, id, collectionField, collectionItemId, "viewCollectionItem"); // Since this is a read-only view, actions don't make sense in this context EntityForm ef = (EntityForm) model.asMap().get("entityForm"); ef.removeAllActions(); return returnPath; }
From source file:org.wise.portal.presentation.web.controllers.teacher.project.customized.ShareProjectController.java
/** * On submission of the AddSharedTeacherParameters, the specified * teacher is granted the specified permission to the specified project. * @param params the object that contains values from the form * @param bindingResult the object used for validation in which errors will be stored * @param request the http request/* w w w. j av a2 s. com*/ * @param model the model object that contains values for the page to use when rendering the view * @param sessionStatus the session status * @return the path of the view to display */ @RequestMapping(method = RequestMethod.POST) protected String onSubmit(@ModelAttribute("addSharedTeacherParameters") AddSharedTeacherParameters params, BindingResult bindingResult, HttpServletRequest request, Model model, SessionStatus sessionStatus) { String view = formView; //get the signed in user User signedInUser = ControllerUtil.getSignedInUser(); //get the project Project project = params.getProject(); //get the project id Serializable projectId = project.getId(); try { //get the project project = projectService.getById(projectId); params.setProject(project); } catch (ObjectNotFoundException e1) { e1.printStackTrace(); } //get the username that we are going to share the project with String sharedOwnerUsername = params.getSharedOwnerUsername(); //get the user object associated with the user name User retrievedUser = userService.retrieveUserByUsername(sharedOwnerUsername); //get the context path e.g. /wise String contextPath = request.getContextPath(); if (retrievedUser == null) { //we could not find the user so we will display an error message model.addAttribute("message", "Username not recognized. Make sure to use the exact spelling of the username."); view = formView; } else if (!retrievedUser.getUserDetails().hasGrantedAuthority(UserDetailsService.TEACHER_ROLE)) { //the user entered is not a teacher so we will display an error message model.addAttribute("message", "The user is not a teacher and thus cannot be added as a shared teacher."); view = formView; } else { //check if the signed in user is giving sharing permissions to the other user if (params.getPermission().equals(UserDetailsService.PROJECT_SHARE_ROLE)) { if (!project.getOwner().equals(signedInUser) && !signedInUser.isAdmin()) { /* * the signed in user is not the owner of the project and is not an admin * so we will not let them give sharing permissions to the other user * and display an error message */ model.addAttribute("message", "You cannot give sharing permissions because you are not the actual owner of this project."); view = formView; } } try { // first check if we're removing a shared teacher String removeUserFromProject = request.getParameter("removeUserFromProject"); if (removeUserFromProject != null && Boolean.valueOf(removeUserFromProject)) { //remove the shared owner projectService.removeSharedTeacherFromProject(sharedOwnerUsername, project); } else { // we're adding a new shared teacher or changing her permissions boolean newSharedOwner = false; if (!project.getSharedowners().contains(retrievedUser)) { //the other teacher is a new shared owner newSharedOwner = true; } //add the shared teacher to the project projectService.addSharedTeacherToProject(params); // only send email if this is a new shared owner if (newSharedOwner) { Locale locale = request.getLocale(); ShareProjectEmailService emailService = new ShareProjectEmailService(signedInUser, retrievedUser, project, ControllerUtil.getBaseUrlString(request), locale, contextPath); Thread thread = new Thread(emailService); thread.start(); } } view = successView; //sessionStatus.setComplete(); } catch (ObjectNotFoundException e) { //there was an error adding or removing the new shared teacher view = formView; } catch (Exception ex) { // exception sending email, ignore ex.printStackTrace(); } } String message = null; //get the model as a map so we can add objects to it Map<String, Object> asMap = model.asMap(); try { //add the project, teacher names, and shared owners into the model populateModel(asMap, signedInUser, project, message); } catch (Exception e) { e.printStackTrace(); } //add the project id to the model model.addAttribute(PROJECTID_PARAM_NAME, project.getId()); return view; }
From source file:org.wise.portal.presentation.web.controllers.teacher.RegisterTeacherController.java
/** * Populate the model with objects the form requires * @param modelMap the model to populate * @return the model/*from w ww . j a v a 2 s . c o m*/ */ protected Model populateModel(Model model) { //get the model as a map so we can add objects to it Map<String, Object> asMap = model.asMap(); try { //populate the model with objects the form requires populateModel(asMap); } catch (Exception e) { e.printStackTrace(); } return model; }
From source file:org.wise.portal.presentation.web.controllers.teacher.run.ShareProjectRunController.java
/** * On submission of the AddSharedTeacherParameters, the specified * teacher is granted the specified permission to the specified run. * Only teachers can be added as a shared teacher to a run. * @param params the model object that contains values for the page to use when rendering the view * @param bindingResult the object used for validation in which errors will be stored * @param request the http request object * @param model the object that contains values to be displayed on the page * @param sessionStatus the session status object * @return the path of the view to display *//*from w ww. j a v a 2 s.c o m*/ @RequestMapping(method = RequestMethod.POST) protected String onSubmit(@ModelAttribute("addSharedTeacherParameters") AddSharedTeacherParameters params, BindingResult bindingResult, HttpServletRequest request, Model model, SessionStatus sessionStatus) { String view = formView; //get the signed in user User signedInUser = ControllerUtil.getSignedInUser(); //get the run Run run = params.getRun(); //get run id Long runId = run.getId(); try { //get the run run = runService.retrieveById(runId); params.setRun(run); } catch (ObjectNotFoundException e1) { e1.printStackTrace(); } //the error message to display to the user if any String message = null; //get the user that we will share the run with User retrievedUser = userService.retrieveUserByUsername(params.getSharedOwnerUsername()); if (retrievedUser == null) { //we could not find the user name message = "Username not recognized. Make sure to use the exact spelling of the username."; view = formView; } else if (!retrievedUser.getUserDetails().hasGrantedAuthority(UserDetailsService.TEACHER_ROLE)) { //the user name entered is not a teacher message = "The user is not a teacher and thus cannot be added as a shared teacher."; view = formView; } else { try { // first check if we're removing a shared teacher String removeUserFromRun = request.getParameter("removeUserFromRun"); if (removeUserFromRun != null && Boolean.valueOf(removeUserFromRun)) { //remove the shared teacher runService.removeSharedTeacherFromRun(params.getSharedOwnerUsername(), run.getId()); } else { // we're adding a new shared teacher or changing her permissions if (run.getSharedowners().contains(retrievedUser)) { //the user is already a shared owner so we will update their permissions runService.updateSharedTeacherForRun(params); } else { //the user is not a shared owner yet so we will add them as a shared teacher //add the shared teacher to the run runService.addSharedTeacherToRun(params); // make a workgroup for this shared teacher for this run String sharedOwnerUsername = params.getSharedOwnerUsername(); User sharedOwner = userService.retrieveUserByUsername(sharedOwnerUsername); Set<User> sharedOwners = new HashSet<User>(); sharedOwners.add(sharedOwner); workgroupService.createWISEWorkgroup("teacher", sharedOwners, run, null); //send an email to the new shared owner Locale locale = request.getLocale(); ProjectRunEmailService emailService = new ProjectRunEmailService(signedInUser, retrievedUser, run, locale); Thread thread = new Thread(emailService); thread.start(); } } } catch (ObjectNotFoundException e) { view = formView; } //sessionStatus.setComplete(); view = successView; } //get the model as a map so we can add objects to it Map<String, Object> asMap = model.asMap(); try { //add the project, teacher names, and shared owners into the model populateModel(asMap, signedInUser, run, message); } catch (Exception e) { e.printStackTrace(); } return view; }
From source file:ru.org.linux.search.SearchController.java
@RequestMapping(value = "/search.jsp", method = { RequestMethod.GET, RequestMethod.HEAD }) public String search(HttpServletRequest request, Model model, @ModelAttribute("query") SearchRequest query, BindingResult bindingResult) throws Exception { Map<String, Object> params = model.asMap(); boolean initial = query.isInitial(); if (!initial && !bindingResult.hasErrors()) { if (!query.getQ().equals(query.getOldQ())) { query.setSection(null);// w ww . j ava 2 s . c o m query.setGroup(0); } query.setOldQ(query.getQ()); if (query.getQ().trim().isEmpty()) { return "redirect:/search.jsp"; } SearchViewer sv = new SearchViewer(query); if (query.getGroup() != 0) { Group group = groupDao.getGroup(query.getGroup()); if ("wiki".equals(query.getSection()) || group.getSectionId() != Integer.valueOf(query.getSection())) { query.setGroup(0); } } QueryResponse response = sv.performSearch(solrServer); long current = System.currentTimeMillis(); SolrDocumentList list = response.getResults(); Collection<SearchItem> res = new ArrayList<SearchItem>(list.size()); for (SolrDocument doc : list) { res.add(new SearchItem(doc, userDao, msgbaseDao, lorCodeService, request.isSecure())); } FacetField sectionFacet = response.getFacetField("section"); if (sectionFacet != null && sectionFacet.getValueCount() > 1) { params.put("sectionFacet", buildSectionFacet(sectionFacet)); } else if (sectionFacet != null && sectionFacet.getValueCount() == 1) { Count first = sectionFacet.getValues().get(0); query.setSection(first.getName()); } FacetField groupFacet = response.getFacetField("group_id"); if (groupFacet != null && groupFacet.getValueCount() > 1) { params.put("groupFacet", buildGroupFacet(query.getSection(), groupFacet)); } long time = System.currentTimeMillis() - current; params.put("result", res); params.put("searchTime", response.getElapsedTime()); params.put("numFound", list.getNumFound()); if (list.getNumFound() > query.getOffset() + SearchViewer.SEARCH_ROWS) { params.put("nextLink", "/search.jsp?" + query.getQuery(query.getOffset() + SearchViewer.SEARCH_ROWS)); } if (query.getOffset() - SearchViewer.SEARCH_ROWS >= 0) { params.put("prevLink", "/search.jsp?" + query.getQuery(query.getOffset() - SearchViewer.SEARCH_ROWS)); } params.put("time", time); } return "search"; }
From source file:sg.ncl.MainController.java
@RequestMapping(value = "/web_vnc/access_node/{teamName}/{expId}/{nodeId}", params = { "portNum" }) public String vncAccessNode(Model model, HttpSession session, RedirectAttributes redirectAttributes, @PathVariable String teamName, @PathVariable Long expId, @PathVariable String nodeId, @NotNull @RequestParam("portNum") Integer portNum) throws WebServiceRuntimeException, NoSuchAlgorithmException { Realization realization = invokeAndExtractRealization(teamName, expId); if (!checkPermissionRealizeExperiment(realization, session)) { log.warn("Permission denied to access experiment {} node for team: {}", realization.getExperimentName(), teamName);// ww w. j a v a2 s . c om redirectAttributes.addFlashAttribute(MESSAGE, permissionDeniedMessage); return REDIRECT_EXPERIMENTS; } HttpEntity<String> request = createHttpEntityHeaderOnly(); ResponseEntity response = restTemplate.exchange(properties.getStatefulExperiment(expId.toString()), HttpMethod.GET, request, String.class); StatefulExperiment statefulExperiment = extractStatefulExperiment(response.getBody().toString()); getDeterUid(model, session); Map attributes = model.asMap(); UriComponents uriComponents = UriComponentsBuilder.fromUriString(vncProperties.getHttp()) .queryParam("host", vncProperties.getHost()) .queryParam("path", qencode(getNodeQualifiedName(statefulExperiment, nodeId) + ":" + portNum, (String) attributes.get(DETER_UID))) .build(); log.info("VNC URI: {}", uriComponents.toString()); return "redirect:" + uriComponents.toString(); }
From source file:uk.ac.abdn.fits.support.thymeleaf.springmail.web.MailController.java
@RequestMapping(value = "/sendMailSimple", method = RequestMethod.POST) public @ResponseBody RESTFulRequest sendSimpleMail(HttpSession session, HttpServletRequest request, // HttpServletResponse response, Model model, final Locale locale) throws MessagingException { String recipientName = "Cheng Zeng"; String recipientEmail = "c.zeng@abdn.ac.uk"; String fname = (String) session.getAttribute("fname"); String lname = (String) session.getAttribute("lname"); String email = (String) session.getAttribute("email"); if (fname != null && lname != null) { recipientName = fname + " " + lname; System.out.println("recipientName: " + recipientName); }/*from w w w. j av a2 s. c o m*/ if (email != null && !email.equals("")) { recipientEmail = email; System.out.println("recipientEmail: " + recipientEmail); } List<TOption> not_relaxed = (List<TOption>) session.getAttribute("options"); List<TOption> relaxed_options = (List<TOption>) session.getAttribute("relaxed_options"); String date_of_travel = (String) session.getAttribute("date_of_travel"); String origin_postcode = (String) session.getAttribute("origin_postcode"); List<TOption> not_relaxed_rtn = (List<TOption>) session.getAttribute("options_rtn"); List<TOption> relaxed_options_rtn = (List<TOption>) session.getAttribute("relaxed_options_rtn"); String origin_postcode_rtn = (String) session.getAttribute("origin_postcode_rtn"); String url = null; View resolvedView; try { model.addAttribute("date_of_travel", date_of_travel); model.addAttribute("origin_postcode", origin_postcode); model.addAttribute("options", not_relaxed); model.addAttribute("relaxed_options", relaxed_options); model.addAttribute("caption", "Transport options ranked using preferences"); model.addAttribute("origin_postcode_rtn", origin_postcode_rtn); model.addAttribute("options_rtn", not_relaxed_rtn); model.addAttribute("relaxed_options_rtn", relaxed_options_rtn); model.addAttribute("email_view", "email_view"); resolvedView = this.viewResolver.resolveViewName("matching", Locale.UK); MockHttpServletResponse mockResp = new MockHttpServletResponse(); resolvedView.render(model.asMap(), request, mockResp); // System.out.println("rendered html : " + mockResp.getContentAsString()); url = saveAsHtml(request, mockResp.getContentAsString()); emailService.sendRichMail(recipientName, recipientEmail, locale, url); } catch (Exception e) { e.printStackTrace(); } return new RESTFulRequest(1, "mail sent to " + recipientEmail); }