Search in sources :

Example 1 with MdxConnectionAction

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

the class MDXBaseComponent method getConnection.

protected IPentahoConnection getConnection() {
    // first attempt to get the connection metadata from the catalog service. if that is not successful,
    // get the connection using the original approach.
    MdxConnectionAction connAction = (MdxConnectionAction) getActionDefinition();
    String catalogName = connAction.getCatalog().getStringValue();
    IMondrianCatalogService mondrianCatalogService = // $NON-NLS-1$
    PentahoSystem.get(IMondrianCatalogService.class, "IMondrianCatalogService", PentahoSessionHolder.getSession());
    MondrianCatalog catalog = mondrianCatalogService.getCatalog(catalogName, PentahoSessionHolder.getSession());
    if (catalog == null) {
        return getConnectionOrig();
    }
    Util.PropertyList connectProperties = Util.parseConnectString(catalog.getDataSourceInfo());
    Properties properties = new Properties();
    Iterator<Pair<String, String>> iter = connectProperties.iterator();
    while (iter.hasNext()) {
        Pair<String, String> pair = iter.next();
        properties.put(pair.getKey(), pair.getValue());
    }
    properties.put("Catalog", catalog.getDefinition());
    properties.put("Provider", "mondrian");
    properties.put("PoolNeeded", "false");
    properties.put(RolapConnectionProperties.Locale.name(), LocaleHelper.getLocale().toString());
    debug("Mondrian Connection Properties: " + properties.toString());
    MDXConnection mdxConnection = (MDXConnection) PentahoConnectionFactory.getConnection(IPentahoConnection.MDX_DATASOURCE, properties, PentahoSessionHolder.getSession(), this);
    if (connAction != null) {
        if ((connAction.getExtendedColumnNames() != ActionInputConstant.NULL_INPUT)) {
            mdxConnection.setUseExtendedColumnNames(connAction.getExtendedColumnNames().getBooleanValue());
        }
    }
    return mdxConnection;
}
Also used : MDXConnection(org.pentaho.platform.plugin.services.connections.mondrian.MDXConnection) MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) TemplateUtil(org.pentaho.platform.engine.services.runtime.TemplateUtil) Util(mondrian.olap.Util) MdxConnectionAction(org.pentaho.actionsequence.dom.actions.MdxConnectionAction) IMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService) RolapConnectionProperties(mondrian.rolap.RolapConnectionProperties) Properties(java.util.Properties) Pair(mondrian.util.Pair)

Example 2 with MdxConnectionAction

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

the class MDXBaseComponent method validateAction.

@Override
protected boolean validateAction() {
    boolean actionValidated = true;
    MdxQueryAction queryAction = null;
    MdxConnectionAction connAction = null;
    try {
        if (getActionDefinition() instanceof MdxQueryAction) {
            queryAction = (MdxQueryAction) getActionDefinition();
            actionValidated = isConnectionInfoSpecified(queryAction);
            if (actionValidated) {
                if (queryAction.getQuery() == ActionInputConstant.NULL_INPUT) {
                    error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0001_QUERY_NOT_SPECIFIED", // $NON-NLS-1$
                    getActionName()));
                    actionValidated = false;
                }
            }
            if (actionValidated) {
                if ((queryAction.getOutputResultSet() == null) && (queryAction.getOutputPreparedStatement() == null)) {
                    error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0003_OUTPUT_NOT_SPECIFIED", // $NON-NLS-1$
                    getActionName()));
                    actionValidated = false;
                }
            }
        } else if (getActionDefinition() instanceof MdxConnectionAction) {
            connAction = (MdxConnectionAction) getActionDefinition();
            actionValidated = isConnectionInfoSpecified(connAction);
            if (connAction.getOutputConnection() == null) {
                error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0003_OUTPUT_NOT_SPECIFIED", // $NON-NLS-1$
                getActionName()));
                actionValidated = false;
            }
        }
    } catch (Exception e) {
        actionValidated = false;
        error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0004_VALIDATION_FAILED", getActionName()), // $NON-NLS-1$
        e);
    }
    return actionValidated;
}
Also used : MdxConnectionAction(org.pentaho.actionsequence.dom.actions.MdxConnectionAction) MdxQueryAction(org.pentaho.actionsequence.dom.actions.MdxQueryAction) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)

Example 3 with MdxConnectionAction

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

the class MDXBaseComponent method getConnectionOrig.

protected IPentahoConnection getConnectionOrig() {
    IPentahoConnection localConnection = null;
    MdxConnectionAction connAction = (MdxConnectionAction) getActionDefinition();
    try {
        String mdxConnectionStr = connAction.getMdxConnectionString().getStringValue();
        Properties mdxConnectionProps = (Properties) connAction.getConnectionProps().getValue();
        String jdbcStr = connAction.getConnection().getStringValue();
        String jndiStr = connAction.getJndi().getStringValue();
        String location = connAction.getLocation().getStringValue();
        String role = connAction.getRole().getStringValue();
        String catalog = connAction.getCatalog().getStringValue();
        if ((catalog == null) && (connAction.getCatalogResource() != null)) {
            IActionSequenceResource resource = getResource(connAction.getCatalogResource().getName());
            catalog = resource.getAddress();
            if (resource.getSourceType() == IActionSequenceResource.URL_RESOURCE) {
                if (!catalog.startsWith("solution:") && !catalog.startsWith("http:")) {
                    // $NON-NLS-1$
                    if (fileExistsInRepository(catalog)) {
                        // About allowed "solution:"
                        // Extra step to make sure that remote mondrian models
                        // fully qualified aren't munged
                        // MB
                        // $NON-NLS-1$
                        catalog = "solution:" + catalog;
                    }
                }
            } else if ((resource.getSourceType() == IActionSequenceResource.SOLUTION_FILE_RESOURCE) || (resource.getSourceType() == IActionSequenceResource.FILE_RESOURCE)) {
                if (!catalog.startsWith("solution:")) {
                    // $NON-NLS-1$
                    catalog = "solution:" + catalog;
                }
            }
        }
        if (catalog == null) {
            // $NON-NLS-1$
            warn(Messages.getInstance().getString("MDXBaseComponent.ERROR_0007_CATALOG_NOT_DEFINED", getActionName()));
        } else {
            if (mdxConnectionProps != null) {
                mdxConnectionProps.put(MdxConnectionAction.CATALOG_ELEMENT, catalog);
            }
        }
        String userId = connAction.getUserId().getStringValue();
        String password = connAction.getPassword().getStringValue();
        if (mdxConnectionProps != null) {
            localConnection = PentahoConnectionFactory.getConnection(IPentahoConnection.MDX_DATASOURCE, mdxConnectionProps, getSession(), this);
        } else {
            if (mdxConnectionStr != null) {
                localConnection = PentahoConnectionFactory.getConnection(IPentahoConnection.MDX_DATASOURCE, mdxConnectionStr, getSession(), this);
            } else {
                String connectStr = null;
                if (jdbcStr != null) {
                    // $NON-NLS-1$
                    connectStr = jdbcStr + "; Catalog=" + catalog;
                } else if (jndiStr != null) {
                    IDBDatasourceService datasourceService = PentahoSystem.getObjectFactory().get(IDBDatasourceService.class, null);
                    if (datasourceService.getDataSource(jndiStr) == null) {
                        // $NON-NLS-1$
                        error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0005_INVALID_CONNECTION"));
                        return null;
                    }
                    // $NON-NLS-1$ //$NON-NLS-2$
                    connectStr = "dataSource=" + jndiStr + "; Catalog=" + catalog;
                    // Add extra definitions from platform mondrian metadata
                    MondrianCatalog mc = getMondrianCatalog(catalog);
                    try {
                        connectStr += ";" + mc.getDataSourceInfo();
                    } catch (Exception e) {
                    // Just swallow the exception
                    }
                }
                if (role != null) {
                    // $NON-NLS-1$
                    connectStr += "; Role=" + role;
                }
                Properties props = new Properties();
                props.setProperty(IPentahoConnection.CONNECTION, connectStr);
                props.setProperty(IPentahoConnection.PROVIDER, location);
                if (userId != null) {
                    props.setProperty(IPentahoConnection.USERNAME_KEY, userId);
                }
                if (password != null) {
                    props.setProperty(IPentahoConnection.PASSWORD_KEY, password);
                }
                localConnection = PentahoConnectionFactory.getConnection(IPentahoConnection.MDX_DATASOURCE, props, getSession(), this);
            }
            if (localConnection == null) {
                // $NON-NLS-1$
                error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0005_INVALID_CONNECTION"));
                return null;
            }
        }
        if (localConnection instanceof MDXConnection) {
            MDXConnection mdxConn = (MDXConnection) localConnection;
            if (connAction != null) {
                if ((connAction.getExtendedColumnNames() != ActionInputConstant.NULL_INPUT)) {
                    mdxConn.setUseExtendedColumnNames(connAction.getExtendedColumnNames().getBooleanValue());
                }
            }
        }
        return localConnection;
    } catch (Exception e) {
        // $NON-NLS-1$
        error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0006_EXECUTE_FAILED", getActionName()), e);
    }
    return null;
}
Also used : IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) MDXConnection(org.pentaho.platform.plugin.services.connections.mondrian.MDXConnection) MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) MdxConnectionAction(org.pentaho.actionsequence.dom.actions.MdxConnectionAction) RolapConnectionProperties(mondrian.rolap.RolapConnectionProperties) Properties(java.util.Properties) IDBDatasourceService(org.pentaho.platform.api.data.IDBDatasourceService) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) IActionSequenceResource(org.pentaho.platform.api.engine.IActionSequenceResource)

Example 4 with MdxConnectionAction

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

the class MDXBaseComponent method executeAction.

@Override
protected boolean executeAction() {
    boolean value = false;
    /*
     * This is the query part. You would need a connection to execute the query. The connection will either come in as
     * an INPUT (prepared_component) or will be specified right there.
     * 
     * So check if a prepared component exists, if not create a new connection. If connection is not null, proceed to
     * work on the query part.
     * 
     * In the query section you can either execute the query right away or prepare it to be used later by a sub report.
     */
    try {
        if (getActionDefinition() instanceof MdxQueryAction) {
            MdxQueryAction queryAction = (MdxQueryAction) getActionDefinition();
            // instead of creating our own.
            if (queryAction.getMdxConnection() != ActionInputConstant.NULL_INPUT) {
                if (queryAction.getMdxConnection().getValue() != null) {
                    connectionOwner = false;
                    IPreparedComponent component = (IPreparedComponent) queryAction.getMdxConnection().getValue();
                    IPentahoConnection conn = component.shareConnection();
                    if (conn.getDatasourceType() == IPentahoConnection.MDX_DATASOURCE) {
                        connection = conn;
                    } else {
                        error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0001_INVALID_CONNECTION_TYPE", // $NON-NLS-1$
                        getActionName()));
                    }
                } else {
                    error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0002_CONNECTION_NOT_AVAILABLE", // $NON-NLS-1$
                    getActionName()));
                }
            } else {
                dispose();
                connection = getDatasourceConnection();
            }
            if (connection != null) {
                String query = queryAction.getQuery().getStringValue();
                if (queryAction.getOutputPreparedStatement() != null) {
                    // prepare the query for execution, but don't execute quite yet.
                    prepareQuery(query);
                    // set the output as self, which will be used later by another component.
                    setOutputValue(IPreparedComponent.PREPARED_COMPONENT_NAME, this);
                    value = true;
                } else {
                    value = runQuery(connection, query);
                }
            } else {
                error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0004_NO_CONNECTION_INFO", // $NON-NLS-1$
                getActionName()));
            }
        } else if (getActionDefinition() instanceof MdxConnectionAction) {
            dispose();
            connection = getDatasourceConnection();
            if (connection != null) {
                setOutputValue(IPreparedComponent.PREPARED_COMPONENT_NAME, this);
                value = true;
            }
        } else {
            error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0004_VALIDATION_FAILED", // $NON-NLS-1$
            getActionName()));
        }
    } catch (Exception e) {
        // $NON-NLS-1$
        error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0006_EXECUTE_FAILED", getActionName()), e);
    }
    return value;
}
Also used : IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) MdxConnectionAction(org.pentaho.actionsequence.dom.actions.MdxConnectionAction) MdxQueryAction(org.pentaho.actionsequence.dom.actions.MdxQueryAction) IPreparedComponent(org.pentaho.platform.api.data.IPreparedComponent) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)

Aggregations

MdxConnectionAction (org.pentaho.actionsequence.dom.actions.MdxConnectionAction)4 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)3 Properties (java.util.Properties)2 RolapConnectionProperties (mondrian.rolap.RolapConnectionProperties)2 MdxQueryAction (org.pentaho.actionsequence.dom.actions.MdxQueryAction)2 IPentahoConnection (org.pentaho.commons.connection.IPentahoConnection)2 MondrianCatalog (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog)2 MDXConnection (org.pentaho.platform.plugin.services.connections.mondrian.MDXConnection)2 Util (mondrian.olap.Util)1 Pair (mondrian.util.Pair)1 IDBDatasourceService (org.pentaho.platform.api.data.IDBDatasourceService)1 IPreparedComponent (org.pentaho.platform.api.data.IPreparedComponent)1 IActionSequenceResource (org.pentaho.platform.api.engine.IActionSequenceResource)1 TemplateUtil (org.pentaho.platform.engine.services.runtime.TemplateUtil)1 IMondrianCatalogService (org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService)1