Search in sources :

Example 1 with IAction

use of org.pentaho.platform.api.action.IAction in project pentaho-platform by pentaho.

the class QuartzSchedulerIT method fireJobCompletedTest.

@Test
public void fireJobCompletedTest() throws Exception {
    final IAction actionBean = mock(IAction.class);
    final String actionUser = "actionUser";
    final ISchedulerListener schedulerListener = mock(ISchedulerListener.class);
    scheduler.addListener(schedulerListener);
    final Map<String, Serializable> params = new HashMap<>();
    final IBackgroundExecutionStreamProvider streamProvider = mock(IBackgroundExecutionStreamProvider.class);
    scheduler.fireJobCompleted(actionBean, actionUser, params, streamProvider);
    verify(schedulerListener, times(1)).jobCompleted(eq(actionBean), eq(actionUser), eq(params), eq(streamProvider));
}
Also used : IBackgroundExecutionStreamProvider(org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider) Serializable(java.io.Serializable) IAction(org.pentaho.platform.api.action.IAction) HashMap(java.util.HashMap) ISchedulerListener(org.pentaho.platform.api.scheduler2.ISchedulerListener) Test(org.junit.Test)

Example 2 with IAction

use of org.pentaho.platform.api.action.IAction in project pentaho-platform by pentaho.

the class DefaultPluginManager method getAction.

public IAction getAction(String type, String perspectiveName) {
    IAction action = null;
    // $NON-NLS-1$
    String beanId = (perspectiveName == null) ? type : type + "." + perspectiveName;
    try {
        action = (IAction) getBean(beanId, IAction.class);
    } catch (NoSuchBeanDefinitionException e) {
        // fallback condition, look for a type agnostic content generator
        try {
            action = (IAction) getBean(perspectiveName, IAction.class);
        } catch (NoSuchBeanDefinitionException e2) {
            throw new NoSuchBeanDefinitionException("Failed to find bean: " + e.getMessage() + " : " + e2.getMessage());
        }
    }
    return action;
}
Also used : IAction(org.pentaho.platform.api.action.IAction) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException)

Example 3 with IAction

use of org.pentaho.platform.api.action.IAction in project pentaho-platform by pentaho.

the class ActionRunnerTest method testCallWithStreamProvider.

@Test
public void testCallWithStreamProvider() throws Exception {
    Map<String, Serializable> paramsMap = createMapWithUserLocale();
    IAction actionBeanSpy = Mockito.spy(new TestAction());
    IBackgroundExecutionStreamProvider mockStreamProvider = Mockito.mock(IBackgroundExecutionStreamProvider.class);
    InputStream mockInputStream = Mockito.mock(InputStream.class);
    OutputStream mockOutputStream = Mockito.mock(OutputStream.class);
    when(mockStreamProvider.getInputStream()).thenReturn(mockInputStream);
    String mockOutputPath = "/someUser/someOutput";
    when(mockStreamProvider.getOutputPath()).thenReturn(mockOutputPath);
    when(mockStreamProvider.getOutputStream()).thenReturn(mockOutputStream);
    ISecurityHelper mockSecurityHelper = Mockito.mock(ISecurityHelper.class);
    SecurityHelper.setMockInstance(mockSecurityHelper);
    when(mockSecurityHelper.runAsUser(Mockito.anyString(), Mockito.any())).thenReturn(mockOutputPath);
    PowerMockito.mockStatic(PentahoSystem.class);
    IUnifiedRepository mockRepository = Mockito.mock(IUnifiedRepository.class);
    when(PentahoSystem.get(isA(IUnifiedRepository.class.getClass()), Mockito.any())).thenReturn(mockRepository);
    IAuthorizationPolicy mockAuthorizationPolicy = Mockito.mock(IAuthorizationPolicy.class);
    when(PentahoSystem.get(isA(IAuthorizationPolicy.class.getClass()), Mockito.any())).thenReturn(mockAuthorizationPolicy);
    when(mockAuthorizationPolicy.isAllowed(SchedulerOutputPathResolver.SCHEDULER_ACTION_NAME)).thenReturn(true);
    String repoId = "SOME_REPO_ID";
    Map<String, Serializable> dummyMetaData = new HashMap<>();
    dummyMetaData.put(RepositoryFile.SCHEDULABLE_KEY, true);
    when(mockRepository.getFileMetadata(repoId)).thenReturn(dummyMetaData);
    RepositoryFile mockRepoFile = Mockito.mock(RepositoryFile.class);
    when(mockRepoFile.isFolder()).thenReturn(true);
    when(mockRepoFile.getId()).thenReturn(repoId);
    ActionRunner actionRunner = new ActionRunner(actionBeanSpy, "actionUser", paramsMap, mockStreamProvider);
    actionRunner.call();
    Mockito.verify(actionBeanSpy).execute();
}
Also used : IBackgroundExecutionStreamProvider(org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider) Serializable(java.io.Serializable) IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) IAction(org.pentaho.platform.api.action.IAction) HashMap(java.util.HashMap) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) TestAction(org.pentaho.platform.util.bean.TestAction) ISecurityHelper(org.pentaho.platform.api.engine.ISecurityHelper) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with IAction

use of org.pentaho.platform.api.action.IAction in project pentaho-platform by pentaho.

the class ActionDelegate method executeAction.

/**
 * Wires up inputs outputs and resources to an Action and executes it.
 */
@Override
protected boolean executeAction() throws Throwable {
    // 
    // Set inputs
    // 
    InputErrorCallback errorCallback = new InputErrorCallback();
    for (IActionInput input : getActionDefinition().getInputs()) {
        Object inputValue = input.getValue();
        if (input instanceof ActionInputConstant) {
            // if the input is coming from the component definition section,
            // do parameter replacement on the string and the result of that
            // is the input value
            inputValue = input.getStringValue(true);
        }
        errorCallback.setValue(inputValue);
        actionHarness.setValue(input.getName(), inputValue, errorCallback, COMPATIBILITY_FORMATTER, ALTERNATE_INDEX_FORMATTER);
    }
    // 
    // Set resources
    // 
    ResourceCallback resourceCallback = new ResourceCallback();
    for (IActionResource res : getActionDefinition().getResources()) {
        actionHarness.setValue(res.getName(), res.getInputStream(), resourceCallback, COMPATIBILITY_FORMATTER, ALTERNATE_INDEX_FORMATTER);
    }
    // 
    // Provide output stream for the streaming action. We are going to look for all outputs where
    // type = "content", and derive output streams to hand to the IStreamingAction.
    // 
    Map<String, IContentItem> outputContentItems = new HashMap<String, IContentItem>();
    StreamOutputErrorCallback streamingOutputCallback = new StreamOutputErrorCallback();
    OuputStreamGenerator outputStreamGenerator = new OuputStreamGenerator(outputContentItems);
    IActionOutput[] contentOutputs = getActionDefinition().getOutputs(ActionSequenceDocument.CONTENT_TYPE);
    if (contentOutputs.length > 0) {
        for (IActionOutput contentOutput : contentOutputs) {
            outputStreamGenerator.setContentOutput(contentOutput);
            actionHarness.setValue(contentOutput.getName(), outputStreamGenerator, streamingOutputCallback, STREAM_APPENDER_FORMATTER, COMPATIBILITY_FORMATTER, ALTERNATE_INDEX_FORMATTER);
        }
    }
    // 
    if (actionBean instanceof IAction) {
        ((IAction) actionBean).execute();
    }
    // 
    for (IActionOutput output : actionDefintionOutputs) {
        String outputName = output.getName();
        outputName = COMPATIBILITY_FORMATTER.format(outputName);
        // if streaming output, add it to the context and don't try to get it from the Action bean
        if (outputContentItems.containsKey(outputName)) {
            IContentItem contentItem = outputContentItems.get(outputName);
            if (!(contentItem instanceof SimpleContentItem)) {
                // this is a special output for streaming actions and does not require a bean accessor
                output.setValue(contentItem);
            }
        } else if (actionHarness.isReadable(outputName)) {
            Object outputVal = actionHarness.getValue(outputName);
            output.setValue(outputVal);
        } else {
            if (loggingLevel <= ILogger.WARN) {
                warn(// $NON-NLS-1$
                Messages.getInstance().getString(// $NON-NLS-1$
                "ActionDelegate.WARN_OUTPUT_NOT_READABLE", outputName, output.getType(), actionBean.getClass().getSimpleName()));
            }
        }
    }
    return true;
}
Also used : IAction(org.pentaho.platform.api.action.IAction) HashMap(java.util.HashMap) ActionInputConstant(org.pentaho.actionsequence.dom.ActionInputConstant) IActionOutput(org.pentaho.actionsequence.dom.IActionOutput) SimpleContentItem(org.pentaho.platform.engine.core.output.SimpleContentItem) IActionResource(org.pentaho.actionsequence.dom.IActionResource) IActionInput(org.pentaho.actionsequence.dom.IActionInput) IContentItem(org.pentaho.platform.api.repository.IContentItem)

Example 5 with IAction

use of org.pentaho.platform.api.action.IAction 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)

Aggregations

IAction (org.pentaho.platform.api.action.IAction)15 HashMap (java.util.HashMap)9 Serializable (java.io.Serializable)8 Test (org.junit.Test)8 IBackgroundExecutionStreamProvider (org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 TestAction (org.pentaho.platform.util.bean.TestAction)3 ArrayList (java.util.ArrayList)2 ActionInvokeStatus (org.pentaho.platform.action.ActionInvokeStatus)2 ActionInvocationException (org.pentaho.platform.api.action.ActionInvocationException)2 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)2 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)2 ActionSequenceAction (org.pentaho.platform.plugin.action.builtin.ActionSequenceAction)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Date (java.util.Date)1 List (java.util.List)1 Element (org.dom4j.Element)1 ExpectedException (org.junit.rules.ExpectedException)1