use of org.pentaho.platform.api.engine.IActionSequence in project pentaho-platform by pentaho.
the class InputFormComponent method getXmlContent.
/*
* (non-Javadoc)
*
* @see org.pentaho.core.ui.component.BaseUIComponent#getXmlContent()
*/
@Override
public Document getXmlContent() {
ActionSequenceJCRHelper actionHelper = new ActionSequenceJCRHelper(getSession());
IActionSequence actionSequence = actionHelper.getActionSequence(ActionInfo.buildSolutionPath(solution, path, actionName), getLoggingLevel(), RepositoryFilePermission.READ);
if (actionSequence == null) {
// TODO log this
// $NON-NLS-1$
error(Messages.getInstance().getString("InputForm.ERROR_0004_ACTION_NOT_FOUND") + solution + path + actionName);
return null;
}
List actions = actionSequence.getActionDefinitionsAndSequences();
ISolutionActionDefinition action = (ISolutionActionDefinition) actions.get(0);
Node node = action.getComponentSection();
if (node == null) {
// $NON-NLS-1$
error(Messages.getInstance().getString("InputForm.ERROR_0005_INBOX_DEFINITION_MISSING") + solution + path + actionName);
return null;
}
if (templateName == null) {
// see if the template is specified in the action document
// $NON-NLS-1$
Node templateNode = node.selectSingleNode("//template");
if (templateNode != null) {
templateName = templateNode.getText();
}
if (templateName == null) {
// $NON-NLS-1$
error(Messages.getInstance().getString("InputForm.ERROR_0006_TEMPLATE_NOT_SPECIFIED"));
return null;
}
}
// $NON-NLS-1$
Node xFormNode = node.selectSingleNode("//xForm");
try {
String actionTitle = actionSequence.getTitle();
if (actionTitle != null) {
// $NON-NLS-1$
setXslProperty("title", actionTitle);
}
String description = actionSequence.getDescription();
if (description != null) {
// $NON-NLS-1$
setXslProperty("description", description);
}
String xFormHtml = XForm.transformSnippet(xFormNode, getSession(), new SolutionURIResolver());
if (xFormHtml == null) {
// $NON-NLS-1$
error(Messages.getInstance().getString("InputForm.ERROR_0007_INBOX_DEFINITION_INVALID") + solution + path + actionName);
return null;
}
Document document = DocumentHelper.parseText(xFormHtml);
// $NON-NLS-1$
Node xFormHtmlNode = document.selectSingleNode("//xForm");
// $NON-NLS-1$
setXslProperty("xForm", xFormHtmlNode.asXML());
if ((stylesheetName != null) && !"".equals(stylesheetName)) {
// $NON-NLS-1$
// $NON-NLS-1$
setXslProperty("css", stylesheetName);
}
// $NON-NLS-1$
setXsl("text/html", templateName);
return document;
} catch (Exception e) {
return null;
}
}
use of org.pentaho.platform.api.engine.IActionSequence in project pentaho-platform by pentaho.
the class SolutionEngine method createActionSequenceFromXml.
private IActionSequence createActionSequenceFromXml(final String actionDef) {
try {
Document actionSequenceDocument = XmlDom4JHelper.getDocFromString(actionDef, null);
if (actionSequenceDocument == null) {
return null;
}
IActionSequence actionSequence = SequenceDefinition.ActionSequenceFactory(actionSequenceDocument, "", this, // $NON-NLS-1$
PentahoSystem.getApplicationContext(), loggingLevel);
return (actionSequence);
} catch (Exception e) {
// ignore
}
return null;
}
use of org.pentaho.platform.api.engine.IActionSequence in project pentaho-platform by pentaho.
the class SolutionEngine method executeInternal.
@SuppressWarnings({ "unchecked" })
protected IRuntimeContext executeInternal(final String sequencePath, final String processId, final boolean async, final boolean instanceEnds, final Map parameterProviderMap, final String actionSequenceXML) {
long start = System.currentTimeMillis();
parameterProviders.putAll(parameterProviderMap);
parameterProviders.put(PentahoSystem.SCOPE_GLOBAL, PentahoSystem.getGlobalParameters());
// load the solution action document
if (debug) {
// $NON-NLS-1$
debug(Messages.getInstance().getString("SolutionEngine.DEBUG_LOADING_ACTION_DEFINITION"));
}
IActionSequence actionSequence = null;
if (actionSequenceXML != null) {
actionSequence = createActionSequenceFromXml(actionSequenceXML);
} else {
actionSequence = createActionSequence(sequencePath);
}
if (actionSequence == null) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("SolutionEngine.ERROR_0007_ACTION_EXECUTION_FAILED"));
status = IRuntimeContext.RUNTIME_STATUS_FAILURE;
long end = System.currentTimeMillis();
AuditHelper.audit(session.getId(), session.getName(), sequencePath, getObjectName(), processId, MessageTypes.INSTANCE_FAILED, runtime.getInstanceId(), Messages.getInstance().getErrorString("SolutionEngine.ERROR_0007_ACTION_EXECUTION_FAILED"), ((float) (end - start) / 1000), // $NON-NLS-1$
this);
return runtime;
}
runtime.setActionSequence(actionSequence);
if (parameterXsl != null) {
runtime.setParameterXsl(parameterXsl);
}
if (forcePrompt) {
runtime.setPromptStatus(IRuntimeContext.PROMPT_WAITING);
} else {
runtime.setPromptStatus(IRuntimeContext.PROMPT_NO);
}
boolean validating = true;
try {
runtime.validateSequence(FilenameUtils.getName(sequencePath), execListener);
validating = false;
runtime.executeSequence(doneListener, execListener, async);
if (instanceEnds) {
long end = System.currentTimeMillis();
AuditHelper.audit(session.getId(), session.getName(), sequencePath, getObjectName(), processId, MessageTypes.INSTANCE_END, runtime.getInstanceId(), "", ((float) (end - start) / 1000), // $NON-NLS-1$
this);
}
status = runtime.getStatus();
} catch (ActionSequenceException ex) {
String errorMsg = null;
status = validating ? IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_FAIL : IRuntimeContext.RUNTIME_STATUS_FAILURE;
// This next line is a bit of a workaround, to make up for a deficiency in the SolutionEngine api.
// What would be nice is to have the exception that is being caught here actually be thrown out of this
// method. However, the ISolutionEngine interface that this class implements doesn't allow exceptions to be
// thrown from this method. Since we can't change the signature of public API's with a minor release we need
// a
// workaround. We've created an new error method in PentahoMessenger that takes the exception and stuffs it
// in
// the messages list maintained within PentahoMessenger. Callers of this method that want to know if an
// ActionSequenceException occurred should first call getStatus(). If the status does not
// indicate success then call getMessages() and check if there is an exception in the list of messages.
error(ex);
long end = System.currentTimeMillis();
AuditHelper.audit(session.getId(), session.getName(), sequencePath, getObjectName(), processId, MessageTypes.INSTANCE_FAILED, runtime.getInstanceId(), errorMsg, ((float) (end - start) / 1000), // $NON-NLS-1$
this);
}
return runtime;
}
use of org.pentaho.platform.api.engine.IActionSequence in project pentaho-platform by pentaho.
the class SolutionEngineInteractivityService method doGet.
@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
PentahoSystem.systemEntryPoint();
try {
IPentahoSession userSession = getPentahoSession(request);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// $NON-NLS-1$
String solutionName = request.getParameter("solution");
// $NON-NLS-1$
String actionPath = request.getParameter("path");
// $NON-NLS-1$
String actionName = request.getParameter("action");
IActionSequence actionSequence = new ActionSequenceJCRHelper().getActionSequence(ActionInfo.buildSolutionPath(solutionName, actionPath, actionName), PentahoSystem.loggingLevel, RepositoryFilePermission.READ);
String fileName = null;
if (actionSequence != null) {
String title = actionSequence.getTitle();
if ((title != null) && (title.length() > 0)) {
fileName = title;
} else {
String sequenceName = actionSequence.getSequenceName();
if ((sequenceName != null) && (sequenceName.length() > 0)) {
fileName = sequenceName;
} else {
List actionDefinitionsList = actionSequence.getActionDefinitionsAndSequences();
int i = 0;
boolean done = false;
while ((actionDefinitionsList.size() > i) && !done) {
IActionDefinition actionDefinition = (IActionDefinition) actionDefinitionsList.get(i);
String componentName = actionDefinition.getComponentName();
if ((componentName != null) && (componentName.length() > 0)) {
fileName = componentName;
done = true;
} else {
i++;
}
}
}
}
}
IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
HttpOutputHandler outputHandler = createOutputHandler(response, outputStream);
outputHandler.setSession(userSession);
IMimeTypeListener listener = new HttpMimeTypeListener(request, response);
listener.setName(fileName);
outputHandler.setMimeTypeListener(listener);
SimpleUrlFactory urlFactory = new SimpleUrlFactory(requestContext.getContextPath() + // $NON-NLS-1$
"SolutionEngineInteractivityService?");
IParameterProvider requestParameters = new HttpRequestParameterProvider(request);
setupOutputHandler(outputHandler, requestParameters);
HttpServletRequestHandler requestHandler = getRequestHandler(request, response, userSession, requestParameters, outputStream, outputHandler, urlFactory);
handleActionRequest(request, response, outputHandler, requestHandler, requestParameters, outputStream, null);
} finally {
PentahoSystem.systemExitPoint();
}
}
use of org.pentaho.platform.api.engine.IActionSequence in project pentaho-platform by pentaho.
the class HttpWebService method doParameter.
private void doParameter(final String solutionName, final String actionPath, final String actionName, final IParameterProvider parameterProvider, final OutputStream outputStream, final IPentahoSession userSession, final HttpServletResponse response) throws IOException {
final IActionSequence actionSequence = new ActionSequenceJCRHelper().getActionSequence(ActionInfo.buildSolutionPath(solutionName, actionPath, actionName), PentahoSystem.loggingLevel, RepositoryFilePermission.READ);
if (actionSequence == null) {
logger.debug(Messages.getInstance().getString("HttpWebService.ERROR_0002_NOTFOUND", solutionName, actionPath, actionName));
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
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);
}
// built in parameters: solution, path, action, prompt, instance-id
createParameterElement(parametersElement, "solution", String.class, null, "system", "system", new String[] { solutionName });
createParameterElement(parametersElement, "path", String.class, null, "system", "system", new String[] { actionPath });
createParameterElement(parametersElement, "action", String.class, null, "system", "system", new String[] { actionName });
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) });
} catch (Exception e) {
logger.warn(Messages.getInstance().getString("HttpWebService.ERROR_0003_UNEXPECTED"), e);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
// no close, as far as I know tomcat does not like it that much ..
final XMLWriter writer = new XMLWriter(outputStream, OutputFormat.createPrettyPrint());
writer.write(document);
writer.flush();
}
Aggregations