Search in sources :

Example 11 with IActionInput

use of org.pentaho.actionsequence.dom.IActionInput 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 12 with IActionInput

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

the class UtilityComponent method executeGetMapValuesAction.

private boolean executeGetMapValuesAction(final PrintMapValsAction getMapValsAction) {
    IActionInput propertyMap = getMapValsAction.getPropertyMap();
    IActionInput[] keys = getMapValsAction.getKeys();
    boolean result = true;
    try {
        if (!(propertyMap.getValue() instanceof Map)) {
            // $NON-NLS-1$ //$NON-NLS-2$
            error(Messages.getInstance().getErrorString("UtilityComponent.ERROR_0004_PARAMETER_NOT_MAP", "property-map"));
            result = false;
        } else {
            Map srcMap = (Map) propertyMap.getValue();
            for (IActionInput element : keys) {
                String key = element.getStringValue();
                getMapValsAction.getOutput(key).setValue(srcMap.get(key));
            }
        }
    } catch (Exception e) {
        // $NON-NLS-1$
        error(Messages.getInstance().getString("UtilityComponent.ERROR_0005_GET_MAP_VALUES_ERROR"));
        result = false;
    }
    return result;
}
Also used : IActionInput(org.pentaho.actionsequence.dom.IActionInput) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with IActionInput

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

the class UtilityComponent method executeCopyAction.

private boolean executeCopyAction(final CopyParamAction copyParamAction) {
    boolean result = true;
    IActionInput actionInput = copyParamAction.getCopyFrom();
    IActionOutput actionOutput = copyParamAction.getOutputCopy();
    if ((actionInput instanceof ActionInput) && (actionOutput != null)) {
        try {
            actionOutput.setValue(actionInput.getValue());
        } catch (Exception ex) {
            result = false;
        }
    }
    return result;
}
Also used : ActionInput(org.pentaho.actionsequence.dom.ActionInput) IActionInput(org.pentaho.actionsequence.dom.IActionInput) IActionInput(org.pentaho.actionsequence.dom.IActionInput) IActionOutput(org.pentaho.actionsequence.dom.IActionOutput)

Example 14 with IActionInput

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

the class UtilityComponent method executePrintParamAction.

private boolean executePrintParamAction(final PrintParamAction printParamAction) {
    // $NON-NLS-1$
    String delimiter = printParamAction.getDelimiter().getStringValue("");
    IActionInput[] inputsToPrint = printParamAction.getInputsToPrint();
    boolean result = true;
    try {
        // $NON-NLS-1$
        StringBuffer sb = new StringBuffer("\n***************************************************************\n");
        for (IActionInput element : inputsToPrint) {
            // $NON-NLS-1$
            sb.append(element.getStringValue("")).append(delimiter);
        }
        // $NON-NLS-1$
        sb.append("\n***************************************************************\n");
        info(sb.toString());
    } catch (Exception e) {
        // $NON-NLS-1$
        error(Messages.getInstance().getString("UtilityComponent.ERROR_0002_MESSAGE_LOG_ERROR"));
        result = false;
    }
    return result;
}
Also used : IActionInput(org.pentaho.actionsequence.dom.IActionInput)

Example 15 with IActionInput

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

the class EmailComponent method validateAction.

@Override
public boolean validateAction() {
    boolean result = true;
    // make sure that we can get a "to" email address
    if (!(getActionDefinition() instanceof EmailAction)) {
        error(Messages.getInstance().getErrorString("ComponentBase.ERROR_0001_UNKNOWN_ACTION_TYPE", // $NON-NLS-1$
        getActionDefinition().getElement().asXML()));
        result = false;
    } else {
        EmailAction emailAction = (EmailAction) getActionDefinition();
        IActionInput to = emailAction.getTo();
        IActionInput subject = emailAction.getSubject();
        IActionInput plainMsg = emailAction.getMessagePlain();
        IActionInput htmlMsg = emailAction.getMessageHtml();
        if (to == ActionInputConstant.NULL_INPUT) {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("Email.ERROR_0001_TO_NOT_DEFINED", getActionName()));
            result = false;
        } else if (subject == ActionInputConstant.NULL_INPUT) {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("Email.ERROR_0002_SUBJECT_NOT_DEFINED", getActionName()));
            result = false;
        } else if ((plainMsg == ActionInputConstant.NULL_INPUT) && (htmlMsg == ActionInputConstant.NULL_INPUT)) {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("Email.ERROR_0003_BODY_NOT_DEFINED", getActionName()));
            result = false;
        }
    }
    return result;
}
Also used : IActionInput(org.pentaho.actionsequence.dom.IActionInput) EmailAction(org.pentaho.actionsequence.dom.actions.EmailAction)

Aggregations

IActionInput (org.pentaho.actionsequence.dom.IActionInput)15 IActionOutput (org.pentaho.actionsequence.dom.IActionOutput)5 JFreeReportAction (org.pentaho.actionsequence.dom.actions.JFreeReportAction)4 TableModel (javax.swing.table.TableModel)3 IActionDefinition (org.pentaho.actionsequence.dom.IActionDefinition)3 IPreparedComponent (org.pentaho.platform.api.data.IPreparedComponent)3 PentahoTableModel (org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ActionInput (org.pentaho.actionsequence.dom.ActionInput)2 IActionResource (org.pentaho.actionsequence.dom.IActionResource)2 AbstractRelationalDbAction (org.pentaho.actionsequence.dom.actions.AbstractRelationalDbAction)2 SqlConnectionAction (org.pentaho.actionsequence.dom.actions.SqlConnectionAction)2 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)2 PentahoTableDataFactory (org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1