Example usage for org.springframework.web.context.request WebRequest getParameter

List of usage examples for org.springframework.web.context.request WebRequest getParameter

Introduction

In this page you can find the example usage for org.springframework.web.context.request WebRequest getParameter.

Prototype

@Nullable
String getParameter(String paramName);

Source Link

Document

Return the request parameter of the given name, or null if none.

Usage

From source file:cz.zcu.kiv.eegdatabase.logic.controller.list.hardware.HardwareMultiController.java

@RequestMapping(value = "lists/hardware-definitions/list.html", method = RequestMethod.GET)
public String showSelectForm(WebRequest webRequest, ModelMap model, HttpServletRequest request) {
    log.debug("Processing hardware list controller");
    SelectGroupCommand selectGroupCommand = new SelectGroupCommand();
    String defaultHardware = messageSource.getMessage("label.defaultHardware", null,
            RequestContextUtils.getLocale(request));
    fillAuthResearchGroupList(defaultHardware);
    String idString = webRequest.getParameter("groupid");
    if (auth.isAdmin()) {
        if (idString != null) {
            int id = Integer.parseInt(idString);
            if (id != DEFAULT_ID) {
                fillHardwareList(id);//from  www. java 2s.  co m
                selectGroupCommand.setResearchGroupId(id);
            } else {
                fillHardwareList(DEFAULT_ID);
                selectGroupCommand.setResearchGroupId(DEFAULT_ID);
            }

        } else {
            fillHardwareList(DEFAULT_ID);
            selectGroupCommand.setResearchGroupId(DEFAULT_ID);
        }
        model.addAttribute("userIsExperimenter", true);
    } else {
        if (!researchGroupList.isEmpty()) {
            if (idString != null) {
                int id = Integer.parseInt(idString);
                fillHardwareList(id);
                selectGroupCommand.setResearchGroupId(id);
            } else {
                int myGroup = researchGroupList.get(0).getResearchGroupId();
                fillHardwareList(myGroup);
                selectGroupCommand.setResearchGroupId(myGroup);
            }
            model.addAttribute("userIsExperimenter", auth.userIsExperimenter());
        } else {
            model.addAttribute("userIsExperimenter", false);
        }
    }
    model.addAttribute("selectGroupCommand", selectGroupCommand);
    model.addAttribute("hardwareList", hardwareList);
    model.addAttribute("researchGroupList", researchGroupList);

    return "lists/hardware/list";
}

From source file:cz.zcu.kiv.eegdatabase.logic.controller.list.personoptparamdef.PersonOptParamDefMultiController.java

@RequestMapping(value = "lists/person-optional-parameters/list.html", method = RequestMethod.GET)
public String showSelectForm(WebRequest webRequest, ModelMap model, HttpServletRequest request) {
    log.debug("Processing personOptParamDef list controller");
    SelectGroupCommand selectGroupCommand = new SelectGroupCommand();
    String defaultPersonOptParamDef = messageSource.getMessage("label.defaultPersonOptParamDef", null,
            RequestContextUtils.getLocale(request));
    fillAuthResearchGroupList(defaultPersonOptParamDef);
    String idString = webRequest.getParameter("groupid");
    if (auth.isAdmin()) {
        if (idString != null) {
            int id = Integer.parseInt(idString);
            if (id != DEFAULT_ID) {
                fillPersonOptParamDefList(id);
                selectGroupCommand.setResearchGroupId(id);
            } else {
                fillPersonOptParamDefList(DEFAULT_ID);
                selectGroupCommand.setResearchGroupId(DEFAULT_ID);
            }/*from w w  w  . ja  va2 s .  c  o  m*/

        } else {
            fillPersonOptParamDefList(DEFAULT_ID);
            selectGroupCommand.setResearchGroupId(DEFAULT_ID);
        }
        model.addAttribute("userIsExperimenter", true);
    } else {
        if (!researchGroupList.isEmpty()) {
            if (idString != null) {
                int id = Integer.parseInt(idString);
                fillPersonOptParamDefList(id);
                selectGroupCommand.setResearchGroupId(id);
            } else {
                int myGroup = researchGroupList.get(0).getResearchGroupId();
                fillPersonOptParamDefList(myGroup);
                selectGroupCommand.setResearchGroupId(myGroup);
            }
            model.addAttribute("userIsExperimenter", auth.userIsExperimenter());
        } else {
            model.addAttribute("userIsExperimenter", false);
        }
    }
    model.addAttribute("selectGroupCommand", selectGroupCommand);
    model.addAttribute("personOptParamDefList", personOptParamDefList);
    model.addAttribute("researchGroupList", researchGroupList);

    return "lists/personAdditionalParams/list";
}

From source file:cz.zcu.kiv.eegdatabase.logic.controller.list.filemetadata.FileMetadataParamDefMultiController.java

@RequestMapping(value = "lists/file-metadata-definitions/list.html", method = RequestMethod.GET)
public String showSelectForm(WebRequest webRequest, ModelMap model, HttpServletRequest request) {
    log.debug("Processing fileMetadataParamDef list controller");
    SelectGroupCommand selectGroupCommand = new SelectGroupCommand();
    String defaultFileMetadataParamDef = messageSource.getMessage("label.defaultFileMetadataParamDef", null,
            RequestContextUtils.getLocale(request));
    fillAuthResearchGroupList(defaultFileMetadataParamDef);
    String idString = webRequest.getParameter("groupid");
    if (auth.isAdmin()) {
        if (idString != null) {
            int id = Integer.parseInt(idString);
            if (id != DEFAULT_ID) {
                fillFileMetadataParamDefList(id);
                selectGroupCommand.setResearchGroupId(id);
            } else {
                fillFileMetadataParamDefList(DEFAULT_ID);
                selectGroupCommand.setResearchGroupId(DEFAULT_ID);
            }//from  w w  w .j  a v a2 s . c om

        } else {
            fillFileMetadataParamDefList(DEFAULT_ID);
            selectGroupCommand.setResearchGroupId(DEFAULT_ID);
        }
        model.addAttribute("userIsExperimenter", true);
    } else {
        if (!researchGroupList.isEmpty()) {
            if (idString != null) {
                int id = Integer.parseInt(idString);
                fillFileMetadataParamDefList(id);
                selectGroupCommand.setResearchGroupId(id);
            } else {
                int myGroup = researchGroupList.get(0).getResearchGroupId();
                fillFileMetadataParamDefList(myGroup);
                selectGroupCommand.setResearchGroupId(myGroup);
            }
            model.addAttribute("userIsExperimenter", auth.userIsExperimenter());
        } else {
            model.addAttribute("userIsExperimenter", false);
        }
    }
    model.addAttribute("selectGroupCommand", selectGroupCommand);
    model.addAttribute("fileMetadataParamDefList", fileMetadataParamDefList);
    model.addAttribute("researchGroupList", researchGroupList);

    return "lists/fileMetadataParams/list";
}

From source file:io.github.proxyprint.kitchen.controllers.printshops.ReviewController.java

@ApiOperation(value = "Edit an existing printshop review", notes = "404 if the printshop or the review doesn't exist.")
@Secured({ "ROLE_USER" })
@RequestMapping(value = "/printshops/{printShopId}/reviews/{reviewId}", method = RequestMethod.PUT)
public ResponseEntity<String> editPrintShopReview(@PathVariable("printShopId") long printShopId,
        @PathVariable("reviewId") long reviewId, Principal principal, WebRequest request) {
    PrintShop pShop = this.printshops.findOne(printShopId);
    if (pShop == null) {
        return new ResponseEntity(HttpStatus.NOT_FOUND);
    }/*from  w ww .  j  a v a  2 s.co m*/

    Review review = this.reviews.findOne(reviewId);
    if (review == null) {
        return new ResponseEntity(HttpStatus.NOT_FOUND);
    } else if (!review.getConsumer().getUsername().equals(principal.getName())) {
        return new ResponseEntity(HttpStatus.UNAUTHORIZED);
    }

    pShop.removeReview(review);

    String reviewText = request.getParameter("review");
    int rating = Integer.parseInt(request.getParameter("rating"));

    review.setDescription(reviewText);
    review.setRating(rating);

    pShop.addReview(review);
    pShop.updatePrintShopRating();

    this.printshops.save(pShop);
    return new ResponseEntity(this.GSON.toJson(review), HttpStatus.OK);
}

From source file:cz.zcu.kiv.eegdatabase.logic.controller.list.experimentoptparamdef.ExperimentOptParamDefMultiController.java

@RequestMapping(value = "lists/experiment-optional-parameters/list.html", method = RequestMethod.GET)
public String showSelectForm(WebRequest webRequest, ModelMap model, HttpServletRequest request) {
    log.debug("Processing experimentOptParamDef list controller");
    SelectGroupCommand selectGroupCommand = new SelectGroupCommand();
    String defaultExperimentOptParamDef = messageSource.getMessage("label.defaultExperimentOptParamDef", null,
            RequestContextUtils.getLocale(request));
    fillAuthResearchGroupList(defaultExperimentOptParamDef);
    String idString = webRequest.getParameter("groupid");
    if (auth.isAdmin()) {
        if (idString != null) {
            int id = Integer.parseInt(idString);
            if (id != DEFAULT_ID) {
                fillExperimentOptParamDefList(id);
                selectGroupCommand.setResearchGroupId(id);
            } else {
                fillExperimentOptParamDefList(DEFAULT_ID);
                selectGroupCommand.setResearchGroupId(DEFAULT_ID);
            }//from w w w .  j a  v a  2 s .com

        } else {
            fillExperimentOptParamDefList(DEFAULT_ID);
            selectGroupCommand.setResearchGroupId(DEFAULT_ID);
        }
        model.addAttribute("userIsExperimenter", true);
    } else {
        if (!researchGroupList.isEmpty()) {
            if (idString != null) {
                int id = Integer.parseInt(idString);
                fillExperimentOptParamDefList(id);
                selectGroupCommand.setResearchGroupId(id);
            } else {
                int myGroup = researchGroupList.get(0).getResearchGroupId();
                fillExperimentOptParamDefList(myGroup);
                selectGroupCommand.setResearchGroupId(myGroup);
            }
            model.addAttribute("userIsExperimenter", auth.userIsExperimenter());
        } else {
            model.addAttribute("userIsExperimenter", false);
        }
    }
    model.addAttribute("selectGroupCommand", selectGroupCommand);
    model.addAttribute("experimentOptParamDefList", experimentOptParamDefList);
    model.addAttribute("researchGroupList", researchGroupList);

    return "lists/measurationAdditionalParams/list";
}

From source file:org.openmrs.module.cohort.web.controller.AddCohortAttributesController.java

@RequestMapping(value = "/module/cohort/addCohortAttributes.form", method = RequestMethod.POST)
public String onSubmit(WebRequest request, HttpSession httpSession, ModelMap model,
        @RequestParam(required = false, value = "cohortAttributeTypeId") Integer cohort_attribute_type,
        @RequestParam(required = false, value = "selectedvalue") String description,
        @ModelAttribute("cohortatt") CohortAttribute cohortattribute, BindingResult errors) {
    CohortService departmentService = Context.getService(CohortService.class);
    //PatientService patientService=Context.getService(PatientService.class);
    // List<String> cohortm=new ArrayList<String>();
    //CohortM cohort=null;
    CohortAttributeType a = null;/*from   ww  w. ja  v a 2  s . c  o  m*/
    Integer id = Integer.parseInt(request.getParameter("ca"));
    List<CohortM> cohort1 = departmentService.findCohort(id);
    if (description == "") {
        httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "Values cannot be null");
    }
    List<CohortAttributeType> att = departmentService.findCohortAttType(cohort_attribute_type);
    for (int i = 0; i < att.size(); i++) {
        a = att.get(i);
    }
    cohortattribute.setCohort(cohort1.get(0));
    cohortattribute.setValue(description);
    cohortattribute.setCohortAttributeType(a);
    departmentService.saveCohortAttributes(cohortattribute);
    httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "insertion success");
    if ("Next".equalsIgnoreCase(request.getParameter("next"))) {
        departmentService.saveCohortAttributes(cohortattribute);
        httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "insertion success");
        String redirectUrl = "/module/cohort/cPatients.form?cpid=" + cohortattribute.getCohort().getCohortId();
        return "redirect:" + redirectUrl;
    }
    return "redirect:" + "/module/cohort/addCohortAttributes.form?ca="
            + cohortattribute.getCohort().getCohortId();
}

From source file:org.easit.core.controllers.signin.SigninController.java

/**
 * Internal helpers/*from  w ww.j  av  a  2 s . c o  m*/
 * Exchange the authorization code for an access token
 */
private String exchange_code_for_access_token(WebRequest request) throws Exception {
    // Exchange the authorization code for an access token
    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost(environment.getProperty("flowManager.url")
            + environment.getProperty("flowManager.exchange_accesstoken"));

    // add header 
    List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
    urlParameters.add(new BasicNameValuePair("grant_type", "authorization_code"));
    urlParameters.add(new BasicNameValuePair("code", request.getParameter("code")));
    urlParameters.add(new BasicNameValuePair("redirect_uri",
            environment.getProperty("project.url") + "/oauth_signin/authorize_callback"));
    urlParameters.add(new BasicNameValuePair("client_id", environment.getProperty("flowManager.client_id")));
    urlParameters
            .add(new BasicNameValuePair("client_secret", environment.getProperty("flowManager.client_secret")));
    post.setEntity(new UrlEncodedFormEntity(urlParameters, "UTF-8"));

    //Exchange the authorization code for an access token
    HttpResponse response = client.execute(post);

    //NOT Correct answer
    if (response.getStatusLine().getStatusCode() != 200) {

        logger.info("ERROR:");
        logger.info("URL target: " + environment.getProperty("flowManager.url")
                + environment.getProperty("flowManager.exchange_accesstoken"));

        logger.info(post.toString());
        for (Header header : post.getAllHeaders()) {
            logger.info(header.getName() + " : " + header.getValue());
        }

        String content = EntityUtils.toString(new UrlEncodedFormEntity(urlParameters, "UTF-8"));
        logger.info("");
        logger.info(content);
        logger.info("");

        logger.info("Failed : HTTP error code : " + response.getStatusLine().getStatusCode());
        throw new Exception("Failed : HTTP error code : " + response.getStatusLine().getStatusCode());
    }

    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    StringBuffer result = new StringBuffer();
    String line = "";
    while ((line = rd.readLine()) != null) {
        result.append(line);
    }

    logger.info("ACCESS:" + result);

    //Extract the access token
    JSONObject json = new JSONObject(result.toString());
    Map<String, String> output = new HashMap<String, String>();
    CoreUtils.parse(json, output);
    return output.get("access_token");
}

From source file:org.openmrs.module.conceptsearch.web.controller.AdvancedSearchFormController.java

@RequestMapping(value = "/module/conceptsearch/advancedSearch", method = RequestMethod.POST)
public void performAdvancedSearch(ModelMap model, WebRequest request, HttpSession session) {
    ConceptSearchService searchService = (ConceptSearchService) Context.getService(ConceptSearchService.class);
    Collection<Concept> rslt = new Vector<Concept>();
    ConceptSearch cs = new ConceptSearch("");
    DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    Date dateFrom = null;/*from w  w  w. j  av a  2s  .c o  m*/
    Date dateTo = null;

    //get all search parameters
    String searchName = request.getParameter("conceptQuery");
    String searchDescription = request.getParameter("conceptDescription");
    String[] searchDatatypes = request.getParameterValues("conceptDatatype");
    String[] searchClassesString = request.getParameterValues("conceptClasses");
    String searchIsSet = request.getParameter("conceptIsSet");

    String searchDateFrom = request.getParameter("dateFrom");
    String searchDateTo = request.getParameter("dateTo");
    String[] searchUsedAs = request.getParameterValues("conceptUsedAs");

    try {
        if (searchDateFrom != null && !searchDateFrom.isEmpty())
            dateFrom = df.parse(searchDateFrom);
        if (searchDateTo != null && !searchDateTo.isEmpty())
            dateTo = df.parse(searchDateTo);
    } catch (ParseException ex) {
        log.error("Error converting strings to date ", ex);
        dateFrom = null;
        dateTo = null;
    }
    ;

    //check for correct selections
    if (searchDatatypes == null) {
        searchDatatypes = null;
        cs.setDataTypes(new Vector<ConceptDatatype>());
    }

    if (searchClassesString == null) {
        searchClassesString = null;
        cs.setConceptClasses(new Vector<ConceptClass>());
    }

    if (searchIsSet == null) {
        searchIsSet = null;
        cs.setIsSet(-1);
    } else {
        cs.setIsSet(Integer.parseInt(searchIsSet));
    }

    if (searchDateFrom == null || searchDateFrom.isEmpty()) {
        searchDateFrom = null;
    } else {
        cs.setDateFrom(dateFrom);
    }

    if (searchDateTo == null || searchDateTo.isEmpty()) {
        searchDateTo = null;
    } else {
        cs.setDateTo(dateTo);
    }

    if (searchUsedAs == null) {
        cs.setConceptUsedAs(null);
    } else {
        List<String> usedAsList = Arrays.asList(searchUsedAs);
        cs.setConceptUsedAs(usedAsList);
    }

    //maintain cs object: keep track of all entered information
    cs.setSearchQuery(searchName);

    if (searchDescription != null) {
        String[] searchTerms = searchDescription.split(" ");
        List<String> searchTermsList = Arrays.asList(searchTerms);
        cs.setSearchTerms(searchTermsList);
    }

    if (searchDatatypes != null) {
        List<String> searchDatatypesList = Arrays.asList(searchDatatypes);
        List<ConceptDatatype> dataTypesList = new Vector<ConceptDatatype>();

        for (String s : searchDatatypesList) {
            dataTypesList.add(searchService.getConceptDatatypeById(Integer.parseInt(s)));
        }
        cs.setDataTypes(dataTypesList);
    }

    if (searchClassesString != null) {
        List<String> searchClassesList = Arrays.asList(searchClassesString);
        List<ConceptClass> classesList = new Vector<ConceptClass>();

        for (String s : searchClassesList) {
            classesList.add(searchService.getConceptClassById(Integer.parseInt(s)));
        }
        cs.setConceptClasses(classesList);
    }

    //perform search using ConceptSearchService
    rslt = searchService.getConcepts(cs);

    //add the results to a DTO to avoid Hibernate's lazy loading
    List<ConceptSearchResult> resList = new ArrayList<ConceptSearchResult>();
    for (Concept c : rslt) {
        if (cs.getConceptUsedAs() == null || searchService.isConceptUsedAs(c, cs)) {
            ConceptSearchResult res = new ConceptSearchResult(c);
            res.setNumberOfObs(searchService.getNumberOfObsForConcept(c.getConceptId()));
            resList.add(res);
        }
    }

    // add results to ListHolder
    PagedListHolder resListHolder = new PagedListHolder(resList);
    resListHolder.setPageSize(DEFAULT_RESULT_PAGE_SIZE);

    //add results to view
    model.addAttribute("conceptSearch", cs);
    model.addAttribute("searchResult", resListHolder);

    //add search results to session to make them available for other methods
    session.setAttribute("conceptSearch", cs);
    session.setAttribute("searchResult", resListHolder);
    session.setAttribute("sortResults", resListHolder);

    //remember the last ten search queries
    List<ConceptSearch> historyQueries = (List<ConceptSearch>) session.getAttribute("historyQuery");
    if (historyQueries != null) {
        historyQueries.add(cs);

        if (historyQueries.size() > 10) {
            historyQueries.remove(historyQueries.remove(0));
        }
    } else {
        historyQueries = new ArrayList<ConceptSearch>();
        historyQueries.add(cs);
    }
    session.setAttribute("historyQuery", historyQueries);
}

From source file:org.openmrs.module.personalhr.web.controller.PhrUserFormController.java

@ModelAttribute("user")
public User formBackingObject(final WebRequest request,
        @RequestParam(required = false, value = "sharingToken") final String sharingToken,
        @RequestParam(required = false, value = "person_id") final Integer personId) {
    log.debug("Entering PhrUserFormController:formBackingObject: sharingToken=" + sharingToken + ", personId="
            + personId);//from ww  w .  j  a  v a  2s .  com

    final String userId = request.getParameter("userId");
    User u = null;
    try {
        u = Context.getUserService().getUser(Integer.valueOf(userId));
    } catch (final Exception ex) {
    }
    if (u == null) {
        u = new User();
        log.debug("Entering PhrUserFormController:formBackingObject...new User" + u);
    }
    if (personId != null) {
        Person per = Context.getPersonService().getPerson(personId);
        int count = per.getAttributeMap().size();
        log.debug("attributeMap size = " + count);
        u.setPerson(per);
    } else if (u.getPerson() == null) {
        final Person p = new Person();
        p.addName(new PersonName());
        u.setPerson(p);
        log.debug("Entering PhrUserFormController:formBackingObject...setPerson" + p);
    } else {
        int count = u.getPerson().getAttributeMap().size();
        log.debug("attributeMap size = " + count);
    }

    return u;
}