List of usage examples for org.jfree.data.category DefaultCategoryDataset getRowCount
@Override public int getRowCount()
From source file:com.naryx.tagfusion.cfm.tag.awt.cfCHART.java
private CategoryPlot getCategoryPlot(List<cfCHARTSERIESData> series, String xAxisTitle, String yAxisTitle, String labelFormat, boolean bShowMarkers, int markerSize, boolean bShow3D, String tipStyle, String drillDownUrl, int xOffset, int yOffset, int yAxisUnits, String seriesPlacement, boolean bSortXAxis, int height, String[] yAxisSymbols, int gridLines) throws cfmRunTimeException { // Create a category plot CategoryPlot plot = new CategoryPlot(); // Set the domain axis (the x-axis) org.jfree.chart.axis.CategoryAxis categoryAxis; if (bShow3D)/* ww w. j a v a2 s. c o m*/ categoryAxis = new CategoryAxis3D(xAxisTitle); else categoryAxis = new CategoryAxis(xAxisTitle); plot.setDomainAxis(categoryAxis); // Set the range axis (the y-axis) ValueAxis valueAxis; DateFormat dateFormat = null; NumberFormat numberFormat = null; // Ignore a label format of date if the y-axis is using symbols if (labelFormat.equals("date") && (yAxisSymbols == null)) { valueAxis = new DateAxis(yAxisTitle); dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); ((DateAxis) valueAxis).setDateFormatOverride(dateFormat); } else { if (yAxisSymbols != null) { valueAxis = new SymbolAxis(yAxisTitle, yAxisSymbols); ((SymbolAxis) valueAxis).setGridBandsVisible(false); ((SymbolAxis) valueAxis).setAutoRangeStickyZero(true); } else if (bShow3D) { valueAxis = new NumberAxis3D(yAxisTitle); } else { valueAxis = new NumberAxis(yAxisTitle); } if (labelFormat.equals("currency")) { ((NumberAxis) valueAxis).setNumberFormatOverride(NumberFormat.getCurrencyInstance()); numberFormat = NumberFormat.getCurrencyInstance(); } else if (labelFormat.equals("percent")) { numberFormat = NumberFormat.getPercentInstance(); numberFormat.setMaximumFractionDigits(3); // without this change .11443 // would be displayed as 11% // instead of 11.443% ((NumberAxis) valueAxis).setNumberFormatOverride(numberFormat); } else { numberFormat = NumberFormat.getInstance(); } if (yAxisUnits != 0) ((NumberAxis) valueAxis).setTickUnit(new NumberTickUnit(yAxisUnits)); } plot.setRangeAxis(valueAxis); // Add a dataset and renderer for each series int barChartDatasetIndex = -1; int hBarChartDatasetIndex = -1; int num = 0; MinMaxData minMax = new MinMaxData(); for (int i = 0; i < series.size(); i++) { cfCHARTSERIESData seriesData = series.get(i); // If the sortXAxis attribute was set to "yes" then sort the data. // NOTE: this attribute is only used with category charts. if (bSortXAxis) seriesData.sort(); DefaultCategoryDataset dataset; if ((barChartDatasetIndex != -1) && (seriesData.getType().equals("bar"))) { dataset = (DefaultCategoryDataset) plot.getDataset(barChartDatasetIndex); addSeriesDataToDataset(seriesData, dataset, minMax); // Set the paint style for this series setPaintStyle(seriesData.getPaintStyle(), plot.getRenderer(barChartDatasetIndex), dataset.getRowCount() - 1, height); // Add the color list for this series to the custom color renderer CustomColorRenderer cr = (CustomColorRenderer) plot.getRenderer(barChartDatasetIndex); cr.addColors(getColorList(seriesData)); continue; } else if ((hBarChartDatasetIndex != -1) && (seriesData.getType().equals("horizontalbar"))) { dataset = (DefaultCategoryDataset) plot.getDataset(hBarChartDatasetIndex); addSeriesDataToDataset(seriesData, dataset, minMax); // Set the paint style for this series setPaintStyle(seriesData.getPaintStyle(), plot.getRenderer(hBarChartDatasetIndex), dataset.getRowCount() - 1, height); // Add the color list for this series to the custom color renderer CustomColorRenderer cr = (CustomColorRenderer) plot.getRenderer(hBarChartDatasetIndex); cr.addColors(getColorList(seriesData)); continue; } else { dataset = new DefaultCategoryDataset(); addSeriesDataToDataset(seriesData, dataset, minMax); } plot.setDataset(num, dataset); AbstractCategoryItemRenderer renderer = null; if (seriesData.getType().equals("bar")) { plot.setOrientation(PlotOrientation.VERTICAL); renderer = getBarRenderer(seriesPlacement, bShow3D, xOffset, yOffset, getColorList(seriesData)); ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER); renderer.setPositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER); renderer.setNegativeItemLabelPosition(position2); ((BarRenderer) renderer).setItemMargin(0.0); // The margin between items // in the same category categoryAxis.setCategoryMargin(0.2); // The margin between each category barChartDatasetIndex = num; } else if (seriesData.getType().equals("horizontalbar")) { plot.setOrientation(PlotOrientation.HORIZONTAL); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); renderer = getBarRenderer(seriesPlacement, bShow3D, xOffset, yOffset, getColorList(seriesData)); if (bShow3D) { // change rendering order to ensure that bar overlapping is the // right way around plot.setRowRenderingOrder(org.jfree.util.SortOrder.DESCENDING); plot.setColumnRenderingOrder(org.jfree.util.SortOrder.DESCENDING); } ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); renderer.setPositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT); renderer.setNegativeItemLabelPosition(position2); ((BarRenderer) renderer).setItemMargin(0.0); // The margin between items // in the same category categoryAxis.setCategoryMargin(0.2); // The margin between each category hBarChartDatasetIndex = num; } else if (seriesData.getType().equals("line")) { if (bShow3D) { renderer = new LineRenderer3D(); ((LineRenderer3D) renderer).setXOffset(xOffset); ((LineRenderer3D) renderer).setYOffset(yOffset); } else { renderer = new LineAndShapeRenderer(true, false); } // Enable/Disable displaying of markers ((LineAndShapeRenderer) renderer).setShapesVisible(bShowMarkers); // Set the shape of the markers based on the markerSize value ((LineAndShapeRenderer) renderer).setShape(getMarker(seriesData.getMarkerStyle(), markerSize)); } else if (seriesData.getType().equals("area")) { if (seriesPlacement.equals("stacked")) renderer = new StackedAreaRenderer(); // this doesn't work for some // reason else renderer = new AreaRenderer(); // Truncate the first and last values to match CFMX 7 ((AreaRenderer) renderer).setEndType(AreaRendererEndType.TRUNCATE); categoryAxis.setCategoryMargin(0.0); } else if (seriesData.getType().equals("step")) { renderer = new CategoryStepRenderer(true); } else if (seriesData.getType().equals("scatter")) { renderer = new LineAndShapeRenderer(false, true); // Set the shape of the markers based on the markerSize value ((LineAndShapeRenderer) renderer).setShape(getMarker(seriesData.getMarkerStyle(), markerSize)); } if (!tipStyle.equals("none")) { if (dateFormat != null) renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("({0}, {1}) = {2}", dateFormat)); else renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("({0}, {1}) = {2}", numberFormat)); } if (drillDownUrl != null) { if (dateFormat != null) renderer.setBaseItemURLGenerator( new com.newatlanta.bluedragon.CategoryURLGenerator(drillDownUrl, dateFormat)); else renderer.setBaseItemURLGenerator( new com.newatlanta.bluedragon.CategoryURLGenerator(drillDownUrl, numberFormat)); } if (seriesData.getSeriesColor() != null) renderer.setSeriesPaint(0, convertStringToColor(seriesData.getSeriesColor())); String dataLabelStyle = seriesData.getDataLabelStyle(); if (labelFormat.equals("date")) { if (dataLabelStyle.equals("none")) { renderer.setItemLabelsVisible(false); } else { setCategoryItemLabelsData(renderer, seriesData); if (dataLabelStyle.equals("value")) renderer.setItemLabelGenerator( new CategoryItemLabelGenerator("{2}", dateFormat, yAxisSymbols)); else if (dataLabelStyle.equals("rowlabel")) renderer.setItemLabelGenerator( new CategoryItemLabelGenerator("{0}", dateFormat, yAxisSymbols)); else if (dataLabelStyle.equals("columnlabel")) renderer.setItemLabelGenerator( new CategoryItemLabelGenerator("{1}", dateFormat, yAxisSymbols)); else if (dataLabelStyle.equals("pattern")) renderer.setItemLabelGenerator( new CategoryItemLabelGenerator("{1} {2}", dateFormat, yAxisSymbols)); else renderer.setItemLabelGenerator( new CategoryItemLabelGenerator(dataLabelStyle, dateFormat, yAxisSymbols)); } } else { if (dataLabelStyle.equals("none")) { renderer.setItemLabelsVisible(false); } else { setCategoryItemLabelsData(renderer, seriesData); if (dataLabelStyle.equals("value")) renderer.setItemLabelGenerator( new CategoryItemLabelGenerator("{2}", numberFormat, yAxisSymbols)); else if (dataLabelStyle.equals("rowlabel")) renderer.setItemLabelGenerator( new CategoryItemLabelGenerator("{0}", numberFormat, yAxisSymbols)); else if (dataLabelStyle.equals("columnlabel")) renderer.setItemLabelGenerator( new CategoryItemLabelGenerator("{1}", numberFormat, yAxisSymbols)); else if (dataLabelStyle.equals("pattern")) renderer.setItemLabelGenerator( new CategoryItemLabelGenerator("{1} {2} ({3} of {4})", numberFormat, yAxisSymbols)); else renderer.setItemLabelGenerator( new CategoryItemLabelGenerator(dataLabelStyle, numberFormat, yAxisSymbols)); } } // Add the renderer to the plot. // NOTE: this must be done before the setPaintStyle() call so the // DrawingSupplier object // will be set up properly for the generation of default colors. plot.setRenderer(num, renderer); // Set the paint style for this series (series 0) if (seriesData.getType().equals("bar") || seriesData.getType().equals("horizontalbar") || seriesData.getType().equals("area")) setPaintStyle(seriesData.getPaintStyle(), renderer, 0, height); num++; } // If gridLines was specified then we need to calculate the yAxisUnits if ((gridLines != -1) && (valueAxis instanceof NumberAxis)) { // Calculate the yAxisUnits we need to use to create the number of // gridLines yAxisUnits = calculateYAxisUnits(gridLines, minMax); // Set the yAxisUnits ((NumberAxis) valueAxis).setTickUnit(new NumberTickUnit(yAxisUnits)); } return plot; }
From source file:org.miloss.fgsms.services.rs.impl.reports.ws.TotalMessageSizeByServiceByMethod.java
/** * {@inheritDoc}/* w w w .j ava2s .co m*/ */ @Override public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files, TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx) throws IOException { Connection con = Utility.getPerformanceDBConnection(); try { PreparedStatement cmd = null; long itemcount = 0; ResultSet rs = null; DefaultCategoryDataset set = new DefaultCategoryDataset(); JFreeChart chart = null; data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>"); data.append( "This represents the total combined request and response message size of each service grouped by method.<br />"); //add description data.append( "<table class=\"table table-hover\"><tr><th>URL</th><th>Action</th><th>Total Message Size (bytes)</th></tr>"); for (int i = 0; i < urls.size(); i++) { if (!isPolicyTypeOf(urls.get(i), PolicyType.TRANSACTIONAL)) { continue; } //https://github.com/mil-oss/fgsms/issues/112 if (!UserIdentityUtil.hasReadAccess(currentuser, "getReport", urls.get(i), classification, ctx)) { continue; } String url = Utility.encodeHTML(BaseReportGenerator.getPolicyDisplayName(urls.get(i))); try { List<String> actions = getSoapActions(urls.get(i), con); itemcount = actions.size(); for (int k = 0; k < actions.size(); k++) { long count = -1; try { cmd = con.prepareStatement( "select SUM(responseSize + requestSize) as messagesSize from RawData where URI=? and " + "(UTCdatetime > ?) and (UTCdatetime < ?) and soapaction=? and (requestsize>=0) and (responsesize>=0);"); cmd.setString(1, urls.get(i)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); cmd.setString(4, actions.get(k)); rs = cmd.executeQuery(); try { if (rs.next()) { count = rs.getLong(1); } } catch (Exception ex) { log.log(Level.DEBUG, null, ex); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } data.append("<tr><td>").append(url).append("</td><td>"); data.append(Utility.encodeHTML(actions.get(k))).append("</td><td>"); if (count >= 0) { data.append(count + " bytes"); } else { data.append("N/A"); } data.append("</td></tr>"); set.addValue(count, actions.get(k), url); } } catch (Exception ex) { data.append("0 bytes</td></tr>"); log.log(Level.ERROR, "Error opening or querying the database.", ex); } } chart = org.jfree.chart.ChartFactory.createBarChart(GetDisplayName(), "Service URL", "", set, PlotOrientation.HORIZONTAL, true, false, false); data.append("</table>"); try { ChartUtilities.saveChartAsPNG(new File( path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart, 1500, pixelHeightCalc(set.getRowCount())); } catch (IOException ex) { log.log(Level.ERROR, "Error saving chart image for request", ex); } data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">"); files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"); } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(con); } }
From source file:org.miloss.fgsms.services.rs.impl.reports.ws.ThroughputByServiceByMethod.java
/** * {@inheritDoc}//from ww w . ja v a 2s .c om */ @Override public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files, TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx) throws IOException { double d = range.getEnd().getTimeInMillis() - range.getStart().getTimeInMillis(); double day = d / 86400000; double hours = d / 3600000; double min = d / 60000; double sec = d / 1000; Connection con = Utility.getPerformanceDBConnection(); try { PreparedStatement cmd = null; ResultSet rs = null; DefaultCategoryDataset set = new DefaultCategoryDataset(); JFreeChart chart = null; data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>"); data.append(GetHtmlFormattedHelp() + "<br />"); data.append( "<table class=\"table table-hover\"><tr><th>URL</th><th>Method</th><th>Invocations</th><th>Msg/Day</th><th>Msg/Hour</th><th>Msg/Min</th><th>Msg/Sec</th></tr>"); for (int i = 0; i < urls.size(); i++) { if (!isPolicyTypeOf(urls.get(i), PolicyType.TRANSACTIONAL)) { continue; } //https://github.com/mil-oss/fgsms/issues/112 if (!UserIdentityUtil.hasReadAccess(currentuser, "getReport", urls.get(i), classification, ctx)) { continue; } String url = Utility.encodeHTML(BaseReportGenerator.getPolicyDisplayName(urls.get(i))); try { List<String> actions = getSoapActions(urls.get(i), con); for (int k = 0; k < actions.size(); k++) { long count = 0; try { cmd = con.prepareStatement( "select count(*) from RawData where URI=? and soapaction=? and " + "(UTCdatetime > ?) and (UTCdatetime < ?) ;"); cmd.setString(1, urls.get(i)); cmd.setString(2, actions.get(k)); cmd.setLong(3, range.getStart().getTimeInMillis()); cmd.setLong(4, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); try { if (rs.next()) { count = rs.getLong(1); } } catch (Exception ex) { log.log(Level.DEBUG, null, ex); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } data.append("<tr><td>").append(url).append("</td><td>") .append(Utility.encodeHTML(actions.get(k))).append("</td><td>"); data.append(count + ""); data.append("</td><td>").append(format.format((double) ((double) count / day))) .append("</td><td>").append(format.format((double) ((double) count / hours))) .append("</td><td>").append(format.format((double) ((double) count / min))) .append("</td><td>").append(format.format((double) ((double) count / sec))) .append("</td></tr>"); if (count > 0) { set.addValue((double) ((double) count / day), actions.get(k), url); } } } catch (Exception ex) { log.log(Level.ERROR, "Error opening or querying the database.", ex); } } chart = org.jfree.chart.ChartFactory.createBarChart(GetDisplayName(), "Service URL", "", set, PlotOrientation.HORIZONTAL, true, false, false); data.append("</table>"); try { ChartUtilities.saveChartAsPNG(new File( path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart, 1500, pixelHeightCalc(set.getRowCount())); } catch (IOException ex) { log.log(Level.ERROR, "Error saving chart image for request", ex); } data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">"); files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"); } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(con); } }
From source file:org.miloss.fgsms.services.rs.impl.reports.ws.TotalMessageSizesByService.java
/** * {@inheritDoc}/*from ww w .ja v a2 s. c om*/ */ @Override public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files, TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx) throws IOException { Connection con = Utility.getPerformanceDBConnection(); try { PreparedStatement cmd = null; ResultSet rs = null; DefaultCategoryDataset set = new DefaultCategoryDataset(); JFreeChart chart = null; data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>"); data.append( "This represents the total transmitted message size, request + response, for each service over the given period of time.<br />"); data.append( "<table class=\"table table-hover\"><tr><th>URL</th><th>Total Message Size (bytes)</th></tr>"); for (int i = 0; i < urls.size(); i++) { if (!isPolicyTypeOf(urls.get(i), PolicyType.TRANSACTIONAL)) { continue; } //https://github.com/mil-oss/fgsms/issues/112 if (!UserIdentityUtil.hasReadAccess(currentuser, "getReport", urls.get(i), classification, ctx)) { continue; } String url = Utility.encodeHTML(BaseReportGenerator.getPolicyDisplayName(urls.get(i))); long count = 0; try { cmd = con .prepareStatement("select sum(requestsize + responsesize) from rawdata where uri=? and " + "(UTCdatetime > ?) and (UTCdatetime < ?) and (requestsize>=0) and (responsesize>=0);"); cmd.setString(1, urls.get(i)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); try { if (rs.next()) { count = rs.getLong(1); } } catch (Exception ex) { log.log(Level.DEBUG, null, ex); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } count = 0; try { cmd = con .prepareStatement("select avg(requestsize + responsesize) from rawdata where uri=? and " + "(UTCdatetime > ?) and (UTCdatetime < ?) ;"); cmd.setString(1, urls.get(i)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); try { if (rs.next()) { count = rs.getLong(1); } } catch (Exception ex) { // log.log(Level.WARN, " error querying database for average message size url:" + urls.get(i), ex); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } data.append("<tr><td>").append(url).append("</td><td>"); if (count > 0) { data.append(count + " bytes"); set.addValue(count, url, url); } else data.append("N/A"); data.append("</td></tr>"); } chart = org.jfree.chart.ChartFactory.createBarChart(GetDisplayName(), "Service URL", "", set, PlotOrientation.HORIZONTAL, true, false, false); data.append("</table>"); try { ChartUtilities.saveChartAsPNG(new File( path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart, 1500, pixelHeightCalc(set.getRowCount())); } catch (IOException ex) { log.log(Level.ERROR, "Error saving chart image for request", ex); } data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">"); files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"); } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(con); } }
From source file:org.miloss.fgsms.services.rs.impl.reports.ws.SuccessFailureCountByService.java
/** * {@inheritDoc}/* www . j av a 2s . co m*/ */ @Override public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files, TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx) throws IOException { Connection con = Utility.getPerformanceDBConnection(); try { PreparedStatement cmd = null; ResultSet rs = null; DefaultCategoryDataset set = new DefaultCategoryDataset(); JFreeChart chart = null; data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>"); data.append("This represents service invocation by success and failure rates.<br />"); data.append( "<table class=\"table table-hover\"><tr><th>URL</th><th>Successes</th><th>Failures</th></tr>"); try { for (int i = 0; i < urls.size(); i++) { if (!isPolicyTypeOf(urls.get(i), PolicyType.TRANSACTIONAL)) { continue; } //https://github.com/mil-oss/fgsms/issues/112 if (!UserIdentityUtil.hasReadAccess(currentuser, "getReport", urls.get(i), classification, ctx)) { continue; } String url = Utility.encodeHTML(BaseReportGenerator.getPolicyDisplayName(urls.get(i))); data.append("<tr><td>").append(url).append("</td>"); int success = 0; int failures = 0; //could this use the raw data tally table instead? try { cmd = con.prepareStatement( "select count(*) from RawData where uri=? and success=false and UTCdatetime > ? and UTCdatetime < ?;"); cmd.setString(1, urls.get(i)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); try { rs.next(); failures = rs.getInt(1); } catch (Exception ex) { log.log(Level.DEBUG, null, ex); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } try { cmd = con.prepareStatement( "select count(*) from RawData where uri=? and success=true and UTCdatetime > ? and UTCdatetime < ?;"); cmd.setString(1, urls.get(i)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); try { rs.next(); success = rs.getInt(1); } catch (Exception ex) { log.log(Level.DEBUG, null, ex); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } data.append("<td>").append(success + "").append("</td>"); data.append("<td>").append(failures + "").append("</td></tr>"); set.addValue(success, url + " Success", url + " Success"); set.addValue(failures, url + " Failures", url + " Failures"); } } catch (Exception ex) { log.log(Level.ERROR, "Error generating chart information.", ex); } chart = org.jfree.chart.ChartFactory.createBarChart(GetDisplayName(), "Services", "", set, PlotOrientation.HORIZONTAL, true, false, false); data.append("</table>"); try { ChartUtilities.saveChartAsPNG(new File( path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart, 1500, pixelHeightCalc(set.getRowCount())); } catch (IOException ex) { log.log(Level.ERROR, "Error saving chart image for request", ex); } data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">"); files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"); } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(con); } }
From source file:org.miloss.fgsms.services.rs.impl.reports.ws.SuccessFailureCountByHostingServer.java
/** * {@inheritDoc}/*from ww w .ja v a 2s . c o m*/ */ @Override public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files, TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx) throws IOException { if (!UserIdentityUtil.hasGlobalAdministratorRole(currentuser, "SUCCESS_FAILURE_COUNT_BY_HOSTING_SERVER", classification, ctx)) { data.append("<h2>Access for " + GetDisplayName() + " was denied for non-global admin users</h2>"); } Connection con = Utility.getPerformanceDBConnection(); try { PreparedStatement cmd = null; ResultSet rs = null; DefaultCategoryDataset set = new DefaultCategoryDataset(); JFreeChart chart = null; data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>"); data.append( "This represents Web Application Server utilization (host) by success and failure rates.<br />"); data.append( "<table class=\"table table-hover\"><tr><th>Host</th><th>Successes</th><th>Failures</th></tr>"); List<String> dcs = new ArrayList<String>(); try { cmd = con.prepareStatement("select hostingsource from RawData group by hostingsource;"); rs = cmd.executeQuery(); while (rs.next()) { dcs.add(rs.getString(1)); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } try { // itemcount = dcs.size(); for (int i = 0; i < dcs.size(); i++) { data.append("<tr><td>").append(Utility.encodeHTML(dcs.get(i))).append("</td>"); int success = 0; int failures = 0; try { cmd = con.prepareStatement( "select count(*) from RawData where hostingsource=? and success=false and UTCdatetime > ? and UTCdatetime < ?;"); cmd.setString(1, dcs.get(i)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); try { if (rs.next()) { failures = rs.getInt(1); } } catch (Exception ex) { log.log(Level.DEBUG, null, ex); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } try { cmd = con.prepareStatement( "select count(*) from RawData where hostingsource=? and success=true and UTCdatetime > ? and UTCdatetime < ?;"); cmd.setString(1, dcs.get(i)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); try { if (rs.next()) { success = rs.getInt(1); } } catch (Exception ex) { log.log(Level.DEBUG, null, ex); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } data.append("<td>").append(success + "").append("</td>"); data.append("<td>").append(failures + "").append("</td></tr>"); if (success > 0) { set.addValue(success, dcs.get(i) + " Success", dcs.get(i) + " Success"); } if (failures > 0) { set.addValue(failures, dcs.get(i) + " Failures", dcs.get(i) + " Failures"); } } } catch (Exception ex) { log.log(Level.ERROR, "Error generating chart information.", ex); } chart = org.jfree.chart.ChartFactory.createBarChart(GetDisplayName(), "Hosting Servers", "", set, PlotOrientation.HORIZONTAL, true, false, false); data.append("</table>"); try { ChartUtilities.saveChartAsPNG(new File( path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart, 1500, pixelHeightCalc(set.getRowCount())); } catch (IOException ex) { log.log(Level.ERROR, "Error saving chart image for request", ex); } data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">"); files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"); } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(con); } }
From source file:org.miloss.fgsms.services.rs.impl.reports.ws.InvocationsByConsumer.java
/** * {@inheritDoc}/*from w ww . j ava2 s .c om*/ */ @Override public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files, TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx) throws IOException { Connection con = Utility.getPerformanceDBConnection(); try { PreparedStatement cmd = null; PreparedStatement userQuery = null; ResultSet rs = null; DefaultCategoryDataset set = new DefaultCategoryDataset(); JFreeChart chart = null; data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>"); data.append("This represents service usage by consumer for the provided services.<br />"); //add description data.append("<table class=\"table table-hover\"><tr><th>User</th><th>Invocations</th></tr>"); ResultSet actionRS = null; Set<String> users = new HashSet<String>(); try { userQuery = con.prepareStatement("select consumeridentity from rawdata group by consumeridentity"); actionRS = userQuery.executeQuery(); users.add("unspecified"); while (actionRS.next()) { try { String s = actionRS.getString(1); s = s.trim(); if (!Utility.stringIsNullOrEmpty(s)) { String[] items = s.split(";"); for (int x = 0; x < items.length; x++) { if (!Utility.stringIsNullOrEmpty(items[x])) { users.add(items[x].trim()); } } } } catch (Exception ex) { log.log(Level.WARN, " error querying database", ex); } } } catch (Exception ex) { log.log(Level.WARN, " error querying database", ex); } finally { DBUtils.safeClose(actionRS); DBUtils.safeClose(userQuery); } try { Iterator<String> iterator = users.iterator(); while (iterator.hasNext()) { String u = iterator.next(); try { if (u.equalsIgnoreCase("unspecified")) { cmd = con.prepareStatement( "select count(*) from RawData where consumeridentity is null and " + "(UTCdatetime > ?) and (UTCdatetime < ?)"); cmd.setLong(1, range.getStart().getTimeInMillis()); cmd.setLong(2, range.getEnd().getTimeInMillis()); } else { cmd = con.prepareStatement("select count(*) from RawData where consumeridentity=? and " + "(UTCdatetime > ?) and (UTCdatetime < ?)"); cmd.setString(1, u); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); } rs = cmd.executeQuery(); long count = 0; try { if (rs.next()) { count = rs.getLong(1); } } catch (Exception ex) { log.log(Level.DEBUG, " error querying database", ex); } data.append("<tr><td>").append(Utility.encodeHTML(u)).append("</td><td>"); data.append(count + "").append("</td></tr>"); if (count > 0) { set.addValue(count, u, u); } } catch (Exception ex) { log.log(Level.WARN, " error querying database", ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } } } catch (Exception ex) { data.append("0</td></tr>"); log.log(Level.ERROR, "Error opening or querying the database.", ex); } finally { DBUtils.safeClose(cmd); } chart = org.jfree.chart.ChartFactory.createBarChart(GetDisplayName(), "Consumers", "", set, PlotOrientation.HORIZONTAL, true, false, false); data.append("</table>"); try { ChartUtilities.saveChartAsPNG(new File( path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart, 1500, pixelHeightCalc(set.getRowCount())); } catch (IOException ex) { log.log(Level.ERROR, "Error saving chart image for request", ex); } data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">"); files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"); } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(con); } }
From source file:org.miloss.fgsms.services.rs.impl.reports.ws.SuccessFailureCountByServiceByMethod.java
/** * {@inheritDoc}/*from w ww . j av a 2 s . com*/ */ @Override public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files, TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx) throws IOException { Connection con = Utility.getPerformanceDBConnection(); try { PreparedStatement cmd = null; ResultSet rs = null; DefaultCategoryDataset set = new DefaultCategoryDataset(); JFreeChart chart = null; data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>"); data.append("This represents the success and failure counts by Service by Method<br />"); //add description data.append( "<table class=\"table table-hover\"><tr><th>URL</th><th>Method</th><th>Success</th><th>Failure</th></tr>"); for (int i = 0; i < urls.size(); i++) { if (!isPolicyTypeOf(urls.get(i), PolicyType.TRANSACTIONAL)) { continue; } //https://github.com/mil-oss/fgsms/issues/112 if (!UserIdentityUtil.hasReadAccess(currentuser, "getReport", urls.get(i), classification, ctx)) { continue; } String url = Utility.encodeHTML(BaseReportGenerator.getPolicyDisplayName(urls.get(i))); try { List<String> actions = getSoapActions(urls.get(i), con); for (int k = 0; k < actions.size(); k++) { long success = 0; long failures = 0; try { cmd = con.prepareStatement("select count(*) from RawData where URI=? and " + "(UTCdatetime > ?) and (UTCdatetime < ?) and soapaction=? and success=true;"); cmd.setString(1, urls.get(i)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); cmd.setString(4, actions.get(k)); rs = cmd.executeQuery(); try { if (rs.next()) { success = rs.getLong(1); } } catch (Exception ex) { log.log(Level.DEBUG, null, ex); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } try { cmd = con.prepareStatement("select count(*) from RawData where URI=? and " + "(UTCdatetime > ?) and (UTCdatetime < ?) and soapaction=? and success=false;"); cmd.setString(1, urls.get(i)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); cmd.setString(4, actions.get(k)); rs = cmd.executeQuery(); try { if (rs.next()) { failures = rs.getLong(1); } } catch (Exception ex) { log.log(Level.DEBUG, null, ex); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } data.append("<tr><td>").append(url).append("</td><td>"); data.append(Utility.encodeHTML(actions.get(k))).append("</td><td>").append(success + "") .append("</td><td>").append(failures + "").append("</td></tr>"); if (success > 0) { set.addValue(success, url + " Success", url + " Success"); } if (failures > 0) { set.addValue(failures, url + " Failures", url + " Failures"); } } } catch (Exception ex) { data.append("0 bytes</td></tr>"); log.log(Level.ERROR, "Error opening or querying the database.", ex); } } chart = org.jfree.chart.ChartFactory.createBarChart(GetDisplayName(), "Service URL", "", set, PlotOrientation.HORIZONTAL, true, false, false); data.append("</table>"); try { ChartUtilities.saveChartAsPNG(new File( path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart, 1500, pixelHeightCalc(set.getRowCount())); } catch (IOException ex) { log.log(Level.ERROR, "Error saving chart image for request", ex); } data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">"); files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"); } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(con); } }