Search in sources :

Example 1 with JFreeReportAction

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

the class JFreeReportComponent method getReportFromResource.

private MasterReport getReportFromResource() throws ResourceException, IOException {
    JFreeReportAction jFreeReportAction = (JFreeReportAction) getActionDefinition();
    MasterReport report = null;
    Object reportDefinition = jFreeReportAction.getReportDefinition();
    IActionSequenceResource resource = null;
    if (reportDefinition instanceof ActionResource) {
        resource = getResource(((ActionResource) reportDefinition).getName());
    }
    if (resource != null) {
        if (resource.getSourceType() == IActionResource.XML) {
            String repDef = resource.getAddress();
            ReportGenerator generator = ReportGenerator.createInstance();
            // add the runtime context so that PentahoResourceData class can get access to the solution repo
            // generator.setObject(PentahoResourceData.PENTAHO_RUNTIME_CONTEXT_KEY, getRuntimeContext());
            // Read the encoding from the XML file - see BISERVER-895
            final String encoding = XmlHelper.getEncoding(repDef, null);
            ByteArrayInputStream inStream = new ByteArrayInputStream(repDef.getBytes(encoding));
            InputSource repDefInputSource = new InputSource(inStream);
            repDefInputSource.setEncoding(encoding);
            report = generator.parseReport(repDefInputSource, getDefinedResourceURL(null));
        } else {
            report = parseReport(resource);
        }
    }
    return report;
}
Also used : JFreeReportAction(org.pentaho.actionsequence.dom.actions.JFreeReportAction) MasterReport(org.pentaho.reporting.engine.classic.core.MasterReport) ReportGenerator(org.pentaho.reporting.engine.classic.core.modules.parser.base.ReportGenerator) InputSource(org.xml.sax.InputSource) ByteArrayInputStream(java.io.ByteArrayInputStream) IActionResource(org.pentaho.actionsequence.dom.IActionResource) ActionResource(org.pentaho.actionsequence.dom.ActionResource) IActionSequenceResource(org.pentaho.platform.api.engine.IActionSequenceResource)

Example 2 with JFreeReportAction

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

the class JFreeReportComponent method initReportConfigParameters.

private boolean initReportConfigParameters(final MasterReport report) {
    JFreeReportAction jFreeReportAction = (JFreeReportAction) getActionDefinition();
    boolean result = true;
    if (isDefinedInput(AbstractJFreeReportComponent.DATACOMPONENT_REPORTTEMP_OBJINPUT)) {
        Object reportConfigParams = jFreeReportAction.getReportConfig().getValue();
        if (reportConfigParams != null) {
            if (reportConfigParams instanceof IPentahoResultSet) {
                setReportConfigParameters(report, (IPentahoResultSet) reportConfigParams);
            } else if (reportConfigParams instanceof Map) {
                setReportConfigParameters(report, (Map) reportConfigParams);
            } else if (reportConfigParams instanceof JFreeReportAction.StaticReportConfig) {
                setReportConfigParameters(report, (JFreeReportAction.StaticReportConfig) reportConfigParams);
            } else {
                error(Messages.getInstance().getErrorString(// $NON-NLS-1$
                "JFreeReport.ERROR_0026_UNKNOWN_REPORT_CONFIGURATION_PARAMETERS"));
                result = false;
            }
        }
    }
    return result;
}
Also used : JFreeReportAction(org.pentaho.actionsequence.dom.actions.JFreeReportAction) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with JFreeReportAction

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

the class JFreeReportComponent method getInputParamDataFactory.

private PentahoTableDataFactory getInputParamDataFactory() {
    PentahoTableDataFactory factory = null;
    JFreeReportAction jFreeReportAction = (JFreeReportAction) getActionDefinition();
    ActionInput reportDataParam = (ActionInput) jFreeReportAction.getData();
    Object dataObject = reportDataParam != null ? reportDataParam.getValue() : null;
    if ((dataObject instanceof IPentahoResultSet) || (dataObject instanceof TableModel)) {
        factory = new PentahoTableDataFactory();
        if (dataObject instanceof IPentahoResultSet) {
            IPentahoResultSet resultset = (IPentahoResultSet) dataObject;
            if (resultset.isScrollable()) {
                resultset.beforeFirst();
            } else {
                // $NON-NLS-1$
                debug("ResultSet is not scrollable. Copying into memory");
                IPentahoResultSet memSet = resultset.memoryCopy();
                resultset.close();
                resultset = memSet;
            }
            factory.addTable(AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT, new PentahoTableModel(resultset));
        } else if (dataObject instanceof TableModel) {
            factory.addTable(AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT, (TableModel) dataObject);
        }
        IActionInput[] subreportQueries = jFreeReportAction.getSubreportQueryParams();
        for (IActionInput element : subreportQueries) {
            dataObject = element.getValue();
            if (dataObject instanceof IPreparedComponent) {
                factory.addPreparedComponent(element.getName(), (IPreparedComponent) dataObject);
            } else if (dataObject instanceof IPentahoResultSet) {
                final IPentahoResultSet resultset = (IPentahoResultSet) dataObject;
                resultset.beforeFirst();
                factory.addTable(element.getName(), new PentahoTableModel(resultset));
            } else if (dataObject instanceof TableModel) {
                factory.addTable(element.getName(), (TableModel) dataObject);
            }
        }
    }
    return factory;
}
Also used : JFreeReportAction(org.pentaho.actionsequence.dom.actions.JFreeReportAction) PentahoTableModel(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) ActionInput(org.pentaho.actionsequence.dom.ActionInput) IActionInput(org.pentaho.actionsequence.dom.IActionInput) IActionInput(org.pentaho.actionsequence.dom.IActionInput) PentahoTableDataFactory(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory) TableModel(javax.swing.table.TableModel) PentahoTableModel(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel) IPreparedComponent(org.pentaho.platform.api.data.IPreparedComponent)

Example 4 with JFreeReportAction

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

the class JFreeReportComponent method getContentItem.

protected IContentItem getContentItem(final String mimeType, final String extension) {
    JFreeReportAction jFreeReportAction = (JFreeReportAction) getActionDefinition();
    // Try to get the output from the action-sequence document.
    IContentItem contentItem = null;
    IActionOutput actionOutput = jFreeReportAction.getOutputReport();
    if (actionOutput != null) {
        contentItem = getOutputItem(actionOutput.getName(), mimeType, extension);
        contentItem.setMimeType(mimeType);
    } else if (getOutputNames().size() == 1) {
        String outputName = (String) getOutputNames().iterator().next();
        contentItem = getOutputContentItem(outputName, mimeType);
        contentItem.setMimeType(mimeType);
    }
    return contentItem;
}
Also used : JFreeReportAction(org.pentaho.actionsequence.dom.actions.JFreeReportAction) IActionOutput(org.pentaho.actionsequence.dom.IActionOutput) IContentItem(org.pentaho.platform.api.repository.IContentItem)

Example 5 with JFreeReportAction

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

the class JFreeReportComponent method generateReport.

private boolean generateReport(final MasterReport report, final PentahoTableDataFactory factory) throws IOException {
    JFreeReportAction jFreeReportAction = (JFreeReportAction) getActionDefinition();
    boolean result = false;
    try {
        applyThreadPriority();
        // this might be invalid in case the action is contained in a sub-directory.
        final String baseName = IOUtils.getInstance().stripFileExtension(getActionName());
        final String path = getSolutionPath();
        final PentahoResourceBundleFactory bundleFactory = new PentahoResourceBundleFactory(path, baseName, getSession());
        report.setResourceBundleFactory(bundleFactory);
        // set the default resourcebundle. This allows users to override the
        // resource-bundle in case they want to keep common strings in a common
        // collection.
        report.getReportConfiguration().setConfigProperty(ResourceBundleFactory.DEFAULT_RESOURCE_BUNDLE_CONFIG_KEY, baseName);
        if (factory != null) {
            report.setDataFactory(factory);
        }
        String printerName = jFreeReportAction.getPrinterName().getStringValue();
        String outputFormat = jFreeReportAction.getOutputType().getStringValue();
        if (printerName != null) {
            result = print(report, getActionTitle(), printerName);
        } else if (AbstractJFreeReportComponent.REPORTALLCONTENT_OUTPUTTYPE_SWING.equals(outputFormat)) {
            if (GraphicsEnvironment.isHeadless()) {
                result = writeSwingPreview(report);
            }
            // $NON-NLS-1$
            warn(Messages.getInstance().getString("JFreeReportAllContentComponent.WARN_HEADLESSMODE_ACTIVE"));
        } else if (AbstractJFreeReportComponent.REPORTALLCONTENT_OUTPUTTYPE_HTML.equals(outputFormat) || AbstractJFreeReportComponent.REPORTALLCONTENT_OUTPUTTYPE_PDF.equals(outputFormat) || AbstractJFreeReportComponent.REPORTALLCONTENT_OUTPUTTYPE_XLS.equals(outputFormat) || AbstractJFreeReportComponent.REPORTALLCONTENT_OUTPUTTYPE_CSV.equals(outputFormat) || AbstractJFreeReportComponent.REPORTALLCONTENT_OUTPUTTYPE_RTF.equals(outputFormat) || AbstractJFreeReportComponent.REPORTALLCONTENT_OUTPUTTYPE_XML.equals(outputFormat)) {
            String mimeType = getMimeType(outputFormat);
            String fileExtention = getFileExtension(outputFormat);
            IContentItem contentItem = getContentItem(mimeType, fileExtention);
            OutputStream outputStream = null;
            if (contentItem != null) {
                outputStream = contentItem.getOutputStream(getActionName());
            } else {
                outputStream = getDefaultOutputStream(mimeType);
            }
            result = writeReport(outputFormat, report, outputStream, jFreeReportAction.getReportGenerationYieldRate().getIntValue(0), jFreeReportAction.getHtmlContentHandlerUrlPattern().getStringValue());
            if (contentItem != null) {
                contentItem.closeOutputStream();
            }
        } else {
            // $NON-NLS-1$
            warn(Messages.getInstance().getString("JFreeReportAllContentComponent.WARN_NO_PRINTER_GIVEN"));
        }
    } finally {
        if (factory != null) {
            // force close the factory
            factory.closeTables();
        }
    }
    return result;
}
Also used : JFreeReportAction(org.pentaho.actionsequence.dom.actions.JFreeReportAction) OutputStream(java.io.OutputStream) IContentItem(org.pentaho.platform.api.repository.IContentItem) PentahoResourceBundleFactory(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoResourceBundleFactory)

Aggregations

JFreeReportAction (org.pentaho.actionsequence.dom.actions.JFreeReportAction)14 IActionInput (org.pentaho.actionsequence.dom.IActionInput)5 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)4 PentahoTableModel (org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel)4 MasterReport (org.pentaho.reporting.engine.classic.core.MasterReport)4 TableModel (javax.swing.table.TableModel)3 IActionResource (org.pentaho.actionsequence.dom.IActionResource)3 PentahoTableDataFactory (org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 DataSource (javax.activation.DataSource)2 PrintException (javax.print.PrintException)2 ActionInput (org.pentaho.actionsequence.dom.ActionInput)2 IActionSequenceResource (org.pentaho.platform.api.engine.IActionSequenceResource)2 IContentItem (org.pentaho.platform.api.repository.IContentItem)2 ReportProcessingException (org.pentaho.reporting.engine.classic.core.ReportProcessingException)2 ReportGenerator (org.pentaho.reporting.engine.classic.core.modules.parser.base.ReportGenerator)2 ContentIOException (org.pentaho.reporting.libraries.repository.ContentIOException)2