use of org.pentaho.platform.api.engine.IActionSequence in project pentaho-platform by pentaho.
the class RuntimeContext method performActions.
private void performActions(final IActionSequence sequence, final IActionCompleteListener doneListener, final IExecutionListener execListener, final boolean async) throws ActionSequenceException {
IConditionalExecution conditional = sequence.getConditionalExecution();
if (conditional != null) {
try {
if (!conditional.shouldExecute(paramManager.getAllParameters(), RuntimeContext.logger)) {
// audit(MessageTypes.ACTION_SEQUENCE_EXECUTE_CONDITIONAL, MessageTypes.NOT_EXECUTED, "", 0); //$NON-NLS-1$ //$NON-NLS-2$
if (RuntimeContext.debug) {
// $NON-NLS-1$
this.debug(Messages.getInstance().getString("RuntimeContext.INFO_ACTION_NOT_EXECUTED"));
}
status = IRuntimeContext.RUNTIME_STATUS_SUCCESS;
return;
}
} catch (Exception ex) {
// $NON-NLS-1$
currentComponent = "";
status = IRuntimeContext.RUNTIME_STATUS_FAILURE;
throw new ActionExecutionException(Messages.getInstance().getErrorString(// $NON-NLS-1$
"RuntimeContext.ERROR_0032_CONDITIONAL_EXECUTION_FAILED"), // $NON-NLS-1$
ex, session.getName(), instanceId, getActionSequence().getSequenceName(), null);
}
}
List defList = sequence.getActionDefinitionsAndSequences();
Object listItem;
for (Iterator actIt = defList.iterator(); actIt.hasNext(); ) {
listItem = actIt.next();
if (listItem instanceof IActionSequence) {
executeSequence((IActionSequence) listItem, doneListener, execListener, async);
} else if (listItem instanceof ISolutionActionDefinition) {
ISolutionActionDefinition actionDef = (ISolutionActionDefinition) listItem;
currentComponent = actionDef.getComponentName();
paramManager.setCurrentParameters(actionDef);
try {
executeAction(actionDef, parameterProviders, doneListener, execListener, async);
paramManager.addOutputParameters(actionDef);
} catch (ActionSequenceException ex) {
// $NON-NLS-1$
currentComponent = "";
status = IRuntimeContext.RUNTIME_STATUS_FAILURE;
throw ex;
}
}
if (promptStatus == IRuntimeContext.PROMPT_NOW) {
break;
}
// $NON-NLS-1$
currentComponent = "";
}
status = IRuntimeContext.RUNTIME_STATUS_SUCCESS;
}
use of org.pentaho.platform.api.engine.IActionSequence in project pentaho-platform by pentaho.
the class RuntimeContext method validateComponents.
private void validateComponents(final IActionSequence sequence, final IExecutionListener execListener) throws ActionValidationException {
List defList = sequence.getActionDefinitionsAndSequences();
Object listItem;
for (Iterator it = defList.iterator(); it.hasNext(); ) {
listItem = it.next();
if (listItem instanceof IActionSequence) {
validateComponents((IActionSequence) listItem, execListener);
} else if (listItem instanceof ISolutionActionDefinition) {
ISolutionActionDefinition actionDef = (ISolutionActionDefinition) listItem;
if (RuntimeContext.debug) {
// $NON-NLS-1$
debug(Messages.getInstance().getString("RuntimeContext.DEBUG_VALIDATING_COMPONENT", actionDef.getComponentName()));
}
IComponent component = null;
try {
component = resolveComponent(actionDef, instanceId, processId, session);
component.setLoggingLevel(loggingLevel);
// allow the ActionDefinition to cache the component
actionDef.setComponent(component);
paramManager.setCurrentParameters(actionDef);
/*
* We need to catch checked and unchecked exceptions here so we can create an ActionSequeceException with
* contextual information, including the root cause. Allowing unchecked exceptions to pass through would
* prevent valuable feedback in the log or response.
*/
} catch (Throwable ex) {
ActionDefinition actionDefinition = new ActionDefinition((Element) actionDef.getNode(), null);
throw new ActionValidationException(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0009_COULD_NOT_CREATE_COMPONENT", // $NON-NLS-1$
actionDef.getComponentName().trim()), // $NON-NLS-1$
ex, session.getName(), instanceId, getActionSequence().getSequenceName(), actionDefinition.getDescription(), actionDefinition.getComponentName());
}
int validateResult = IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_OK;
try {
validateResult = component.validate();
/*
* We need to catch checked and unchecked exceptions here so we can create an ActionSequeceException with
* contextual information, including the root cause. Allowing unchecked exceptions to pass through would
* prevent valuable feedback in the log or response.
*/
} catch (Throwable t) {
throw new ActionValidationException(Messages.getInstance().getErrorString(// $NON-NLS-1$
"RuntimeContext.ERROR_0035_ACTION_VALIDATION_FAILED"), // $NON-NLS-1$
t, session.getName(), instanceId, getActionSequence().getSequenceName(), component.getActionDefinition());
}
if (validateResult != IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_OK) {
throw new ActionValidationException(Messages.getInstance().getErrorString(// $NON-NLS-1$
"RuntimeContext.ERROR_0035_ACTION_VALIDATION_FAILED"), session.getName(), instanceId, getActionSequence().getSequenceName(), component.getActionDefinition());
}
paramManager.addOutputParameters(actionDef);
// $NON-NLS-1$
setCurrentComponent("");
setCurrentActionDef(null);
}
}
if (execListener != null) {
execListener.validated(this);
}
}
use of org.pentaho.platform.api.engine.IActionSequence in project pentaho-platform by pentaho.
the class SequenceDefinition method getNextLoopGroup.
private static IActionSequence getNextLoopGroup(final ISequenceDefinition seqDef, final Node actionsNode, final String solutionPath, final ILogger logger, final int loggingLevel) {
// $NON-NLS-1$
String loopParameterName = XmlDom4JHelper.getNodeText("@loop-on", actionsNode);
// $NON-NLS-1$ //$NON-NLS-2$
boolean loopUsingPeek = "true".equalsIgnoreCase(XmlDom4JHelper.getNodeText("@peek-only", actionsNode));
Node actionDefinitionNode;
ActionDefinition actionDefinition;
List actionDefinitionList = new ArrayList();
// $NON-NLS-1$
List nodeList = actionsNode.selectNodes("*");
Iterator actionDefinitionNodes = nodeList.iterator();
while (actionDefinitionNodes.hasNext()) {
actionDefinitionNode = (Node) actionDefinitionNodes.next();
if (actionDefinitionNode.getName().equals("actions")) {
// $NON-NLS-1$
actionDefinitionList.add(SequenceDefinition.getNextLoopGroup(seqDef, actionDefinitionNode, solutionPath, logger, loggingLevel));
} else if (actionDefinitionNode.getName().equals("action-definition")) {
// $NON-NLS-1$
actionDefinition = new ActionDefinition(actionDefinitionNode, logger);
actionDefinition.setLoggingLevel(loggingLevel);
actionDefinitionList.add(actionDefinition);
}
}
// action sequences with 0 actions are valid, see: JIRA PLATFORM-837
IConditionalExecution conditionalExecution = // $NON-NLS-1$
SequenceDefinition.parseConditionalExecution(actionsNode, logger, "condition");
ActionSequence sequence = new ActionSequence(loopParameterName, seqDef, actionDefinitionList, loopUsingPeek);
sequence.setConditionalExecution(conditionalExecution);
return sequence;
}
use of org.pentaho.platform.api.engine.IActionSequence in project pentaho-platform by pentaho.
the class IsOutputParameterTest method testIsOutputParameter.
/**
* Assert parameters with is-output-parameter=false don't appear in output
*
* @throws XmlParseException
*/
public void testIsOutputParameter() throws XmlParseException {
startTest();
ISolutionEngine solutionEngine = ServiceTestHelper.getSolutionEngine();
String xactionStr = ServiceTestHelper.getXAction(SOLUTION_PATH, "services/" + xactionName);
Document actionSequenceDocument = XmlDom4JHelper.getDocFromString(xactionStr, null);
IActionSequence actionSequence = SequenceDefinition.ActionSequenceFactory(actionSequenceDocument, "", this, // $NON-NLS-1$
PentahoSystem.getApplicationContext(), DEBUG);
Map allParameters = actionSequence.getOutputDefinitions();
Set<String> outParameters = new HashSet<String>();
Set<String> nonOutParameters = new HashSet<String>();
for (Object key : allParameters.keySet()) {
IActionParameter param = (IActionParameter) allParameters.get(key);
if (param.isOutputParameter()) {
outParameters.add(param.getName());
} else {
nonOutParameters.add(param.getName());
}
}
Assert.assertEquals("expected 2 outputable parameters in xaction", 2, outParameters.size());
Assert.assertEquals("expected 1 paramater with is-output-parameter=false", 1, nonOutParameters.size());
IRuntimeContext runtimeContext = // $NON-NLS-1$
solutionEngine.execute(// $NON-NLS-1$
xactionStr, // $NON-NLS-1$
xactionName, // $NON-NLS-1$
"simple output test", // $NON-NLS-1$
false, // $NON-NLS-1$
true, // $NON-NLS-1$
null, // $NON-NLS-1$
false, // $NON-NLS-1$
new HashMap(), null, null, new SimpleUrlFactory(""), // $NON-NLS-1$
new ArrayList());
IParameterManager paramManager = runtimeContext.getParameterManager();
Assert.assertEquals(outParameters.size(), paramManager.getCurrentOutputNames().size());
for (Object key : paramManager.getCurrentOutputNames()) {
Assert.assertTrue("output parameter not found in definition", outParameters.contains(key));
Assert.assertFalse("non-output parameter in output", nonOutParameters.contains(key));
}
finishTest();
}
use of org.pentaho.platform.api.engine.IActionSequence in project pentaho-platform by pentaho.
the class XactionUtil method doParameter.
@SuppressWarnings({ "unchecked", "rawtypes" })
public static String doParameter(final RepositoryFile file, IParameterProvider parameterProvider, final IPentahoSession userSession) throws IOException {
ActionSequenceJCRHelper helper = new ActionSequenceJCRHelper();
final IActionSequence actionSequence = helper.getActionSequence(file.getPath(), PentahoSystem.loggingLevel, RepositoryFilePermission.READ);
final Document document = DocumentHelper.createDocument();
try {
final Element parametersElement = document.addElement("parameters");
// noinspection unchecked
final Map<String, IActionParameter> params = actionSequence.getInputDefinitionsForParameterProvider(IParameterProvider.SCOPE_REQUEST);
for (final Map.Entry<String, IActionParameter> entry : params.entrySet()) {
final String paramName = entry.getKey();
final IActionParameter paramDef = entry.getValue();
final String value = paramDef.getStringValue();
final Class type;
// defined as constant (string)
if (IActionParameter.TYPE_LIST.equalsIgnoreCase(paramDef.getType())) {
type = String[].class;
} else {
type = String.class;
}
final String label = paramDef.getSelectionDisplayName();
final String[] values;
if (StringUtils.isEmpty(value)) {
values = new String[0];
} else {
values = new String[] { value };
}
createParameterElement(parametersElement, paramName, type, label, "user", "parameters", values);
}
createParameterElement(parametersElement, "path", String.class, null, "system", "system", new String[] { file.getPath() });
createParameterElement(parametersElement, "prompt", String.class, null, "system", "system", new String[] { "yes", "no" });
createParameterElement(parametersElement, "instance-id", String.class, null, "system", "system", new String[] { parameterProvider.getStringParameter("instance-id", null) });
// no close, as far as I know tomcat does not like it that much ..
OutputFormat format = OutputFormat.createCompactFormat();
format.setSuppressDeclaration(true);
// $NON-NLS-1$
format.setEncoding("utf-8");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
XMLWriter writer = new XMLWriter(outputStream, format);
writer.write(document);
writer.flush();
return outputStream.toString("utf-8");
} catch (Exception e) {
logger.warn(Messages.getInstance().getString("HttpWebService.ERROR_0003_UNEXPECTED"), e);
return null;
}
}
Aggregations