Search in sources :

Example 16 with ISolutionEngine

use of org.pentaho.platform.api.engine.ISolutionEngine in project pentaho-platform by pentaho.

the class ActionFilterDefinition method getResultSet.

/**
 * If the <data-output> element is present in the xml file, its text specifies the name of the output parameter
 * in the runtime context containing the result set.
 *
 * However, the <data-output> element is not required. If this element is not in the xml file, then the first
 * parameter in the runtime context's output of type "resultset" contains the result set.
 */
@Override
protected IPentahoResultSet getResultSet(final Map parameterProviders) {
    // create an instance of the solution engine to execute the specified
    // action
    // TODO we need to ensure that this data is cached (not live) so that we
    // can validate selections
    // $NON-NLS-1$
    String solution = XmlDom4JHelper.getNodeText("data-solution", node);
    // $NON-NLS-1$
    String actionPath = XmlDom4JHelper.getNodeText("data-path", node);
    // $NON-NLS-1$
    String actionName = XmlDom4JHelper.getNodeText("data-action", node);
    // $NON-NLS-1$
    String listSource = XmlDom4JHelper.getNodeText("data-output", node);
    ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, session);
    solutionEngine.setLoggingLevel(ILogger.DEBUG);
    solutionEngine.init(session);
    OutputStream outputStream = null;
    SimpleOutputHandler outputHandler = null;
    outputHandler = new SimpleOutputHandler(outputStream, false);
    ArrayList messages = new ArrayList();
    String processId = this.getClass().getName();
    String instanceId = null;
    IRuntimeContext context = null;
    try {
        String actionSeqPath = ActionInfo.buildSolutionPath(solution, actionPath, actionName);
        context = solutionEngine.execute(actionSeqPath, processId, false, true, instanceId, false, parameterProviders, outputHandler, null, null, messages);
        if (listSource != null) {
            if (context.getOutputNames().contains(listSource)) {
                IActionParameter output = context.getOutputParameter(listSource);
                IPentahoResultSet results = output.getValueAsResultSet();
                if (results != null) {
                    results = results.memoryCopy();
                }
                return results;
            } else {
                // this is an error
                return null;
            }
        } else {
            // return the first list that we find...
            Iterator it = context.getOutputNames().iterator();
            while (it.hasNext()) {
                IActionParameter output = (IActionParameter) it.next();
                if (output.getType().equalsIgnoreCase(IActionParameter.TYPE_RESULT_SET)) {
                    IPentahoResultSet results = output.getValueAsResultSet();
                    if (results != null) {
                        results = results.memoryCopy();
                    }
                    return results;
                }
            }
        }
        return null;
    } finally {
        if (context != null) {
            context.dispose();
        }
    }
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 17 with ISolutionEngine

use of org.pentaho.platform.api.engine.ISolutionEngine in project pentaho-platform by pentaho.

the class SolutionHelper method execute.

/**
 * Runs an action sequence. This method uses the base URL set by the Application Context
 *
 * @param description
 *          An identifier for this process. This is used for auditing and logging purposes only.
 * @param session
 *          The user session that is requesting this execution. This is used for auditing and logging and also
 *          can be used in action sequences (for example to filter data)
 * @param actionSequence
 *          Path to the action sequence file
 * @param parameters
 *          Parameters to be passed to the action sequence
 * @param outputStream
 *          The output stream for content generated by the action sequence. Can be null.
 * @param execListener
 *          An execution listener for feedback during execution. Can be null.
 * @return
 */
public static ISolutionEngine execute(final String description, final IPentahoSession session, final String actionSequence, final Map parameters, OutputStream outputStream, final IExecutionListener execListener, final boolean collateMessages, final boolean manageHibernate) {
    if (manageHibernate) {
        PentahoSystem.systemEntryPoint();
    }
    ISolutionEngine solutionEngine = null;
    try {
        solutionEngine = PentahoSystem.get(ISolutionEngine.class, session);
        solutionEngine.init(session);
        solutionEngine.setlistener(execListener);
        SimpleParameterProvider parameterProvider = new SimpleParameterProvider(parameters);
        IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
        String url = requestContext.getContextPath();
        // Modifications by Ezequiel Cuellar
        // Old code.
        // String baseUrl = PentahoSystem.getApplicationContext().getBaseUrl();
        // New code. Since the SubActionComponent is being instantiated below to return feedback
        // it is necesary to configure the baseUrl to include the ViewAction.
        Object actionUrlComponent = parameters.get(StandardSettings.ACTION_URL_COMPONENT);
        if ((actionUrlComponent != null) && (actionUrlComponent.toString().length() > 0)) {
            url += actionUrlComponent.toString();
        } else {
            // $NON-NLS-1$
            url += "ViewAction?";
        }
        HashMap<String, IParameterProvider> parameterProviderMap = new HashMap<String, IParameterProvider>();
        parameterProviderMap.put(IParameterProvider.SCOPE_REQUEST, parameterProvider);
        IPentahoUrlFactory urlFactory = new SimpleUrlFactory(url);
        String processName = description;
        boolean persisted = false;
        // for now, the messages list needs to be untyped since we may put exceptions as well as strings in it
        List<?> messages = null;
        if (collateMessages) {
            messages = new ArrayList();
        }
        if (outputStream == null) {
            outputStream = new ByteArrayOutputStream(0);
        }
        SimpleOutputHandler outputHandler = null;
        if (outputStream != null) {
            // Modifications by Ezequiel Cuellar
            // Old code.
            // outputHandler = new SimpleOutputHandler(outputStream, false);
            // New code. Without setting the allowFeedback parameter to true it is assumed that SubActionComponent
            // instances
            // are never capable of returning feedback which may not always be the case.
            outputHandler = new SimpleOutputHandler(outputStream, true);
            outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_DEFAULT);
        }
        solutionEngine.execute(actionSequence, processName, false, true, null, persisted, parameterProviderMap, outputHandler, null, urlFactory, messages);
    } finally {
        if (manageHibernate) {
            PentahoSystem.systemExitPoint();
        }
    }
    return solutionEngine;
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IPentahoUrlFactory(org.pentaho.platform.api.engine.IPentahoUrlFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IPentahoRequestContext(org.pentaho.platform.api.engine.IPentahoRequestContext) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 18 with ISolutionEngine

use of org.pentaho.platform.api.engine.ISolutionEngine in project pentaho-platform by pentaho.

the class AbstractChartComponent method getActionData.

/**
 * Gets a IPentahoResultSet from the action output
 *
 * @return IPentahoResultSet
 */
public IPentahoResultSet getActionData() {
    // create an instance of the solution engine to execute the specified
    // action
    ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, getSession());
    solutionEngine.setLoggingLevel(ILogger.DEBUG);
    solutionEngine.init(getSession());
    HashMap parameterProviders = getParameterProviders();
    OutputStream outputStream = null;
    SimpleOutputHandler outputHandler = null;
    outputHandler = new SimpleOutputHandler(outputStream, false);
    ArrayList messages = new ArrayList();
    String processId = this.getClass().getName();
    context = // $NON-NLS-1$ //$NON-NLS-2$
    solutionEngine.execute(// $NON-NLS-1$ //$NON-NLS-2$
    actionPath, // $NON-NLS-1$ //$NON-NLS-2$
    processId, // $NON-NLS-1$ //$NON-NLS-2$
    false, // $NON-NLS-1$ //$NON-NLS-2$
    true, // $NON-NLS-1$ //$NON-NLS-2$
    instanceId, // $NON-NLS-1$ //$NON-NLS-2$
    false, parameterProviders, outputHandler, null, urlFactory, messages);
    if (context == null) {
        // this went badly wrong
        return null;
    }
    if (actionOutput != null) {
        if (context.getOutputNames().contains(actionOutput)) {
            IActionParameter output = context.getOutputParameter(actionOutput);
            IPentahoResultSet results = output.getValueAsResultSet();
            if (results != null) {
                results = results.memoryCopy();
            }
            return results;
        } else {
            // this is an error
            return null;
        }
    } else {
        for (Object objAp : context.getOutputNames()) {
            IActionParameter output = (IActionParameter) objAp;
            if (output.getType().equalsIgnoreCase(IActionParameter.TYPE_RESULT_SET)) {
                IPentahoResultSet results = output.getValueAsResultSet();
                if (results != null) {
                    results = results.memoryCopy();
                }
                return results;
            }
        }
    }
    return null;
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) HashMap(java.util.HashMap) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 19 with ISolutionEngine

use of org.pentaho.platform.api.engine.ISolutionEngine in project pentaho-platform by pentaho.

the class XactionUtil method executeInternal.

@SuppressWarnings("rawtypes")
protected static IRuntimeContext executeInternal(RepositoryFile file, IParameterProvider requestParams, HttpServletRequest httpServletRequest, IOutputHandler outputHandler, Map<String, IParameterProvider> parameterProviders, IPentahoSession userSession, boolean forcePrompt, List messages) throws Exception {
    String processId = XactionUtil.class.getName();
    // $NON-NLS-1$
    String instanceId = httpServletRequest.getParameter("instance-id");
    // $NON-NLS-1$
    SimpleUrlFactory urlFactory = new SimpleUrlFactory("");
    ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, userSession);
    ISystemSettings systemSettings = PentahoSystem.getSystemSettings();
    if (solutionEngine == null) {
        throw new ObjectFactoryException("No Solution Engine");
    }
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    boolean instanceEnds = "true".equalsIgnoreCase(requestParams.getStringParameter("instanceends", "true"));
    // $NON-NLS-1$ //$NON-NLS-2$
    String parameterXsl = systemSettings.getSystemSetting("default-parameter-xsl", "DefaultParameterForm.xsl");
    solutionEngine.setLoggingLevel(2);
    solutionEngine.init(userSession);
    solutionEngine.setForcePrompt(forcePrompt);
    if (parameterXsl != null) {
        solutionEngine.setParameterXsl(parameterXsl);
    }
    return solutionEngine.execute(file.getPath(), processId, false, instanceEnds, instanceId, false, parameterProviders, outputHandler, null, urlFactory, messages);
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) ISystemSettings(org.pentaho.platform.api.engine.ISystemSettings)

Example 20 with ISolutionEngine

use of org.pentaho.platform.api.engine.ISolutionEngine in project pentaho-platform by pentaho.

the class ActionSequenceActionTest method setUp.

@Before
public void setUp() throws ObjectFactoryException {
    IRuntimeContext context = mock(IRuntimeContext.class);
    when(context.getOutputContentItems()).thenReturn(expectedContentItem);
    when(context.getStatus()).thenReturn(IRuntimeContext.RUNTIME_STATUS_SUCCESS);
    final ISolutionEngine engine = mock(ISolutionEngine.class);
    when(engine.execute(anyString(), anyString(), anyBoolean(), anyBoolean(), anyString(), anyBoolean(), anyMap(), any(IOutputHandler.class), any(IActionCompleteListener.class), any(IPentahoUrlFactory.class), anyList())).thenReturn(context);
    pentahoObjectFactory = mock(IPentahoObjectFactory.class);
    when(pentahoObjectFactory.objectDefined(anyString())).thenReturn(true);
    when(pentahoObjectFactory.get(this.anyClass(), anyString(), any(IPentahoSession.class))).thenAnswer(new Answer<Object>() {

        @Override
        public ISolutionEngine answer(InvocationOnMock invocation) throws Throwable {
            return engine;
        }
    });
    PentahoSystem.registerObjectFactory(pentahoObjectFactory);
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IOutputHandler(org.pentaho.platform.api.engine.IOutputHandler) IPentahoUrlFactory(org.pentaho.platform.api.engine.IPentahoUrlFactory) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) IActionCompleteListener(org.pentaho.platform.api.engine.IActionCompleteListener) Before(org.junit.Before)

Aggregations

ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)37 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)27 ArrayList (java.util.ArrayList)26 HashMap (java.util.HashMap)25 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)22 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)13 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)11 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)9 IPentahoUrlFactory (org.pentaho.platform.api.engine.IPentahoUrlFactory)9 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)5 OutputStream (java.io.OutputStream)4 Iterator (java.util.Iterator)4 Map (java.util.Map)4 File (java.io.File)3 FileReader (java.io.FileReader)3 IOException (java.io.IOException)3 Reader (java.io.Reader)3 BigDecimal (java.math.BigDecimal)3