Java Code Examples for org.pentaho.di.trans.TransMeta#getVariable()
The following examples show how to use
org.pentaho.di.trans.TransMeta#getVariable() .
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: CypherDialog.java From knowbi-pentaho-pdi-neo4j-output with Apache License 2.0 | 5 votes |
private synchronized void preview() { CypherMeta oneMeta = new CypherMeta(); this.getInfo(oneMeta); TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation(this.transMeta, oneMeta, this.wStepname.getText()); this.transMeta.getVariable("Internal.Transformation.Filename.Directory"); previewMeta.getVariable("Internal.Transformation.Filename.Directory"); EnterNumberDialog numberDialog = new EnterNumberDialog(this.shell, this.props.getDefaultPreviewSize(), BaseMessages.getString(PKG, "CypherDialog.PreviewSize.DialogTitle"), BaseMessages.getString(PKG, "CypherDialog.PreviewSize.DialogMessage") ); int previewSize = numberDialog.open(); if (previewSize > 0) { TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog(this.shell, previewMeta, new String[]{this.wStepname.getText()}, new int[]{previewSize}); progressDialog.open(); Trans trans = progressDialog.getTrans(); String loggingText = progressDialog.getLoggingText(); if (!progressDialog.isCancelled() && trans.getResult() != null && trans.getResult().getNrErrors() > 0L) { EnterTextDialog etd = new EnterTextDialog(this.shell, BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title", new String[0]), BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message", new String[0]), loggingText, true); etd.setReadOnly(); etd.open(); } PreviewRowsDialog prd = new PreviewRowsDialog(this.shell, this.transMeta, 0, this.wStepname.getText(), progressDialog.getPreviewRowsMeta(this.wStepname.getText()), progressDialog.getPreviewRows(this.wStepname.getText()), loggingText); prd.open(); } }
Example 2
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 3
Source File: DataSetHelper.java From pentaho-pdi-dataset with Apache License 2.0 | 4 votes |
private void saveUnitTest( MetaStoreFactory<TransUnitTest> testFactory, TransUnitTest unitTest, TransMeta transMeta ) throws MetaStoreException { // Build relative path whenever a transformation is saved // if ( StringUtils.isNotEmpty( transMeta.getFilename() ) ) { // Set the filename to be safe // unitTest.setTransFilename( transMeta.getFilename() ); String basePath = unitTest.getBasePath(); if ( StringUtils.isEmpty( basePath ) ) { basePath = transMeta.getVariable( DataSetConst.VARIABLE_UNIT_TESTS_BASE_PATH ); } basePath = transMeta.environmentSubstitute( basePath ); if ( StringUtils.isNotEmpty( basePath ) ) { // See if the basePath is present in the filename // Then replace the filename // try { FileObject baseFolder = KettleVFS.getFileObject( basePath ); FileObject transFile = KettleVFS.getFileObject( transMeta.getFilename() ); FileObject parent = transFile.getParent(); while ( parent != null ) { if ( parent.equals( baseFolder ) ) { // Here we are, we found the base folder in the transformation file // String transFilename = transFile.toString(); String baseFoldername = parent.toString(); // Final validation & unit test filename correction // if ( transFilename.startsWith( baseFoldername ) ) { String relativeFile = transFilename.substring( baseFoldername.length() ); String filename; if ( relativeFile.startsWith( "/" ) ) { filename = "." + relativeFile; } else { filename = "./" + relativeFile; } // Set the transformation filename to the relative path // unitTest.setTransFilename( filename ); LogChannel.GENERAL.logBasic( "Unit test '" + unitTest.getName() + "' : Saved relative path to transformation: " + filename ); } } parent = parent.getParent(); } } catch ( Exception e ) { throw new MetaStoreException( "Error calculating relative unit test file path", e ); } } } testFactory.saveElement( unitTest ); }
Example 4
Source File: CsvInputDialog.java From pentaho-kettle with Apache License 2.0 | 4 votes |
private synchronized void preview() { // Create the XML input step CsvInputMeta oneMeta = new CsvInputMeta(); getInfo( oneMeta ); TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation( transMeta, oneMeta, wStepname.getText() ); transMeta.getVariable( "Internal.Transformation.Filename.Directory" ); previewMeta.getVariable( "Internal.Transformation.Filename.Directory" ); EnterNumberDialog numberDialog = new EnterNumberDialog( shell, props.getDefaultPreviewSize(), BaseMessages.getString( PKG, "CsvInputDialog.PreviewSize.DialogTitle" ), BaseMessages.getString( PKG, "CsvInputDialog.PreviewSize.DialogMessage" ) ); int previewSize = numberDialog.open(); if ( previewSize > 0 ) { TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog( shell, previewMeta, new String[] { wStepname.getText() }, new int[] { previewSize } ); progressDialog.open(); Trans trans = progressDialog.getTrans(); String loggingText = progressDialog.getLoggingText(); if ( !progressDialog.isCancelled() ) { if ( trans.getResult() != null && trans.getResult().getNrErrors() > 0 ) { EnterTextDialog etd = new EnterTextDialog( shell, BaseMessages.getString( PKG, "System.Dialog.PreviewError.Title" ), BaseMessages .getString( PKG, "System.Dialog.PreviewError.Message" ), loggingText, true ); etd.setReadOnly(); etd.open(); } } PreviewRowsDialog prd = new PreviewRowsDialog( shell, transMeta, SWT.NONE, wStepname.getText(), progressDialog.getPreviewRowsMeta( wStepname .getText() ), progressDialog.getPreviewRows( wStepname.getText() ), loggingText ); prd.open(); } }
Example 5
Source File: SapInputDialog.java From pentaho-kettle with Apache License 2.0 | 4 votes |
private void preview() { // Create the XML input step SapInputMeta oneMeta = new SapInputMeta(); getInfo( oneMeta ); TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation( transMeta, oneMeta, wStepname.getText() ); transMeta.getVariable( "Internal.Transformation.Filename.Directory" ); previewMeta.getVariable( "Internal.Transformation.Filename.Directory" ); EnterNumberDialog numberDialog = new EnterNumberDialog( shell, props.getDefaultPreviewSize(), BaseMessages.getString( PKG, "CsvInputDialog.PreviewSize.DialogTitle" ), BaseMessages.getString( PKG, "CsvInputDialog.PreviewSize.DialogMessage" ) ); int previewSize = numberDialog.open(); if ( previewSize > 0 ) { TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog( shell, previewMeta, new String[] { wStepname.getText() }, new int[] { previewSize } ); progressDialog.open(); Trans trans = progressDialog.getTrans(); String loggingText = progressDialog.getLoggingText(); if ( !progressDialog.isCancelled() ) { if ( trans.getResult() != null && trans.getResult().getNrErrors() > 0 ) { EnterTextDialog etd = new EnterTextDialog( shell, BaseMessages.getString( PKG, "System.Dialog.PreviewError.Title" ), BaseMessages .getString( PKG, "System.Dialog.PreviewError.Message" ), loggingText, true ); etd.setReadOnly(); etd.open(); } } PreviewRowsDialog prd = new PreviewRowsDialog( shell, transMeta, SWT.NONE, wStepname.getText(), progressDialog.getPreviewRowsMeta( wStepname .getText() ), progressDialog.getPreviewRows( wStepname.getText() ), loggingText ); prd.open(); } }