Search in sources :

Example 1 with ActionInputConstant

use of org.pentaho.actionsequence.dom.ActionInputConstant 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 2 with ActionInputConstant

use of org.pentaho.actionsequence.dom.ActionInputConstant in project pentaho-platform by pentaho.

the class MDXBaseComponentTest method shouldAddSolutionPrefixIfFileExistsInRepository.

@Test
@SuppressWarnings("unchecked")
public void shouldAddSolutionPrefixIfFileExistsInRepository() throws ObjectFactoryException, DBDatasourceServiceException {
    mdxBaseComponent.setActionDefinition(connAction);
    when(connAction.getMdxConnectionString()).thenReturn(IActionInput.NULL_INPUT);
    when(connAction.getConnectionProps()).thenReturn(IActionInput.NULL_INPUT);
    when(connAction.getConnection()).thenReturn(IActionInput.NULL_INPUT);
    when(connAction.getJndi()).thenReturn(new ActionInputConstant("", null));
    when(connAction.getLocation()).thenReturn(new ActionInputConstant("", null));
    when(connAction.getRole()).thenReturn(IActionInput.NULL_INPUT);
    when(connAction.getCatalog()).thenReturn(IActionInput.NULL_INPUT);
    when(connAction.getUserId()).thenReturn(IActionInput.NULL_INPUT);
    when(connAction.getPassword()).thenReturn(IActionInput.NULL_INPUT);
    when(connAction.getCatalogResource()).thenReturn(catalogResource);
    when(catalogResource.getName()).thenReturn("catalog name");
    PentahoSystem.registerObject(mdxConnection);
    PentahoSystem.registerPrimaryObjectFactory(objFactory);
    PentahoSessionHolder.setSession(session);
    when(objFactory.get(any(Class.class), anyString(), any(IPentahoSession.class))).thenReturn(mdxConnection);
    IDBDatasourceService datasourceService = mock(IDBDatasourceService.class);
    when(objFactory.objectDefined("IDBDatasourceService")).thenReturn(true);
    when(objFactory.get(any(Class.class), eq("IDBDatasourceService"), any(IPentahoSession.class))).thenReturn(datasourceService);
    DataSource dataSource = mock(DataSource.class);
    when(datasourceService.getDataSource(anyString())).thenReturn(dataSource);
    mdxBaseComponent.setRuntimeContext(runtimeContext);
    when(runtimeContext.getResourceDefintion("catalog name")).thenReturn(catalogActionSeqRes);
    when(catalogActionSeqRes.getSourceType()).thenReturn(IActionSequenceResource.URL_RESOURCE);
    MondrianCatalog mc = mock(MondrianCatalog.class);
    doReturn(mc).when(mdxBaseComponent).getMondrianCatalog(anyString());
    // using the same prepared environment for several checks...
    // if file exists in repository, then the "solution:" prefix should be added
    when(catalogActionSeqRes.getAddress()).thenReturn("fileName");
    doReturn(true).when(mdxBaseComponent).fileExistsInRepository("fileName");
    mdxBaseComponent.getConnectionOrig();
    verify(mdxBaseComponent).getMondrianCatalog("solution:fileName");
    verify(mdxBaseComponent, times(1)).fileExistsInRepository(anyString());
    // if file exists in repository, then the "solution:" prefix should NOT be added,
    // and the file therefore should be read from file system further
    when(catalogActionSeqRes.getAddress()).thenReturn("fileName");
    doReturn(false).when(mdxBaseComponent).fileExistsInRepository("fileName");
    mdxBaseComponent.getConnectionOrig();
    verify(mdxBaseComponent).getMondrianCatalog("fileName");
    verify(mdxBaseComponent, times(2)).fileExistsInRepository(anyString());
    // if filename already starts from "solution:" prefix,
    // then no need to check file existence in repository
    when(catalogActionSeqRes.getAddress()).thenReturn("solution:fileName");
    mdxBaseComponent.getConnectionOrig();
    verify(mdxBaseComponent, times(2)).fileExistsInRepository(anyString());
    // same here: if the resource is http link, then no need to check it in repository
    when(catalogActionSeqRes.getAddress()).thenReturn("http:fileName");
    mdxBaseComponent.getConnectionOrig();
    verify(mdxBaseComponent, times(2)).fileExistsInRepository(anyString());
}
Also used : MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) ActionInputConstant(org.pentaho.actionsequence.dom.ActionInputConstant) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IDBDatasourceService(org.pentaho.platform.api.data.IDBDatasourceService) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Aggregations

ActionInputConstant (org.pentaho.actionsequence.dom.ActionInputConstant)2 HashMap (java.util.HashMap)1 DataSource (javax.sql.DataSource)1 Test (org.junit.Test)1 IActionInput (org.pentaho.actionsequence.dom.IActionInput)1 IActionOutput (org.pentaho.actionsequence.dom.IActionOutput)1 IActionResource (org.pentaho.actionsequence.dom.IActionResource)1 IAction (org.pentaho.platform.api.action.IAction)1 IDBDatasourceService (org.pentaho.platform.api.data.IDBDatasourceService)1 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)1 IContentItem (org.pentaho.platform.api.repository.IContentItem)1 SimpleContentItem (org.pentaho.platform.engine.core.output.SimpleContentItem)1 MondrianCatalog (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog)1