Search in sources :

Example 1 with JFreeReportGenAction

use of org.pentaho.actionsequence.dom.actions.JFreeReportGenAction in project pentaho-platform by pentaho.

the class JFreeReportGeneratorComponent method executeAction.

@Override
protected boolean executeAction() {
    /*
     * The on-the-fly JFreeReport generator will expect the following: =============================================
     * 
     * INPUT: Path (String) to Existing JFreeReport to use as "template" OutputStream to write generated report
     * IPentahoResultSet List of Columns to "Group" List of column widths
     * 
     * OUTPUT: JFreeReport XML to provided Path or OutputStream
     * 
     * ASSUMPTIONS: List of column widths - last provided item is to be repeated for all remaining columns Perform
     * ItemSumFunction on all numeric columns per group and grand total Perform ItemSumFunction on calculated column per
     * group and grand total Groups and Items will be removed from template (we will retain font/color data)
     * =============================================
     * 
     * public OnTheFlyJFreeReportGenerator(String path, IPentahoResultSet set, List groupLabels, List widths,
     * OutputStream stream) ------ public void process()
     */
    JFreeReportGenAction genAction = null;
    if (!(getActionDefinition() instanceof JFreeReportGenAction)) {
        error(Messages.getInstance().getErrorString("JFreeReportGeneratorComponent.ERROR_0001_UNKNOWN_ACTION_TYPE", // $NON-NLS-1$
        getActionDefinition().getElement().asXML()));
        return false;
    } else {
        genAction = (JFreeReportGenAction) getActionDefinition();
        resultSet = (IPentahoResultSet) genAction.getResultSet().getValue();
        Node componentNode = null;
        String settingsFromActionSequence = null;
        try {
            settingsFromActionSequence = genAction.getComponentSettings().getStringValue();
        } catch (Exception ex) {
        // ignore
        }
        if (settingsFromActionSequence != null) {
            try {
                Document settingsDoc = XmlDom4JHelper.getDocFromString(settingsFromActionSequence, new PentahoEntityResolver());
                componentNode = settingsDoc.getRootElement();
            } catch (Exception e) {
                // $NON-NLS-1$
                error("Could not get settings from action sequence document", e);
                return false;
            }
        } else {
            componentNode = getComponentDefinition();
        }
        try {
            compPath = genAction.getTemplatePath().getStringValue();
            path = PentahoSystem.getApplicationContext().getSolutionPath(compPath);
            orientation = genAction.getOrientation().getStringValue();
            nullString = genAction.getNullString().getStringValue();
            horizontalOffset = genAction.getHorizontalOffset().getIntValue(horizontalOffset);
            reportName = genAction.getReportName().getStringValue();
            createSubTotals = genAction.getCreateSubTotals().getBooleanValue(false);
            createGrandTotals = genAction.getCreateGrandTotals().getBooleanValue(false);
            createRowBanding = genAction.getCreateRowBanding().getBooleanValue(false);
            createTotalColumn = genAction.getCreateTotalColumn().getBooleanValue(false);
            totalColumnName = genAction.getTotalColumnName().getStringValue();
            totalColumnWidth = genAction.getTotalColumnWidth().getIntValue(totalColumnWidth);
            totalColumnFormat = genAction.getTotalColumnFormat().getStringValue();
            rowBandingColor = genAction.getRowBandingColor().getStringValue();
            spacerWidth = genAction.getSpacerWidth().getIntValue(spacerWidth);
            columnHeaderBackgroundColor = genAction.getColumnHeaderBackgroundColor().getStringValue();
            columnHeaderForegroundColor = genAction.getColumnHeaderForegroundColor().getStringValue();
            columnHeaderFontFace = genAction.getColumnHeaderFontFace().getStringValue();
            columnHeaderFontSize = genAction.getColumnHeaderFontSize().getStringValue();
            columnHeaderGap = genAction.getColumnHeaderGap().getIntValue(columnHeaderGap);
        } catch (Exception e) {
            e.printStackTrace();
        }
        // Get the group display labels
        List groupLabelNodes = componentNode.selectNodes(JFreeReportGeneratorComponent.GROUP_LABELS_PROP + "/" + // $NON-NLS-1$
        JFreeReportGeneratorComponent.GROUP_LABEL_PROP);
        if (groupLabelNodes != null) {
            groupLabels = new String[groupLabelNodes.size()];
            for (int i = 0; i < groupLabels.length; i++) {
                groupLabels[i] = ((Node) groupLabelNodes.get(i)).getText();
            }
        }
        // Get the grouped columns indices
        List groupedColumnsIndicesNodes = componentNode.selectNodes(JFreeReportGeneratorComponent.GROUPED_COLUMNS_PROP + "/" + // $NON-NLS-1$
        JFreeReportGeneratorComponent.GROUPED_COLUMN_INDICES_PROP);
        if (groupedColumnsIndicesNodes != null) {
            groupIndices = new int[groupedColumnsIndicesNodes.size()];
            for (int i = 0; i < groupIndices.length; i++) {
                groupIndices[i] = Integer.parseInt(((Node) groupedColumnsIndicesNodes.get(i)).getText()) - 1;
            // I am zero based, this is not
            }
        }
        // get display names
        List displayNameNodes = componentNode.selectNodes(JFreeReportGeneratorComponent.COLUMN_NAMES_PROP + "/" + // $NON-NLS-1$
        JFreeReportGeneratorComponent.COLUMN_NAME_PROP);
        if (displayNameNodes != null) {
            displayNames = new String[displayNameNodes.size()];
            for (int i = 0; i < displayNames.length; i++) {
                displayNames[i] = ((Node) displayNameNodes.get(i)).getText();
            }
        }
        // get column alignments
        List columnAlignmentNodes = componentNode.selectNodes(JFreeReportGeneratorComponent.COLUMN_ALIGNMENTS_PROP + "/" + // $NON-NLS-1$
        JFreeReportGeneratorComponent.COLUMN_ALIGNMENT_PROP);
        if (columnAlignmentNodes != null) {
            columnAlignments = new String[columnAlignmentNodes.size()];
            for (int i = 0; i < columnAlignments.length; i++) {
                columnAlignments[i] = ((Node) columnAlignmentNodes.get(i)).getText();
            }
        }
        // Get the column widths
        List widthNodes = componentNode.selectNodes(JFreeReportGeneratorComponent.COLUMN_WIDTHS_PROP + "/" + // $NON-NLS-1$
        JFreeReportGeneratorComponent.WIDTH_PROP);
        if (widthNodes != null) {
            widths = new int[widthNodes.size()];
            for (int i = 0; i < widths.length; i++) {
                widths[i] = Integer.valueOf(((Node) widthNodes.get(i)).getText()).intValue();
            }
        }
        // Get the column item hides
        List itemHideNodes = componentNode.selectNodes(JFreeReportGeneratorComponent.ITEM_HIDES_PROP + "/" + // $NON-NLS-1$
        JFreeReportGeneratorComponent.ITEM_HIDE_PROP);
        if (itemHideNodes != null) {
            itemHides = new boolean[itemHideNodes.size()];
            for (int i = 0; i < itemHides.length; i++) {
                itemHides[i] = Boolean.valueOf(((Node) itemHideNodes.get(i)).getText()).booleanValue();
            }
        }
        // Get the column formats
        List formatNodes = componentNode.selectNodes(JFreeReportGeneratorComponent.COLUMN_FORMATS_PROP + "/" + // $NON-NLS-1$
        JFreeReportGeneratorComponent.FORMAT_PROP);
        if (formatNodes != null) {
            formats = new String[formatNodes.size()];
            for (int i = 0; i < formats.length; i++) {
                formats[i] = ((Node) formatNodes.get(i)).getText();
            }
        }
    }
    String reportDefinition = process();
    if (reportDefinition != null) {
        if (genAction.getOutputReportDefinition() != null) {
            genAction.getOutputReportDefinition().setValue(reportDefinition);
        } else {
            // This is to support the old way where
            // we did not check if report-definition existed in the output section
            setOutputValue(JFreeReportGenAction.REPORT_DEFINITION, reportDefinition);
        }
    }
    return true;
}
Also used : JFreeReportGenAction(org.pentaho.actionsequence.dom.actions.JFreeReportGenAction) Node(org.dom4j.Node) List(java.util.List) LinkedList(java.util.LinkedList) Document(org.dom4j.Document) PentahoEntityResolver(org.pentaho.platform.engine.services.solution.PentahoEntityResolver)

Aggregations

LinkedList (java.util.LinkedList)1 List (java.util.List)1 Document (org.dom4j.Document)1 Node (org.dom4j.Node)1 JFreeReportGenAction (org.pentaho.actionsequence.dom.actions.JFreeReportGenAction)1 PentahoEntityResolver (org.pentaho.platform.engine.services.solution.PentahoEntityResolver)1