use of org.pentaho.actionsequence.dom.IActionOutput in project pentaho-platform by pentaho.
the class HQLBaseComponent method executeAction.
@Override
protected boolean executeAction() {
boolean returnValue = true;
try {
if (getActionDefinition() instanceof HQLQueryAction) {
HQLQueryAction queryAction = (HQLQueryAction) getActionDefinition();
String[] classNames = null;
String query = queryAction.getQuery().getStringValue();
if (queryAction.getInputSharedConnection() != ActionInputConstant.NULL_INPUT) {
connectionOwner = false;
IPreparedComponent component = (IPreparedComponent) queryAction.getInputSharedConnection().getValue();
IPentahoConnection conn = component.shareConnection();
if (IPentahoConnection.HQL_DATASOURCE.equals(conn.getDatasourceType())) {
connection = conn;
} else {
connection = null;
returnValue = false;
error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0001_INVALID_CONNECTION_TYPE", // $NON-NLS-1$
getActionName()));
}
} else {
createBasicConnection(queryAction, classNames);
}
if (connection != null) {
IActionOutput actionOutput = queryAction.getOutputPreparedStatementParam();
if (actionOutput != null) {
// prepare the query for execution, but don't execute quite yet.
prepareQuery(query);
// set the output as self, which will be used later by another component.
actionOutput.setValue(this);
} else {
return runQuery(connection, classNames, query);
}
}
} else if (getActionDefinition() instanceof HQLConnectionAction) {
HQLConnectionAction connAction = (HQLConnectionAction) getActionDefinition();
String[] classNames = null;
createBasicConnection(connAction, classNames);
if (connection != null) {
IActionOutput outputConnection = connAction.getOutputConnectionParam();
if (outputConnection != null) {
outputConnection.setValue(this);
}
}
} else {
returnValue = false;
error(Messages.getInstance().getErrorString("HQLBaseComponent.ERROR_00011_INVALID_HQL_COMPONENT", // $NON-NLS-1$
getActionName()));
}
} catch (Exception e) {
returnValue = false;
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("HQLBaseComponent.ERROR_00012_EXECUTE_FAILED", getActionName()), e);
}
return returnValue;
}
use of org.pentaho.actionsequence.dom.IActionOutput in project pentaho-platform by pentaho.
the class JavascriptRule method validateAction.
@Override
protected boolean validateAction() {
boolean actionValidated = true;
JavascriptAction jscriptAction = null;
if (getActionDefinition() instanceof JavascriptAction) {
jscriptAction = (JavascriptAction) getActionDefinition();
// get report connection setting
if (jscriptAction.getScript() == ActionInputConstant.NULL_INPUT) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("JSRULE.ERROR_0001_SCRIPT_NOT_DEFINED", getActionName()));
actionValidated = false;
}
if (actionValidated) {
if (jscriptAction.getOutputs().length <= 0) {
// $NON-NLS-1$
error(Messages.getInstance().getString("Template.ERROR_0002_OUTPUT_COUNT_WRONG"));
actionValidated = false;
}
}
if (actionValidated) {
// getOutputNames();
IActionOutput[] outputs = jscriptAction.getOutputs();
/*
* if the number of action def outputs is more than 1 and if the fist output var defined in the input section is
* named output1 then the xaction is defined oldstyle and we should check if there is corresponding o/p variable
* defined in the input section for each output var defined in the output section. NOTE: With the old style you
* can only have output defined as "output#" where # is a number.
*/
if ((outputs.length > 1) && (jscriptAction.getInput("output1") != ActionInputConstant.NULL_INPUT)) {
// $NON-NLS-1$
oldStyleOutputs = true;
for (int i = 1; i <= outputs.length; ++i) {
if (jscriptAction.getInput("output" + i) == ActionInputConstant.NULL_INPUT) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("JavascriptRule.ERROR_0006_NO_MAPPED_OUTPUTS", String.valueOf(outputs.length), // $NON-NLS-1$
String.valueOf(i)));
actionValidated = false;
break;
}
}
}
}
} else {
actionValidated = false;
error(Messages.getInstance().getErrorString("ComponentBase.ERROR_0001_UNKNOWN_ACTION_TYPE", // $NON-NLS-1$
getActionDefinition().getElement().asXML()));
}
return actionValidated;
}
use of org.pentaho.actionsequence.dom.IActionOutput in project pentaho-platform by pentaho.
the class JavascriptRule method executeAction.
/*
* (non-Javadoc)
*
* @see org.pentaho.component.ComponentBase#execute()
*/
@Override
protected boolean executeAction() {
Context cx = ContextFactory.getGlobal().enterContext();
StringBuffer buffer = new StringBuffer();
@SuppressWarnings("unchecked") Iterator<String> iter = getResourceNames().iterator();
while (iter.hasNext()) {
IActionSequenceResource resource = getResource(iter.next().toString());
// If this is a javascript resource then append it to the script string
if ("text/javascript".equalsIgnoreCase(resource.getMimeType())) {
// $NON-NLS-1$
buffer.append(getResourceAsString(resource));
}
}
List<String> outputNames = new ArrayList<String>();
JavascriptAction jscriptAction = (JavascriptAction) getActionDefinition();
IActionOutput[] actionOutputs = jscriptAction.getOutputs();
if (actionOutputs.length == 1) {
String outputName = actionOutputs[0].getName();
outputNames.add(outputName);
} else {
if (oldStyleOutputs) {
int i = 1;
while (true) {
if (jscriptAction.getInput("output" + i) != ActionInputConstant.NULL_INPUT) {
// $NON-NLS-1$
// $NON-NLS-1$
outputNames.add(jscriptAction.getInput("output" + i).getStringValue());
} else {
break;
}
i++;
}
} else {
for (IActionOutput element : actionOutputs) {
outputNames.add(element.getName());
}
}
}
boolean success = false;
try {
String script = jscriptAction.getScript().getStringValue();
if (script == null) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("JSRULE.ERROR_0001_SCRIPT_NOT_DEFINED", getActionName()));
} else {
buffer.append(script);
script = buffer.toString();
if (ComponentBase.debug) {
// $NON-NLS-1$
debug("script=" + script);
}
try {
ScriptableObject scriptable = new RhinoScriptable();
// initialize the standard javascript objects
Scriptable scope = cx.initStandardObjects(scriptable);
Object resultObject = executeScript(scriptable, scope, script, cx);
if (oldStyleOutputs) {
if (resultObject instanceof org.mozilla.javascript.NativeArray) {
// we need to convert this to an ArrayList
NativeArray jsArray = (NativeArray) resultObject;
int length = (int) jsArray.getLength();
for (int i = 0; i < length; i++) {
Object value = jsArray.get(i, scriptable);
if (i < outputNames.size()) {
jscriptAction.getOutput(outputNames.get(i).toString()).setValue(convertWrappedJavaObject(value));
} else {
break;
}
}
} else {
jscriptAction.getOutput(outputNames.get(0).toString()).setValue(convertWrappedJavaObject(resultObject));
}
} else {
if ((outputNames.size() == 1) && (resultObject != null)) {
jscriptAction.getOutput(outputNames.get(0).toString()).setValue(convertWrappedJavaObject(resultObject));
} else {
List<String> setOutputs = new ArrayList<String>(outputNames.size());
Object[] ids = ScriptableObject.getPropertyIds(scope);
for (Object element : ids) {
int idx = outputNames.indexOf(element.toString());
if (idx >= 0) {
jscriptAction.getOutput(outputNames.get(idx).toString()).setValue(convertWrappedJavaObject(ScriptableObject.getProperty(scope, (String) element)));
setOutputs.add(outputNames.get(idx));
}
}
// So, set it to null.
if (setOutputs.size() != outputNames.size()) {
for (int i = 0; i < outputNames.size(); i++) {
if (setOutputs.indexOf(outputNames.get(i)) < 0) {
// An output that wasn't set in the
// javascript component
jscriptAction.getOutput(outputNames.get(i).toString()).setValue(null);
}
}
}
}
}
success = true;
} catch (Exception e) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("JSRULE.ERROR_0003_EXECUTION_FAILED"), e);
}
}
} finally {
Context.exit();
}
return success;
}
use of org.pentaho.actionsequence.dom.IActionOutput 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;
}
use of org.pentaho.actionsequence.dom.IActionOutput in project pentaho-platform by pentaho.
the class UtilityComponent method executeFormatAction.
private boolean executeFormatAction(final FormatMsgAction formatMsgAction) {
boolean result = true;
String formatString = formatMsgAction.getFormatString().getStringValue();
IActionOutput actionOutput = formatMsgAction.getOutputString();
IActionInput[] msgInputs = formatMsgAction.getMsgInputs();
ArrayList formatArgs = new ArrayList();
for (IActionInput element : msgInputs) {
formatArgs.add(element.getStringValue());
}
try {
MessageFormat mf = new MessageFormat(formatString);
String theResult = mf.format(formatArgs.toArray());
if (actionOutput != null) {
actionOutput.setValue(theResult);
}
} catch (Exception ex) {
result = false;
}
return result;
}
Aggregations