List of usage examples for org.springframework.web.context.request WebRequest getParameter
@Nullable String getParameter(String paramName);
From source file:org.broadleafcommerce.common.web.BroadleafSandBoxResolverImpl.java
/** * Allows a user in SandBox mode to override the current time and date being used by the system. * //from w ww. j a va 2 s . c o m * @param request */ private void setContentTime(WebRequest request) { String sandboxDateTimeParam = request.getParameter(SANDBOX_DATE_TIME_VAR); if (!sandBoxPreviewEnabled) { sandboxDateTimeParam = null; } Date overrideTime = null; try { if (request.getParameter(SANDBOX_DATE_TIME_RIBBON_OVERRIDE_PARAM) != null) { overrideTime = readDateFromRequest(request); } else if (sandboxDateTimeParam != null) { if (LOG.isDebugEnabled()) { LOG.debug("Setting date/time using " + sandboxDateTimeParam); } overrideTime = CONTENT_DATE_FORMATTER.parse(sandboxDateTimeParam); } } catch (ParseException e) { LOG.debug(e); } if (BLCRequestUtils.isOKtoUseSession(request)) { if (overrideTime == null) { overrideTime = (Date) request.getAttribute(SANDBOX_DATE_TIME_VAR, WebRequest.SCOPE_GLOBAL_SESSION); } else { if (LOG.isDebugEnabled()) { LOG.debug("Setting date-time for sandbox mode to " + overrideTime + " for sandboxDateTimeParam = " + sandboxDateTimeParam); } request.setAttribute(SANDBOX_DATE_TIME_VAR, overrideTime, WebRequest.SCOPE_GLOBAL_SESSION); } } if (overrideTime != null) { FixedTimeSource ft = new FixedTimeSource(overrideTime.getTime()); SystemTime.setLocalTimeSource(ft); } else { SystemTime.resetLocalTimeSource(); } }
From source file:org.broadleafcommerce.common.web.BroadleafSandBoxResolverImpl.java
private Date readDateFromRequest(WebRequest request) throws ParseException { String date = request.getParameter(SANDBOX_DISPLAY_DATE_TIME_DATE_PARAM); String minutes = request.getParameter(SANDBOX_DISPLAY_DATE_TIME_MINUTES_PARAM); String hours = request.getParameter(SANDBOX_DISPLAY_DATE_TIME_HOURS_PARAM); String ampm = request.getParameter(SANDBOX_DISPLAY_DATE_TIME_AMPM_PARAM); if (StringUtils.isEmpty(minutes)) { minutes = Integer.toString(SystemTime.asCalendar().get(Calendar.MINUTE)); }//from ww w.j av a2 s.com if (StringUtils.isEmpty(hours)) { hours = Integer.toString(SystemTime.asCalendar().get(Calendar.HOUR_OF_DAY)); } String dateString = date + " " + hours + ":" + minutes + " " + ampm; if (LOG.isDebugEnabled()) { LOG.debug("Setting date/time using " + dateString); } Date parsedDate = CONTENT_DATE_PARSE_FORMAT.parse(dateString); return parsedDate; }
From source file:org.broadleafcommerce.core.web.processor.BroadleafCacheProcessor.java
public boolean isCachingEnabled() { boolean enabled = !systemPropertiesService.resolveBooleanSystemProperty("disableThymeleafTemplateCaching"); if (enabled) { // check for a URL param that overrides caching - useful for testing if this processor is incorrectly // caching a page (possibly due to an bad cacheKey). BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext(); if (brc != null && brc.getWebRequest() != null) { WebRequest request = brc.getWebRequest(); String disableCachingParam = request.getParameter("disableThymeleafTemplateCaching"); if ("true".equals(disableCachingParam)) { return false; }/*from w w w . j av a2 s . c o m*/ } } return enabled; }
From source file:org.broadleafcommerce.openadmin.web.filter.BroadleafAdminRequestProcessor.java
protected void prepareProfile(WebRequest request, BroadleafRequestContext brc) { AdminUser adminUser = adminRemoteSecurityService.getPersistentAdminUser(); if (adminUser == null) { //clear any profile if (BLCRequestUtils.isOKtoUseSession(request)) { request.removeAttribute(PROFILE_REQ_PARAM, WebRequest.SCOPE_GLOBAL_SESSION); }// w ww .j a va 2 s . c om } else { Site profile = null; if (StringUtils.isNotBlank(request.getParameter(PROFILE_REQ_PARAM))) { Long profileId = Long.parseLong(request.getParameter(PROFILE_REQ_PARAM)); profile = siteService.retrievePersistentSiteById(profileId); if (profile == null) { throw new IllegalArgumentException( String.format("Unable to find the requested profile: %s", profileId)); } } if (profile == null) { Long previouslySetProfileId = null; if (BLCRequestUtils.isOKtoUseSession(request)) { previouslySetProfileId = (Long) request.getAttribute(PROFILE_REQ_PARAM, WebRequest.SCOPE_GLOBAL_SESSION); } if (previouslySetProfileId != null) { profile = siteService.retrievePersistentSiteById(previouslySetProfileId); } } if (profile == null) { List<Site> profiles = new ArrayList<Site>(); if (brc.getNonPersistentSite() != null) { Site currentSite = siteService.retrievePersistentSiteById(brc.getNonPersistentSite().getId()); if (extensionManager != null) { ExtensionResultHolder<Set<Site>> profilesResult = new ExtensionResultHolder<Set<Site>>(); extensionManager.getProxy().retrieveProfiles(currentSite, profilesResult); if (!CollectionUtils.isEmpty(profilesResult.getResult())) { profiles.addAll(profilesResult.getResult()); } } } if (profiles.size() == 1) { profile = profiles.get(0); } } if (profile != null) { if (BLCRequestUtils.isOKtoUseSession(request)) { request.setAttribute(PROFILE_REQ_PARAM, profile.getId(), WebRequest.SCOPE_GLOBAL_SESSION); } brc.setCurrentProfile(profile); } } }
From source file:org.broadleafcommerce.openadmin.web.filter.BroadleafAdminRequestProcessor.java
protected void prepareCatalog(WebRequest request, BroadleafRequestContext brc) { AdminUser adminUser = adminRemoteSecurityService.getPersistentAdminUser(); if (adminUser == null) { //clear any catalog if (BLCRequestUtils.isOKtoUseSession(request)) { request.removeAttribute(CATALOG_REQ_PARAM, WebRequest.SCOPE_GLOBAL_SESSION); }/*from w w w .j a v a2 s . c o m*/ } else { Catalog catalog = null; if (StringUtils.isNotBlank(request.getParameter(CATALOG_REQ_PARAM))) { Long catalogId = Long.parseLong(request.getParameter(CATALOG_REQ_PARAM)); catalog = siteService.findCatalogById(catalogId); if (catalog == null) { throw new IllegalArgumentException( String.format("Unable to find the requested catalog: %s", catalogId)); } } if (catalog == null) { Long previouslySetCatalogId = null; if (BLCRequestUtils.isOKtoUseSession(request)) { previouslySetCatalogId = (Long) request.getAttribute(CATALOG_REQ_PARAM, WebRequest.SCOPE_GLOBAL_SESSION); } if (previouslySetCatalogId != null) { catalog = siteService.findCatalogById(previouslySetCatalogId); } } if (catalog == null) { List<Catalog> catalogs = new ArrayList<Catalog>(); if (brc.getNonPersistentSite() != null) { Site currentSite = siteService.retrievePersistentSiteById(brc.getNonPersistentSite().getId()); if (extensionManager != null) { ExtensionResultHolder<Set<Catalog>> catalogResult = new ExtensionResultHolder<Set<Catalog>>(); extensionManager.getProxy().retrieveCatalogs(currentSite, catalogResult); if (!CollectionUtils.isEmpty(catalogResult.getResult())) { catalogs.addAll(catalogResult.getResult()); } } } if (catalogs.size() == 1) { catalog = catalogs.get(0); } } if (catalog != null) { if (BLCRequestUtils.isOKtoUseSession(request)) { request.setAttribute(CATALOG_REQ_PARAM, catalog.getId(), WebRequest.SCOPE_GLOBAL_SESSION); } brc.setCurrentCatalog(catalog); } } }
From source file:org.broadleafcommerce.openadmin.web.filter.BroadleafAdminRequestProcessor.java
protected void prepareSandBox(WebRequest request, BroadleafRequestContext brc) { AdminUser adminUser = adminRemoteSecurityService.getPersistentAdminUser(); if (adminUser == null) { //clear any sandbox if (BLCRequestUtils.isOKtoUseSession(request)) { request.removeAttribute(BroadleafSandBoxResolver.SANDBOX_ID_VAR, WebRequest.SCOPE_GLOBAL_SESSION); }/*from w w w . j av a 2s . c om*/ } else { SandBox sandBox = null; if (StringUtils.isNotBlank(request.getParameter(SANDBOX_REQ_PARAM))) { Long sandBoxId = Long.parseLong(request.getParameter(SANDBOX_REQ_PARAM)); sandBox = sandBoxService.retrieveUserSandBoxForParent(adminUser.getId(), sandBoxId); if (sandBox == null) { SandBox approvalOrUserSandBox = sandBoxService.retrieveSandBoxManagementById(sandBoxId); if (approvalOrUserSandBox != null) { if (approvalOrUserSandBox.getSandBoxType().equals(SandBoxType.USER)) { sandBox = approvalOrUserSandBox; } else { sandBox = sandBoxService.createUserSandBox(adminUser.getId(), approvalOrUserSandBox); } } } } if (sandBox == null) { Long previouslySetSandBoxId = null; if (BLCRequestUtils.isOKtoUseSession(request)) { previouslySetSandBoxId = (Long) request.getAttribute(BroadleafSandBoxResolver.SANDBOX_ID_VAR, WebRequest.SCOPE_GLOBAL_SESSION); } if (previouslySetSandBoxId != null) { sandBox = sandBoxService.retrieveSandBoxManagementById(previouslySetSandBoxId); } } if (sandBox == null) { List<SandBox> defaultSandBoxes = sandBoxService.retrieveSandBoxesByType(SandBoxType.DEFAULT); if (defaultSandBoxes.size() > 1) { throw new IllegalStateException("Only one sandbox should be configured as default"); } SandBox defaultSandBox; if (defaultSandBoxes.size() == 1) { defaultSandBox = defaultSandBoxes.get(0); } else { defaultSandBox = sandBoxService.createDefaultSandBox(); } sandBox = sandBoxService.retrieveUserSandBoxForParent(adminUser.getId(), defaultSandBox.getId()); if (sandBox == null) { sandBox = sandBoxService.createUserSandBox(adminUser.getId(), defaultSandBox); } } // If the user just changed sandboxes, we want to update the database record. Long previouslySetSandBoxId = null; if (BLCRequestUtils.isOKtoUseSession(request)) { previouslySetSandBoxId = (Long) request.getAttribute(BroadleafSandBoxResolver.SANDBOX_ID_VAR, WebRequest.SCOPE_GLOBAL_SESSION); } if (previouslySetSandBoxId != null && !sandBox.getId().equals(previouslySetSandBoxId)) { adminUser.setLastUsedSandBoxId(sandBox.getId()); adminUser = adminSecurityService.saveAdminUser(adminUser); } if (BLCRequestUtils.isOKtoUseSession(request)) { request.setAttribute(BroadleafSandBoxResolver.SANDBOX_ID_VAR, sandBox.getId(), WebRequest.SCOPE_GLOBAL_SESSION); } brc.setSandBox(sandBox); brc.setDeployBehavior(deployBehaviorUtil.isProductionSandBoxMode() ? DeployBehavior.CLONE_PARENT : DeployBehavior.OVERWRITE_PARENT); brc.getAdditionalProperties().put("adminUser", adminUser); } }
From source file:org.focusns.web.portal.Portal.java
@RequestMapping("/portal") public String doRender(@RequestParam(required = false) String mode, @RequestParam(required = false) String projectCode, @RequestParam String path, WebRequest webRequest) throws Exception { ///*from www . j ava 2 s.c o m*/ String categoryCode = null; // export project if (StringUtils.hasText(projectCode)) { Project project = projectService.getProject(projectCode); if (project != null) { ProjectCategory projectCategory = categoryService.getCategory(project.getCategoryId()); categoryCode = projectCategory.getCode(); // webRequest.setAttribute("project", project, WebRequest.SCOPE_REQUEST); webRequest.setAttribute(Project.KEY, project, WebRequest.SCOPE_REQUEST); webRequest.setAttribute("projectCategory", projectCategory, WebRequest.SCOPE_REQUEST); webRequest.setAttribute(ProjectCategory.KEY, projectCategory, WebRequest.SCOPE_REQUEST); // export feature String featureCode = webRequest.getParameter("featureCode"); if (StringUtils.hasText(featureCode)) { ProjectFeature projectFeature = featureService.getProjectFeature(project.getId(), featureCode); webRequest.setAttribute("projectFeature", projectFeature, WebRequest.SCOPE_REQUEST); webRequest.setAttribute(ProjectFeature.KEY, projectFeature, WebRequest.SCOPE_REQUEST); } } } // export ProjectUser ProjectUser projectUser = (ProjectUser) webRequest.getAttribute(ProjectUser.KEY, WebRequest.SCOPE_SESSION); if (projectUser != null) { webRequest.setAttribute("user", projectUser, WebRequest.SCOPE_REQUEST); webRequest.setAttribute(ProjectUser.KEY, projectUser, WebRequest.SCOPE_REQUEST); } // PageConfig pageConfig = resolvePage(path, mode, categoryCode); Assert.notNull(pageConfig, String.format("Page %s not found!", path)); // processPageConfig(pageConfig, webRequest); // webRequest.setAttribute("pageConfig", pageConfig, WebRequest.SCOPE_REQUEST); // return "viewName"; }
From source file:org.openmrs.module.cohort.web.controller.AddCohortAttributesTypeController.java
@RequestMapping(value = "/module/cohort/addcohortattributestype.form", method = RequestMethod.POST) public String onSubmit(WebRequest request, HttpSession httpSession, ModelMap model, @RequestParam(required = false, value = "name") String attribute_type, @RequestParam(required = false, value = "description") String description, @ModelAttribute("cohortattributes") CohortAttributeType cohortattributes, BindingResult errors) { CohortService departmentService = Context.getService(CohortService.class); //PatientService patientService=Context.getService(PatientService.class); String voided = request.getParameter("voided"); String format = request.getParameter("format"); this.validator.validate(cohortattributes, errors); System.out.println("Before BR"); if (errors.hasErrors()) { System.out.println("BR has errors: " + errors.getErrorCount()); System.out.println(errors.getAllErrors()); model.addAttribute("cohortattributes", new CohortAttributeType()); List<String> formats = new ArrayList<String>( FieldGenHandlerFactory.getSingletonInstance().getHandlers().keySet()); formats.add("java.lang.Character"); formats.add("java.lang.Integer"); formats.add("java.lang.Float"); formats.add("java.lang.Boolean"); model.addAttribute("formats", formats); return "/module/cohort/addcohortattributestype"; }/*from w ww . jav a 2 s . c o m*/ if (attribute_type.length() > 20) { httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "attribute type cannot be greater than 20"); } else { cohortattributes.setFormat(format); departmentService.saveCohort(cohortattributes); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "insertion success"); } return null; }
From source file:org.openmrs.module.cohort.web.controller.AddCohortController.java
@RequestMapping(value = "module/cohort/addcohort.form", method = RequestMethod.POST) public String onSubmit(WebRequest request, HttpSession httpSession, HttpServletRequest request1, @RequestParam(required = false, value = "name") String cohort_name, @RequestParam(required = false, value = "description") String description, @RequestParam(required = false, value = "startDate") String start_date, @RequestParam(required = false, value = "endDate") String end_date, @ModelAttribute("cohortmodule") CohortM cohortmodule, BindingResult errors, ModelMap model) { CohortType cohort1 = new CohortType(); CohortProgram prg = new CohortProgram(); Location loc = new Location(); String cohort_program = request.getParameter("format1"); String cohort_type_name = request.getParameter("format"); String location = request.getParameter("location"); CohortService departmentService = Context.getService(CohortService.class); if (!Context.isAuthenticated()) { errors.reject("Required"); }/*from ww w. j a v a 2 s .c o m*/ this.validator.validate(cohortmodule, errors); System.out.println("Before BR"); if (errors.hasErrors()) { System.out.println("BR has errors: " + errors.getErrorCount()); System.out.println(errors.getAllErrors()); return "/module/cohort/addcohort"; } else { /*try { java.util.Date start = new SimpleDateFormat("yyyy/MM/dd HH:mm", Locale.ENGLISH).parse(start_date); java.util.Date end = new SimpleDateFormat("yyyy/MM/dd HH:mm", Locale.ENGLISH).parse(end_date); if (start.compareTo(end) < 0 || start.compareTo(end)==0) {*/ //cohortmodule.setLocation(location); List<CohortProgram> list2 = departmentService.findCohortProgram(cohort_program); List<CohortType> cohorttype1 = departmentService.findCohortType(cohort_type_name); LocationService service = Context.getLocationService(); List<Location> formats = service.getLocations(location); for (int j = 0; j < formats.size(); j++) { loc = formats.get(j); } for (int i = 0; i < cohorttype1.size(); i++) { cohort1 = cohorttype1.get(i); } for (int a = 0; a < list2.size(); a++) { prg = list2.get(a); } cohortmodule.setCohortProgram(prg); cohortmodule.setClocation(loc); cohortmodule.setCohortType(cohort1); departmentService.saveCohort(cohortmodule); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "insertion success"); model.addAttribute("locations", formats); model.addAttribute("formats", cohorttype1); model.addAttribute("formats1", list2); model.addAttribute("cohortmodule", cohortmodule); if ("Next".equalsIgnoreCase(request.getParameter("next"))) { departmentService.saveCohort(cohortmodule); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "insertion success"); String redirectUrl = "/module/cohort/addcohortattributes.form?ca=" + cohortmodule.getCohortId(); return "redirect:" + redirectUrl; } } //} /*catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } }*/ return null; }
From source file:org.openmrs.module.cohort.web.controller.AddCohortController.java
@RequestMapping(value = "module/cohort/cpatients.form", method = RequestMethod.POST) public void onClick(WebRequest request, HttpSession httpSession, ModelMap model, @RequestParam(required = false, value = "type") String type, @RequestParam(required = false, value = "startDate") String startDate, @RequestParam("cpid") Integer id, @RequestParam("patient_id") Integer pid, @ModelAttribute("cpatient") CohortMember cpatient, @ModelAttribute("patient") Patient patient, BindingResult errors) { CohortM cohort = new CohortM(); CohortRole c2 = new CohortRole(); List<String> names = new ArrayList<String>(); List<String> type1 = new ArrayList<String>(); CohortService departmentService = Context.getService(CohortService.class); PatientService ps = Context.getPatientService(); /* List<Patient> pn=ps.getAllPatients();*/ String cname;// ww w.ja v a 2 s . c om List<CohortM> cohort1 = departmentService.findCohort(id); for (int i = 0; i < cohort1.size(); i++) { cohort = cohort1.get(i); cname = cohort.getName(); List<CohortRole> cr = departmentService.findRoles(cname); for (int k = 0; k < cr.size(); k++) { CohortRole c3 = cr.get(k); type1.add(c3.getName()); } } //List<CohortRole> cr=departmentService.findRoles(cname); /*for(int k=0;k<cr.size();k++) { CohortRole c3=cr.get(k); type1.add(c3.getName()); }*/ /*for(int b=0;b<pn.size();b++) { Patient p1 = pn.get(b); names.add(p1.getGivenName()); }*/ //model.addAttribute("pnames",names); model.addAttribute("formats", type1); patient = ps.getPatient(pid); String rolname = request.getParameter("format"); List<CohortRole> crole = departmentService.findCohortRoles(rolname); for (int g = 0; g < crole.size(); g++) { c2 = crole.get(g); } cpatient.setPerson(patient); cpatient.setCohort(cohort); cpatient.setRole(c2); departmentService.saveCPatient(cpatient); model.addAttribute("formats", crole); model.addAttribute("cpatient", cpatient); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Insertion success"); }