List<LiveStatistics> liveList = null;
String seriesLabel = null;
Alert alert = null;
GroupedStatistics groupedStatistics = null;
XYDataSetCollection valueCollection = new XYDataSetCollection();
//TODO: This if-else code block needs refactoring. Its not DRY
if (isAlertChart(id)) {
id = id.replaceAll("\\%20", " ").replaceAll("\\%25", "%");
String alertName = id.substring(8, id.length());
log.info("isAlert! " + alertName);
alert = getBerkeleyTreeMenuService().getAlert(alertName, loggedInAccountName);
if (alert != null) {
chartPath = alert.getGuiPath();
seriesLabel = "Alert: " + alert.getAlertName();
}
liveList = getBerkeleyTreeMenuService().getLiveStatistics(chartPath, loggedInAccountName, fromPeriod, toPeriod);
Collections.sort(liveList);
valueCollection = ChartUtil.generateChart(liveList, seriesLabel, fromPeriod * 15000, toPeriod * 15000, chartResolution);
valueCollection.addDataList(ChartUtil.buildWarningList(alert, AlertStatus.CRITICAL, fromPeriod * 15000, toPeriod * 15000));
valueCollection.addDataList(ChartUtil.buildWarningList(alert, AlertStatus.WARNING, fromPeriod * 15000, toPeriod * 15000));
log.info("alert: " + alert);
log.info("chartPath: " + chartPath);
} else if (isGroupedStatisticsChart(id)) {
id = id.replaceAll("\\%20", " ").replaceAll("\\%25", "%");
chartPath = id;
String groupName = id.substring(5, id.length());
log.info("isGroupedStat! " + groupName);
groupedStatistics = getBerkeleyTreeMenuService().getGroupedStatistics(groupName, loggedInAccountName);
if (groupedStatistics != null) {
log.info("groupedStats: " + groupedStatistics.getName() + " :. " + groupedStatistics.getGroupedPathList().size());
seriesLabel = "Grouped Statistics: " + groupedStatistics.getName();
for (String gsPath : groupedStatistics.getGroupedPathList()) {
log.info("\tgroupedStats Path: " + gsPath);
liveList = getBerkeleyTreeMenuService().getLiveStatistics(gsPath, loggedInAccountName, fromPeriod, toPeriod);
Collections.sort(liveList);
for (XYDataList dataList : ChartUtil.generateChart(liveList, gsPath, fromPeriod * 15000, toPeriod * 15000, chartResolution).getDataList()) {
valueCollection.addDataList(dataList);
}
}
}
} else {
id = id.replaceAll("\\%20", " ").replaceAll("\\%25", "%");