Search in sources :

Example 1 with PentahoDataFactory

use of org.pentaho.platform.plugin.action.jfreereport.helper.PentahoDataFactory in project pentaho-platform by pentaho.

the class JFreeReportComponent method getJarDataFactory.

private PentahoTableDataFactory getJarDataFactory() throws Exception {
    PentahoTableDataFactory factory = null;
    JFreeReportAction jFreeReportAction = (JFreeReportAction) getActionDefinition();
    try {
        org.pentaho.actionsequence.dom.IActionResource actionResource = jFreeReportAction.getDataJar().getJar();
        if (actionResource != null) {
            DataSource dataSource = new ActivationHelper.PentahoStreamSourceWrapper(actionResource.getDataSource());
            InputStream in = dataSource.getInputStream();
            try {
                // not being able to read a single char is definitly a big boo ..
                if (in.read() == -1) {
                    // $NON-NLS-1$
                    throw new Exception(Messages.getInstance().getErrorString("JFreeReport.ERROR_0009_REPORT_JAR_UNREADABLE"));
                } else {
                    final ClassLoader loader = ReportUtils.createJarLoader(getSession(), getResource(actionResource.getName()));
                    if (loader == null) {
                        throw new Exception(Messages.getInstance().getString(// $NON-NLS-1$
                        "JFreeReportDataComponent.ERROR_0035_COULD_NOT_CREATE_CLASSLOADER"));
                    } else if (!isDefinedInput(AbstractJFreeReportComponent.DATACOMPONENT_CLASSLOCINPUT)) {
                        throw new Exception(Messages.getInstance().getErrorString(// $NON-NLS-1$
                        "JFreeReport.ERROR_0012_CLASS_LOCATION_MISSING"));
                    } else {
                        // Get input parameters, and set them as properties in the report
                        // object.
                        final ReportParameterValues reportProperties = new ReportParameterValues();
                        IActionInput[] actionInputs = jFreeReportAction.getInputs();
                        for (IActionInput element : actionInputs) {
                            final Object paramValue = element.getValue();
                            if (paramValue instanceof Object[]) {
                                final Object[] values = (Object[]) paramValue;
                                final StringBuffer valuesBuffer = new StringBuffer();
                                // TODO support non-string items
                                for (int z = 0; z < values.length; z++) {
                                    if (z == 0) {
                                        valuesBuffer.append(values[z].toString());
                                    } else {
                                        valuesBuffer.append(',').append(values[z].toString());
                                    }
                                }
                                reportProperties.put(element.getName(), valuesBuffer.toString());
                            } else {
                                reportProperties.put(element.getName(), paramValue);
                            }
                        }
                        final DataFactory dataFactory = new PentahoDataFactory(loader);
                        final TableModel model = dataFactory.queryData(jFreeReportAction.getDataJar().getDataClass(), new ParameterDataRow(reportProperties));
                        factory = new PentahoTableDataFactory(AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT, model);
                    }
                }
            } catch (Exception e) {
                // $NON-NLS-1$
                throw new Exception(Messages.getInstance().getErrorString("JFreeReport.ERROR_0009_REPORT_JAR_UNREADABLE"));
            }
        }
    } catch (FileNotFoundException e1) {
        throw new Exception(Messages.getInstance().getErrorString("JFreeReport.ERROR_0010_REPORT_JAR_MISSING", // $NON-NLS-1$
        jFreeReportAction.getDataJar().toString()));
    }
    return factory;
}
Also used : JFreeReportAction(org.pentaho.actionsequence.dom.actions.JFreeReportAction) IActionResource(org.pentaho.actionsequence.dom.IActionResource) PentahoTableDataFactory(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) PentahoDataFactory(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoDataFactory) PentahoTableDataFactory(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory) DataFactory(org.pentaho.reporting.engine.classic.core.DataFactory) ParameterDataRow(org.pentaho.reporting.engine.classic.core.ParameterDataRow) PrintException(javax.print.PrintException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ContentIOException(org.pentaho.reporting.libraries.repository.ContentIOException) ReportProcessingException(org.pentaho.reporting.engine.classic.core.ReportProcessingException) ResourceException(org.pentaho.reporting.libraries.resourceloader.ResourceException) IOException(java.io.IOException) DataSource(javax.activation.DataSource) IActionInput(org.pentaho.actionsequence.dom.IActionInput) PentahoDataFactory(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoDataFactory) TableModel(javax.swing.table.TableModel) PentahoTableModel(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel) ReportParameterValues(org.pentaho.reporting.engine.classic.core.util.ReportParameterValues)

Example 2 with PentahoDataFactory

use of org.pentaho.platform.plugin.action.jfreereport.helper.PentahoDataFactory in project pentaho-platform by pentaho.

the class JFreeReportDataComponent method getJarDataFactory.

@SuppressWarnings("unused")
private PentahoTableDataFactory getJarDataFactory() throws Exception {
    PentahoTableDataFactory factory = null;
    if (isDefinedResource(AbstractJFreeReportComponent.DATACOMPONENT_JARINPUT)) {
        final IActionSequenceResource resource = getResource(AbstractJFreeReportComponent.DATACOMPONENT_JARINPUT);
        final InputStream in;
        try {
            in = resource.getInputStream(RepositoryFilePermission.READ, LocaleHelper.getLocale());
            try {
                // not being able to read a single char is definitly a big boo ..
                if (in.read() == -1) {
                    // $NON-NLS-1$
                    throw new Exception(Messages.getInstance().getErrorString("JFreeReport.ERROR_0009_REPORT_JAR_UNREADABLE"));
                } else {
                    final ClassLoader loader = ReportUtils.createJarLoader(getSession(), resource);
                    if (loader == null) {
                        throw new Exception(Messages.getInstance().getString(// $NON-NLS-1$
                        "JFreeReportDataComponent.ERROR_0035_COULD_NOT_CREATE_CLASSLOADER"));
                    } else if (!isDefinedInput(AbstractJFreeReportComponent.DATACOMPONENT_CLASSLOCINPUT)) {
                        throw new Exception(Messages.getInstance().getErrorString(// $NON-NLS-1$
                        "JFreeReport.ERROR_0012_CLASS_LOCATION_MISSING"));
                    } else {
                        final String classLocation = getInputStringValue(AbstractJFreeReportComponent.DATACOMPONENT_CLASSLOCINPUT);
                        // Get input parameters, and set them as properties in the report
                        // object.
                        final ReportParameterValues reportProperties = new ReportParameterValues();
                        final Set paramNames = getInputNames();
                        final Iterator it = paramNames.iterator();
                        while (it.hasNext()) {
                            final String paramName = (String) it.next();
                            final Object paramValue = getInputValue(paramName);
                            if (paramValue instanceof Object[]) {
                                final Object[] values = (Object[]) paramValue;
                                final StringBuffer valuesBuffer = new StringBuffer();
                                // TODO support non-string items
                                for (int i = 0; i < values.length; i++) {
                                    if (i == 0) {
                                        valuesBuffer.append(values[i].toString());
                                    } else {
                                        valuesBuffer.append(',').append(values[i].toString());
                                    }
                                }
                                reportProperties.put(paramName, valuesBuffer.toString());
                            } else {
                                reportProperties.put(paramName, paramValue);
                            }
                        }
                        final DataFactory dataFactory = new PentahoDataFactory(loader);
                        final TableModel model = dataFactory.queryData(classLocation, new ParameterDataRow(reportProperties));
                        factory = new PentahoTableDataFactory(AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT, model);
                    }
                }
            } catch (Exception e) {
                // $NON-NLS-1$
                throw new Exception(Messages.getInstance().getErrorString("JFreeReport.ERROR_0009_REPORT_JAR_UNREADABLE"));
            }
        } catch (FileNotFoundException e1) {
            throw new Exception(Messages.getInstance().getErrorString("JFreeReport.ERROR_0010_REPORT_JAR_MISSING", // $NON-NLS-1$
            resource.getAddress()));
        }
    }
    return factory;
}
Also used : Set(java.util.Set) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) PentahoTableDataFactory(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) PentahoTableDataFactory(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory) DataFactory(org.pentaho.reporting.engine.classic.core.DataFactory) PentahoDataFactory(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoDataFactory) ParameterDataRow(org.pentaho.reporting.engine.classic.core.ParameterDataRow) FileNotFoundException(java.io.FileNotFoundException) IActionSequenceResource(org.pentaho.platform.api.engine.IActionSequenceResource) Iterator(java.util.Iterator) PentahoDataFactory(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoDataFactory) PentahoTableModel(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel) TableModel(javax.swing.table.TableModel) ReportParameterValues(org.pentaho.reporting.engine.classic.core.util.ReportParameterValues)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 TableModel (javax.swing.table.TableModel)2 PentahoDataFactory (org.pentaho.platform.plugin.action.jfreereport.helper.PentahoDataFactory)2 PentahoTableDataFactory (org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory)2 PentahoTableModel (org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel)2 DataFactory (org.pentaho.reporting.engine.classic.core.DataFactory)2 ParameterDataRow (org.pentaho.reporting.engine.classic.core.ParameterDataRow)2 ReportParameterValues (org.pentaho.reporting.engine.classic.core.util.ReportParameterValues)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 DataSource (javax.activation.DataSource)1 PrintException (javax.print.PrintException)1 IActionInput (org.pentaho.actionsequence.dom.IActionInput)1 IActionResource (org.pentaho.actionsequence.dom.IActionResource)1 JFreeReportAction (org.pentaho.actionsequence.dom.actions.JFreeReportAction)1 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)1