List of usage examples for org.springframework.ui Model asMap
Map<String, Object> asMap();
From source file:com.jd.survey.web.survey.PrivateSurveyController.java
/** * Updates a survey page /*from ww w . j a v a 2s.co m*/ * @param surveyPage * @param backAction * @param proceedAction * @param bindingResult * @param uiModel * @param principal * @param httpServletRequest * @return */ @Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN", "ROLE_SURVEY_PARTICIPANT" }) @RequestMapping(method = RequestMethod.POST, produces = "text/html") public String updateSurveyPage(@Valid SurveyPage surveyPage, @RequestParam(value = "_back", required = false) String backAction, @RequestParam(value = "_proceed", required = false) String proceedAction, BindingResult bindingResult, Model uiModel, Principal principal, HttpServletRequest httpServletRequest) { try { String login = principal.getName(); Short order = surveyPage.getOrder(); if (proceedAction != null) { //next button Survey survey = surveyService.survey_findById(surveyPage.getSurvey().getId()); //Check if the user is authorized if (!survey.getLogin().equals(login)) { log.warn(UNAUTHORIZED_ATTEMPT_TO_ACCESS_SURVEY_WARNING_MESSAGE + survey.getId() + REQUEST_PATH_WARNING_MESSAGE + httpServletRequest.getPathInfo() + FROM_USER_LOGIN_WARNING_MESSAGE + principal.getName() + FROM_IP_WARNING_MESSAGE + httpServletRequest.getLocalAddr()); return "accessDenied"; } //Check that the survey was not submitted if (!(survey.getStatus().equals(SurveyStatus.I) || survey.getStatus().equals(SurveyStatus.R))) { log.warn(UNAUTHORIZED_ATTEMPT_TO_EDIT_SUBMITTED_SURVEY_WARNING_MESSAGE + survey.getId() + REQUEST_PATH_WARNING_MESSAGE + httpServletRequest.getPathInfo() + FROM_USER_LOGIN_WARNING_MESSAGE + principal.getName() + FROM_IP_WARNING_MESSAGE + httpServletRequest.getLocalAddr()); return "accessDenied"; } List<SurveyPage> surveyPages = surveyService.surveyPage_getAll(surveyPage.getSurvey().getId(), messageSource.getMessage(DATE_FORMAT, null, LocaleContextHolder.getLocale())); surveyPage.setSurvey(survey); surveyPage = surveyService.surveyPage_updateSettings(surveyPage); //populate the uploaded files MultipartHttpServletRequest multiPartRequest = (MultipartHttpServletRequest) httpServletRequest; Iterator<String> fileNames = multiPartRequest.getFileNames(); while (fileNames.hasNext()) { String fileName = fileNames.next(); Long questionId = Long.parseLong(fileName.toUpperCase().replace("FILE", "")); for (QuestionAnswer questionAnswer : surveyPage.getQuestionAnswers()) { if (questionAnswer.getQuestion().getId().equals(questionId) && multiPartRequest.getFile(fileName).getBytes().length > 0) { questionAnswer.setSurveyDocument(new SurveyDocument(survey.getId(), questionId, multiPartRequest.getFile(fileName).getName(), multiPartRequest.getFile(fileName).getContentType(), multiPartRequest.getFile(fileName).getBytes())); } } } Policy policy = Policy.getInstance(this.getClass().getResource(POLICY_FILE_LOCATION)); AntiSamy as = new AntiSamy(); for (QuestionAnswer questionAnswer : surveyPage.getQuestionAnswers()) { if (questionAnswer.getQuestion().getType().getIsTextInput()) { CleanResults cr = as.scan(questionAnswer.getStringAnswerValue(), policy); questionAnswer.setStringAnswerValue(cr.getCleanHTML()); } } GlobalSettings globalSettings = applicationSettingsService.getSettings(); SurveyPageValidator validator = new SurveyPageValidator( messageSource.getMessage(DATE_FORMAT, null, LocaleContextHolder.getLocale()), globalSettings.getValidContentTypes(), globalSettings.getValidImageTypes(), globalSettings.getMaximunFileSize(), globalSettings.getInvalidContentMessage(), globalSettings.getInvalidFileSizeMessage()); validator.validate(surveyPage, bindingResult); if (bindingResult.hasErrors()) { /* for (ObjectError err :bindingResult.getAllErrors()) { log.info("getObjectName:" + err.getObjectName() + " getCode:" + err.getCode() + " getDefaultMessage:" + err.getDefaultMessage()); log.info("toString:" + err.toString()); } */ uiModel.addAttribute("survey_base_path", "private"); uiModel.addAttribute("survey", survey); uiModel.addAttribute("surveyPage", surveyPage); uiModel.addAttribute("surveyDefinition", surveySettingsService.surveyDefinition_findById(surveyPage.getSurvey().getTypeId())); uiModel.addAttribute("surveyPages", surveyPages); return "surveys/page"; } surveyService.surveyPage_update(surveyPage, messageSource.getMessage(DATE_FORMAT, null, LocaleContextHolder.getLocale())); //get the survey pages from the database again, prvious call updates visibility when there is branching logic surveyPages = surveyService.surveyPage_getAll(surveyPage.getSurvey().getId(), messageSource.getMessage(DATE_FORMAT, null, LocaleContextHolder.getLocale())); order = getNextPageOrder(surveyPages, order); if (order.equals((short) 0)) { //Submit page uiModel.asMap().clear(); return "redirect:/private/submit/" + encodeUrlPathSegment(surveyPage.getSurvey().getId().toString(), httpServletRequest); } else { //go to the next page uiModel.asMap().clear(); return "redirect:/private/" + encodeUrlPathSegment(surveyPage.getSurvey().getId().toString(), httpServletRequest) + "/" + encodeUrlPathSegment(order.toString(), httpServletRequest); } } else {//back button Survey survey = surveyService.survey_findById(surveyPage.getSurvey().getId()); //Check if the user is authorized if (!survey.getLogin().equals(login)) { log.warn(UNAUTHORIZED_ATTEMPT_TO_ACCESS_SURVEY_WARNING_MESSAGE + survey.getId() + REQUEST_PATH_WARNING_MESSAGE + httpServletRequest.getPathInfo() + FROM_USER_LOGIN_WARNING_MESSAGE + principal.getName() + FROM_IP_WARNING_MESSAGE + httpServletRequest.getLocalAddr()); return "accessDenied"; } List<SurveyPage> surveyPages = surveyService.surveyPage_getAll(surveyPage.getSurvey().getId(), messageSource.getMessage(DATE_FORMAT, null, LocaleContextHolder.getLocale())); order = getPreviousPageOrder(surveyPages, order); if (order.equals((short) 0)) { //Go to the surveyEntries page uiModel.asMap().clear(); return "redirect:/private/" + encodeUrlPathSegment(survey.getTypeId().toString(), httpServletRequest) + "?list"; } else { //go to previous page uiModel.asMap().clear(); return "redirect:/private/" + encodeUrlPathSegment(survey.getId().toString(), httpServletRequest) + "/" + encodeUrlPathSegment(order.toString(), httpServletRequest); } } } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.jd.survey.web.survey.PublicSurveyController.java
/** * Returns the survey logo image binary * @param departmentId//from w w w . j ava 2 s. c o m * @param uiModel * @param httpServletRequest * @return */ @RequestMapping(value = "/logo/{id}", produces = "text/html") public void getSurveyLogo(@PathVariable("id") Long surveyDefinitionId, Model uiModel, Principal principal, HttpServletRequest httpServletRequest, HttpServletResponse response) { try { uiModel.asMap().clear(); //Check if the user is authorized SurveyDefinition surveyDefinition = surveySettingsService.surveyDefinition_findById(surveyDefinitionId); if (!surveyDefinition.getIsPublic()) {//survey definition not open to the public //attempt to access a private survey definition from a public open url log.warn(SURVEY_NOT_PUBLIC_WARNING_MESSAGE + httpServletRequest.getPathInfo() + FROM_IP_WARNING_MESSAGE + httpServletRequest.getLocalAddr()); throw (new RuntimeException("Unauthorized access to logo")); } else { //response.setContentType("image/png"); ServletOutputStream servletOutputStream = response.getOutputStream(); servletOutputStream.write(surveyDefinition.getLogo()); servletOutputStream.flush(); } } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.jd.survey.web.survey.PublicSurveyController.java
/** * Handles the post from the submit page * @param proceed//ww w . ja va 2 s. c om * @param survey * @param bindingResult * @param uiModel * @param httpServletRequest * @return */ @RequestMapping(value = "/submit", method = RequestMethod.POST, produces = "text/html") public String submitSurvey(@RequestParam(value = "id", required = true) Long surveyId, @RequestParam(value = "_submit", required = false) String proceedAction, Model uiModel, HttpServletRequest httpServletRequest) { log.info("submitPost(open): id= " + surveyId); try { if (proceedAction != null) { //submit button uiModel.asMap().clear(); Survey survey = surveyService.survey_submit(surveyId); SurveyDefinition surveyDefinition = surveySettingsService .surveyDefinition_findById(survey.getTypeId()); //survey definition not open to the public if (!surveyDefinition.getIsPublic()) { //attempt to access a private survey definition from a public open url log.warn(SURVEY_NOT_PUBLIC_WARNING_MESSAGE + httpServletRequest.getPathInfo() + FROM_IP_WARNING_MESSAGE + httpServletRequest.getLocalAddr()); return "accessDenied"; } //Attempt to access a survey from different IP Address if (!survey.getIpAddress().equalsIgnoreCase(httpServletRequest.getLocalAddr())) { log.warn( UNAUTHORIZED_ATTEMPT_TO_ACCESS_SURVEY_WARNING_MESSAGE + httpServletRequest.getPathInfo() + FROM_IP_WARNING_MESSAGE + httpServletRequest.getLocalAddr()); return "accessDenied"; } if (surveyDefinition.getAllowMultipleSubmissions()) { return "redirect:/open/" + encodeUrlPathSegment(survey.getTypeId().toString(), httpServletRequest) + "?list"; } else { uiModel.asMap().clear(); StringWriter sw = new StringWriter(); VelocityContext velocityContext = new VelocityContext(); Velocity.evaluate(velocityContext, sw, "velocity-log", surveyDefinition.getCompletedSurveyTemplate()); uiModel.addAttribute("completedMessage", sw.toString().trim()); return "surveys/submitted"; } } else { uiModel.asMap().clear(); Survey survey = surveyService.survey_findById(surveyId); SurveyDefinition surveyDefinition = surveySettingsService .surveyDefinition_findById(survey.getTypeId()); //survey definition not open to the public if (!surveyDefinition.getIsPublic()) { //attempt to access a private survey definition from a public open url log.warn(SURVEY_NOT_PUBLIC_WARNING_MESSAGE + httpServletRequest.getPathInfo() + FROM_IP_WARNING_MESSAGE + httpServletRequest.getLocalAddr()); return "accessDenied"; } //Attempt to access a survey from different IP Address if (!survey.getIpAddress().equalsIgnoreCase(httpServletRequest.getLocalAddr())) { log.warn( UNAUTHORIZED_ATTEMPT_TO_ACCESS_SURVEY_WARNING_MESSAGE + httpServletRequest.getPathInfo() + FROM_IP_WARNING_MESSAGE + httpServletRequest.getLocalAddr()); return "accessDenied"; } List<SurveyPage> surveyPages = surveyService.surveyPage_getAll(surveyId, messageSource.getMessage(DATE_FORMAT, null, LocaleContextHolder.getLocale())); Short order = (short) surveyPages.size(); return "redirect:/open/" + encodeUrlPathSegment(survey.getId().toString(), httpServletRequest) + "/" + encodeUrlPathSegment(order.toString(), httpServletRequest); } } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.jd.survey.web.survey.PublicSurveyController.java
/** * Updates a survey page//w w w . ja va 2 s.c o m * @param surveyPage * @param backAction * @param proceedAction * @param bindingResult * @param uiModel * @param httpServletRequest * @return */ @RequestMapping(method = RequestMethod.POST, produces = "text/html") public String updateSurveyPage(@Valid SurveyPage surveyPage, @RequestParam(value = "_back", required = false) String backAction, @RequestParam(value = "_proceed", required = false) String proceedAction, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) { try { Short order = surveyPage.getOrder(); Survey survey = surveyService.survey_findById(surveyPage.getSurvey().getId()); SurveyDefinition surveyDefinition = surveySettingsService.surveyDefinition_findById(survey.getTypeId()); if (!surveyDefinition.getIsPublic()) {//survey definition not open to the public //attempt to access a private survey definition from a public open url log.warn(SURVEY_NOT_PUBLIC_WARNING_MESSAGE + httpServletRequest.getPathInfo() + FROM_IP_WARNING_MESSAGE + httpServletRequest.getLocalAddr()); return "accessDenied"; } //Attempt to access a survey from different IP Address if (!survey.getIpAddress().equalsIgnoreCase(httpServletRequest.getLocalAddr())) { log.warn(UNAUTHORIZED_ATTEMPT_TO_ACCESS_SURVEY_WARNING_MESSAGE + httpServletRequest.getPathInfo() + FROM_IP_WARNING_MESSAGE + httpServletRequest.getLocalAddr()); return "accessDenied"; } if (proceedAction != null) { //next button List<SurveyPage> surveyPages = surveyService.surveyPage_getAll(surveyPage.getSurvey().getId(), messageSource.getMessage(DATE_FORMAT, null, LocaleContextHolder.getLocale())); surveyPage.setOrder(surveyPages.get(surveyPage.getOrder() - 1).getOrder()); surveyPage.setTitle(surveyPages.get(surveyPage.getOrder() - 1).getTitle()); surveyPage.setInstructions(surveyPages.get(surveyPage.getOrder() - 1).getInstructions()); surveyPage.setSurvey(survey); surveyPage = surveyService.surveyPage_updateSettings(surveyPage); //populate the uploaded files MultipartHttpServletRequest multiPartRequest = (MultipartHttpServletRequest) httpServletRequest; Iterator<String> fileNames = multiPartRequest.getFileNames(); while (fileNames.hasNext()) { String fileName = fileNames.next(); Long questionId = Long.parseLong(fileName.toUpperCase().replace("FILE", "")); for (QuestionAnswer questionAnswer : surveyPage.getQuestionAnswers()) { if (questionAnswer.getQuestion().getId().equals(questionId) && multiPartRequest.getFile(fileName).getBytes().length > 0) { questionAnswer.setSurveyDocument(new SurveyDocument(survey.getId(), questionId, multiPartRequest.getFile(fileName).getName(), multiPartRequest.getFile(fileName).getContentType(), multiPartRequest.getFile(fileName).getBytes())); } } } Policy policy = Policy.getInstance(this.getClass().getResource(POLICY_FILE_LOCATION)); AntiSamy as = new AntiSamy(); for (QuestionAnswer questionAnswer : surveyPage.getQuestionAnswers()) { if (questionAnswer.getQuestion().getType().getIsTextInput()) { CleanResults cr = as.scan(questionAnswer.getStringAnswerValue(), policy); questionAnswer.setStringAnswerValue(cr.getCleanHTML()); } } GlobalSettings globalSettings = applicationSettingsService.getSettings(); SurveyPageValidator validator = new SurveyPageValidator( messageSource.getMessage(DATE_FORMAT, null, LocaleContextHolder.getLocale()), globalSettings.getValidContentTypes(), globalSettings.getValidImageTypes(), globalSettings.getMaximunFileSize(), globalSettings.getInvalidContentMessage(), globalSettings.getInvalidFileSizeMessage()); validator.validate(surveyPage, bindingResult); if (bindingResult.hasErrors()) { /* for (ObjectError err :bindingResult.getAllErrors()) { log.info("getObjectName:" + err.getObjectName() + " getCode:" + err.getCode() + " getDefaultMessage:" + err.getDefaultMessage()); log.info("toString:" + err.toString()); } */ uiModel.addAttribute("survey_base_path", "open"); uiModel.addAttribute("survey", survey); uiModel.addAttribute("surveyDefinition", surveySettingsService.surveyDefinition_findById(survey.getTypeId())); uiModel.addAttribute("surveyPage", surveyPage); uiModel.addAttribute("surveyPages", surveyPages); return "surveys/page"; } surveyService.surveyPage_update(surveyPage, messageSource.getMessage(DATE_FORMAT, null, LocaleContextHolder.getLocale())); //get the survey pages from the database again, prvious call updates visibility when there is branching logic surveyPages = surveyService.surveyPage_getAll(surveyPage.getSurvey().getId(), messageSource.getMessage(DATE_FORMAT, null, LocaleContextHolder.getLocale())); order = getNextPageOrder(surveyPages, order); if (order.equals((short) 0)) { //Submit page uiModel.asMap().clear(); return "redirect:/open/submit/" + encodeUrlPathSegment(surveyPage.getSurvey().getId().toString(), httpServletRequest); } else { //go to the next page uiModel.asMap().clear(); return "redirect:/open/" + encodeUrlPathSegment(surveyPage.getSurvey().getId().toString(), httpServletRequest) + "/" + encodeUrlPathSegment(order.toString(), httpServletRequest); } } else {//back button List<SurveyPage> surveyPages = surveyService.surveyPage_getAll(surveyPage.getSurvey().getId(), messageSource.getMessage(DATE_FORMAT, null, LocaleContextHolder.getLocale())); order = getPreviousPageOrder(surveyPages, order); if (order.equals((short) 0)) { //Go to the surveyEntries page uiModel.asMap().clear(); return "redirect:/open/" + encodeUrlPathSegment(survey.getTypeId().toString(), httpServletRequest) + "?list"; } else { //go to previous page uiModel.asMap().clear(); return "redirect:/open/" + encodeUrlPathSegment(survey.getId().toString(), httpServletRequest) + "/" + encodeUrlPathSegment(order.toString(), httpServletRequest); } } } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.springsource.hq.plugin.tcserver.serverconfig.web.controllers.HomeController.java
/** * Checks the current session for a username. If one exists, it compares it to the current username. If the two * usernames do not match, the session is invalidated, a new session is created and the current username is stored * in the new session./* www.j a v a 2s . c om*/ */ private void checkOrAddUsernameAndResetSession(HttpServletRequest request, Model model, String currentUsername) { logger.info("Current username: " + currentUsername); Map<?, ?> modelMap = model.asMap(); String storedUsername = (String) modelMap.get("username"); if (storedUsername == null) { model.addAttribute("username", currentUsername); logger.info("Added username " + currentUsername + " to the session"); } else if (!storedUsername.equals(currentUsername)) { logger.info("Found username (" + currentUsername + ") in the session; invalidating session"); request.getSession(false).invalidate(); request.getSession(true); model.addAttribute("username", currentUsername); logger.info("Added username " + currentUsername + " to the new session"); } }
From source file:com.xxd.web.controller.usercenter.CompanyController.java
/** * ?//from w ww .j av a 2s . c om * ?CompanyInterceptor * @return */ @GetMapping("/account.html") public String companyAccount(Model model, @CookieValue(value = Constant.TOKEN) String token, @RequestHeader("User-Agent") String ua) { JSONObject globalData = (JSONObject) model.asMap().get("globalData"); int userid = ((AccountUserInfoVo) model.asMap().get("userInfo")).getUserid(); model.addAttribute("companyDetailInfo", new CompanyAccountDetailInfoCommand(userid).execute()); model.addAttribute("companyLoanInfoList", new CompanyAccountLoanInfoCommand(userid).execute()); JsonUtil.copyValues(globalData, new UserDetailInfoCommand(token, ua).execute()); return "usercenter/company/account"; }
From source file:com.xxd.web.controller.usercenter.CompanyController.java
@RequestMapping(value = "/dealDetail.html") public String dealDetail(Model model, @CookieValue(value = Constant.TOKEN) String token, @RequestHeader("User-Agent") String ua) { JSONObject globalData = (JSONObject) model.asMap().get("globalData"); JsonUtil.copyValues(globalData, new AssetOverViewCommand(token, ua).execute()); return "/usercenter/company/dealDetail"; }
From source file:de.hybris.platform.addressaddon.handlers.ChineseAddressHandler.java
public ChineseAddressForm setChineseAddressFormInModel(final Model model) { final AddressForm addressForm = (AddressForm) model.asMap().get("addressForm"); final ChineseAddressForm chineseAddressForm = new ChineseAddressForm(); BeanUtils.copyProperties(addressForm, chineseAddressForm); model.addAttribute("addressForm", chineseAddressForm); return chineseAddressForm; }
From source file:de.hybris.platform.addressaddon.handlers.ChineseAddressHandler.java
public void prepareAddressForm(final Model model, final ChineseAddressForm addressForm) { final AddressData addressData = (AddressData) model.asMap().get("addressData"); if (addressData != null) { addressForm.setCellphone(addressData.getCellphone()); addressForm.setFullname(addressData.getFullname()); final RegionData region = addressData.getRegion(); if (region != null && StringUtils.isNotEmpty(region.getIsocode())) { model.addAttribute("cities", chineseAddressFacade.getCitiesForRegion(region.getIsocode())); }/*from w ww . ja v a2 s . co m*/ final CityData city = addressData.getCity(); if (city != null && StringUtils.isNotEmpty(city.getCode())) { model.addAttribute("districts", chineseAddressFacade.getDistrictsForCity(city.getCode())); addressForm.setCityIso(city.getCode()); } final DistrictData district = addressData.getDistrict(); if (district != null && StringUtils.isNotEmpty(district.getCode())) { addressForm.setDistrictIso(addressData.getDistrict().getCode()); } } }
From source file:net.longfalcon.web.AdminUserController.java
@RequestMapping(value = "/admin/user-delete", method = RequestMethod.POST) public View userDeletePost(@RequestParam(value = "id") Long id, Model model) { User user = userDAO.findByUserId(id); if (user == null) { _log.error("userId=" + id + " does not exist."); } else {/*ww w. j a va 2s. com*/ userDAO.delete(user); } Integer offset = (Integer) model.asMap().get("pagerOffset"); String orderBy = (String) model.asMap().get("orderBy"); return safeRedirect("/admin/user-list?ob=" + orderBy + "&offset=" + offset); }