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;
}
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());
}
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());
}
Aggregations