org.pentaho.di.ui.spoon.trans.TransGraph Java Examples
The following examples show how to use
org.pentaho.di.ui.spoon.trans.TransGraph.
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: ExpandedContentManager.java From pentaho-kettle with Apache License 2.0 | 6 votes |
/** * showExpandedContent( TransGraph graph ) * * @param graph * TransGraph to create the web browser for. If the wev browser hasn't been created this will create one. * Else it will just bring the web browser associated to this TransGraph to the top. */ public static void showExpandedContent( TransGraph graph ) { if ( graph == null ) { return; } Browser browser = getExpandedContentForTransGraph( graph ); if ( browser == null ) { return; } if ( !isVisible( graph ) ) { maximizeExpandedContent( browser ); } if ( Const.isOSX() && graph.isExecutionResultsPaneVisible() ) { graph.extraViewComposite.setVisible( false ); } browser.moveAbove( null ); browser.getParent().layout( true ); browser.getParent().redraw(); }
Example #2
Source File: ExpandedContentManagerTest.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Test public void testShowTransformationBrowserh() { TransGraph transGraphMock = mock( TransGraph.class ); Control control1 = mock( Control.class ); Control control2 = mock( Control.class ); Browser browser = mock( Browser.class ); SashForm sash = mock( SashForm.class ); when( sash.getWeights() ).thenReturn( new int[] { 277, 722 } ); Composite comp1 = mock( Composite.class ); Composite comp2 = mock( Composite.class ); Composite comp3 = mock( Composite.class ); Composite comp4 = mock( Composite.class ); when( browser.getParent() ).thenReturn( comp1 ); when( comp1.getParent() ).thenReturn( comp2 ); when( comp2.getParent() ).thenReturn( comp3 ); when( comp3.getParent() ).thenReturn( sash ); when( comp4.getParent() ).thenReturn( sash ); Control[] children = new Control[] { control1, control2, browser }; when( transGraphMock.getChildren() ).thenReturn( children ); ExpandedContentManager.createExpandedContent( transGraphMock, "" ); verify( browser ).setUrl( "" ); }
Example #3
Source File: DataSetHelper.java From pentaho-pdi-dataset with Apache License 2.0 | 6 votes |
public void detachUnitTest() { Spoon spoon = ( (Spoon) SpoonFactory.getInstance() ); try { TransGraph transGraph = spoon.getActiveTransGraph(); if ( transGraph == null ) { return; } TransMeta transMeta = spoon.getActiveTransformation(); if ( transMeta == null ) { return; } // Remove // activeTests.remove( transMeta ); transMeta.setVariable( DataSetConst.VAR_RUN_UNIT_TEST, "N" ); spoon.refreshGraph(); } catch ( Exception e ) { new ErrorDialog( spoon.getShell(), "Error", "Error detaching unit test", e ); } }
Example #4
Source File: GraphTest.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Test public void testRightClickStepSelection() { TransGraph graph = mock( TransGraph.class ); StepMeta meta1 = mock( StepMeta.class ); StepMeta meta2 = mock( StepMeta.class ); StepMeta meta3 = mock( StepMeta.class ); wireSelected( meta1, meta2, meta3 ); List<StepMeta> selected = new ArrayList<>( 2 ); meta2.setSelected( true ); meta3.setSelected( true ); selected.add( meta2 ); selected.add( meta3 ); doCallRealMethod().when( graph ).doRightClickSelection( meta1, selected ); graph.doRightClickSelection( meta1, selected ); assertTrue( meta1.isSelected() ); assertEquals( meta1, selected.get( 0 ) ); assertEquals( 1, selected.size() ); assertFalse( meta2.isSelected() || meta3.isSelected() ); }
Example #5
Source File: GraphTest.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Test public void testRightClickAlreadySelected() { TransGraph graph = mock( TransGraph.class ); StepMeta meta1 = mock( StepMeta.class ); StepMeta meta2 = mock( StepMeta.class ); wireSelected( meta1, meta2 ); List<StepMeta> selected = new ArrayList<>( 2 ); meta1.setSelected( true ); meta2.setSelected( true ); selected.add( meta1 ); selected.add( meta2 ); doCallRealMethod().when( graph ).doRightClickSelection( meta1, selected ); graph.doRightClickSelection( meta1, selected ); assertEquals( 2, selected.size() ); assertTrue( selected.contains( meta1 ) ); assertTrue( selected.contains( meta2 ) ); assertTrue( meta1.isSelected() && meta2.isSelected() ); }
Example #6
Source File: SpoonTabsDelegate.java From pentaho-kettle with Apache License 2.0 | 6 votes |
public EngineMetaInterface getActiveMeta() { TabSet tabfolder = spoon.tabfolder; if ( tabfolder == null ) { return null; } TabItem tabItem = tabfolder.getSelected(); if ( tabItem == null ) { return null; } // What transformation is in the active tab? // TransLog, TransGraph & TransHist contain the same transformation // TabMapEntry mapEntry = getTab( tabfolder.getSelected() ); EngineMetaInterface meta = null; if ( mapEntry != null ) { if ( mapEntry.getObject() instanceof TransGraph ) { meta = ( mapEntry.getObject() ).getMeta(); } if ( mapEntry.getObject() instanceof JobGraph ) { meta = ( mapEntry.getObject() ).getMeta(); } } return meta; }
Example #7
Source File: GraphTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void testRightClickNoSelection() { TransGraph graph = mock( TransGraph.class ); StepMeta meta1 = mock( StepMeta.class ); wireSelected( meta1 ); List<StepMeta> selected = new ArrayList<>(); doCallRealMethod().when( graph ).doRightClickSelection( meta1, selected ); graph.doRightClickSelection( meta1, selected ); assertEquals( 1, selected.size() ); assertTrue( selected.contains( meta1 ) ); assertTrue( meta1.isSelected() ); }
Example #8
Source File: ExpandedContentManager.java From pentaho-kettle with Apache License 2.0 | 5 votes |
/** * hideExpandedContent( TransGraph graph ) * * @param graph * the TransGraph whose web browser will be hidden */ public static void hideExpandedContent( TransGraph graph ) { doToExpandedContent( graph, browser -> { if ( Const.isOSX() && graph.isExecutionResultsPaneVisible() ) { graph.extraViewComposite.setVisible( true ); } browser.moveBelow( null ); browser.getParent().layout( true, true ); browser.getParent().redraw(); } ); }
Example #9
Source File: ExpandedContentManager.java From pentaho-kettle with Apache License 2.0 | 5 votes |
/** * doToExpandedContent( TransGraph graph ) * * @param graph * the TransGraph whose web browser will be hidden * @param browserAction Consumer for acting on the browser */ private static void doToExpandedContent( TransGraph graph, Consumer<Browser> browserAction ) { Browser browser = getExpandedContentForTransGraph( graph ); if ( browser == null ) { return; } SashForm sash = (SashForm) spoonInstance().getDesignParent(); sash.setWeights( spoonInstance().getTabSet().getSelected().getSashWeights() ); browserAction.accept( browser ); }
Example #10
Source File: MainSpoonPerspective.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Override public EngineMetaInterface getActiveMeta() { if ( tabfolder == null ) { return null; } TabItem tabItem = tabfolder.getSelected(); if ( tabItem == null ) { return null; } // What transformation is in the active tab? // TransLog, TransGraph & TransHist contain the same transformation // TabMapEntry mapEntry = ( (Spoon) SpoonFactory.getInstance() ).delegates.tabs.getTab( tabfolder.getSelected() ); EngineMetaInterface meta = null; if ( mapEntry != null ) { if ( mapEntry.getObject() instanceof TransGraph ) { meta = ( mapEntry.getObject() ).getMeta(); } if ( mapEntry.getObject() instanceof JobGraph ) { meta = ( mapEntry.getObject() ).getMeta(); } } return meta; }
Example #11
Source File: SpoonTransformationDelegateTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings( "ResultOfMethodCallIgnored" ) public void testSetParamsIntoMetaInExecuteTransformation() throws KettleException { doCallRealMethod().when( delegate ).executeTransformation( transMeta, true, false, false, false, false, null, false, LogLevel.BASIC ); RowMetaInterface rowMeta = mock( RowMetaInterface.class ); TransExecutionConfiguration transExecutionConfiguration = mock( TransExecutionConfiguration.class ); TransGraph activeTransGraph = mock( TransGraph.class ); activeTransGraph.transLogDelegate = mock( TransLogDelegate.class ); doReturn( rowMeta ).when( spoon.variables ).getRowMeta(); doReturn( EMPTY_STRING_ARRAY ).when( rowMeta ).getFieldNames(); doReturn( transExecutionConfiguration ).when( spoon ).getTransExecutionConfiguration(); doReturn( MAP_WITH_TEST_PARAM ).when( transExecutionConfiguration ).getParams(); doReturn( activeTransGraph ).when( spoon ).getActiveTransGraph(); doReturn( TEST_LOG_LEVEL ).when( transExecutionConfiguration ).getLogLevel(); doReturn( TEST_BOOLEAN_PARAM ).when( transExecutionConfiguration ).isClearingLog(); doReturn( TEST_BOOLEAN_PARAM ).when( transExecutionConfiguration ).isSafeModeEnabled(); doReturn( TEST_BOOLEAN_PARAM ).when( transExecutionConfiguration ).isGatheringMetrics(); delegate.executeTransformation( transMeta, true, false, false, false, false, null, false, LogLevel.BASIC ); verify( transMeta ).setParameterValue( TEST_PARAM_KEY, TEST_PARAM_VALUE ); verify( transMeta ).activateParameters(); verify( transMeta ).setLogLevel( TEST_LOG_LEVEL ); verify( transMeta ).setClearingLog( TEST_BOOLEAN_PARAM ); verify( transMeta ).setSafeModeEnabled( TEST_BOOLEAN_PARAM ); verify( transMeta ).setGatheringMetrics( TEST_BOOLEAN_PARAM ); }
Example #12
Source File: DataSetHelper.java From pentaho-pdi-dataset with Apache License 2.0 | 5 votes |
public void clearInputDataSet() { Spoon spoon = ( (Spoon) SpoonFactory.getInstance() ); TransGraph transGraph = spoon.getActiveTransGraph(); TransMeta transMeta = spoon.getActiveTransformation(); StepMeta stepMeta = transGraph.getCurrentStep(); if ( transGraph == null || transMeta == null || stepMeta == null ) { return; } if ( checkTestPresent( spoon, transMeta ) ) { return; } try { TransUnitTest currentUnitTest = getCurrentUnitTest( transMeta ); TransUnitTestSetLocation inputLocation = currentUnitTest.findInputLocation( stepMeta.getName() ); if ( inputLocation != null ) { currentUnitTest.getInputDataSets().remove( inputLocation ); } saveUnitTest( getHierarchy().getTestFactory(), currentUnitTest, transMeta ); transGraph.redraw(); } catch ( Exception e ) { new ErrorDialog( spoon.getShell(), "Error", "Error saving unit test", e ); } }
Example #13
Source File: ExpandedContentManagerTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void testIsBrowserVisibleTransGraph() { TransGraph transGraphMock = mock( TransGraph.class ); Control control1 = mock( Control.class ); Control control2 = mock( Control.class ); Browser browser = mock( Browser.class ); Control[] children = new Control[] { control1, control2, browser }; when( transGraphMock.getChildren() ).thenReturn( children ); Boolean result = ExpandedContentManager.isVisible( transGraphMock ); assertFalse( result ); children = new Control[] { browser, control1, control2 }; when( transGraphMock.getChildren() ).thenReturn( children ); result = ExpandedContentManager.isVisible( transGraphMock ); assertTrue( result ); }
Example #14
Source File: ExpandedContentManagerTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void testHideExpandedContentManager() throws Exception { TransGraph transGraph = mock( TransGraph.class ); Browser browser = mock( Browser.class ); SashForm sashForm = mock( SashForm.class ); Composite parent = setupExpandedContentMocks( transGraph, browser, sashForm ); ExpandedContentManager.hideExpandedContent( transGraph ); verify( browser ).moveBelow( null ); verify( parent ).layout( true, true ); verify( parent ).redraw(); verify( sashForm ).setWeights( new int[] { 3, 2, 1 } ); }
Example #15
Source File: ExpandedContentManagerTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void testCloseExpandedContentManager() throws Exception { TransGraph transGraph = mock( TransGraph.class ); Browser browser = mock( Browser.class ); SashForm sashForm = mock( SashForm.class ); setupExpandedContentMocks( transGraph, browser, sashForm ); ExpandedContentManager.closeExpandedContent( transGraph ); verify( browser ).close(); verify( sashForm ).setWeights( new int[] { 3, 2, 1 } ); }
Example #16
Source File: ExpandedContentManagerTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private Composite setupExpandedContentMocks( TransGraph transGraph, Browser browser, SashForm sashForm ) { Spoon spoon = mock( Spoon.class ); Composite parent = mock( Composite.class ); TabSet tabSet = mock( TabSet.class ); TabItem tabItem = mock( TabItem.class ); ExpandedContentManager.spoonSupplier = () -> spoon; when( spoon.getDesignParent() ).thenReturn( sashForm ); when( spoon.getTabSet() ).thenReturn( tabSet ); when( tabSet.getSelected() ).thenReturn( tabItem ); when( tabItem.getSashWeights() ).thenReturn( new int[] { 3, 2, 1 } ); when( transGraph.getChildren() ).thenReturn( new Control[]{ browser } ); when( browser.getParent() ).thenReturn( parent ); return parent; }
Example #17
Source File: SparkTuningStepHandler.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@SuppressWarnings( "squid:S1181" ) public void openSparkTuning() { TransGraph transGraph = Spoon.getInstance().getActiveTransGraph(); StepMeta stepMeta = transGraph.getCurrentStep(); String title = BaseMessages.getString( PKG, "TransGraph.Dialog.SparkTuning.Title" ) + " - " + stepMeta.getName(); List<String> tuningProperties = SparkTunableProperties.getProperties( stepMeta.getStepID() ); PropertiesComboDialog dialog = new PropertiesComboDialog( transGraph.getParent().getShell(), transGraph.getTransMeta(), stepMeta.getAttributes( SPARK_TUNING_PROPERTIES ), title, Const.getDocUrl( BaseMessages.getString( PKG, "SparkTuning.Help.Url" ) ), BaseMessages.getString( PKG, "SparkTuning.Help.Title" ), BaseMessages.getString( PKG, "SparkTuning.Help.Header" ) ); dialog.setComboOptions( tuningProperties ); try { Map<String, String> properties = dialog.open(); // null means the cancel button was clicked otherwise ok was clicked if ( null != properties ) { stepMeta.setAttributes( SPARK_TUNING_PROPERTIES, properties ); stepMeta.setChanged(); transGraph.getSpoon().setShellText(); } } catch ( Throwable e ) { new ErrorDialog( Spoon.getInstance().getShell(), BaseMessages.getString( PKG, "SparkTuning.UnexpectedError" ), BaseMessages .getString( PKG, "SparkTuning.UnexpectedError" ), e ); } }
Example #18
Source File: ExpandedContentManager.java From pentaho-kettle with Apache License 2.0 | 5 votes |
/** * getExpandedContentForTransGraph * * @param graph * a TransGraph object that will be interrogated for a web browser * @return a web browser that is associated with the TransGraph or null if it has yet to be created. */ public static Browser getExpandedContentForTransGraph( TransGraph graph ) { for ( Control control : graph.getChildren() ) { if ( control instanceof Browser ) { return (Browser) control; } } return null; }
Example #19
Source File: ExpandedContentManager.java From pentaho-kettle with Apache License 2.0 | 5 votes |
/** * isBrowserVisible( TransGraph graph ) * * @param graph * a TransGraph object that is being interrogated to see if the web browser is the topmost control * @return true if the web browser is the topmost control of the graph */ public static boolean isVisible( TransGraph graph ) { if ( graph != null ) { if ( graph.getChildren().length > 0 ) { return graph.getChildren()[0] instanceof Browser; } } return false; }
Example #20
Source File: SpoonTransformationDelegate.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public TransGraph findTransGraphOfTransformation( TransMeta transMeta ) { // Now loop over the entries in the tab-map for ( TabMapEntry mapEntry : spoon.delegates.tabs.getTabs() ) { if ( mapEntry.getObject() instanceof TransGraph ) { TransGraph transGraph = (TransGraph) mapEntry.getObject(); if ( transGraph.getMeta().equals( transMeta ) ) { return transGraph; } } } return null; }
Example #21
Source File: SpoonTransformationDelegate.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public void tabSelected( TabItem item ) { List<TabMapEntry> collection = spoon.delegates.tabs.getTabs(); // See which core objects to show // for ( TabMapEntry entry : collection ) { if ( item.equals( entry.getTabItem() ) ) { // TabItemInterface itemInterface = entry.getObject(); // // Another way to implement this may be to keep track of the // state of the core object tree in method // addCoreObjectsToTree() // if ( entry.getObject() instanceof TransGraph || entry.getObject() instanceof JobGraph ) { EngineMetaInterface meta = entry.getObject().getMeta(); if ( meta != null ) { meta.setInternalKettleVariables(); } if ( spoon.getCoreObjectsState() != SpoonInterface.STATE_CORE_OBJECTS_SPOON ) { spoon.refreshCoreObjects(); } } } } // Also refresh the tree spoon.refreshTree(); spoon.enableMenus(); }
Example #22
Source File: JobGraph.java From pentaho-kettle with Apache License 2.0 | 5 votes |
/** * Finds the last active transformation in the running job to the opened transMeta * * @param transGraph * @param jobEntryCopy */ private void attachActiveTrans( TransGraph transGraph, TransMeta newTrans, JobEntryCopy jobEntryCopy ) { if ( job != null && transGraph != null ) { Trans trans = spoon.findActiveTrans( job, jobEntryCopy ); transGraph.setTrans( trans ); if ( !transGraph.isExecutionResultsPaneVisible() ) { transGraph.showExecutionResults(); } transGraph.setControlStates(); } }
Example #23
Source File: DataSetHelper.java From pentaho-pdi-dataset with Apache License 2.0 | 5 votes |
private void tweakUnitTestStep( TransTweak stepTweak, boolean enable ) { Spoon spoon = ( (Spoon) SpoonFactory.getInstance() ); TransGraph transGraph = spoon.getActiveTransGraph(); IMetaStore metaStore = spoon.getMetaStore(); if ( transGraph == null ) { return; } StepMeta stepMeta = transGraph.getCurrentStep(); TransMeta transMeta = spoon.getActiveTransformation(); if ( stepMeta == null || transMeta == null ) { return; } if ( checkTestPresent( spoon, transMeta ) ) { return; } try { TransUnitTest unitTest = getCurrentUnitTest( transMeta ); TransUnitTestTweak unitTestTweak = unitTest.findTweak( stepMeta.getName() ); if ( unitTestTweak != null ) { unitTest.getTweaks().remove( unitTestTweak ); } if ( enable ) { unitTest.getTweaks().add( new TransUnitTestTweak( stepTweak, stepMeta.getName() ) ); } saveUnitTest( getHierarchy().getTestFactory(), unitTest, transMeta ); spoon.refreshGraph(); } catch ( Exception exception ) { new ErrorDialog( spoon.getShell(), "Error", "Error tweaking transformation unit test on step '" + stepMeta.getName() + "' with operation " + stepTweak.name(), exception ); } }
Example #24
Source File: DataSetHelper.java From pentaho-pdi-dataset with Apache License 2.0 | 5 votes |
public void selectUnitTest() { Spoon spoon = ( (Spoon) SpoonFactory.getInstance() ); try { TransGraph transGraph = spoon.getActiveTransGraph(); IMetaStore metaStore = spoon.getMetaStore(); if ( transGraph == null ) { return; } TransMeta transMeta = spoon.getActiveTransformation(); if ( transMeta == null ) { return; } FactoriesHierarchy hierarchy = getHierarchy(); List<String> testNames = hierarchy.getTestFactory().getElementNames(); String[] names = testNames.toArray( new String[ testNames.size() ] ); Arrays.sort( names ); EnterSelectionDialog esd = new EnterSelectionDialog( spoon.getShell(), names, "Select a unit test", "Select the unit test to use" ); String testName = esd.open(); if ( testName != null ) { TransUnitTest unitTest = hierarchy.getTestFactory().loadElement( testName ); if ( unitTest == null ) { throw new KettleException( "Unit test '" + testName + "' could not be found (deleted)?" ); } selectUnitTest( transMeta, unitTest ); Spoon.getInstance().refreshGraph(); } } catch ( Exception e ) { new ErrorDialog( spoon.getShell(), "Error", "Error selecting a new transformation unit test", e ); } }
Example #25
Source File: DataSetHelper.java From pentaho-pdi-dataset with Apache License 2.0 | 5 votes |
public void createUnitTest() { Spoon spoon = ( (Spoon) SpoonFactory.getInstance() ); TransGraph transGraph = spoon.getActiveTransGraph(); if ( transGraph == null ) { return; } TransMeta transMeta = transGraph.getTransMeta(); createUnitTest( spoon, transMeta ); }
Example #26
Source File: DataSetHelper.java From pentaho-pdi-dataset with Apache License 2.0 | 5 votes |
public void clearGoldenDataSet() { Spoon spoon = ( (Spoon) SpoonFactory.getInstance() ); TransGraph transGraph = spoon.getActiveTransGraph(); TransMeta transMeta = spoon.getActiveTransformation(); StepMeta stepMeta = transGraph.getCurrentStep(); if ( transGraph == null || transMeta == null || stepMeta == null ) { return; } if ( checkTestPresent( spoon, transMeta ) ) { return; } try { TransUnitTest currentUnitTest = getCurrentUnitTest( transMeta ); TransUnitTestSetLocation goldenLocation = currentUnitTest.findGoldenLocation( stepMeta.getName() ); if ( goldenLocation != null ) { currentUnitTest.getGoldenDataSets().remove( goldenLocation ); } saveUnitTest( getHierarchy().getTestFactory(), currentUnitTest, transMeta ); } catch ( Exception e ) { new ErrorDialog( spoon.getShell(), "Error", "Error saving unit test", e ); } transMeta.setChanged(); transGraph.redraw(); }
Example #27
Source File: BeamHelper.java From kettle-beam with Apache License 2.0 | 5 votes |
private void setCurrentStepBeamFlag(String key, String value) { TransGraph transGraph = spoon.getActiveTransGraph(); if (transGraph==null) { return; } StepMeta stepMeta = transGraph.getCurrentStep(); if (stepMeta==null) { return; } stepMeta.setAttribute(BeamConst.STRING_KETTLE_BEAM, key, value); transGraph.redraw(); }
Example #28
Source File: SpoonTransformationDelegate.java From pentaho-kettle with Apache License 2.0 | 4 votes |
void addTabsToTransGraph( TransGraph transGraph ) { transGraph.addAllTabs(); transGraph.extraViewTabFolder.setSelection( transGraph.transHistoryDelegate.getTransHistoryTab() ); }
Example #29
Source File: DataSetHelper.java From pentaho-pdi-dataset with Apache License 2.0 | 4 votes |
/** * Ask which data set to write to * Ask for the mapping between the output row and the data set field * Start the transformation and capture the output of the step, write to the database table backing the data set. */ public void writeStepDataToDataSet() { Spoon spoon = ( (Spoon) SpoonFactory.getInstance() ); TransGraph transGraph = spoon.getActiveTransGraph(); IMetaStore metaStore = spoon.getMetaStore(); if ( transGraph == null ) { return; } StepMeta stepMeta = transGraph.getCurrentStep(); TransMeta transMeta = spoon.getActiveTransformation(); if ( stepMeta == null || transMeta == null ) { return; } if ( transMeta.hasChanged() ) { MessageBox box = new MessageBox( spoon.getShell(), SWT.OK | SWT.ICON_INFORMATION ); box.setText( "Save transformation" ); box.setMessage( "Please save your transformation first." ); box.open(); return; } try { FactoriesHierarchy hierarchy = getHierarchy(); MetaStoreFactory<DataSetGroup> groupFactory = hierarchy.getGroupFactory(); List<DatabaseMeta> databases = getAvailableDatabases( spoon.getRepository() ); groupFactory.addNameList( DataSetConst.DATABASE_LIST_KEY, databases ); List<DataSetGroup> groups = groupFactory.getElements(); MetaStoreFactory<DataSet> setFactory = hierarchy.getSetFactory(); setFactory.addNameList( DataSetConst.GROUP_LIST_KEY, groups ); // Ask which data set to write to // List<String> setNames = setFactory.getElementNames(); Collections.sort( setNames ); EnterSelectionDialog esd = new EnterSelectionDialog( spoon.getShell(), setNames.toArray( new String[ setNames.size() ] ), "Select the set", "Select the data set to edit..." ); String setName = esd.open(); if ( setName == null ) { return; } DataSet dataSet = setFactory.loadElement( setName ); String[] setFields = new String[ dataSet.getFields().size() ]; for ( int i = 0; i < setFields.length; i++ ) { setFields[ i ] = dataSet.getFields().get( i ).getFieldName(); } RowMetaInterface rowMeta = transMeta.getStepFields( stepMeta ); String[] stepFields = new String[ rowMeta.size() ]; for ( int i = 0; i < rowMeta.size(); i++ ) { ValueMetaInterface valueMeta = rowMeta.getValueMeta( i ); stepFields[ i ] = valueMeta.getName(); } // Ask for the mapping between the output row and the data set field // EnterMappingDialog mappingDialog = new EnterMappingDialog( spoon.getShell(), stepFields, setFields ); List<SourceToTargetMapping> mapping = mappingDialog.open(); if ( mapping == null ) { return; } // Run the transformation. We want to use the standard Spoon runFile() method // So we need to leave the source to target mapping list somewhere so it can be picked up later. // For now we'll leave it where we need it. // WriteToDataSetExtensionPoint.stepsMap.put( transMeta.getName(), stepMeta ); WriteToDataSetExtensionPoint.mappingsMap.put( transMeta.getName(), mapping ); WriteToDataSetExtensionPoint.setsMap.put( transMeta.getName(), dataSet ); // Signal to the transformation xp plugin to inject data into some data set // transMeta.setVariable( DataSetConst.VAR_WRITE_TO_DATASET, "Y" ); spoon.runFile(); } catch ( Exception e ) { new ErrorDialog( spoon.getShell(), "Error", "Error creating a new data set", e ); } }
Example #30
Source File: DataSetHelper.java From pentaho-pdi-dataset with Apache License 2.0 | 4 votes |
/** * Create a new data set with the output from */ public void createDataSetFromStep() { Spoon spoon = ( (Spoon) SpoonFactory.getInstance() ); TransGraph transGraph = spoon.getActiveTransGraph(); IMetaStore metaStore = spoon.getMetaStore(); if ( transGraph == null ) { return; } StepMeta stepMeta = transGraph.getCurrentStep(); TransMeta transMeta = spoon.getActiveTransformation(); if ( stepMeta == null || transMeta == null ) { return; } try { FactoriesHierarchy hierarchy = getHierarchy(); MetaStoreFactory<DataSetGroup> groupFactory = hierarchy.getGroupFactory(); List<DatabaseMeta> databases = getAvailableDatabases( spoon.getRepository() ); groupFactory.addNameList( DataSetConst.DATABASE_LIST_KEY, databases ); List<DataSetGroup> groups = groupFactory.getElements(); MetaStoreFactory<DataSet> setFactory = hierarchy.getSetFactory(); setFactory.addNameList( DataSetConst.GROUP_LIST_KEY, groups ); DataSet dataSet = new DataSet(); RowMetaInterface rowMeta = transMeta.getStepFields( stepMeta ); for ( int i = 0; i < rowMeta.size(); i++ ) { ValueMetaInterface valueMeta = rowMeta.getValueMeta( i ); String setFieldname = valueMeta.getName(); String columnName = "field" + i; DataSetField field = new DataSetField( setFieldname, columnName, valueMeta.getType(), valueMeta.getLength(), valueMeta.getPrecision(), valueMeta.getComments(), valueMeta.getFormatMask() ); dataSet.getFields().add( field ); } editDataSet( spoon, dataSet, groups, setFactory, null ); } catch ( Exception e ) { new ErrorDialog( spoon.getShell(), "Error", "Error creating a new data set", e ); } }