Search in sources :

Example 1 with PivotModel

use of org.pivot4j.PivotModel in project bamboobsc by billchen198318.

the class Pivot4JUtils method getPivotModel.

private static PivotModel getPivotModel(OlapDataSource dataSource, String mdx) throws Exception {
    PivotModel model = new PivotModelImpl(dataSource);
    model.setMdx(mdx);
    model.initialize();
    return model;
}
Also used : PivotModel(org.pivot4j.PivotModel) PivotModelImpl(org.pivot4j.impl.PivotModelImpl)

Example 2 with PivotModel

use of org.pivot4j.PivotModel in project bamboobsc by billchen198318.

the class Pivot4JUtils method exportExcelFile.

public static File exportExcelFile(String mondrianUrl, String mdx, boolean showDimensionTitle, boolean showParentMembers) throws Exception {
    if (StringUtils.isBlank(mondrianUrl) || StringUtils.isBlank(mdx)) {
        throw new java.lang.IllegalArgumentException("mondrian url and MDX cannot blank.");
    }
    File file = new File(Constants.getWorkTmpDir() + "/" + SimpleUtils.getUUIDStr() + ".xlsx");
    OutputStream os = new FileOutputStream(file);
    OlapConnection connection = OlapUtils.getConnection(mondrianUrl);
    OlapDataSource dataSource = new SingleConnectionOlapDataSource(connection);
    try {
        PivotModel model = getPivotModel(dataSource, mdx);
        TableRenderer renderer = getTableRenderer(showDimensionTitle, showParentMembers);
        ExcelExporter exporter = new ExcelExporter(os);
        exporter.setFormat(Format.XSSF);
        renderer.render(model, exporter);
    } catch (Exception e) {
        file = null;
        throw e;
    } finally {
        if (os != null) {
            IOUtils.closeQuietly(os);
            os = null;
        }
        OlapUtils.nullConnection(connection);
        connection = null;
        dataSource = null;
    }
    return file;
}
Also used : TableRenderer(org.pivot4j.ui.table.TableRenderer) SingleConnectionOlapDataSource(org.pivot4j.datasource.SingleConnectionOlapDataSource) OlapDataSource(org.olap4j.OlapDataSource) PivotModel(org.pivot4j.PivotModel) ExcelExporter(org.pivot4j.ui.poi.ExcelExporter) OlapConnection(org.olap4j.OlapConnection) SingleConnectionOlapDataSource(org.pivot4j.datasource.SingleConnectionOlapDataSource) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) IOException(java.io.IOException)

Example 3 with PivotModel

use of org.pivot4j.PivotModel in project bamboobsc by billchen198318.

the class Pivot4JUtils method rendererHtml.

public static String rendererHtml(String mondrianUrl, String mdx, boolean showDimensionTitle, boolean showParentMembers) throws Exception {
    if (StringUtils.isBlank(mondrianUrl) || StringUtils.isBlank(mdx)) {
        throw new java.lang.IllegalArgumentException("mondrian url and MDX cannot blank.");
    }
    String body = "";
    OlapConnection connection = OlapUtils.getConnection(mondrianUrl);
    OlapDataSource dataSource = new SingleConnectionOlapDataSource(connection);
    try {
        PivotModel model = getPivotModel(dataSource, mdx);
        TableRenderer renderer = getTableRenderer(showDimensionTitle, showParentMembers);
        StringWriter writer = new StringWriter();
        renderer.render(model, new HtmlRenderCallback(writer));
        //writer.write(body);
        body = writer.toString();
        writer.flush();
        writer.close();
    } catch (Exception e) {
        throw e;
    } finally {
        OlapUtils.nullConnection(connection);
        connection = null;
        dataSource = null;
    }
    return body;
}
Also used : TableRenderer(org.pivot4j.ui.table.TableRenderer) SingleConnectionOlapDataSource(org.pivot4j.datasource.SingleConnectionOlapDataSource) OlapDataSource(org.olap4j.OlapDataSource) PivotModel(org.pivot4j.PivotModel) StringWriter(java.io.StringWriter) OlapConnection(org.olap4j.OlapConnection) SingleConnectionOlapDataSource(org.pivot4j.datasource.SingleConnectionOlapDataSource) HtmlRenderCallback(org.pivot4j.ui.html.HtmlRenderCallback) IOException(java.io.IOException)

Aggregations

PivotModel (org.pivot4j.PivotModel)3 IOException (java.io.IOException)2 OlapConnection (org.olap4j.OlapConnection)2 OlapDataSource (org.olap4j.OlapDataSource)2 SingleConnectionOlapDataSource (org.pivot4j.datasource.SingleConnectionOlapDataSource)2 TableRenderer (org.pivot4j.ui.table.TableRenderer)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 StringWriter (java.io.StringWriter)1 PivotModelImpl (org.pivot4j.impl.PivotModelImpl)1 HtmlRenderCallback (org.pivot4j.ui.html.HtmlRenderCallback)1 ExcelExporter (org.pivot4j.ui.poi.ExcelExporter)1