Search in sources :

Example 1 with ActionInvokeStatus

use of org.pentaho.platform.action.ActionInvokeStatus in project pentaho-platform by pentaho.

the class DefaultActionInvoker method invokeActionImpl.

/**
 * Invokes the provided {@link IAction} as the provided {@code actionUser}.
 *
 * @param actionBean the {@link IAction} being invoked
 * @param actionUser The user invoking the {@link IAction}
 * @param params     the {@link Map} or parameters needed to invoke the {@link IAction}
 * @return the {@link IActionInvokeStatus} object containing information about the action invocation
 * @throws Exception when the {@code IAction} cannot be invoked for some reason.
 */
protected IActionInvokeStatus invokeActionImpl(final IAction actionBean, final String actionUser, final Map<String, Serializable> params) throws Exception {
    final String workItemName = ActionUtil.extractName(params);
    if (actionBean == null || params == null) {
        final String failureMessage = Messages.getInstance().getCantInvokeNullAction();
        WorkItemLifecycleEventUtil.publish(workItemName, params, WorkItemLifecyclePhase.FAILED, failureMessage);
        throw new ActionInvocationException(failureMessage);
    }
    WorkItemLifecycleEventUtil.publish(workItemName, params, WorkItemLifecyclePhase.IN_PROGRESS);
    if (logger.isDebugEnabled()) {
        logger.debug(Messages.getInstance().getRunningInBackgroundLocally(actionBean.getClass().getName(), params));
    }
    // set the locale, if not already set
    if (params.get(LocaleHelper.USER_LOCALE_PARAM) == null || StringUtils.isEmpty(params.get(LocaleHelper.USER_LOCALE_PARAM).toString())) {
        params.put(LocaleHelper.USER_LOCALE_PARAM, LocaleHelper.getLocale());
    }
    // remove the scheduling infrastructure properties
    ActionUtil.removeKeyFromMap(params, ActionUtil.INVOKER_ACTIONCLASS);
    ActionUtil.removeKeyFromMap(params, ActionUtil.INVOKER_ACTIONID);
    ActionUtil.removeKeyFromMap(params, ActionUtil.INVOKER_ACTIONUSER);
    // build the stream provider
    final IBackgroundExecutionStreamProvider streamProvider = getStreamProvider(params);
    ActionUtil.removeKeyFromMap(params, ActionUtil.INVOKER_STREAMPROVIDER);
    ActionUtil.removeKeyFromMap(params, ActionUtil.INVOKER_UIPASSPARAM);
    final ActionRunner actionBeanRunner = new ActionRunner(actionBean, actionUser, params, streamProvider);
    final IActionInvokeStatus status = new ActionInvokeStatus();
    status.setStreamProvider(streamProvider);
    boolean requiresUpdate = false;
    try {
        if ((StringUtil.isEmpty(actionUser)) || (actionUser.equals("system session"))) {
            // $NON-NLS-1$
            // For now, don't try to run quartz jobs as authenticated if the user
            // that created the job is a system user. See PPP-2350
            requiresUpdate = SecurityHelper.getInstance().runAsAnonymous(actionBeanRunner);
        } else {
            requiresUpdate = SecurityHelper.getInstance().runAsUser(actionUser, actionBeanRunner);
        }
    } catch (final Throwable t) {
        WorkItemLifecycleEventUtil.publish(workItemName, params, WorkItemLifecyclePhase.FAILED, t.toString());
        status.setThrowable(t);
    }
    status.setRequiresUpdate(requiresUpdate);
    // Set the execution Status
    status.setExecutionStatus(actionBean.isExecutionSuccessful());
    return status;
}
Also used : IBackgroundExecutionStreamProvider(org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider) IActionInvokeStatus(org.pentaho.platform.api.action.IActionInvokeStatus) ActionInvokeStatus(org.pentaho.platform.action.ActionInvokeStatus) IActionInvokeStatus(org.pentaho.platform.api.action.IActionInvokeStatus) ActionInvocationException(org.pentaho.platform.api.action.ActionInvocationException)

Example 2 with ActionInvokeStatus

use of org.pentaho.platform.action.ActionInvokeStatus in project pentaho-platform by pentaho.

the class LocalActionInvokerTest method invokeActionTest.

@Test
public void invokeActionTest() throws Exception {
    Map<String, Serializable> testMap = new HashMap<>();
    testMap.put(ActionUtil.QUARTZ_ACTIONCLASS, "one");
    testMap.put(ActionUtil.QUARTZ_ACTIONUSER, "two");
    IAction iaction = ActionUtil.createActionBean(ActionSequenceAction.class.getName(), null);
    ActionInvokeStatus actionInvokeStatus = (ActionInvokeStatus) defaultActionInvoker.invokeAction(iaction, "aUser", testMap);
    Assert.assertFalse(actionInvokeStatus.requiresUpdate());
}
Also used : Serializable(java.io.Serializable) ActionInvokeStatus(org.pentaho.platform.action.ActionInvokeStatus) IAction(org.pentaho.platform.api.action.IAction) HashMap(java.util.HashMap) ActionSequenceAction(org.pentaho.platform.plugin.action.builtin.ActionSequenceAction) Test(org.junit.Test)

Example 3 with ActionInvokeStatus

use of org.pentaho.platform.action.ActionInvokeStatus in project pentaho-platform by pentaho.

the class LocalActionInvokerTest method invokeActionLocallyTest.

@Test
public void invokeActionLocallyTest() throws Exception {
    Map<String, Serializable> testMap = new HashMap<>();
    testMap.put(ActionUtil.QUARTZ_ACTIONCLASS, "one");
    testMap.put(ActionUtil.QUARTZ_ACTIONUSER, "two");
    IAction iaction = ActionUtil.createActionBean(ActionSequenceAction.class.getName(), null);
    ActionInvokeStatus actionInvokeStatus = (ActionInvokeStatus) defaultActionInvoker.invokeAction(iaction, "aUser", testMap);
    Assert.assertFalse(actionInvokeStatus.requiresUpdate());
}
Also used : Serializable(java.io.Serializable) ActionInvokeStatus(org.pentaho.platform.action.ActionInvokeStatus) IAction(org.pentaho.platform.api.action.IAction) HashMap(java.util.HashMap) ActionSequenceAction(org.pentaho.platform.plugin.action.builtin.ActionSequenceAction) Test(org.junit.Test)

Aggregations

ActionInvokeStatus (org.pentaho.platform.action.ActionInvokeStatus)3 Serializable (java.io.Serializable)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 IAction (org.pentaho.platform.api.action.IAction)2 ActionSequenceAction (org.pentaho.platform.plugin.action.builtin.ActionSequenceAction)2 ActionInvocationException (org.pentaho.platform.api.action.ActionInvocationException)1 IActionInvokeStatus (org.pentaho.platform.api.action.IActionInvokeStatus)1 IBackgroundExecutionStreamProvider (org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider)1