List of usage examples for org.springframework.web.context.request WebRequest getParameter
@Nullable String getParameter(String paramName);
From source file:org.openmrs.module.cohort.web.controller.AddCohortController.java
@RequestMapping(value = "module/cohort/groupcohort.form", method = RequestMethod.POST) public String onSubmit1(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, @RequestParam(required = false, value = "patient_id") Integer pid, @ModelAttribute("cohortmodule") CohortM cohortmodule, @ModelAttribute("cpatient") CohortMember cohortmember, @ModelAttribute("patient") Patient patient, BindingResult errors, ModelMap model) { CohortProgram cp1 = new CohortProgram(); CohortRole c2 = new CohortRole(); CohortType ct1 = new CohortType(); List<String> cohortm = new ArrayList<String>(); List<String> type = new ArrayList<String>(); LocationService service = Context.getLocationService(); List<Location> formats = service.getAllLocations(); Location loc = new Location(); model.addAttribute("locations", formats); CohortService service1 = Context.getService(CohortService.class); List<CohortM> cp = service1.findCohorts(); for (int i = 0; i < cp.size(); i++) { CohortM c = cp.get(i);/*from w w w .j a va 2s.c o m*/ cohortm.add(c.getName()); List<CohortRole> cr = service1.findRoles(c.getName()); for (int k = 0; k < cr.size(); k++) { CohortRole c3 = cr.get(k); type.add(c3.getName()); } } model.addAttribute("formats", cohortm); model.addAttribute("formats1", type); String cohort_name1 = request.getParameter("format"); List<CohortM> cc = service1.findCohorts(cohort_name1); for (int j = 0; j < cc.size(); j++) { CohortM c1 = cc.get(j); cp1 = c1.getCohortProgram(); ct1 = c1.getCohortType(); } String location = request.getParameter("location"); List<Location> loc1 = service.getLocations(location); for (int k = 0; k < loc1.size(); k++) { loc = loc1.get(k); } PatientService ps = Context.getPatientService(); patient = ps.getPatient(pid); String rolname = request.getParameter("format"); List<CohortRole> crole = service1.findCohortRoles(rolname); for (int g = 0; g < crole.size(); g++) { c2 = crole.get(g); } cohortmodule.setCohortProgram(cp1); cohortmodule.setCohortType(ct1); cohortmodule.setClocation(loc); cohortmodule.setGroupCohort(true); cohortmember.setCohort(cohortmodule); cohortmember.setRole(c2); cohortmember.setPerson(patient); cohortmember.setHead(true); service1.saveCohort(cohortmodule); service1.saveCPatient(cohortmember); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "insertion success"); if ("Next".equalsIgnoreCase(request.getParameter("next"))) { service1.saveCohort(cohortmodule); service1.saveCPatient(cohortmember); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "insertion success"); String redirectUrl = "/module/cohort/addcohortattributes.form?ca=" + cohortmodule.getCohortId(); return "redirect:" + redirectUrl; } return null; }
From source file:org.openmrs.module.cohort.web.controller.AddEncounter.java
@RequestMapping(value = "/module/cohort/addenc.form", method = RequestMethod.POST) public ModelAndView onSubmit(WebRequest request, HttpSession httpSession, ModelMap model, @RequestParam(required = false, value = "encounterDateTime") String date, @RequestParam(required = false, value = "visit") Integer id, @ModelAttribute("cohortencounters") CohortEncounter cencounters, BindingResult errors) { CohortService departmentService = Context.getService(CohortService.class); if (!Context.isAuthenticated()) { errors.reject("Required"); }//from w ww .j av a2 s . com EncounterService enctype = Context.getEncounterService(); List<EncounterType> enctypes = enctype.getAllEncounterTypes(); EncounterType e = new EncounterType(); Location l = new Location(); LocationService service = Context.getLocationService(); List<String> cohortnames = new ArrayList<String>(); CohortService cservice = Context.getService(CohortService.class); CohortM c1 = new CohortM(); Form f = new Form(); CohortVisit cvis = new CohortVisit(); FormService fs = Context.getFormService(); List<String> fo = new ArrayList<String>(); List<Form> form = fs.getAllForms(); for (int h = 0; h < form.size(); h++) { Form b = form.get(h); fo.add(b.getName()); } List<Integer> cvisit = new ArrayList<Integer>(); List<CohortVisit> cv = cservice.findCohortVisit(); for (int a = 0; a < cv.size(); a++) { CohortVisit v = cv.get(a); cvisit.add(v.getId()); } model.addAttribute("forms", fo); model.addAttribute("visits", cvisit); List<CohortM> list1 = cservice.findCohorts(); for (int d = 0; d < list1.size(); d++) { CohortM c = list1.get(d); cohortnames.add(c.getName()); } List<String> etype = new ArrayList<String>(); for (int k = 0; k < enctypes.size(); k++) { EncounterType ec = enctypes.get(k); etype.add(e.getName()); } List<Location> formats = service.getAllLocations(); model.addAttribute("locations", formats); model.addAttribute("enctypes", etype); String encountertype = request.getParameter("enctype"); String location = request.getParameter("location"); String cohort = request.getParameter("names"); String f1 = request.getParameter("form"); if (date == "") { httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "Values cannot be null"); } else { List<CohortM> cohort2 = cservice.findCohorts(cohort); for (int i = 0; i < cohort2.size(); i++) { c1 = cohort2.get(i); } List<EncounterType> enctypes1 = enctype.findEncounterTypes(encountertype); for (int g = 0; g < enctypes1.size(); g++) { e = enctypes1.get(g); } List<Location> loc = service.getLocations(location); for (int j = 0; j < loc.size(); j++) { l = loc.get(j); } List<Form> fm = fs.findForms(f1, false, false); for (int b = 0; b < fm.size(); b++) { f = fm.get(b); } List<CohortVisit> cvi = cservice.findCohortVisit(id); for (int c = 0; c < cvi.size(); c++) { cvis = cvi.get(c); } cencounters.setForm(f); cencounters.setVisit(cvis); cencounters.setCohort(c1); cencounters.setEncounterType(e); cencounters.setLocation(l); departmentService.saveCohortEncounters(cencounters); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "insertion success"); } return null; }
From source file:org.openmrs.module.cohort.web.controller.AddRoleController.java
@RequestMapping(value = "module/cohort/arole.form", method = RequestMethod.POST) public String onSubmit(WebRequest request, HttpSession httpSession, HttpServletRequest request1, @RequestParam(required = false, value = "name") String cohort_name, @ModelAttribute("cohortrole") CohortRole cohortrole, BindingResult errors, ModelMap model) { CohortRole cr = new CohortRole(); CohortType cohort1 = new CohortType(); String cohort_type_name = request.getParameter("format"); CohortService departmentService = Context.getService(CohortService.class); if (!Context.isAuthenticated()) { errors.reject("Required"); }/*from w w w .j a va2 s. c o m*/ this.validator.validate(cohortrole, 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/arole"; } if (cohort_name.length() > 20) { httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "name cannot be greater than 20"); } else { List<CohortType> cohorttype1 = departmentService.findCohortType(cohort_type_name); for (int i = 0; i < cohorttype1.size(); i++) { cohort1 = cohorttype1.get(i); } cohortrole.setCohortType(cohort1); departmentService.saveCohortRole(cohortrole); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "insertion success"); model.addAttribute("formats", cohorttype1); } //} /*catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } }*/ return null; }
From source file:org.openmrs.module.openhmis.cashier.web.controller.JasperReportController.java
@Override public String parse(int reportId, WebRequest request, HttpServletResponse response) throws IOException { int timesheetId; String temp = request.getParameter("timesheetId"); if (!StringUtils.isEmpty(temp) && StringUtils.isNumeric(temp)) { timesheetId = Integer.parseInt(temp); } else {/* ww w . j ava2 s. c o m*/ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "The timesheet id ('" + temp + "') must be " + "defined and be numeric."); return null; } HashMap<String, Object> params = new HashMap<String, Object>(); params.put("timesheetId", timesheetId); return renderReport(reportId, params, "Cashier Shift Report - " + temp, response); }
From source file:org.openmrs.module.openhmis.inventory.web.controller.JasperReportController.java
private String renderExpiringStocksReport(int reportId, WebRequest request, HttpServletResponse response) throws IOException { Date expiryDate = null;//from w ww .j a v a2 s . c o m SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); String temp = request.getParameter("expiresBy"); if (!StringUtils.isEmpty(temp)) { try { expiryDate = dateFormat.parse(temp); } catch (Exception ex) { // Whatevs... dealing with stupid checked exceptions } } if (expiryDate == null) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "The expiry date must be defined."); return null; } String stockroomId = request.getParameter("stockroomId"); HashMap<String, Object> params = new HashMap<String, Object>(); params.put("expiresBy", expiryDate); if (StringUtils.isNotBlank(stockroomId)) { params.put("stockroomId", stockroomId); } return renderReport(reportId, params, null, response); }
From source file:org.openmrs.module.patientmodule.web.controller.PatientModuleManageController.java
@RequestMapping(value = "/module/patientmodule/addPatientModule.form", method = RequestMethod.POST) public String submitPatientModule(WebRequest request, HttpSession httpSession, ModelMap model, @RequestParam(required = false, value = "action") String action, @ModelAttribute("patientModule") PatientModule patientModule, BindingResult errors) { MessageSourceService mss = Context.getMessageSourceService(); model.addAttribute("hello", ""); PatientModuleService patientModuleService = Context.getService(PatientModuleService.class); if (!Context.isAuthenticated()) { errors.reject("patientModule.auth.required"); } else if (mss.getMessage("patientModule.purgePatientModule").equals(action)) { try {//from ww w.j a v a2 s . com patientModuleService.purgePatientModule(patientModule); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "patientModule.delete.success"); return "redirect:patientModuleList.list"; } catch (Exception ex) { httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "patientModule.delete.failure"); log.error("Failed to delete patientModule", ex); return "redirect:patientModuleForm.form?nationalId=" + request.getParameter("nationalId"); } } else { patientModuleService.savePatient(patientModule); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "patientModule.saved"); } return "redirect:patientModuleList.list"; }
From source file:org.openmrs.module.reporting.web.datasets.PatientDataSetEditor.java
@RequestMapping(value = "/module/reporting/datasets/patientDataSetEditor-sortColumns", method = RequestMethod.POST) public String sortColumns(WebRequest request, HttpSession session) { final List<String> columnOrder = new ArrayList<String>(); int i = 0;// ww w . jav a 2 s . c o m while (true) { String colName = request.getParameter("column" + i); if (colName == null) break; columnOrder.add(colName); ++i; } PatientDataSetDefinition dsd = getFromSession(session); Collections.sort(dsd.getColumnDefinitions(), new Comparator<RowPerObjectColumnDefinition>() { public int compare(RowPerObjectColumnDefinition left, RowPerObjectColumnDefinition right) { Integer leftIndex = columnOrder.indexOf(left.getName()); Integer rightIndex = columnOrder.indexOf(right.getName()); return leftIndex.compareTo(rightIndex); } }); putInSession(session, dsd, true); return "redirect:patientDataSetEditor.form"; }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.SessionController1_8.java
/** * Tells the user their sessionId, and whether or not they are authenticated. * /*w w w . ja v a 2 s. c om*/ * @param request * @return * @should return the session id if the user is authenticated * @should return the session id if the user is not authenticated */ @RequestMapping(method = RequestMethod.GET) @ResponseBody public Object get(WebRequest request) { boolean authenticated = Context.isAuthenticated(); SimpleObject session = new SimpleObject(); session.add("sessionId", request.getSessionId()).add("authenticated", authenticated); if (authenticated) { String repParam = request.getParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION); Representation rep = (repParam != null) ? restService.getRepresentation(repParam) : Representation.DEFAULT; session.add("user", ConversionUtil.convertToRepresentation(Context.getAuthenticatedUser(), rep)); session.add("locale", Context.getLocale()); session.add("allowedLocales", Context.getAdministrationService().getAllowedLocales()); } return session; }
From source file:org.openmrs.web.controller.user.UserFormController.java
/** * @should work for an example// www. ja v a 2s. com */ @RequestMapping(value = "/admin/users/user.form", method = RequestMethod.POST) public String handleSubmission(WebRequest request, HttpSession httpSession, ModelMap model, @RequestParam(required = false, value = "action") String action, @RequestParam(required = false, value = "userFormOldPassword") String oldPassword, @RequestParam(required = false, value = "userFormPassword") String password, @RequestParam(required = false, value = "secretQuestion") String secretQuestion, @RequestParam(required = false, value = "secretAnswer") String secretAnswer, @RequestParam(required = false, value = "confirm") String confirm, @RequestParam(required = false, value = "forcePassword") Boolean forcePassword, @RequestParam(required = false, value = "roleStrings") String[] roles, @RequestParam(required = false, value = "createNewPerson") String createNewPerson, @ModelAttribute("user") User user, BindingResult errors) { UserService us = Context.getUserService(); MessageSourceService mss = Context.getMessageSourceService(); if (!Context.isAuthenticated()) { errors.reject("auth.invalid"); } else if (mss.getMessage("User.assumeIdentity").equals(action)) { Context.becomeUser(user.getSystemId()); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "User.assumeIdentity.success"); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ARGS, user.getPersonName()); return "redirect:/index.htm"; } else if (mss.getMessage("User.delete").equals(action)) { try { Context.getUserService().purgeUser(user); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "User.delete.success"); return "redirect:users.list"; } catch (Exception ex) { httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "User.delete.failure"); log.error("Failed to delete user", ex); return "redirect:/admin/users/user.form?userId=" + request.getParameter("userId"); } } else if (mss.getMessage("User.retire").equals(action)) { String retireReason = request.getParameter("retireReason"); if (!(StringUtils.hasText(retireReason))) { errors.rejectValue("retireReason", "User.disableReason.empty"); return showForm(user.getUserId(), createNewPerson, user, model); } else { us.retireUser(user, retireReason); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "User.retiredMessage"); } } else if (mss.getMessage("User.unRetire").equals(action)) { us.unretireUser(user); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "User.unRetiredMessage"); } else { // check if username is already in the database if (us.hasDuplicateUsername(user)) { errors.rejectValue("username", "error.username.taken"); } // check if password and password confirm are identical if (password == null || password.equals("XXXXXXXXXXXXXXX")) { password = ""; } if (confirm == null || confirm.equals("XXXXXXXXXXXXXXX")) { confirm = ""; } if (!password.equals(confirm)) { errors.reject("error.password.match"); } if (password.length() == 0 && isNewUser(user)) { errors.reject("options.login.password.null"); } //check password strength if (password.length() > 0) { try { OpenmrsUtil.validatePassword(user.getUsername(), password, user.getSystemId()); } catch (PasswordException e) { errors.reject(e.getMessage()); } } Set<Role> newRoles = new HashSet<Role>(); if (roles != null) { for (String r : roles) { // Make sure that if we already have a detached instance of this role in the // user's roles, that we don't fetch a second copy of that same role from // the database, or else hibernate will throw a NonUniqueObjectException. Role role = null; if (user.getRoles() != null) { for (Role test : user.getRoles()) { if (test.getRole().equals(r)) { role = test; } } } if (role == null) { role = us.getRole(r); user.addRole(role); } newRoles.add(role); } } if (user.getRoles() == null) { newRoles.clear(); } else { user.getRoles().retainAll(newRoles); } String[] keys = request.getParameterValues("property"); String[] values = request.getParameterValues("value"); if (keys != null && values != null) { for (int x = 0; x < keys.length; x++) { String key = keys[x]; String val = values[x]; user.setUserProperty(key, val); } } if (StringUtils.hasLength(secretQuestion) && !StringUtils.hasLength(secretAnswer)) { errors.reject("error.User.secretAnswer.empty"); } else if (!StringUtils.hasLength(secretQuestion) && StringUtils.hasLength(secretAnswer)) { errors.reject("error.User.secretQuestion.empty"); } new UserProperties(user.getUserProperties()).setSupposedToChangePassword(forcePassword); userValidator.validate(user, errors); if (errors.hasErrors()) { return showForm(user.getUserId(), createNewPerson, user, model); } if (isNewUser(user)) { us.createUser(user, password); } else { us.saveUser(user); if (!"".equals(password) && Context.hasPrivilege(PrivilegeConstants.EDIT_USER_PASSWORDS)) { if (log.isDebugEnabled()) { log.debug("calling changePassword for user " + user + " by user " + Context.getAuthenticatedUser()); } us.changePassword(user, oldPassword, password); } } if (StringUtils.hasLength(secretQuestion) && StringUtils.hasLength(secretAnswer)) { us.changeQuestionAnswer(user, secretQuestion, secretAnswer); } httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "User.saved"); } return "redirect:users.list"; }
From source file:org.sparkcommerce.core.web.processor.SparkCacheProcessor.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). SparkRequestContext brc = SparkRequestContext.getSparkRequestContext(); if (brc != null && brc.getWebRequest() != null) { WebRequest request = brc.getWebRequest(); String disableCachingParam = request.getParameter("disableThymeleafTemplateCaching"); if ("true".equals(disableCachingParam)) { return false; }/*from w ww . ja v a2 s . co m*/ } } return enabled; }