Search in sources :

Example 1 with TemplateMsgAction

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

the class TemplateComponent method executeAction.

@Override
protected boolean executeAction() {
    try {
        TemplateMsgAction actionDefinition = (TemplateMsgAction) getActionDefinition();
        String template = null;
        template = actionDefinition.getTemplate().getStringValue();
        if ((null == template) && isDefinedResource(TemplateComponent.TEMPLATE)) {
            // $NON-NLS-1$
            IActionSequenceResource resource = getResource("template");
            template = getResourceAsString(resource);
        }
        String outputName = (String) getOutputNames().iterator().next();
        IActionParameter outputParam = getOutputItem(outputName);
        if (outputParam.getType().equals(IActionParameter.TYPE_CONTENT)) {
            String mimeType = actionDefinition.getMimeType().getStringValue();
            String extension = actionDefinition.getExtension().getStringValue();
            // This would prevent null values being passed as parameters to getOutputItem
            if (mimeType == null) {
                // $NON-NLS-1$
                mimeType = "";
            }
            if (extension == null) {
                // $NON-NLS-1$
                extension = "";
            }
            // Removing the null check here because if we avoid null exception it gives misleading hibernate
            // stale data exception which has nothing to do with a report that simply reads data.
            IContentItem outputItem = getOutputContentItem(outputName, mimeType);
            // IContentItem outputItem = getOutputItem(outputName, mimeType, extension);
            OutputStream outputStream = outputItem.getOutputStream(getActionName());
            outputStream.write(applyInputsToFormat(template).getBytes(LocaleHelper.getSystemEncoding()));
            outputItem.closeOutputStream();
            return true;
        } else {
            setOutputValue(outputName, applyInputsToFormat(template));
        }
        return true;
    } catch (Exception e) {
        // $NON-NLS-1$
        error(Messages.getInstance().getString("Template.ERROR_0004_COULD_NOT_FORMAT_TEMPLATE"), e);
        return false;
    }
}
Also used : OutputStream(java.io.OutputStream) IContentItem(org.pentaho.platform.api.repository.IContentItem) TemplateMsgAction(org.pentaho.actionsequence.dom.actions.TemplateMsgAction) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) IActionSequenceResource(org.pentaho.platform.api.engine.IActionSequenceResource)

Example 2 with TemplateMsgAction

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

the class TemplateComponent method validateAction.

@Override
protected boolean validateAction() {
    // see if we have a template defined
    TemplateMsgAction actionDefinition = (TemplateMsgAction) getActionDefinition();
    boolean templateOk = false;
    if (null != actionDefinition.getTemplate()) {
        templateOk = true;
    } else if (isDefinedResource(TemplateComponent.TEMPLATE)) {
        templateOk = true;
    }
    if (!templateOk) {
        // $NON-NLS-1$
        error(Messages.getInstance().getString("Template.ERROR_0001_TEMPLATE_NOT_DEFINED"));
        return false;
    }
    Set outputs = getOutputNames();
    if ((outputs == null) || (outputs.size() == 0) || (outputs.size() > 1)) {
        // $NON-NLS-1$
        error(Messages.getInstance().getString("Template.ERROR_0002_OUTPUT_COUNT_WRONG"));
        return false;
    }
    return true;
}
Also used : Set(java.util.Set) TemplateMsgAction(org.pentaho.actionsequence.dom.actions.TemplateMsgAction)

Aggregations

TemplateMsgAction (org.pentaho.actionsequence.dom.actions.TemplateMsgAction)2 OutputStream (java.io.OutputStream)1 Set (java.util.Set)1 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)1 IActionSequenceResource (org.pentaho.platform.api.engine.IActionSequenceResource)1 IContentItem (org.pentaho.platform.api.repository.IContentItem)1