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

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

Introduction

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

Prototype

Map<String, String[]> getParameterMap();

Source Link

Document

Return a immutable Map of the request parameters, with parameter names as map keys and parameter values as map values.

Usage

From source file:edu.jhuapl.openessence.controller.ReportController.java

@RequestMapping("/chartJson")
public @ResponseBody Map<String, Object> chartJson(WebRequest request, HttpServletRequest servletRequest,
        @RequestParam("dsId") JdbcOeDataSource ds, ChartModel chartModel) throws ErrorMessageException {

    log.info(LogStatements.GRAPHING.getLoggingStmt() + request.getUserPrincipal().getName());

    final List<Filter> filters = new Filters().getFilters(request.getParameterMap(), ds, null, 0, null, 0);
    final List<Dimension> results = ControllerUtils.getResultDimensionsByIds(ds,
            request.getParameterValues("results"));

    Dimension filterDimension = null;
    if (results.get(0).getFilterBeanId() != null && results.get(0).getFilterBeanId().length() > 0) {
        filterDimension = ds.getFilterDimension(results.get(0).getFilterBeanId());
    }//from w ww .java2 s.c o m
    // if not provided, use the result dimension
    // it means name and id columns are same...
    if (filterDimension != null) {
        results.add(results.size(), filterDimension);
    }

    // Subset of results, should check
    final List<Dimension> charts = ControllerUtils.getResultDimensionsByIds(ds,
            request.getParameterValues("charts"));

    final List<Dimension> accumulations = ControllerUtils.getAccumulationsByIds(ds,
            request.getParameterValues("accumId"));

    final List<OrderByFilter> sorts = new ArrayList<OrderByFilter>();
    try {
        sorts.addAll(Sorters.getSorters(request.getParameterMap()));
    } catch (Exception e) {
        log.warn("Unable to get sorters, using default ordering");
    }

    // TODO put this on ChartModel
    //default to white allows clean copy paste of charts from browser
    Color backgroundColor = Color.WHITE;

    String bgParam = request.getParameter("backgroundColor");
    if (bgParam != null && !"".equals(bgParam)) {
        if ("transparent".equalsIgnoreCase(bgParam)) {
            backgroundColor = new Color(255, 255, 255, 0);
        } else {
            backgroundColor = ControllerUtils.getColorsFromHex(Color.WHITE, bgParam)[0];
        }
    }

    String graphBarUrl = request.getContextPath() + servletRequest.getServletPath() + "/report/graphBar";
    graphBarUrl = appendGraphFontParam(ds, graphBarUrl);

    String graphPieUrl = request.getContextPath() + servletRequest.getServletPath() + "/report/graphPie";
    graphPieUrl = appendGraphFontParam(ds, graphPieUrl);

    // TODO eliminate all the nesting in response and just use accumulation and chartID properties
    Map<String, Object> response = new HashMap<String, Object>();
    Map<String, Object> graphs = new HashMap<String, Object>();
    response.put("graphs", graphs);

    String clientTimezone = null;
    String timezoneEnabledString = messageSource.getMessage(TIMEZONE_ENABLED, "false");
    if (timezoneEnabledString.equalsIgnoreCase("true")) {
        clientTimezone = ControllerUtils.getRequestTimezoneAsHourMinuteString(request);
    }
    Collection<Record> records = new DetailsQuery().performDetailsQuery(ds, results, accumulations, filters,
            sorts, false, clientTimezone);
    final List<Filter> graphFilters = new Filters().getFilters(request.getParameterMap(), ds, null, 0, null, 0,
            false);
    //for each requested accumulation go through each requested result and create a chart
    for (Dimension accumulation : accumulations) {
        Map<String, Object> accumulationMap = new HashMap<String, Object>();
        // Create charts for dimensions (subset of results)
        for (Dimension chart : charts) {
            DefaultGraphData data = new DefaultGraphData();
            data.setGraphTitle(chartModel.getTitle());
            data.setGraphHeight(chartModel.getHeight());
            data.setGraphWidth(chartModel.getWidth());
            data.setShowLegend(chartModel.isLegend());
            data.setBackgroundColor(backgroundColor);
            data.setShowGraphLabels(chartModel.isShowGraphLabels());
            data.setLabelBackgroundColor(backgroundColor);
            data.setPlotHorizontal(chartModel.isPlotHorizontal());
            data.setNoDataMessage(chartModel.getNoDataMessage());
            data.setTitleFont(new Font("Arial", Font.BOLD, 12));

            GraphObject graph = createGraph(ds, request.getUserPrincipal().getName(), records, chart,
                    filterDimension, accumulation, data, chartModel, graphFilters);
            String graphURL = "";
            if (BAR.equalsIgnoreCase(chartModel.getType())) {
                graphURL = graphBarUrl;
            } else if (PIE.equalsIgnoreCase(chartModel.getType())) {
                graphURL = graphPieUrl;
            }
            graphURL = appendUrlParameter(graphURL, "graphDataId", graph.getGraphDataId());

            chartModel.setImageUrl(graphURL);
            chartModel.setImageMap(graph.getImageMap());
            chartModel.setImageMapName(graph.getImageMapName());

            accumulationMap.put(chart.getId(), chartModel);
        }
        graphs.put(accumulation.getId(), accumulationMap);
    }

    log.info(String.format("Chart JSON Details query for %s", request.getUserPrincipal().getName()));

    return response;
}

From source file:edu.jhuapl.openessence.controller.ReportController.java

@RequestMapping("/timeSeriesJson")
public @ResponseBody Map<String, Object> timeSeriesJson(@RequestParam("dsId") JdbcOeDataSource ds,
        TimeSeriesModel model, Principal principal, WebRequest request, HttpServletRequest servletRequest)
        throws ErrorMessageException {

    Map<String, Object> result = new HashMap<String, Object>();

    DataSeriesSource dss = null;/*w w w. j av a2s .  com*/
    if (ds instanceof DataSeriesSource) {
        dss = (DataSeriesSource) ds;

    }

    String groupId = "";
    String resolution = "";

    // TODO put this logic in a custom HandlerMethodArgumentResolver
    if (model.getTimeseriesGroupResolution() != null) {
        String[] parts = model.getTimeseriesGroupResolution().split(":");
        if (parts.length == 2 && !parts[0].trim().isEmpty() && !parts[1].trim().isEmpty()) {
            groupId = parts[0];
            resolution = parts[1];
        }
    }

    if (groupId == null || groupId.isEmpty()) {
        throw new OeDataSourceException("No Grouping Dimension ID specified");
    }

    GroupingDimension groupingDim = dss.getGroupingDimension(groupId);
    // find resolution handlers as appropriate for groupings
    if (resolution == null || "".equals(groupId)) {
        String[] res = groupingDim.getResolutions().toArray(new String[groupingDim.getResolutions().size()]);
        if (res.length > 0) {
            resolution = res[0];
        }
    }

    if (ds.getDimensionJoiner() != null) {
        ds.getDimensionJoiner().joinDimensions();
    }

    List<Dimension> accumulations = ControllerUtils.getAccumulationsByIds(ds, model.getAccumId());
    List<Dimension> timeseriesDenominators = ControllerUtils.getAccumulationsByIds(ds,
            model.getTimeseriesDenominator(), false);

    final List<OrderByFilter> sorts = new ArrayList<OrderByFilter>();
    GroupingImpl group = new GroupingImpl(groupId, resolution);

    if (resolution.equals(DAILY) && model.getPrepull() < 0) {
        model.setPrepull(DEFAULT_DAILY_PREPULL);
    }

    if (model.getPrepull() < 0) {
        model.setPrepull(0);
    }

    //union accumulations to get all results
    List<Dimension> dimensions = new ArrayList<Dimension>(
            ControllerUtils.unionDimensions(accumulations, timeseriesDenominators));
    List<Grouping> groupings = new ArrayList<Grouping>();
    groupings.add(groupingDim.makeGrouping(resolution));

    //create results group dimension + all dimensions
    final List<Dimension> results = new ArrayList<Dimension>();
    for (Dimension d : dimensions) {
        results.add(ds.getResultDimension(d.getId()));
    }

    Map<String, ResolutionHandler> resolutionHandlers = dss.getGroupingDimension(group.getId())
            .getResolutionsMap();
    List<Filter> filters = new Filters().getFilters(request.getParameterMap(), dss, group.getId(),
            model.getPrepull(), resolution, getCalWeekStartDay(resolutionHandlers));

    String clientTimezone = null;
    String timezoneEnabledString = messageSource.getMessage(TIMEZONE_ENABLED, "false");
    if (timezoneEnabledString.equalsIgnoreCase("true")) {
        clientTimezone = ControllerUtils.getRequestTimezoneAsHourMinuteString(request);
    }
    //details query for all records
    Collection<Record> records = new DetailsQuery().performDetailsQuery(ds, results, dimensions, filters, sorts,
            groupings, false, clientTimezone);

    //create graph data and set known configuration
    DefaultGraphData graphData = new DefaultGraphData();
    graphData.setShowSingleSeverityLegends(false);
    graphData.setGraphTitle(model.getTimeseriesTitle());
    graphData.setGraphWidth(model.getWidth());
    graphData.setGraphHeight(model.getHeight());
    graphData.setShowLegend(true);
    graphData.setBackgroundColor(new Color(255, 255, 255, 0));

    // only set an array if they provided one
    if (model.getGraphBaseColors() != null && model.getGraphBaseColors().length > 0) {
        // TODO leverage Spring to convert colors
        graphData.setGraphBaseColors(ControllerUtils.getColorsFromHex(Color.BLACK, model.getGraphBaseColors()));
    }

    String graphTimeSeriesUrl = request.getContextPath() + servletRequest.getServletPath()
            + "/report/graphTimeSeries";
    graphTimeSeriesUrl = appendGraphFontParam(ds, graphTimeSeriesUrl);

    //TODO, this still uses the html method from the graph module and then wraps in json...move to a pure json method
    Map<String, Object> timeseriesResult = createTimeseries(principal.getName(), dss, filters, group,
            resolution, model.getPrepull(), graphTimeSeriesUrl, records, accumulations, timeseriesDenominators,
            model.getTimeseriesDetectorClass(), model.isIncludeDetails(), model.isDisplayIntervalEndDate(),
            graphData, ControllerUtils.getRequestTimezone(request));

    result.putAll(timeseriesResult);

    return result;
}

From source file:org.codehaus.groovy.grails.scaffolding.DefaultScaffoldRequestHandler.java

public Map handleSave(HttpServletRequest request, HttpServletResponse reponse, ScaffoldCallback callback) {

    Object domainObject = domain.newInstance();
    WebRequest webRequest = (WebRequest) RequestContextHolder.currentRequestAttributes();
    InvokerHelper.setProperty(domainObject, "properties", webRequest.getParameterMap());

    Errors domainObjectErrors = (Errors) InvokerHelper.getProperty(domainObject, "errors");

    Map model = new HashMap();
    model.put(domain.getSingularName(), domainObject);

    if (!domainObjectErrors.hasErrors() && this.domain.save(domainObject, callback)) {
        BeanWrapper domainBean = new BeanWrapperImpl(domainObject);
        Object identity = domainBean.getPropertyValue(domain.getIdentityPropertyName());
        model.put(PARAM_ID, identity);/*from  w ww .j a v  a 2s  .com*/
        callback.setInvoked(true);
    }
    return model;
}

From source file:org.codehaus.groovy.grails.scaffolding.DefaultScaffoldRequestHandler.java

public Map handleUpdate(HttpServletRequest request, HttpServletResponse reponse, ScaffoldCallback callback) {
    Serializable id = getRequestId();
    if (id == null) {
        LOG.debug("[ScaffoldRequestHandler] No ID parameter [" + id + "] for request [update]");
        callback.setInvoked(false);/*from w w  w.j a va2s .co  m*/
        return Collections.EMPTY_MAP;
    }

    Object domainObject = this.domain.get(id);
    WebRequest webRequest = (WebRequest) RequestContextHolder.currentRequestAttributes();
    InvokerHelper.setProperty(domainObject, "properties", webRequest.getParameterMap());

    Errors domainObjectErrors = (Errors) InvokerHelper.getProperty(domainObject, "errors");

    Map model = new HashMap();
    model.put(this.domain.getSingularName(), domainObject);
    model.put(PARAM_ID, id);
    // execute update
    if (!domainObjectErrors.hasErrors() && this.domain.update(domainObject, callback)) {
        callback.setInvoked(true);
    } else {
        callback.setInvoked(false);
    }
    return model;
}