Search in sources :

Example 1 with Slide

use of org.apache.poi.hslf.model.Slide in project ddf by codice.

the class RrdMetricsRetrieverTest method testMetricsPptReport.

@Test
public void testMetricsPptReport() throws Exception {
    String rrdFilename = TEST_DIR + "queryCount_Counter" + RRD_FILE_EXTENSION;
    new RrdFileBuilder().rrdFileName(rrdFilename).build();
    rrdFilename = TEST_DIR + "queryCount_Gauge" + RRD_FILE_EXTENSION;
    long endTime = new RrdFileBuilder().rrdFileName(rrdFilename).dsType(DsType.GAUGE).build();
    List<String> metricNames = new ArrayList<String>();
    metricNames.add("queryCount_Counter");
    metricNames.add("queryCount_Gauge");
    MetricsRetriever metricsRetriever = new RrdMetricsRetriever();
    OutputStream os = metricsRetriever.createPptReport(metricNames, TEST_DIR, START_TIME, endTime);
    InputStream is = new ByteArrayInputStream(((ByteArrayOutputStream) os).toByteArray());
    assertThat(is, not(nullValue()));
    SlideShow ppt = new SlideShow(is);
    Slide[] slides = ppt.getSlides();
    assertThat(slides.length, equalTo(2));
    verifySlide(slides[0], "queryCount_Counter", true);
    verifySlide(slides[1], "queryCount_Gauge", false);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) ByteArrayInputStream(java.io.ByteArrayInputStream) Slide(org.apache.poi.hslf.model.Slide) SlideShow(org.apache.poi.hslf.usermodel.SlideShow) MetricsRetriever(ddf.metrics.reporting.internal.MetricsRetriever) Test(org.junit.Test)

Example 2 with Slide

use of org.apache.poi.hslf.model.Slide in project ddf by codice.

the class RrdMetricsRetrieverTest method testMetricsPptDataWithGauge.

@Test
public void testMetricsPptDataWithGauge() throws Exception {
    String rrdFilename = TEST_DIR + "queryCount_Gauge" + RRD_FILE_EXTENSION;
    long endTime = new RrdFileBuilder().rrdFileName(rrdFilename).dsType(DsType.GAUGE).build();
    MetricsRetriever metricsRetriever = new RrdMetricsRetriever();
    OutputStream os = metricsRetriever.createPptData("queryCount", rrdFilename, START_TIME, endTime);
    InputStream is = new ByteArrayInputStream(((ByteArrayOutputStream) os).toByteArray());
    assertThat(is, not(nullValue()));
    SlideShow ppt = new SlideShow(is);
    Slide[] slides = ppt.getSlides();
    assertThat(slides.length, equalTo(1));
    verifySlide(slides[0], "queryCount", false);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Slide(org.apache.poi.hslf.model.Slide) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SlideShow(org.apache.poi.hslf.usermodel.SlideShow) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) MetricsRetriever(ddf.metrics.reporting.internal.MetricsRetriever) Test(org.junit.Test)

Example 3 with Slide

use of org.apache.poi.hslf.model.Slide in project ddf by codice.

the class RrdMetricsRetriever method createSlide.

/**
     * Adds a slide containing the metric's graph to the PowerPoint slide deck. The title is usually
     * the metric's name and is usually in camelCase format. This will be converted to individual,
     * capitalized words to the slide's title. The metric's data is used to determine the total
     * count across all of the metric's data, which is displayed at the bottom of the slide, under
     * the graph.
     *
     * @param ppt        the PowerPoint slide deck to add this slide to
     * @param title      the title for this slide
     * @param graph      the metric's graph to be added to this slide
     * @param metricData the metric's data
     * @throws IOException
     * @throws MetricsGraphException
     */
private void createSlide(SlideShow ppt, String title, byte[] graph, MetricData metricData) throws IOException, MetricsGraphException {
    LOGGER.trace("ENTERING: createSlide");
    if (LOGGER.isDebugEnabled()) {
        java.awt.Dimension pgsize = ppt.getPageSize();
        // slide width (720)
        int pgx = pgsize.width;
        // slide height (540)
        int pgy = pgsize.height;
        LOGGER.debug("ppt page width = {}", pgx);
        LOGGER.debug("ppt page height = {}", pgy);
    }
    // Convert title, if it is in camelCase, to individual words with each word
    // starting with a capital letter
    String slideTitle = convertCamelCase(title);
    Slide slide = ppt.createSlide();
    // Add the title to the slide
    TextBox titleTextBox = slide.addTitle();
    TextRun textRun = titleTextBox.getTextRun();
    textRun.getRichTextRuns()[0].setFontSize(32);
    titleTextBox.setText(slideTitle);
    titleTextBox.setHorizontalAlignment(TextBox.AlignCenter);
    // Add the metric's graph to the slide
    int idx = ppt.addPicture(graph, Picture.PNG);
    Picture pict = new Picture(idx);
    // set graph's position and size in the slide
    // (Be sure to maintain aspect ratio for the image when specifying the
    // width and height. Refer to width and height values used in createGraph())
    pict.setAnchor(new Rectangle(20, 100, 650, 325));
    slide.addShape(pict);
    // If metric has a total count, add it under the graph on the slide
    if (metricData.hasTotalCount()) {
        TextBox totalCountTextBox = new TextBox();
        textRun = totalCountTextBox.getTextRun();
        textRun.getRichTextRuns()[0].setFontSize(14);
        totalCountTextBox.setText("Total Count: " + metricData.getTotalCount());
        totalCountTextBox.setHorizontalAlignment(TextBox.AlignLeft);
        // x,y values determined relative to x,y of graph's anchor position
        // and the height of the graph
        totalCountTextBox.setAnchor(new Rectangle(20, 450, 250, 80));
        slide.addShape(totalCountTextBox);
    }
    LOGGER.trace("EXITING: createSlide");
}
Also used : Slide(org.apache.poi.hslf.model.Slide) Picture(org.apache.poi.hslf.model.Picture) Rectangle(java.awt.Rectangle) TextBox(org.apache.poi.hslf.model.TextBox) TextRun(org.apache.poi.hslf.model.TextRun)

Example 4 with Slide

use of org.apache.poi.hslf.model.Slide in project ddf by codice.

the class RrdMetricsRetrieverTest method testMetricsPptDataWithCounter.

@Test
public void testMetricsPptDataWithCounter() throws Exception {
    String rrdFilename = TEST_DIR + "queryCount_Counter" + RRD_FILE_EXTENSION;
    long endTime = new RrdFileBuilder().rrdFileName(rrdFilename).build();
    MetricsRetriever metricsRetriever = new RrdMetricsRetriever();
    OutputStream os = metricsRetriever.createPptData("queryCount", rrdFilename, START_TIME, endTime);
    InputStream is = new ByteArrayInputStream(((ByteArrayOutputStream) os).toByteArray());
    assertThat(is, not(nullValue()));
    SlideShow ppt = new SlideShow(is);
    Slide[] slides = ppt.getSlides();
    assertThat(slides.length, equalTo(1));
    verifySlide(slides[0], "queryCount", true);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Slide(org.apache.poi.hslf.model.Slide) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SlideShow(org.apache.poi.hslf.usermodel.SlideShow) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) MetricsRetriever(ddf.metrics.reporting.internal.MetricsRetriever) Test(org.junit.Test)

Example 5 with Slide

use of org.apache.poi.hslf.model.Slide in project ddf by codice.

the class MetricsEndpointTest method testGetMetricsDataAsPpt.

@Test
public void testGetMetricsDataAsPpt() throws Exception {
    // Create RRD file that Metrics Endpoint will detect
    // 15 minutes in seconds
    int dateOffset = 900;
    createRrdFile(dateOffset);
    UriInfo uriInfo = createUriInfo();
    // Get the metrics data from the endpoint
    MetricsEndpoint endpoint = getEndpoint();
    endpoint.setMetricsDir(TEST_DIR);
    Response response = endpoint.getMetricsData("uptime", "ppt", null, null, Integer.toString(dateOffset), "my label", "my title", uriInfo);
    cleanupRrd();
    InputStream is = (InputStream) response.getEntity();
    assertThat(is, not(nullValue()));
    SlideShow ppt = new SlideShow(is);
    Slide[] slides = ppt.getSlides();
    assertThat(slides.length, equalTo(1));
}
Also used : Response(javax.ws.rs.core.Response) Slide(org.apache.poi.hslf.model.Slide) InputStream(java.io.InputStream) SlideShow(org.apache.poi.hslf.usermodel.SlideShow) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Aggregations

Slide (org.apache.poi.hslf.model.Slide)6 InputStream (java.io.InputStream)5 SlideShow (org.apache.poi.hslf.usermodel.SlideShow)5 Test (org.junit.Test)5 MetricsRetriever (ddf.metrics.reporting.internal.MetricsRetriever)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 OutputStream (java.io.OutputStream)3 Response (javax.ws.rs.core.Response)2 UriInfo (javax.ws.rs.core.UriInfo)2 Rectangle (java.awt.Rectangle)1 ArrayList (java.util.ArrayList)1 Picture (org.apache.poi.hslf.model.Picture)1 TextBox (org.apache.poi.hslf.model.TextBox)1 TextRun (org.apache.poi.hslf.model.TextRun)1 JSONObject (org.json.simple.JSONObject)1 Matchers.anyString (org.mockito.Matchers.anyString)1