View Javadoc
1   /*
2    * Licensed under the GPL License. You may not use this file except in compliance with the License.
3    * You may obtain a copy of the License at
4    *
5    *   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6    *
7    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
8    * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
9    * PURPOSE.
10   */
11  package psiprobe.beans.stats.providers;
12  
13  import jakarta.servlet.http.HttpServletRequest;
14  
15  import java.text.MessageFormat;
16  import java.util.ArrayList;
17  import java.util.List;
18  
19  import org.jfree.data.xy.DefaultTableXYDataset;
20  import org.jfree.data.xy.XYDataItem;
21  import org.springframework.web.bind.ServletRequestBindingException;
22  import org.springframework.web.bind.ServletRequestUtils;
23  
24  import psiprobe.model.stats.StatsCollection;
25  
26  /**
27   * The Class StandardSeriesProvider.
28   */
29  public class StandardSeriesProvider extends AbstractSeriesProvider {
30  
31    /** The stat names. */
32    private List<String> statNames = new ArrayList<>(2);
33  
34    /**
35     * Gets the stat names.
36     *
37     * @return the stat names
38     */
39    public List<String> getStatNames() {
40      return statNames;
41    }
42  
43    /**
44     * Sets the stat names.
45     *
46     * @param statNames the new stat names
47     */
48    public void setStatNames(List<String> statNames) {
49      this.statNames = statNames;
50    }
51  
52    @Override
53    public void populate(DefaultTableXYDataset dataset, StatsCollection statsCollection,
54        HttpServletRequest request) {
55  
56      String seriesParam = null;
57      try {
58        seriesParam = ServletRequestUtils.getStringParameter(request, "sp");
59      } catch (ServletRequestBindingException e) {
60        logger.error("", e);
61      }
62      for (int i = 0; i < statNames.size(); i++) {
63        String statName = statNames.get(i);
64        if (seriesParam != null) {
65          statName = MessageFormat.format(statName, seriesParam);
66        }
67        List<XYDataItem> stats = statsCollection.getStats(statName);
68        if (stats != null) {
69          String series =
70              ServletRequestUtils.getStringParameter(request, "s" + (i + 1) + "l", "series" + i);
71          dataset.addSeries(toSeries(series, stats));
72        }
73      }
74    }
75  }