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:org.openmrs.web.controller.location.LocationAttributeTypeFormController.java

/**
 * Handle submission for create or edit/*from  www.  j  av a2  s .  co  m*/
 */
@RequestMapping(value = "/admin/locations/locationAttributeType", method = RequestMethod.POST)
public String handleSubmit(WebRequest request,
        @ModelAttribute("attributeType") LocationAttributeType attributeType, BindingResult errors) {

    LocationService service = Context.getLocationService();

    if (request.getParameter("purge") != null) {
        try {
            service.purgeLocationAttributeType(attributeType);
            request.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "LocationAttributeType.purgedSuccessfully",
                    WebRequest.SCOPE_SESSION);
        } catch (Exception e) {
            request.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "error.object.inuse.cannot.purge",
                    WebRequest.SCOPE_SESSION);
        }
        return "redirect:locationAttributeTypes.list";
    }

    new LocationAttributeTypeValidator().validate(attributeType, errors);

    if (errors.hasErrors()) {
        return null; // redisplay the form

    } else {

        if (request.getParameter("save") != null) {
            Context.getLocationService().saveLocationAttributeType(attributeType);
            request.setAttribute(WebConstants.OPENMRS_MSG_ATTR,
                    Context.getMessageSourceService().getMessage("LocationAttributeType.saved"),
                    WebRequest.SCOPE_SESSION);
        } else if (request.getParameter("retire") != null) {
            String retireReason = request.getParameter("retireReason");
            if (attributeType.getId() != null && !(StringUtils.hasText(retireReason))) {
                errors.reject("retireReason", "general.retiredReason.empty");
                return null;
            }
            Context.getLocationService().retireLocationAttributeType(attributeType, retireReason);
            request.setAttribute(WebConstants.OPENMRS_MSG_ATTR,
                    Context.getMessageSourceService().getMessage("LocationAttributeType.retired"),
                    WebRequest.SCOPE_SESSION);
        } else if (request.getParameter("unretire") != null) {
            Context.getLocationService().unretireLocationAttributeType(attributeType);
            request.setAttribute(WebConstants.OPENMRS_MSG_ATTR,
                    Context.getMessageSourceService().getMessage("LocationAttributeType.unretired"),
                    WebRequest.SCOPE_SESSION);
        }
        return "redirect:/admin/locations/locationAttributeTypes.list";
    }
}

From source file:com.blackducksoftware.tools.appedit.web.controller.appdetails.EditAppDetailsController.java

private AppDetails loadApplication(WebRequest request) throws AppEditControllerException {
    String appId = request.getParameter("appId");
    String appName = request.getParameter("appName");
    // Load application
    AppDetails appDetails = null;/*from  ww  w . j  a  va  2s.  c  o  m*/
    try {
        // load app from Code Center using whatever info we were given (try
        // ID first)
        if (appId != null) {
            appDetails = appService.loadFromId(appId, true);
        } else {
            appDetails = appService.loadFromName(appName, true);
        }
    } catch (Exception e) {
        String msg = "Error loading application: " + e.getMessage();
        throw new AppEditControllerException("error/programError", msg);
    }

    if (appDetails == null) {
        String msg = "Application not found";
        throw new AppEditControllerException("error/programError", msg);
    }
    return appDetails;
}

From source file:org.gvsig.framework.web.controllers.OGCInfoController.java

/**
 * Get layer FeatureInfo of service WMS and show it in page
 *
 * @param request the {@code HttpServletRequest}.
 * @param uiModel the {@code Model}.//from   w ww  .java 2  s.  co m
 * @return ResponseEntity with FeatureInfo data of wms server
 */
@RequestMapping(params = "getWmsFeatureInfo", headers = "Accept=application/json")
public ResponseEntity<String> getWmsFeatureInfo(WebRequest request, Model uiModel) {
    String urlServer = request.getParameter("url");
    String crs = request.getParameter("crs");
    String layers = request.getParameter("layers");
    String styles = request.getParameter("styles");
    int x = Integer.parseInt(request.getParameter("pointX"));
    int y = Integer.parseInt(request.getParameter("pointY"));
    int heigth = Integer.parseInt(request.getParameter("mapHeight"));
    int width = Integer.parseInt(request.getParameter("mapWidth"));
    String bounds = request.getParameter("bounds");

    String featureInfo = null;

    Vector<String> layersVector = new Vector<String>();
    if (StringUtils.isNotEmpty(layers)) {
        Collections.addAll(layersVector, layers.split(","));
    }

    Vector<String> stylesVector = new Vector<String>();
    if (StringUtils.isNotBlank(styles)) {
        Collections.addAll(stylesVector, styles.split(","));
    }

    List<String> boundsTree = new ArrayList<String>();
    if (StringUtils.isNotBlank(bounds)) {
        Collections.addAll(boundsTree, bounds.split(","));
    }

    if (StringUtils.isNotEmpty(urlServer)) {
        featureInfo = ogcInfoServ.getFeatureInfoFromWMS(urlServer, crs, layersVector, stylesVector, x, y,
                heigth, width, boundsTree);
    }

    return new ResponseEntity<String>(featureInfo, HttpStatus.OK);
}

From source file:com.seajas.search.profiler.controller.BrowseController.java

/**
 * Data attribute.//from   w  w  w  .j a va2s .  c  om
 * 
 * @param request
 * @return RepositoryResult
 */
@ModelAttribute("data")
public RepositoryResult populateData(final WebRequest request) {
    // Retrieve the collection

    String collection = !StringUtils.isEmpty(request.getParameter(PARAM_COLLECTION))
            ? request.getParameter(PARAM_COLLECTION)
            : null;

    // Retrieve the start and end dates

    String startDateValue = !StringUtils.isEmpty(request.getParameter(PARAM_START_DATE))
            ? request.getParameter(PARAM_START_DATE)
            : null;
    String endDateValue = !StringUtils.isEmpty(request.getParameter(PARAM_END_DATE))
            ? request.getParameter(PARAM_END_DATE)
            : null;

    Date startDate = null, endDate = null;

    if (startDateValue != null || endDateValue != null) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");

        if (startDateValue != null)
            try {
                startDate = dateFormat.parse(startDateValue);
            } catch (ParseException e) {
                startDate = null;
            }

        if (endDateValue != null)
            try {
                endDate = dateFormat.parse(endDateValue);
            } catch (ParseException e) {
                endDate = null;
            }
    }

    // Retrieve an optional parameter

    Map<String, String> requestParameters = new HashMap<String, String>();

    String requestParameterName = !StringUtils.isEmpty(request.getParameter(PARAM_REQUEST_PARAMETER_NAME))
            ? request.getParameter(PARAM_REQUEST_PARAMETER_NAME)
            : null;
    String requestParameterValue = !StringUtils.isEmpty(request.getParameter(PARAM_REQUEST_PARAMETER_VALUE))
            ? request.getParameter(PARAM_REQUEST_PARAMETER_VALUE)
            : null;

    if (requestParameterName != null && requestParameterValue != null)
        requestParameters.put(requestParameterName, requestParameterValue);

    // Retrieve the feed and page numbers

    Integer sourceId, page, results;

    try {
        sourceId = Integer.valueOf(
                !StringUtils.isEmpty(request.getParameter(PARAM_SOURCE)) ? request.getParameter(PARAM_SOURCE)
                        : null);
    } catch (NumberFormatException e) {
        sourceId = null;
    }

    try {
        page = Integer.valueOf(
                !StringUtils.isEmpty(request.getParameter(PARAM_PAGE)) ? request.getParameter(PARAM_PAGE)
                        : null);
    } catch (NumberFormatException e) {
        page = null;
    }

    try {
        results = Integer.valueOf(!StringUtils.isEmpty(request.getParameter(PARAM_RESULTS_PER_PAGE))
                ? request.getParameter(PARAM_RESULTS_PER_PAGE)
                : null);
    } catch (NumberFormatException e) {
        results = null;
    }

    return repositoryService.findResources(collection, sourceId, null, startDate, endDate,
            page != null ? page : 0, results != null && results > 0 ? results : MAX_RESULTS_PER_PAGE,
            requestParameters);
}

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

@RequestMapping(value = "/module/cohort/addCohortMemberAttributeType.form", method = RequestMethod.POST)
public String onSubmit(WebRequest request, HttpSession httpSession, ModelMap model,
        @ModelAttribute("cohortattributes") CohortMemberAttributeType cohortMemberAttributeType,
        BindingResult errors) {//w  ww  .  ja va2 s.c  om
    CohortService departmentService = Context.getService(CohortService.class);
    String voided = request.getParameter("voided");
    String format = request.getParameter("format");
    this.validator.validate(cohortMemberAttributeType, errors);
    if (errors.hasErrors()) {
        System.out.println("BR has errors: " + errors.getErrorCount());
        System.out.println(errors.getAllErrors());
        return "/module/cohort/addCohortMemberAttributeType";
    } else {
        cohortMemberAttributeType.setFormat(format);
        departmentService.saveCohortMemberAttributeType(cohortMemberAttributeType);
        httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "insertion success");
    }
    return null;
}

From source file:com.seajas.search.profiler.controller.FeedController.java

/**
 * Data attribute.//from  w  w w . j  a  va  2  s  .c o  m
 * 
 * @param request
 * @return FeedPagingResult
 */
@ModelAttribute("data")
public FeedPagingResult populateData(final WebRequest request) {
    String filterQuery = request.getParameter(PARAM_QUERY);

    // Retrieve the feed and page numbers

    Integer page, results;

    try {
        page = Integer.valueOf(
                StringUtils.hasText(request.getParameter(PARAM_PAGE)) ? request.getParameter(PARAM_PAGE)
                        : null);
    } catch (NumberFormatException e) {
        page = 0;
    }

    try {
        results = Integer.valueOf(StringUtils.hasText(request.getParameter(PARAM_RESULTS_PER_PAGE))
                ? request.getParameter(PARAM_RESULTS_PER_PAGE)
                : null);
    } catch (NumberFormatException e) {
        results = MAX_RESULTS_PER_PAGE;
    }

    return retrieveData(filterQuery, page, results);
}

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

@RequestMapping(value = "/module/conceptsearch/advancedSearch", method = RequestMethod.GET, params = "history")
public void loadPastSearchResults(ModelMap model, WebRequest request, HttpSession session) {
    String sHistory = request.getParameter("history");
    int iHistory = Integer.parseInt(sHistory);

    //get past searches
    List<ConceptSearch> historyQueries = (List<ConceptSearch>) session.getAttribute("historyQuery");

    //check if value is valid
    if (historyQueries != null && iHistory > 0 && iHistory <= historyQueries.size()) {

        ConceptSearchService searchService = (ConceptSearchService) Context
                .getService(ConceptSearchService.class);
        Collection<Concept> rslt = new Vector<Concept>();

        ConceptSearch cs = historyQueries.get(iHistory - 1);

        //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);/*from   w w  w  . j a  v  a2  s  . c  o  m*/
            }
        }

        // 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", resList);
        session.setAttribute("sortResults", resListHolder);

    } else {
        log.error("ConceptSearch (cs) index is invalid!");
    }
}

From source file:org.gvsig.framework.web.controllers.OGCInfoController.java

/**
 * Get bounding box for a layers specified.
 * The result can be null if the service haven't defined the values
 * of bounding box.//from   w w  w. ja  v a2  s  .c  o m
 *
 * @param request the {@code HttpServletRequest}.
 * @return ResponseEntity with wmtsInfo
 */
@RequestMapping(value = "/getLayerBoundingBox", headers = "Accept=application/json", produces = {
        "application/json; charset=UTF-8" })
@ResponseBody
public ResponseEntity<List<String>> getLayersBoundingBoxByAjax(WebRequest request) {

    List<String> boundingBox = null;

    String urlServer = request.getParameter("url");
    String typeLayer = request.getParameter("type");
    String crs = request.getParameter("crs");
    String layers = request.getParameter("layers");

    if (StringUtils.isNotEmpty(crs) && StringUtils.isNotEmpty(urlServer) && StringUtils.isNotEmpty(typeLayer)
            && StringUtils.isNotEmpty(layers)) {

        TreeSet<String> listLayers = new TreeSet<String>();
        Collections.addAll(listLayers, layers.split(","));
        boundingBox = ogcInfoServ.getLayersBoundingBox(urlServer, typeLayer, crs, listLayers);
    }

    return new ResponseEntity<List<String>>(boundingBox, HttpStatus.OK);
}

From source file:org.openmrs.web.controller.concept.ConceptAttributeTypeFormController.java

@RequestMapping(value = "/admin/concepts/conceptAttributeType", method = RequestMethod.POST)
public String handleSubmit(WebRequest request,
        @ModelAttribute("attributeType") ConceptAttributeType conceptAttributeType, BindingResult errors) {
    if (Context.isAuthenticated()) {
        ConceptService conceptService = Context.getConceptService();
        if (request.getParameter("purge") != null) {
            return purgeConceptAttributeType(request, conceptAttributeType, conceptService);
        }//from w  w  w. j ava 2s . c o  m
        new ConceptAttributeTypeValidator().validate(conceptAttributeType, errors);
        if (!errors.hasErrors()) {
            if (request.getParameter("retire") != null) {
                return retireConceptAttributeType(request, conceptAttributeType, errors);
            }
            if (request.getParameter("save") != null) {
                return saveConceptAttributeType(request, conceptAttributeType, conceptService);
            }
            if (request.getParameter("unretire") != null) {
                return unretireConceptAttributeType(request, conceptAttributeType);
            }
        }
    }
    return null;
}

From source file:mailjimp.webhook.WebHookController.java

private WebHookData buildData(WebRequest request, final WebHookData data)
        throws ParseException, MailJimpException {
    data.setFiredAt(MailJimpConstants.SDF.parse(request.getParameter("fired_at")));
    data.setRawData(parseRequest(request));
    if (WebHookType.SUBSCRIBE == data.getType() || WebHookType.UNSUBSCRIBE == data.getType()
            || WebHookType.UPDATE_PROFILE == data.getType()) {
        try {//www.  j  av  a2 s .  c  o  m
            final StringWriter json = new StringWriter();
            m.writeValue(json, data.getRawData());
            LOG.debug("JSON: {}", json.toString());
            MemberInfo val = m.readValue(json.toString(), MemberInfo.class);
            data.setMemberInfo(val);
        } catch (Exception ex) {
            LOG.error("Could not convert data to MemberInfo object.", ex);
            throw new MailJimpException("Could not convert data to MemberInfo object.", ex);
        }
    }
    return data;
}