List of usage examples for org.springframework.ui Model asMap
Map<String, Object> asMap();
From source file:com.jd.survey.web.settings.SectorsController.java
@Secured({ "ROLE_ADMIN" }) @RequestMapping(method = RequestMethod.POST, produces = "text/html") public String createPost(@RequestParam(value = "_proceed", required = false) String proceed, @Valid Sector sector, BindingResult bindingResult, Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { log.info("create(): handles " + RequestMethod.POST.toString()); try {/* www.ja v a 2 s .c o m*/ User user = userService.user_findByLogin(principal.getName()); if (!user.isAdmin()) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } if (proceed != null) { if (bindingResult.hasErrors()) { populateEditForm(uiModel, sector, user); return "admin/sectors/create"; } if (surveySettingsService.dataset_findByName(sector.getName()) != null && !surveySettingsService .dataset_findByName(sector.getName()).getId().equals(sector.getId())) { bindingResult.rejectValue("name", "field_unique"); populateEditForm(uiModel, sector, user); return "admin/sectors/update"; } uiModel.asMap().clear(); sector = surveySettingsService.sector_merge(sector); return "redirect:/admin/sectors/" + encodeUrlPathSegment(sector.getId().toString(), httpServletRequest); } else { return "redirect:/admin/sectors"; } } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.jd.survey.web.settings.SectorsController.java
@Secured({ "ROLE_ADMIN" }) @RequestMapping(method = RequestMethod.PUT, produces = "text/html") public String update(@RequestParam(value = "_proceed", required = false) String proceed, @Valid Sector sector, BindingResult bindingResult, Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { log.info("update(): handles PUT"); try {/* w w w . jav a 2 s . com*/ User user = userService.user_findByLogin(principal.getName()); if (!user.isAdmin()) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } if (proceed != null) { if (bindingResult.hasErrors()) { populateEditForm(uiModel, sector, user); return "admin/sectors/update"; } if (surveySettingsService.dataset_findByName(sector.getName()) != null && !surveySettingsService .dataset_findByName(sector.getName()).getId().equals(sector.getId())) { bindingResult.rejectValue("name", "field_unique"); populateEditForm(uiModel, sector, user); return "admin/sectors/update"; } uiModel.asMap().clear(); sector = surveySettingsService.sector_merge(sector); return "redirect:/admin/sectors/" + encodeUrlPathSegment(sector.getId().toString(), httpServletRequest); } else { return "redirect:/admin/sectors"; } } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.jd.survey.web.settings.SectorsController.java
@Secured({ "ROLE_ADMIN" }) @RequestMapping(value = "/surveyTemplates/{id}", method = RequestMethod.DELETE, produces = "text/html") public String deletess(@PathVariable("id") Long id, Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { log.info("delete(): id=" + id); try {//from w w w . j a v a2 s. c o m User user = userService.user_findByLogin(principal.getName()); if (!user.isAdmin()) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } SurveyTemplate surveyTemplate = (SurveyTemplate) surveySettingsService.surveyTemplate_findById(id); surveySettingsService.surveyTemplate_remove(surveyTemplate); uiModel.asMap().clear(); return "redirect:/admin/sectors"; } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.jd.survey.web.settings.SurveyDefinitionController.java
/** * Returns the survey logo image binary * @param departmentId//from w w w . java2 s . com * @param uiModel * @param httpServletRequest * @return */ @Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" }) @RequestMapping(value = "/qr/{id}", produces = "text/html") public void getSurveyQRCode(@PathVariable("id") Long surveyDefinitionId, Model uiModel, Principal principal, HttpServletRequest httpServletRequest, HttpServletResponse response) { try { uiModel.asMap().clear(); User user = userService.user_findByLogin(principal.getName()); //Check if the user is authorized if (!securityService.userIsAuthorizedToManageSurvey(surveyDefinitionId, user)) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); throw (new RuntimeException("Unauthorized access to logo")); } SurveyDefinition surveyDefinition = surveySettingsService.surveyDefinition_findById(surveyDefinitionId); //String surveyLink =messageSource.getMessage(EXTERNAL_SITE_BASE_URL, null, LocaleContextHolder.getLocale()); String surveyLink = externalBaseUrl; if (surveyDefinition.getIsPublic()) { if (surveyLink.endsWith("/")) { surveyLink = surveyLink + "open/" + surveyDefinitionId + "?list"; } else { surveyLink = surveyLink + "/open/" + surveyDefinitionId + "?list"; } } else { if (surveyLink.endsWith("/")) { surveyLink = surveyLink + "private/" + surveyDefinitionId + "?list"; } else { surveyLink = surveyLink + "/private/" + surveyDefinitionId + "?list"; } } response.setContentType("image/png"); ServletOutputStream servletOutputStream = response.getOutputStream(); QRCodeWriter writer = new QRCodeWriter(); BitMatrix bitMatrix = null; try { bitMatrix = writer.encode(surveyLink, BarcodeFormat.QR_CODE, 600, 600); MatrixToImageWriter.writeToStream(bitMatrix, "png", servletOutputStream); } catch (WriterException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } servletOutputStream.flush(); } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.jd.survey.web.settings.SurveyDefinitionController.java
/** * Returns the survey logo image binary * @param departmentId/*from w w w.ja v a2 s. c om*/ * @param uiModel * @param httpServletRequest * @return */ @Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" }) @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(); User user = userService.user_findByLogin(principal.getName()); //Check if the user is authorized if (!securityService.userIsAuthorizedToManageSurvey(surveyDefinitionId, user)) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); throw (new RuntimeException("Unauthorized access to logo")); } SurveyDefinition surveyDefinition = surveySettingsService.surveyDefinition_findById(surveyDefinitionId); //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.settings.SurveyDefinitionController.java
/** * Updates the survey logo//from w w w.ja v a2 s . com * @param file * @param surveyDefinitionId * @param proceed * @param principal * @param uiModel * @param httpServletRequest * @return */ @SuppressWarnings("unchecked") @Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" }) @RequestMapping(value = "/logo", method = RequestMethod.POST, produces = "text/html") public String updateLogo(@RequestParam("file") MultipartFile file, @RequestParam("id") Long surveyDefinitionId, @RequestParam(value = "_proceed", required = false) String proceed, Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { try { User user = userService.user_findByLogin(principal.getName()); //Check if the user is authorized if (!securityService.userIsAuthorizedToManageSurvey(surveyDefinitionId, user)) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } GlobalSettings globalSettings = applicationSettingsService.getSettings(); //validate content type if (file.isEmpty() || !globalSettings.getValidImageTypesAsList().contains(file.getContentType().toLowerCase())) { uiModel.addAttribute("surveyDefinition", surveySettingsService.surveyDefinition_findById(surveyDefinitionId)); uiModel.addAttribute("invalidFile", true); return "settings/surveyDefinitions/logo"; } SurveyDefinition surveyDefinition = surveySettingsService .surveyDefinition_updateLogo(surveyDefinitionId, file.getBytes()); uiModel.asMap().clear(); return "settings/surveyDefinitions/saved"; } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.jd.survey.web.settings.SurveyDefinitionController.java
@Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" }) @RequestMapping(value = "/browsetemplate", method = RequestMethod.POST, produces = "text/html") public String browseTemplatePost(@RequestParam(value = "id", required = false) Long departmentId, @RequestParam(value = "secId", required = false) Long sectorId, @RequestParam(value = "tempId", required = false) Long templateId, @RequestParam("name") String surveyName, @RequestParam(value = "_proceed", required = false) String proceed, Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { try {//from www . jav a 2 s . c o m String login = principal.getName(); User user = userService.user_findByLogin(login); //Check if the user is authorized if (!securityService.userBelongsToDepartment(departmentId, user)) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } if (proceed != null) { Department department = surveySettingsService.department_findById(departmentId); SurveyDefinition sdef = new SurveyDefinition(department, surveyName); if (!surveySettingsService.surveyDefinition_ValidateNameIsUnique(sdef)) { uiModel.addAttribute("department", surveySettingsService.department_findById(departmentId)); uiModel.addAttribute("sector", surveySettingsService.sector_findById(sectorId)); uiModel.addAttribute("templates", surveySettingsService.surveyTemplate_findBySectorId(sectorId)); uiModel.addAttribute("nameDuplicateError", true); return "settings/surveyDefinitions/browsetemplate"; } if (surveyName != null && surveyName.trim().length() > 0 && surveyName.trim().length() < 250) { SurveyTemplate st = surveySettingsService.surveyTemplate_findById(templateId); String jsonString = st.getJson(); SurveyDefinition surveyDefinition = jsonHelperService.deSerializeSurveyDefinition(jsonString); surveyDefinition.setName(surveyName); surveyDefinition = surveySettingsService.surveyDefinition_create(surveyDefinition, departmentId); uiModel.asMap().clear(); surveyDefinition = surveySettingsService.surveyDefinition_merge(surveyDefinition); return "redirect:/settings/surveyDefinitions/" + encodeUrlPathSegment(surveyDefinition.getId().toString(), httpServletRequest); } else { uiModel.addAttribute("department", surveySettingsService.department_findById(departmentId)); uiModel.addAttribute("sector", surveySettingsService.sector_findById(sectorId)); uiModel.addAttribute("templates", surveySettingsService.surveyTemplate_findBySectorId(sectorId)); uiModel.addAttribute("nameError", true); return "settings/surveyDefinitions/browsetemplate"; } } uiModel.addAttribute("departments", surveySettingsService.department_findAll(user)); uiModel.addAttribute("departmentId", departmentId); uiModel.addAttribute("sectors", surveySettingsService.sector_findAll()); return "settings/surveyDefinitions/importtemplate"; } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.jd.survey.web.settings.SurveyDefinitionController.java
@Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" }) @RequestMapping(value = "/savetemplate", method = RequestMethod.POST, produces = "text/html") public String saveTemplatePost(@RequestParam("sid") Long surveyDefinitionId, @RequestParam("secId") Long sectorId, @RequestParam("name") String templateName, @RequestParam("description") String templateDesc, @RequestParam(value = "_proceed", required = false) String proceed, Principal principal, Model uiModel, HttpServletRequest httpServletRequest, HttpServletResponse response) { try {//from ww w . j a va2s . c om if (proceed != null) { if (templateName != null && templateName.trim().length() > 0 && templateName.trim().length() < 250) { Sector sector = surveySettingsService.sector_findById(sectorId); SurveyTemplate st = new SurveyTemplate(); SurveyDefinition surveyDefinition = surveySettingsService .surveyDefinition_findById(surveyDefinitionId); //Set the exported survey definition status to Inactive //problem: sets the published survey to incomplete. surveyDefinition.setStatus(SurveyDefinitionStatus.I); String json = jsonHelperService.serializeSurveyDefinition(surveyDefinition); st.setName(templateName); st.setSector(sector); st.setDescription(templateDesc); st.setJson(json); //Returning the original survey's status to Published. surveyDefinition.setStatus(SurveyDefinitionStatus.P); if (!surveySettingsService.surveyTemplate_ValidateNameIsUnique(st)) { uiModel.addAttribute("sectors", surveySettingsService.sector_findAll()); uiModel.addAttribute("sid", surveyDefinitionId); uiModel.addAttribute("nameDuplicateError", true); return "settings/surveyDefinitions/savetemplate"; } else { st = surveySettingsService.surveyTemplate_merge(st); uiModel.asMap().clear(); return "settings/surveyDefinitions/saved"; } } else { uiModel.addAttribute("sectors", surveySettingsService.sector_findAll()); uiModel.addAttribute("sid", surveyDefinitionId); uiModel.addAttribute("nameError", true); return "settings/surveyDefinitions/savetemplate"; } } //Cancel return "settings/surveyDefinitions/"; } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.jd.survey.web.settings.SurveyDefinitionController.java
/** * creates a new survey definition//ww w. j a v a 2 s. co m * @param proceed * @param surveyDefinition * @param bindingResult * @param uiModel * @param httpServletRequest * @param principal * @return */ @Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" }) @RequestMapping(method = RequestMethod.POST, produces = "text/html") public String createPost(@RequestParam(value = "_proceed", required = false) String proceed, @Valid SurveyDefinition surveyDefinition, BindingResult bindingResult, Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { try { String login = principal.getName(); User user = userService.user_findByLogin(login); //Check if the user is authorized if (!securityService.userBelongsToDepartment(surveyDefinition.getDepartment().getId(), user) && !securityService.userIsAuthorizedToManageSurvey(surveyDefinition.getId(), user)) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } if (proceed != null) { if (bindingResult.hasErrors()) { populateEditForm(uiModel, surveyDefinition, user); return "settings/surveyDefinitions/create"; } if (!surveySettingsService.surveyDefinition_ValidateNameIsUnique(surveyDefinition)) { bindingResult.rejectValue("name", "field_unique"); populateEditForm(uiModel, surveyDefinition, user); return "settings/surveyDefinitions/create"; } //if(surveyDefinition.getSendAutoReminders() == true){ //bindingResult.rejectValue("autoRemindersWeeklyOccurrence", "field_unique"); // } Policy emailTemplatePolicy = Policy.getInstance(this.getClass().getResource(POLICY_FILE_LOCATION)); AntiSamy emailAs = new AntiSamy(); CleanResults crEmail = emailAs.scan(surveyDefinition.getEmailInvitationTemplate(), emailTemplatePolicy); surveyDefinition.setEmailInvitationTemplate(crEmail.getCleanHTML()); Policy completedSurveyPolicy = Policy .getInstance(this.getClass().getResource(POLICY_FILE_LOCATION)); AntiSamy completedSurveyAs = new AntiSamy(); CleanResults crCompletedSurvey = completedSurveyAs .scan(surveyDefinition.getCompletedSurveyTemplate(), completedSurveyPolicy); surveyDefinition.setCompletedSurveyTemplate(crCompletedSurvey.getCleanHTML()); uiModel.asMap().clear(); surveyDefinition = surveySettingsService.surveyDefinition_merge(surveyDefinition); return "redirect:/settings/surveyDefinitions/" + encodeUrlPathSegment(surveyDefinition.getId().toString(), httpServletRequest); } else { return "redirect:/settings/surveyDefinitions"; } } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.jd.survey.web.settings.SurveyDefinitionController.java
/** * Updates a survey definition /* w w w .j a v a 2s .c o m*/ * @param proceed * @param surveyDefinition * @param bindingResult * @param uiModel * @param httpServletRequest * @param principal * @return */ @Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" }) @RequestMapping(method = RequestMethod.PUT, produces = "text/html") public String update(@RequestParam(value = "_proceed", required = false) String proceed, @Valid SurveyDefinition surveyDefinition, BindingResult bindingResult, Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { try { String login = principal.getName(); User user = userService.user_findByLogin(login); //Check if the user is authorized if (!securityService.userIsAuthorizedToManageSurvey(surveyDefinition.getId(), user) && !securityService.userBelongsToDepartment(surveyDefinition.getDepartment().getId(), user)) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } if (proceed != null) { if (bindingResult.hasErrors()) { populateEditForm(uiModel, surveyDefinition, user); return "settings/surveyDefinitions/update"; } if (!surveySettingsService.surveyDefinition_ValidateNameIsUnique(surveyDefinition)) { bindingResult.rejectValue("name", "field_unique"); populateEditForm(uiModel, surveyDefinition, user); return "settings/surveyDefinitions/update"; } System.out.println("!!!!!!!!! MD: " + surveyDefinition.getAllowMultipleSubmissions() + " #################### PUB: " + surveyDefinition.getIsPublic()); Policy emailTemplatePolicy = Policy.getInstance(this.getClass().getResource(POLICY_FILE_LOCATION)); AntiSamy emailAs = new AntiSamy(); CleanResults crEmail = emailAs.scan(surveyDefinition.getEmailInvitationTemplate(), emailTemplatePolicy); surveyDefinition.setEmailInvitationTemplate(crEmail.getCleanHTML()); Policy completedSurveyPolicy = Policy .getInstance(this.getClass().getResource(POLICY_FILE_LOCATION)); AntiSamy completedSurveyAs = new AntiSamy(); CleanResults crCompletedSurvey = completedSurveyAs .scan(surveyDefinition.getCompletedSurveyTemplate(), completedSurveyPolicy); surveyDefinition.setCompletedSurveyTemplate(crCompletedSurvey.getCleanHTML()); uiModel.asMap().clear(); surveyDefinition = surveySettingsService.surveyDefinition_merge(surveyDefinition); System.out.println("!!!!!!!!! MD: " + surveyDefinition.getAllowMultipleSubmissions() + " #################### PUB: " + surveyDefinition.getIsPublic()); return "settings/surveyDefinitions/saved"; } else { return "redirect:/settings/surveyDefinitions/" + encodeUrlPathSegment(surveyDefinition.getId().toString(), httpServletRequest); } } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }