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

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

Introduction

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

Prototype

@Nullable
String[] getParameterValues(String paramName);

Source Link

Document

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

Usage

From source file:me.j360.trace.server.ZipkinQueryApiV1.java

@RequestMapping(value = "/trace/{traceId}", method = RequestMethod.GET, produces = APPLICATION_JSON_VALUE)
public byte[] getTrace(@PathVariable String traceId, WebRequest request) {
    long id = lowerHexToUnsignedLong(traceId);
    String[] raw = request.getParameterValues("raw"); // RequestParam doesn't work for param w/o value
    List<Span> trace = raw != null ? storage.spanStore().getRawTrace(id) : storage.spanStore().getTrace(id);

    if (trace == null) {
        throw new TraceNotFoundException(traceId, id);
    }//from www  .  j  av a2s. co m
    return Codec.JSON.writeSpans(trace);
}

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

/**
 * Render the submit action in the same way as a regular page view is rendered.
 * //from ww w .ja  v  a2 s.  c o  m
 * @param command
 * @param result
 * @param model
 * @param request
 * @return String
 * @throws Exception
 */
@RequestMapping(method = RequestMethod.POST)
public String processSubmit(@ModelAttribute("archiveCommand") final ArchiveCommand command,
        final BindingResult result, final ModelMap model, final WebRequest request) throws Exception {
    Collection<String> archiveUrls = new Vector<String>();

    if (request.getParameterValues("archiveUrls") != null)
        for (String archiveUrl : request.getParameterValues("archiveUrls"))
            archiveUrls.add(archiveUrl);

    command.setArchiveUrls(archiveUrls);

    if (request.getParameter("isEnabled") == null)
        command.setIsEnabled(false);

    validator.validate(command, result);

    if (!result.hasErrors()) {
        if (command.getAction().equals("add"))
            profilerService.addArchive(command.getName(), command.getDescription(),
                    command.getTransformerContent(), command.getInternalLink(), command.getDeletionExpression(),
                    command.getExclusionExpression(), command.getArchiveUrls(), command.getIsEnabled());
        else if (command.getAction().equals("edit"))
            profilerService.modifyArchive(command.getId(), command.getName(), command.getDescription(),
                    command.getTransformerContent(), command.getInternalLink(), command.getDeletionExpression(),
                    command.getExclusionExpression(), command.getArchiveUrls(), command.getIsEnabled());
        else if (command.getAction().equals("delete"))
            profilerService.deleteArchive(command.getId());

        // Re-populate the data

        model.put("data", populateData());

        command.clear();
    }

    return "archives";
}

From source file:net.opentsdb.contrib.tsquare.web.controller.ExtendedApiController.java

@RequestMapping(value = "/q", method = RequestMethod.GET)
public ModelAndView query(@RequestParam(required = true) String start,
        @RequestParam(required = false) String end,
        @RequestParam(required = false, defaultValue = "false") boolean summarize,
        @RequestParam(required = false, defaultValue = "ts") String format,
        @RequestParam(required = false, defaultValue = "false") boolean ms, // millisecond resolution?
        final WebRequest webRequest) throws IOException {

    final String[] inputMetricNames = webRequest.getParameterValues("m");
    Preconditions.checkArgument(inputMetricNames != null && inputMetricNames.length > 0,
            "Input metric names are required.");

    final QueryDurationParams durationParams = parseDurations(start, end);
    if (log.isInfoEnabled()) {
        log.info("{}", durationParams);
    }//  ww w .  j  a  va  2s.  c o  m

    // Prepare queries...
    final MetricParser parser = getTsdbManager().newMetricParser();

    final DataQueryModel model = new DataQueryModel();

    for (final String t : inputMetricNames) {
        final Query q = getTsdbManager().newMetricsQuery();
        durationParams.contributeToQuery(q);

        final Metric metric = parser.parseMetric(t);
        if (summarize) {
            Preconditions.checkState(metric.getAggregator() != null,
                    "A metric-level aggregator is required when 'summarize' is enabled.  Metric: {}", t);
        }

        metric.contributeToQuery(q);
        model.addQuery(new AnnotatedDataQuery(metric, q));
        if (summarize) {
            log.info("Added {} to query (w/ summary) ", metric);
        } else {
            log.info("Added {} to query ", metric);
        }
    }

    if (summarize) {
        model.setResponseWriter(new SummarizedJsonResponseWriter(ms));
    } else if ("highcharts".equalsIgnoreCase(format)) {
        model.setResponseWriter(new HighchartsSeriesResponseWriter(ms));
    } else {
        final GraphiteJsonResponseWriter writer = new GraphiteJsonResponseWriter(ms)
                .setIncludeAggregatedTags(true).setIncludeAllTags(true).setSummarize(false);

        model.setResponseWriter(writer);
    }

    return model.toModelAndView();
}

From source file:zipkin.server.ZipkinQueryApiV1.java

@RequestMapping(value = "/trace/{traceIdHex}", method = RequestMethod.GET, produces = APPLICATION_JSON_VALUE)
public String getTrace(@PathVariable String traceIdHex, WebRequest request) {
    long traceIdHigh = traceIdHex.length() == 32 ? lowerHexToUnsignedLong(traceIdHex, 0) : 0L;
    long traceIdLow = lowerHexToUnsignedLong(traceIdHex);
    String[] raw = request.getParameterValues("raw"); // RequestParam doesn't work for param w/o value
    List<Span> trace = raw != null ? storage.spanStore().getRawTrace(traceIdHigh, traceIdLow)
            : storage.spanStore().getTrace(traceIdHigh, traceIdLow);
    if (trace == null) {
        throw new TraceNotFoundException(traceIdHex, traceIdHigh, traceIdLow);
    }//from www.  j  a va2s. c  o m
    return new String(Codec.JSON.writeSpans(trace), UTF_8);
}

From source file:org.openmrs.module.register.web.controller.ManageRegisterListController.java

@RequestMapping(method = RequestMethod.POST)
public String onSubmit(WebRequest request, HttpServletResponse response, HttpSession httpSession,
        @ModelAttribute("registers") List<Register> registers, BindingResult errors) {
    MessageSourceService mss = Context.getMessageSourceService();

    String success = "";
    String error = "";
    String[] registerIds = request.getParameterValues("registerId");
    if (registerIds != null) {
        RegisterService registerService = (RegisterService) Context.getService(RegisterService.class);

        String deleted = mss.getMessage("general.deleted");
        String notDeleted = mss.getMessage("register.delete.error");

        for (String id : registerIds) {
            try {
                registerService.deleteRegister(new Integer(id));
                if (!success.equals(""))
                    success += "<br/>";
                success += id + " " + deleted;
            } catch (DataIntegrityViolationException e) {
                error = handleRegisterIntegrityException(e, error, notDeleted);
            } catch (APIException e) {
                error = handleRegisterIntegrityException(e, error, notDeleted);
            }/*from   w  w  w  .  j  a  v  a2  s . c  o m*/
        }
    } else {
        httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "register.must.select");
    }

    if (!success.equals(""))
        httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, success);
    if (!error.equals(""))
        httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, error);

    return "redirect:" + MANAGE_REGISTER_LIST;
}

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

/**
 * Render the submit action in the same way as a regular page view is rendered.
 * // w  w w  .j  a  va  2s.  c om
 * @param command
 * @param result
 * @param model
 * @param request
 * @return String
 */
@RequestMapping(method = RequestMethod.POST)
public String processSubmit(@ModelAttribute("feedCommand") final FeedCommand command,
        final BindingResult result, final ModelMap model, final WebRequest request) {
    Collection<String> feedUrls = new ArrayList<String>();

    if (request.getParameterValues("feedUrls") != null)
        for (String feedUrl : request.getParameterValues("feedUrls"))
            if (StringUtils.hasText(feedUrl))
                feedUrls.add(feedUrl);

    command.setFeedUrls(feedUrls);

    Map<String, String> feedResultParameters = new LinkedHashMap<String, String>();

    if (request.getParameterValues("feedParameterKeys") != null)
        for (int i = 0; i < request.getParameterValues("feedParameterKeys").length; i++)
            if (StringUtils.hasText(request.getParameterValues("feedParameterKeys")[i])
                    || StringUtils.hasText(request.getParameterValues("feedParameterValues")[i]))
                feedResultParameters.put(request.getParameterValues("feedParameterKeys")[i],
                        request.getParameterValues("feedParameterValues")[i]);

    command.setFeedParameterKeys(feedResultParameters.keySet());
    command.setFeedParameterValues(feedResultParameters.values());

    if (request.getParameter("isEnabled") == null)
        command.setIsEnabled(false);
    if (request.getParameter("isSummaryBased") == null)
        command.setIsSummaryBased(false);

    validator.validate(command, result);

    if (!result.hasErrors()) {
        Integer landingPage = 0;

        if (command.getAction().equals("add")) {
            Integer feedId = profilerService.addFeed(command.getName(), command.getDescription(),
                    command.getCollection(), command.getFeedEncodingOverride(),
                    command.getResultEncodingOverride(), command.getLanguage(), command.getFeedUrls(),
                    feedResultParameters, command.getIsSummaryBased(), command.getIsEnabled());

            if (feedId != null
                    && (StringUtils.hasText(command.getQueue()) || StringUtils.hasText(command.getStrategy())))
                profilerService.addFeedConnection(feedId,
                        StringUtils.hasText(command.getQueue()) ? command.getQueue() : null,
                        StringUtils.hasText(command.getStrategy()) ? command.getStrategy() : null);

            landingPage = -1;
        } else if (command.getAction().equals("edit")) {
            profilerService.modifyFeed(command.getId(), command.getName(), command.getDescription(),
                    command.getCollection(), command.getFeedEncodingOverride(),
                    command.getResultEncodingOverride(), command.getLanguage(), command.getFeedUrls(),
                    feedResultParameters, command.getIsSummaryBased(), command.getIsEnabled());

            // Always remove the feed connection explicitly, and then re-add it if needed

            profilerService.deleteFeedConnection(command.getId());

            if (StringUtils.hasText(command.getQueue()) || StringUtils.hasText(command.getStrategy())) {
                profilerService.addFeedConnection(command.getId(),
                        StringUtils.hasText(command.getQueue()) ? command.getQueue() : null,
                        StringUtils.hasText(command.getStrategy()) ? command.getStrategy() : null);
            }

            // TODO: Feed anonymization settings

            try {
                landingPage = Integer.valueOf(
                        StringUtils.hasText(request.getParameter(PARAM_PAGE)) ? request.getParameter(PARAM_PAGE)
                                : null);
            } catch (NumberFormatException e) {
                landingPage = 0;
            }
        } else if (command.getAction().equals("delete")) {
            if (repositoryService.deleteResources(null, command.getId(), null, null, null))
                profilerService.deleteFeed(command.getId());

            landingPage = 0;
        }

        // Re-populate the data

        String filterQuery = request.getParameter(PARAM_QUERY);

        Integer results;

        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;
        }

        model.put("data", retrieveData(filterQuery, landingPage, results));

        command.clear();
    }

    return "feeds";
}

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 a  v 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:com.seajas.search.attender.controller.ProfileController.java

/**
 * Render the submit action in the same way as a regular page view is rendered.
 * /*from   w ww .  j  a  v  a2s.  co  m*/
 * @param command
 * @param result
 * @param model
 * @param request
 * @return String
 * @throws Exception
 */
@RequestMapping(method = RequestMethod.POST)
public String processSubmit(@ModelAttribute("profileCommand") final ProfileCommand command,
        final BindingResult result, final ModelMap model, final WebRequest request) throws Exception {
    // Collect and set the subscribers by the individual values

    List<String> subscriberEmails = new ArrayList<String>();
    List<String> subscriberEmailLanguages = new ArrayList<String>();
    List<String> subscriberTimeZones = new ArrayList<String>();
    List<String> subscriberTypes = new ArrayList<String>();
    List<String> subscriberDays = new ArrayList<String>();
    List<String> subscriberHours = new ArrayList<String>();
    List<String> subscriberMinutes = new ArrayList<String>();
    List<String> subscriberIntervals = new ArrayList<String>();
    List<String> subscriberMaximums = new ArrayList<String>();
    List<String> subscriberUniqueIds = new ArrayList<String>();
    List<String> subscriberConfirmations = new ArrayList<String>();
    List<String> subscriberLastNotifications = new ArrayList<String>();

    if (request.getParameterValues("subscriberEmails") != null)
        for (String subscriberEmail : request.getParameterValues("subscriberEmails"))
            subscriberEmails.add(subscriberEmail);

    command.setSubscriberEmails(subscriberEmails);

    if (request.getParameterValues("subscriberEmailLanguages") != null)
        for (String subscriberEmailLanguage : request.getParameterValues("subscriberEmailLanguages"))
            subscriberEmailLanguages.add(subscriberEmailLanguage);

    command.setSubscriberEmailLanguages(subscriberEmailLanguages);

    if (request.getParameterValues("subscriberTimeZones") != null)
        for (String subscriberTimeZone : request.getParameterValues("subscriberTimeZones"))
            subscriberTimeZones.add(subscriberTimeZone);

    command.setSubscriberTimeZones(subscriberTimeZones);

    if (request.getParameterValues("subscriberNotificationTypes") != null)
        for (String subscriberType : request.getParameterValues("subscriberNotificationTypes"))
            subscriberTypes.add(subscriberType);

    command.setSubscriberTypes(subscriberTypes);

    if (request.getParameterValues("subscriberNotificationDays") != null)
        for (String subscriberDay : request.getParameterValues("subscriberNotificationDays"))
            subscriberDays.add(subscriberDay);

    command.setSubscriberDays(subscriberDays);

    if (request.getParameterValues("subscriberNotificationHours") != null)
        for (String subscriberHour : request.getParameterValues("subscriberNotificationHours"))
            subscriberHours.add(subscriberHour);

    command.setSubscriberHours(subscriberHours);

    if (request.getParameterValues("subscriberNotificationMinutes") != null)
        for (String subscriberMinute : request.getParameterValues("subscriberNotificationMinutes"))
            subscriberMinutes.add(subscriberMinute);

    command.setSubscriberMinutes(subscriberMinutes);

    if (request.getParameterValues("subscriberNotificationIntervals") != null)
        for (String subscriberInterval : request.getParameterValues("subscriberNotificationIntervals"))
            subscriberIntervals.add(StringUtils.isEmpty(subscriberInterval) ? "-1" : subscriberInterval);

    command.setSubscriberIntervals(subscriberIntervals);

    if (request.getParameterValues("subscriberNotificationMaximums") != null)
        for (String subscriberMaximum : request.getParameterValues("subscriberNotificationMaximums"))
            subscriberMaximums.add(StringUtils.isEmpty(subscriberMaximum) ? "-1" : subscriberMaximum);

    command.setSubscriberMaximums(subscriberMaximums);

    if (request.getParameterValues("subscriberNotificationUniqueIds") != null)
        for (String subscriberUniqueId : request.getParameterValues("subscriberNotificationUniqueIds"))
            subscriberUniqueIds.add(subscriberUniqueId);

    command.setSubscriberUniqueIds(subscriberUniqueIds);

    if (request.getParameterValues("subscriberNotificationConfirmations") != null)
        for (String subscriberConfirmation : request.getParameterValues("subscriberNotificationConfirmations"))
            subscriberConfirmations.add(subscriberConfirmation);

    command.setSubscriberConfirmations(subscriberConfirmations);

    if (request.getParameterValues("subscriberNotificationLastNotifications") != null)
        for (String subscriberLastNotification : request
                .getParameterValues("subscriberNotificationLastNotifications"))
            subscriberLastNotifications.add(subscriberLastNotification);

    command.setSubscriberLastNotifications(subscriberLastNotifications);

    // Collect and set the parameters

    if (request.getParameterValues("searchParameterFormat") != null)
        command.setSearchParameterFormat(request.getParameterValues("searchParameterFormat")[0]);
    if (request.getParameterValues("searchParameterLanguage") != null)
        command.setSearchParameterLanguage(request.getParameterValues("searchParameterLanguage")[0]);
    if (request.getParameterValues("searchParameterAuthor") != null
            && !StringUtils.isEmpty(request.getParameterValues("searchParameterLanguage")[0]))
        command.setSearchParameterAuthor(request.getParameterValues("searchParameterAuthor")[0]);
    if (request.getParameterValues("searchParameterType") != null
            && !StringUtils.isEmpty(request.getParameterValues("searchParameterType")[0]))
        command.setSearchParameterType(request.getParameterValues("searchParameterType")[0]);
    if (request.getParameterValues("searchParameterGeo") != null
            && !StringUtils.isEmpty(request.getParameterValues("searchParameterGeo")[0]))
        command.setSearchParameterGeo(request.getParameterValues("searchParameterGeo")[0]);

    // Collect and set the taxonomy identifiers

    List<String> taxonomyIdentifiersCommand = new ArrayList<String>();

    if (request.getParameterValues("taxonomyIdentifiersList") != null)
        for (String taxonomyIdentifier : request.getParameterValues("taxonomyIdentifiersList")[0].trim()
                .split(" "))
            if (!StringUtils.isBlank(taxonomyIdentifier))
                taxonomyIdentifiersCommand.add(taxonomyIdentifier.trim());

    command.setTaxonomyIdentifiers(taxonomyIdentifiersCommand);

    // Update the enabled attribute

    if (request.getParameter("isEnabled") == null)
        command.setIsEnabled(false);

    validator.validate(command, result);

    if (!result.hasErrors()) {
        // Any search parameter validation errors should have been caught by the validator

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

        if (!StringUtils.isEmpty(command.getSearchParameterFormat()))
            searchParameters.put("dcterms_format", command.getSearchParameterFormat());
        if (!StringUtils.isEmpty(command.getSearchParameterLanguage()))
            searchParameters.put("dcterms_language", command.getSearchParameterLanguage());
        if (!StringUtils.isEmpty(command.getSearchParameterAuthor()))
            searchParameters.put("dcterms_author", command.getSearchParameterAuthor());
        if (!StringUtils.isEmpty(command.getSearchParameterType()))
            searchParameters.put("dcterms_type", command.getSearchParameterType());
        if (!StringUtils.isEmpty(command.getSearchParameterGeo()))
            searchParameters.put("geo_total", command.getSearchParameterGeo());

        // Any number formatting exceptions should have been caught by the validator

        List<Integer> taxonomyIdentifiers = new ArrayList<Integer>();

        for (String taxonomyIdentifier : command.getTaxonomyIdentifiers()) {
            Integer identifier = Integer.parseInt(taxonomyIdentifier);

            logger.info("Profile will be narrowed down by taxonomy identifiers - adding " + identifier);

            taxonomyIdentifiers.add(identifier);
        }

        // Any length inconsistencies should have been intercepted by the validator

        List<ProfileSubscriber> subscribers = new ArrayList<ProfileSubscriber>();

        if (!command.getAction().equals("delete"))
            for (int i = 0; i < subscriberEmails.size(); i++)
                if (!StringUtils.isEmpty(subscriberEmails.get(i))) {
                    Long subscriberLastNotification = null;
                    String uniqueId = null;

                    if (!StringUtils.isEmpty(subscriberLastNotifications.get(i)))
                        try {
                            subscriberLastNotification = Long.valueOf(subscriberLastNotifications.get(i));
                        } catch (NumberFormatException e) {
                            // Do nothing, if it's simply incorrect
                        }
                    if (!StringUtils.isEmpty(subscriberUniqueIds.get(i))
                            && subscriberUniqueIds.get(i).length() > 10)
                        uniqueId = subscriberUniqueIds.get(i);

                    subscribers.add(new ProfileSubscriber(subscriberEmails.get(i),
                            subscriberEmailLanguages.get(i), Boolean.valueOf(subscriberConfirmations.get(i)),
                            uniqueId, subscriberTimeZones.get(i),
                            NotificationType.valueOf(subscriberTypes.get(i)),
                            Integer.valueOf(subscriberDays.get(i)), Integer.valueOf(subscriberHours.get(i)),
                            Integer.valueOf(subscriberMinutes.get(i)),
                            Integer.valueOf(subscriberIntervals.get(i)),
                            Integer.valueOf(subscriberMaximums.get(i)),
                            subscriberLastNotification != null && subscriberLastNotification > 0
                                    ? new Date(subscriberLastNotification)
                                    : null));
                }

        if (command.getAction().equals("add"))
            attenderService.addProfile(command.getQuery(), command.getIsEnabled(), subscribers,
                    searchParameters, taxonomyIdentifiers);
        else if (command.getAction().equals("edit"))
            attenderService.modifyProfile(command.getId(), command.getQuery(), command.getIsEnabled(),
                    subscribers, searchParameters, taxonomyIdentifiers);
        else if (command.getAction().equals("delete"))
            attenderService.deleteProfile(command.getId());

        // Re-populate the data

        model.put("data", populateData());

        command.clear();
    }

    return "profiles";
}

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

@RequestMapping("/detailsQuery")
public @ResponseBody DataSourceDetails detailsQuery(WebRequest request,
        @RequestParam("dsId") JdbcOeDataSource ds,
        @RequestParam(value = "firstrecord", defaultValue = "0") long firstRecord,
        @RequestParam(value = "pagesize", defaultValue = "200") long pageSize)
        throws ErrorMessageException, OeDataSourceException, OeDataSourceAccessException {

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

    final List<OrderByFilter> sorts = new ArrayList<OrderByFilter>();
    try {//from   w  ww  .  j  ava  2s.  c o m
        sorts.addAll(Sorters.getSorters(request.getParameterMap()));
    } catch (Exception e) {
        log.warn("Unable to get sorters, using default ordering");
    }

    String clientTimezone = null;
    String timezoneEnabledString = messageSource.getMessage(TIMEZONE_ENABLED, "false");
    if (timezoneEnabledString.equalsIgnoreCase("true")) {
        clientTimezone = ControllerUtils.getRequestTimezoneAsHourMinuteString(request);
    }
    return new DetailsQuery().performDetailsQuery(ds, results, accumulations, filters, sorts, false,
            clientTimezone, firstRecord, pageSize, true);
}

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  ww  w.  ja  v  a2  s .c  om*/
    // 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;
}