Search in sources :

Example 1 with ReportSpec

use of org.pentaho.jfreereport.castormodel.reportspec.ReportSpec in project pentaho-platform by pentaho.

the class ReportWizardSpecComponent method getReportSpec.

@SuppressWarnings("deprecation")
public ReportSpec getReportSpec() throws IOException {
    JFreeReportAction jFreeReportAction = (JFreeReportAction) getActionDefinition();
    DataSource dataSource = new ActivationHelper.PentahoStreamSourceWrapper(jFreeReportAction.getReportDefinitionDataSource());
    ReportSpec reportSpec = null;
    reportSpec = loadFromZip(dataSource.getInputStream());
    if (reportSpec == null) {
        dataSource = new ActivationHelper.PentahoStreamSourceWrapper(jFreeReportAction.getReportDefinitionDataSource());
        reportSpec = (ReportSpec) CastorUtility.getInstance().readCastorObject(dataSource.getInputStream(), ReportSpec.class);
    }
    return reportSpec;
}
Also used : JFreeReportAction(org.pentaho.actionsequence.dom.actions.JFreeReportAction) ReportSpec(org.pentaho.jfreereport.castormodel.reportspec.ReportSpec) ActivationHelper(org.pentaho.commons.connection.ActivationHelper) DataSource(javax.activation.DataSource)

Example 2 with ReportSpec

use of org.pentaho.jfreereport.castormodel.reportspec.ReportSpec in project pentaho-platform by pentaho.

the class JFreeReportGeneratorComponent method process.

@SuppressWarnings("deprecation")
public String process() {
    // CREATE report-spec.xml
    // USE passed in jfreeReportTemplate as "include" -- stuff in
    // report-spec
    // GENERATE JFreeReport from report-spec using code already written in
    // DesignerUtility
    // 
    ByteArrayOutputStream outputStream = null;
    try {
        outputStream = new ByteArrayOutputStream();
    } catch (Exception e) {
        getLogger().error(e);
    }
    ReportSpec reportSpec = new ReportSpec();
    reportSpec.setReportName(reportName);
    reportSpec.setHorizontalOffset(horizontalOffset);
    reportSpec.setIncludeSrc(getPath());
    // $NON-NLS-1$
    reportSpec.setQuery("no query");
    reportSpec.setReportSpecChoice(new ReportSpecChoice());
    // $NON-NLS-1$
    reportSpec.getReportSpecChoice().setJndiSource("SampleData");
    reportSpec.setCalculateGrandTotals(createGrandTotals);
    reportSpec.setTopMargin(10);
    reportSpec.setBottomMargin(10);
    reportSpec.setLeftMargin(10);
    reportSpec.setRightMargin(10);
    reportSpec.setUseRowBanding(createRowBanding);
    reportSpec.setColumnHeaderGap(columnHeaderGap);
    if (rowBandingColor != null) {
        reportSpec.setRowBandingColor(rowBandingColor);
    }
    if (columnHeaderBackgroundColor != null) {
        reportSpec.setColumnHeaderBackgroundColor(columnHeaderBackgroundColor);
    }
    if (columnHeaderForegroundColor != null) {
        reportSpec.setColumnHeaderFontColor(columnHeaderForegroundColor);
    }
    if (columnHeaderFontFace != null) {
        reportSpec.setColumnHeaderFontName(columnHeaderFontFace);
    }
    if (columnHeaderFontSize != null) {
        reportSpec.setColumnHeaderFontSize(Integer.parseInt(columnHeaderFontSize));
    }
    reportSpec.setOrientation(orientation);
    Object[] colHeaders = resultSet.getMetaData().getColumnHeaders()[0];
    int totalWidth = reportSpec.getLeftMargin() + reportSpec.getRightMargin();
    List groupsList = new LinkedList();
    List details = new LinkedList();
    // leading spacer
    if (spacerWidth > 0) {
        Field spacer = new Field();
        // $NON-NLS-1$
        spacer.setName("");
        // $NON-NLS-1$
        spacer.setDisplayName("");
        spacer.setType(Types.VARCHAR);
        // $NON-NLS-1$
        spacer.setFormat("");
        // $NON-NLS-1$
        spacer.setHorizontalAlignment("right");
        // $NON-NLS-1$
        spacer.setVerticalAlignment("middle");
        spacer.setWidth(new BigDecimal(spacerWidth));
        spacer.setWidthLocked(true);
        totalWidth += spacerWidth;
        // $NON-NLS-1$
        spacer.setExpression("none");
        spacer.setIsWidthPercent(false);
        spacer.setIsDetail(true);
        reportSpec.addField(spacer);
    }
    for (int i = 0; i < colHeaders.length; i++) {
        // System.out.println("header [" + i + "] = " + colHeaders[i]);
        Class typeClass = null;
        for (int j = 0; j < resultSet.getRowCount(); j++) {
            Object value = resultSet.getValueAt(j, i);
            if ((value != null) && !value.toString().equals("")) {
                // $NON-NLS-1$
                typeClass = value.getClass();
            }
        }
        String columnName = colHeaders[i].toString();
        Field f = new Field();
        f.setName(columnName);
        f.setNullString(getNullString());
        if (isGroup(columnName)) {
            f.setDisplayName(getGroupLabel(columnName, i));
        } else if (i < displayNames.length) {
            f.setDisplayName(displayNames[i]);
        } else {
            f.setDisplayName(columnName);
        }
        f.setIsWidthPercent(false);
        f.setWidth(new BigDecimal(getWidth(columnName)));
        f.setWidthLocked(true);
        f.setIsDetail(!isGroup(columnName));
        if (f.getIsDetail()) {
            details.add(f);
        } else {
            groupsList.add(f);
        }
        // $NON-NLS-1$
        f.setBackgroundColor("#FFFFFF");
        f.setType(getType(typeClass));
        if ((itemHides == null) || (itemHides.length == 0)) {
            f.setUseItemHide(getType(typeClass) == Types.NUMERIC ? false : true);
        } else {
            f.setUseItemHide(useItemHide(columnName));
        }
        // $NON-NLS-1$
        f.setVerticalAlignment("middle");
        f.setFormat(getColumnFormat(columnName));
        String alignment = getColumnAlignment(columnName);
        if (alignment != null) {
            f.setHorizontalAlignment(alignment);
        } else {
            if (f.getIsDetail() && (f.getType() == Types.NUMERIC)) {
                // $NON-NLS-1$
                f.setHorizontalAlignment("right");
            }
        }
        if (f.getIsDetail() && (f.getType() == Types.NUMERIC)) {
            // $NON-NLS-1$
            f.setExpression("sum");
        } else {
            // $NON-NLS-1$
            f.setExpression("none");
        }
        f.setCalculateGroupTotals(createSubTotals);
        reportSpec.addField(f);
        if ((spacerWidth > 0) && f.getIsDetail()) {
            // spacer
            Field spacer = new Field();
            // $NON-NLS-1$
            spacer.setName("");
            // $NON-NLS-1$
            spacer.setDisplayName("");
            spacer.setType(Types.VARCHAR);
            // $NON-NLS-1$
            spacer.setFormat("");
            // $NON-NLS-1$
            spacer.setHorizontalAlignment("right");
            // $NON-NLS-1$
            spacer.setVerticalAlignment("middle");
            spacer.setWidth(new BigDecimal(spacerWidth));
            spacer.setWidthLocked(true);
            totalWidth += spacerWidth;
            // $NON-NLS-1$
            spacer.setExpression("none");
            spacer.setIsWidthPercent(false);
            spacer.setIsDetail(true);
            reportSpec.addField(spacer);
        }
    }
    for (int i = 0; i < details.size(); i++) {
        Field f = (Field) details.get(i);
        totalWidth += f.getWidth().intValue();
    }
    if (createTotalColumn) {
        Field f = new Field();
        // $NON-NLS-1$
        f.setName("TOTAL_COLUMN");
        f.setDisplayName(totalColumnName);
        f.setType(Types.NUMERIC);
        f.setFormat(totalColumnFormat);
        // $NON-NLS-1$
        f.setHorizontalAlignment("right");
        // $NON-NLS-1$
        f.setVerticalAlignment("middle");
        f.setWidth(new BigDecimal(totalColumnWidth));
        f.setWidthLocked(true);
        // $NON-NLS-1$
        f.setExpression("sum");
        f.setIsWidthPercent(false);
        f.setIsDetail(true);
        reportSpec.addField(f);
        totalWidth += totalColumnWidth;
        if (spacerWidth > 0) {
            // spacer
            Field spacer = new Field();
            // $NON-NLS-1$
            spacer.setName("");
            // $NON-NLS-1$
            spacer.setDisplayName("");
            spacer.setType(Types.VARCHAR);
            // $NON-NLS-1$
            spacer.setFormat("");
            // $NON-NLS-1$
            spacer.setHorizontalAlignment("right");
            // $NON-NLS-1$
            spacer.setVerticalAlignment("middle");
            spacer.setWidth(new BigDecimal(spacerWidth));
            spacer.setWidthLocked(true);
            totalWidth += spacerWidth;
            // $NON-NLS-1$
            spacer.setExpression("none");
            spacer.setIsWidthPercent(false);
            spacer.setIsDetail(true);
            reportSpec.addField(spacer);
        }
    }
    try {
        reportSpec.setUseCustomPageFormat(true);
        int width = 612;
        int height = 792;
        if (orientation.equalsIgnoreCase("landscape")) {
            // $NON-NLS-1$
            width = height;
            height = 612;
        }
        // w totalWidth
        // - = ------------
        // h scaledHeight
        int scaledHeight = (height * totalWidth) / width;
        if (orientation.equalsIgnoreCase("landscape")) {
            // $NON-NLS-1$
            reportSpec.setCustomPageFormatHeight(totalWidth);
            reportSpec.setCustomPageFormatWidth(scaledHeight);
            ReportGenerationUtility.createJFreeReportXML(reportSpec, outputStream, scaledHeight, totalWidth, createTotalColumn, totalColumnName, totalColumnWidth, spacerWidth);
        } else {
            reportSpec.setCustomPageFormatHeight(scaledHeight);
            reportSpec.setCustomPageFormatWidth(totalWidth);
            ReportGenerationUtility.createJFreeReportXML(reportSpec, outputStream, totalWidth, scaledHeight, createTotalColumn, totalColumnName, totalColumnWidth, spacerWidth);
        }
    } catch (Exception e) {
    // ignore
    }
    return new String(outputStream.toByteArray());
}
Also used : ReportSpec(org.pentaho.jfreereport.castormodel.reportspec.ReportSpec) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LinkedList(java.util.LinkedList) BigDecimal(java.math.BigDecimal) ReportSpecChoice(org.pentaho.jfreereport.castormodel.reportspec.ReportSpecChoice) Field(org.pentaho.jfreereport.castormodel.reportspec.Field) List(java.util.List) LinkedList(java.util.LinkedList)

Example 3 with ReportSpec

use of org.pentaho.jfreereport.castormodel.reportspec.ReportSpec in project pentaho-platform by pentaho.

the class ReportWizardSpecComponent method loadFromZip.

@SuppressWarnings("deprecation")
private ReportSpec loadFromZip(final InputStream reportSpecInputStream) {
    try {
        ZipInputStream zis = new ZipInputStream(reportSpecInputStream);
        ZipEntry reportSpecEntry = findReportSpec(zis);
        if (reportSpecEntry == null) {
            return null;
        }
        // maybe you should use GZipped streams instead...
        return (ReportSpec) CastorUtility.getInstance().readCastorObject(zis, ReportSpec.class);
    } catch (Exception e) {
        return null;
    }
}
Also used : ReportSpec(org.pentaho.jfreereport.castormodel.reportspec.ReportSpec) ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException)

Example 4 with ReportSpec

use of org.pentaho.jfreereport.castormodel.reportspec.ReportSpec in project pentaho-platform by pentaho.

the class JFreeReportGenerateDefinitionComponent method loadFromZip.

private ReportSpec loadFromZip(final IActionSequenceResource resource) {
    try {
        InputStream reportSpecInputStream = resource.getInputStream(RepositoryFilePermission.READ, LocaleHelper.getLocale());
        ZipInputStream zis = new ZipInputStream(reportSpecInputStream);
        ZipEntry reportSpecEntry = findReportSpec(zis);
        if (reportSpecEntry == null) {
            return null;
        }
        // maybe you should use GZipped streams instead...
        return (ReportSpec) CastorUtility.getInstance().readCastorObject(zis, ReportSpec.class);
    } catch (Exception e) {
        return null;
    }
}
Also used : ReportSpec(org.pentaho.jfreereport.castormodel.reportspec.ReportSpec) ZipInputStream(java.util.zip.ZipInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 5 with ReportSpec

use of org.pentaho.jfreereport.castormodel.reportspec.ReportSpec in project pentaho-platform by pentaho.

the class JFreeReportGenerateDefinitionComponent method executeAction.

@Override
protected boolean executeAction() {
    boolean result = true;
    try {
        ReportSpec reportSpec = getReportSpec();
        if (reportSpec != null) {
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            // $NON-NLS-1$
            ReportGenerationUtility.createJFreeReportXML(reportSpec, outputStream, 0, 0, false, "", 0, 0);
            String reportDefinition = new String(outputStream.toByteArray());
            addTempParameterObject(AbstractJFreeReportComponent.REPORTGENERATEDEFN_REPORTDEFN, reportDefinition);
            // if that parameter is not defined, we do query for backward compatibility.
            if (!isDefinedInput(AbstractJFreeReportComponent.REPORTGENERATEDEFN_REPORTTEMP_PERFQRY) || "true".equals(getInputParameter(AbstractJFreeReportComponent.REPORTGENERATEDEFN_REPORTTEMP_PERFQRY))) {
                // $NON-NLS-1$
                try {
                    addTempParameterObject(AbstractJFreeReportComponent.DATACOMPONENT_DATAINPUT, getResultSet(reportSpec));
                } catch (Exception e) {
                    result = false;
                }
            }
        }
    } catch (FileNotFoundException ex) {
        error(ex.getLocalizedMessage());
        result = false;
    }
    return result;
}
Also used : ReportSpec(org.pentaho.jfreereport.castormodel.reportspec.ReportSpec) FileNotFoundException(java.io.FileNotFoundException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

ReportSpec (org.pentaho.jfreereport.castormodel.reportspec.ReportSpec)6 IOException (java.io.IOException)3 ZipInputStream (java.util.zip.ZipInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 ZipEntry (java.util.zip.ZipEntry)2 BigDecimal (java.math.BigDecimal)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 DataSource (javax.activation.DataSource)1 JFreeReportAction (org.pentaho.actionsequence.dom.actions.JFreeReportAction)1 ActivationHelper (org.pentaho.commons.connection.ActivationHelper)1 Field (org.pentaho.jfreereport.castormodel.reportspec.Field)1 ReportSpecChoice (org.pentaho.jfreereport.castormodel.reportspec.ReportSpecChoice)1 IActionSequenceResource (org.pentaho.platform.api.engine.IActionSequenceResource)1