MDXBaseComponent extends ComponentBase implements IDataComponent, IPreparedComponent { 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:" ) ) { if ( fileExistsInRepository( catalog ) ) { catalog = "solution:" + catalog; } } } else if ( ( resource.getSourceType() == IActionSequenceResource.SOLUTION_FILE_RESOURCE ) || ( resource.getSourceType() == IActionSequenceResource.FILE_RESOURCE ) ) { if ( !catalog.startsWith( "solution:" ) ) { catalog = "solution:" + catalog; } } } if ( catalog == null ) { 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 ) { connectStr = jdbcStr + "; Catalog=" + catalog; } else if ( jndiStr != null ) { IDBDatasourceService datasourceService = PentahoSystem.getObjectFactory().get( IDBDatasourceService.class, null ); if ( datasourceService.getDataSource( jndiStr ) == null ) { error( Messages.getInstance().getErrorString( "MDXBaseComponent.ERROR_0005_INVALID_CONNECTION" ) ); return null; } connectStr = "dataSource=" + jndiStr + "; Catalog=" + catalog; MondrianCatalog mc = getMondrianCatalog( catalog ); try { connectStr += ";" + mc.getDataSourceInfo(); } catch ( Exception e ) { } } if ( role != null ) { 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 ) { 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 ) { error( Messages.getInstance().getErrorString( "MDXBaseComponent.ERROR_0006_EXECUTE_FAILED", getActionName() ), e ); } return null; }  @Override abstract boolean validateSystemSettings(); @Override abstract Log getLogger(); IPentahoResultSet getResultSet(); @Override void done(); void dispose(); IPentahoConnection shareConnection(); IPentahoResultSet executePrepared( final Map preparedParams ); IPentahoConnection getDatasourceConnection(); @Override boolean init(); static final String FORMATTED_CELL_VALUES; }
@Test public void testGetConnectionOrig_null() throws Exception { IPentahoConnection connectionOrig = mdxBaseComponent.getConnectionOrig(); assertNull( connectionOrig ); }
@Test public void testGetConnectionOrig() throws Exception { doReturn( connAction ).when( mdxBaseComponent ).getActionDefinition(); when( connAction.getMdxConnectionString() ).thenReturn( connectionStringAction ); when( connectionStringAction.getStringValue() ).thenReturn( "mdx:localhost:8080" ); when( connAction.getConnectionProps() ).thenReturn( actionInput ); when( actionInput.getValue() ).thenReturn( new Properties() ); when( connAction.getConnection() ).thenReturn( jdbcAction ); when( jdbcAction.getStringValue() ).thenReturn( "psql: when( connAction.getJndi() ).thenReturn( jndiAction ); when( jndiAction.getStringValue() ).thenReturn( "jndi string" ); when( connAction.getLocation() ).thenReturn( locationAction ); when( locationAction.getStringValue() ).thenReturn( "location string" ); when( connAction.getRole() ).thenReturn( roleAction ); when( roleAction.getStringValue() ).thenReturn( "role string" ); when( connAction.getCatalog() ).thenReturn( catalog ); when( catalog.getStringValue() ).thenReturn( null ); when( connAction.getCatalogResource() ).thenReturn( catalogResource ); when( catalogResource.getName() ).thenReturn( "catalog name" ); when( connAction.getUserId() ).thenReturn( userAction ); when( connAction.getPassword() ).thenReturn( userAction ); when( userAction.getStringValue() ).thenReturn( "user/pass" ); PentahoSystem.registerObject( mdxConnection ); PentahoSystem.registerPrimaryObjectFactory( objFactory ); PentahoSessionHolder.setSession( session ); when( objFactory.get( any( Class.class ), anyString(), any( IPentahoSession.class ) ) ).thenReturn( mdxConnection ); mdxBaseComponent.setRuntimeContext( runtimeContext ); when( runtimeContext.getResourceDefintion( "catalog name" ) ).thenReturn( catalogActionSeqRes ); when( catalogActionSeqRes.getSourceType() ).thenReturn( IActionSequenceResource.URL_RESOURCE ); when( catalogActionSeqRes.getAddress() ).thenReturn( "sampledata" ); when( connAction.getExtendedColumnNames() ).thenReturn( ActionInputConstant.NULL_INPUT ); IPentahoConnection connectionOrig = mdxBaseComponent.getConnectionOrig(); assertNotNull( connectionOrig ); assertEquals( mdxConnection, connectionOrig ); }