Search in sources :

Example 6 with ActionHarness

use of org.pentaho.platform.util.beans.ActionHarness in project pentaho-platform by pentaho.

the class ActionHarnessTest method testSetNullIsSkippedWithNotError.

@Test
public void testSetNullIsSkippedWithNotError() throws Exception {
    TestAction action1 = new TestAction();
    ActionHarness harness1 = new ActionHarness(action1);
    // commons bBeanutils will throw exception if you try to type convert a null value. Pentaho BeanUtil
    // will skip the set operation altogether if you try to set a null value on a bean. This test ensures
    // that no exception is thrown in this case. The correct behavior is a message will be logged indicating
    // that the null value could not be set. I don't consider this a "real" type conversion problem like
    // a text string failing conversion to a Long type.. this type of conversion will still fail.
    harness1.setValue("count", null, new EagerFailingCallback());
    // If no exception thrown, then the test is essentially passed. We'll double check that
    // count was not set as well.
    Assert.assertNull("count property should remain null since null set value ops should be skipped", action1.getCount());
}
Also used : ActionHarness(org.pentaho.platform.util.beans.ActionHarness) EagerFailingCallback(org.pentaho.platform.util.beans.BeanUtil.EagerFailingCallback) Test(org.junit.Test)

Example 7 with ActionHarness

use of org.pentaho.platform.util.beans.ActionHarness in project pentaho-platform by pentaho.

the class ActionRunner method callImpl.

private ExecutionResult callImpl() throws Exception {
    boolean executionStatus = true;
    final Object locale = params.get(LocaleHelper.USER_LOCALE_PARAM);
    if (locale instanceof Locale) {
        LocaleHelper.setLocaleOverride((Locale) locale);
    } else {
        LocaleHelper.setLocaleOverride(new Locale((String) locale));
    }
    // sync job params to the action bean
    ActionHarness actionHarness = new ActionHarness(actionBean);
    boolean updateJob = false;
    final Map<String, Object> actionParams = new HashMap<String, Object>();
    actionParams.putAll(params);
    if (streamProvider != null) {
        actionParams.put("inputStream", streamProvider.getInputStream());
    }
    actionHarness.setValues(actionParams, new ActionSequenceCompatibilityFormatter());
    if (actionBean instanceof IVarArgsAction) {
        actionParams.remove("inputStream");
        actionParams.remove("outputStream");
        ((IVarArgsAction) actionBean).setVarArgs(actionParams);
    }
    boolean waitForFileCreated = false;
    OutputStream stream = null;
    if (streamProvider != null) {
        actionParams.remove("inputStream");
        if (actionBean instanceof IStreamingAction) {
            streamProvider.setStreamingAction((IStreamingAction) actionBean);
        }
        // BISERVER-9414 - validate that output path still exist
        SchedulerOutputPathResolver resolver = new SchedulerOutputPathResolver(streamProvider.getOutputPath(), actionUser);
        String outputPath = resolver.resolveOutputFilePath();
        actionParams.put("useJcr", Boolean.TRUE);
        actionParams.put("jcrOutputPath", outputPath.substring(0, outputPath.lastIndexOf("/")));
        if (!outputPath.equals(streamProvider.getOutputPath())) {
            // set fallback path
            streamProvider.setOutputFilePath(outputPath);
            // job needs to be deleted and recreated with the new output path
            updateJob = true;
        }
        stream = streamProvider.getOutputStream();
        if (stream instanceof ISourcesStreamEvents) {
            ((ISourcesStreamEvents) stream).addListener(new IStreamListener() {

                public void fileCreated(final String filePath) {
                    synchronized (lock) {
                        outputFilePath = filePath;
                        lock.notifyAll();
                    }
                }
            });
            waitForFileCreated = true;
        }
        actionParams.put("outputStream", stream);
        // The lineage_id is only useful for the metadata and not needed at this level see PDI-10171
        ActionUtil.removeKeyFromMap(actionParams, ActionUtil.QUARTZ_LINEAGE_ID);
        actionHarness.setValues(actionParams);
    }
    actionBean.execute();
    executionStatus = actionBean.isExecutionSuccessful();
    if (stream != null) {
        IOUtils.closeQuietly(stream);
    }
    if (waitForFileCreated) {
        synchronized (lock) {
            if (outputFilePath == null) {
                lock.wait();
            }
        }
        ActionUtil.sendEmail(actionParams, params, outputFilePath);
        deleteEmptyFile();
    }
    if (actionBean instanceof IPostProcessingAction) {
        closeContentOutputStreams((IPostProcessingAction) actionBean);
        markContentAsGenerated((IPostProcessingAction) actionBean);
    }
    // Create the ExecutionResult to return the status and whether the update is required or not
    ExecutionResult executionResult = new ExecutionResult(updateJob, executionStatus);
    return executionResult;
}
Also used : Locale(java.util.Locale) IStreamListener(org.pentaho.platform.api.repository2.unified.IStreamListener) HashMap(java.util.HashMap) OutputStream(java.io.OutputStream) SchedulerOutputPathResolver(org.pentaho.platform.scheduler2.quartz.SchedulerOutputPathResolver) ISourcesStreamEvents(org.pentaho.platform.api.repository2.unified.ISourcesStreamEvents) IStreamingAction(org.pentaho.platform.api.action.IStreamingAction) IVarArgsAction(org.pentaho.platform.api.action.IVarArgsAction) ActionSequenceCompatibilityFormatter(org.pentaho.platform.engine.services.solution.ActionSequenceCompatibilityFormatter) ActionHarness(org.pentaho.platform.util.beans.ActionHarness) IPostProcessingAction(org.pentaho.platform.api.action.IPostProcessingAction)

Example 8 with ActionHarness

use of org.pentaho.platform.util.beans.ActionHarness in project pentaho-platform by pentaho.

the class ActionHarnessTest method testSetValueNonExistentProperty.

@Test(expected = IllegalAccessException.class)
public void testSetValueNonExistentProperty() throws Exception {
    TestAction action1 = new TestAction();
    ActionHarness harness1 = new ActionHarness(action1);
    harness1.setValue("THISPROPERTYDOESNOTEXIST", "", new EagerFailingCallback());
    Assert.assertEquals("test message action1", harness1.getValue("message"));
}
Also used : ActionHarness(org.pentaho.platform.util.beans.ActionHarness) EagerFailingCallback(org.pentaho.platform.util.beans.BeanUtil.EagerFailingCallback) Test(org.junit.Test)

Example 9 with ActionHarness

use of org.pentaho.platform.util.beans.ActionHarness in project pentaho-platform by pentaho.

the class ActionHarnessTest method testSetValueWithFormatterNonExistentProperty.

@Test(expected = IllegalAccessException.class)
public void testSetValueWithFormatterNonExistentProperty() throws Exception {
    TestAction action1 = new TestAction();
    ActionHarness harness1 = new ActionHarness(action1);
    PropertyNameFormatter f = new PropertyNameFormatter() {

        public String format(String name) {
            return "THISPROPERTYDOESNOTEXIST";
        }
    };
    harness1.setValue("THISWILLGETCLOBBERED", "test message action1", new EagerFailingCallback(), f);
}
Also used : PropertyNameFormatter(org.pentaho.platform.util.beans.PropertyNameFormatter) ActionHarness(org.pentaho.platform.util.beans.ActionHarness) EagerFailingCallback(org.pentaho.platform.util.beans.BeanUtil.EagerFailingCallback) Test(org.junit.Test)

Example 10 with ActionHarness

use of org.pentaho.platform.util.beans.ActionHarness in project pentaho-platform by pentaho.

the class FileResourceContentGenerator method createContent.

@Override
public void createContent(OutputStream out) throws Exception {
    // $NON-NLS-1$
    IParameterProvider pathParams = parameterProviders.get("path");
    IParameterProvider requestParams = parameterProviders.get(IParameterProvider.SCOPE_REQUEST);
    // $NON-NLS-1$
    RepositoryFile file = (RepositoryFile) pathParams.getParameter("file");
    ActionHarness harness = new ActionHarness(this);
    Iterator<?> iter = requestParams.getParameterNames();
    while (iter.hasNext()) {
        String paramName = (String) iter.next();
        harness.setValue(paramName, requestParams.getParameter(paramName));
    }
    this.setOutputStream(out);
    this.setRepositoryFile(file);
    this.execute();
}
Also used : IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) ActionHarness(org.pentaho.platform.util.beans.ActionHarness)

Aggregations

ActionHarness (org.pentaho.platform.util.beans.ActionHarness)10 Test (org.junit.Test)8 EagerFailingCallback (org.pentaho.platform.util.beans.BeanUtil.EagerFailingCallback)5 PropertyNameFormatter (org.pentaho.platform.util.beans.PropertyNameFormatter)2 OutputStream (java.io.OutputStream)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 IAction (org.pentaho.platform.api.action.IAction)1 IPostProcessingAction (org.pentaho.platform.api.action.IPostProcessingAction)1 IStreamingAction (org.pentaho.platform.api.action.IStreamingAction)1 IVarArgsAction (org.pentaho.platform.api.action.IVarArgsAction)1 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)1 ISourcesStreamEvents (org.pentaho.platform.api.repository2.unified.ISourcesStreamEvents)1 IStreamListener (org.pentaho.platform.api.repository2.unified.IStreamListener)1 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)1 ActionSequenceCompatibilityFormatter (org.pentaho.platform.engine.services.solution.ActionSequenceCompatibilityFormatter)1 SchedulerOutputPathResolver (org.pentaho.platform.scheduler2.quartz.SchedulerOutputPathResolver)1