Java Code Examples for org.pentaho.di.trans.TransMeta#getRepository()
The following examples show how to use
org.pentaho.di.trans.TransMeta#getRepository() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ValidateTransUnitTestExtensionPoint.java From pentaho-pdi-dataset with Apache License 2.0 | 4 votes |
@Override public void callExtensionPoint( LogChannelInterface log, Object object ) throws KettleException { if ( !( object instanceof Trans ) ) { return; } final Trans trans = (Trans) object; final TransMeta transMeta = trans.getTransMeta(); boolean runUnitTest = "Y".equalsIgnoreCase( transMeta.getVariable( DataSetConst.VAR_RUN_UNIT_TEST ) ); if ( !runUnitTest ) { return; } // We should always have a unit test name here... String unitTestName = transMeta.getVariable( DataSetConst.VAR_UNIT_TEST_NAME ); if ( StringUtil.isEmpty( unitTestName ) ) { return; } try { IMetaStore metaStore = transMeta.getMetaStore(); Repository repository = transMeta.getRepository(); if ( metaStore == null ) { return; // Nothing to do here, we can't reference data sets. } List<DatabaseMeta> databases = DataSetConst.getAvailableDatabases( repository, transMeta.getSharedObjects() ); FactoriesHierarchy factoriesHierarchy = new FactoriesHierarchy( metaStore, databases ); // If the transformation has a variable set with the unit test in it, we're dealing with a unit test situation. // TransUnitTest unitTest = factoriesHierarchy.getTestFactory().loadElement( unitTestName ); final List<UnitTestResult> results = new ArrayList<UnitTestResult>(); trans.getExtensionDataMap().put( DataSetConst.UNIT_TEST_RESULTS, results ); // Validate execution results with what's in the data sets... // int errors = DataSetConst.validateTransResultAgainstUnitTest( trans, unitTest, factoriesHierarchy, results ); if ( errors == 0 ) { log.logBasic( "Unit test '" + unitTest.getName() + "' passed succesfully" ); } else { log.logBasic( "Unit test '" + unitTest.getName() + "' failed, " + errors + " errors detected, " + results.size() + " comments to report." ); String dontShowResults = transMeta.getVariable( DataSetConst.VAR_DO_NOT_SHOW_UNIT_TEST_ERRORS, "N" ); final Spoon spoon = Spoon.getInstance(); if ( spoon != null && "N".equalsIgnoreCase( dontShowResults ) ) { spoon.getShell().getDisplay().asyncExec( new Runnable() { @Override public void run() { PreviewRowsDialog dialog = new PreviewRowsDialog( spoon.getShell(), trans, SWT.NONE, "Unit test results", UnitTestResult.getRowMeta(), UnitTestResult.getRowData( results ) ); dialog.setDynamic( false ); dialog.setProposingToGetMoreRows( false ); dialog.setProposingToStop( false ); dialog.setTitleMessage( "Unit test results", "Here are the results of the unit test validations:" ); dialog.open(); } } ); } } log.logBasic( "----------------------------------------------" ); for ( UnitTestResult result : results ) { if ( result.getDataSetName() != null ) { log.logBasic( result.getStepName() + " - " + result.getDataSetName() + " : " + result.getComment() ); } else { log.logBasic( result.getComment() ); } } log.logBasic( "----------------------------------------------" ); } catch ( Throwable e ) { log.logError( "Unable to validate unit test/golden rows", e ); } }
Example 2
Source File: DataSetHelper.java From pentaho-pdi-dataset with Apache License 2.0 | 4 votes |
public static List<TransUnitTest> findTransformationUnitTest( TransMeta transMeta, IMetaStore metaStore ) { MetaStoreFactory<TransUnitTest> factory = new MetaStoreFactory<TransUnitTest>( TransUnitTest.class, metaStore, PentahoDefaults.NAMESPACE ); List<TransUnitTest> tests = new ArrayList<TransUnitTest>(); try { List<TransUnitTest> allTests = factory.getElements(); for ( TransUnitTest test : allTests ) { // Match the filename // if ( StringUtils.isNotEmpty( transMeta.getFilename() ) ) { // What's the transformation absolute URI // FileObject transFile = KettleVFS.getFileObject( transMeta.getFilename() ); String transUri = transFile.getName().getURI(); // What's the filename referenced in the test? // FileObject testTransFile = KettleVFS.getFileObject( test.calculateCompleteFilename( transMeta ) ); if ( testTransFile.exists() ) { String testTransUri = testTransFile.getName().getURI(); if ( transUri.equals( testTransUri ) ) { tests.add( test ); } } } else { if ( transMeta.getRepository() != null ) { // No filename, check the object_id ... // if ( transMeta.getObjectId() != null && transMeta.getObjectId().getId().equals( test.getTransObjectId() ) ) { tests.add( test ); } else { // Try the repository path.. // // What is the repsository path? String repositoryPath = transMeta.getRepositoryDirectory().getPath() + "/" + transMeta.getName(); if ( repositoryPath.equals( test.getTransRepositoryPath() ) ) { tests.add( test ); } } } } } } catch ( Exception exception ) { new ErrorDialog( Spoon.getInstance().getShell(), BaseMessages.getString( PKG, "ShowUnitTestMenuExtensionPoint.ErrorFindingUnitTestsForTransformation.Title" ), BaseMessages.getString( PKG, "ShowUnitTestMenuExtensionPoint.ErrorFindingUnitTestsForTransformation.Message" ), exception ); } return tests; }
Example 3
Source File: TransWebSocketEngineAdapter.java From pentaho-kettle with Apache License 2.0 | 4 votes |
private Principal getActingPrincipal( TransMeta transMeta ) { if ( transMeta.getRepository() == null || transMeta.getRepository().getUserInfo() == null ) { return ActingPrincipal.ANONYMOUS; } return new ActingPrincipal( transMeta.getRepository().getUserInfo().getName() ); }
Example 4
Source File: TransSplitter.java From pentaho-kettle with Apache License 2.0 | 4 votes |
protected TransSplitter( TransMeta transMeta, TransMetaFactory transMetaFactory ) throws KettleException { this(); // We want to make sure there is no trace of the old transformation left when we // Modify during split. // As such, we deflate/inflate over XML // String transXML = transMeta.getXML(); this.originalTransformation = transMetaFactory .create( XMLHandler.getSubNode( XMLHandler.loadXMLString( transXML ), TransMeta.XML_TAG ), null ); this.originalTransformation.shareVariablesWith( transMeta ); this.originalTransformation.copyParametersFrom( transMeta ); // Retain repository information this.originalTransformation.setRepository( transMeta.getRepository() ); this.originalTransformation.setRepositoryDirectory( transMeta.getRepositoryDirectory() ); Repository rep = transMeta.getRepository(); if ( rep != null ) { rep.readTransSharedObjects( this.originalTransformation ); } checkClusterConfiguration(); // FIRST : convert the dynamic master into a fixed one. // This is why we copied the original transformation // ClusterSchema clusterSchema = this.originalTransformation.findFirstUsedClusterSchema(); if ( clusterSchema == null ) { throw new KettleException( "No clustering is used in this transformation." ); } if ( clusterSchema.isDynamic() ) { List<SlaveServer> slaveServers = clusterSchema.getSlaveServersFromMasterOrLocal(); SlaveServer masterSlaveServer = clusterSchema.findMaster(); if ( masterSlaveServer == null ) { throw new KettleException( "You always need at least one master in a cluster schema." ); } slaveServers.add( 0, masterSlaveServer ); clusterSchema.setDynamic( false ); clusterSchema.setSlaveServers( slaveServers ); } }