Java Code Examples for org.pentaho.di.ui.spoon.Spoon#getMetaStore()
The following examples show how to use
org.pentaho.di.ui.spoon.Spoon#getMetaStore() .
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: ShowUnitTestMenuExtensionPoint.java From pentaho-pdi-dataset with Apache License 2.0 | 6 votes |
private void editLocation( TransUnitTestSetLocation location, Spoon spoon, TransMeta transMeta ) { try { FactoriesHierarchy hierarchy = new FactoriesHierarchy( spoon.getMetaStore(), spoon.getActiveDatabases() ); Map<String, RowMetaInterface> stepFieldsMap = new HashMap<>(); for ( StepMeta stepMeta : transMeta.getSteps() ) { stepFieldsMap.put( stepMeta.getName(), transMeta.getStepFields( stepMeta ) ); } TransUnitTestSetLocationDialog dialog = new TransUnitTestSetLocationDialog( spoon.getShell(), location, hierarchy.getSetFactory().getElements(), stepFieldsMap ); if ( dialog.open() ) { spoon.refreshGraph(); } } catch ( Exception e ) { new ErrorDialog( spoon.getShell(), "Error", "Error editing dataset location", e ); } }
Example 2
Source File: DataSetHelper.java From pentaho-pdi-dataset with Apache License 2.0 | 6 votes |
public void editDataSetGroup() { Spoon spoon = ( (Spoon) SpoonFactory.getInstance() ); IMetaStore metaStore = spoon.getMetaStore(); MetaStoreFactory<DataSetGroup> groupFactory = new MetaStoreFactory<DataSetGroup>( DataSetGroup.class, metaStore, PentahoDefaults.NAMESPACE ); try { List<String> groupNames = groupFactory.getElementNames(); Collections.sort( groupNames ); EnterSelectionDialog esd = new EnterSelectionDialog( spoon.getShell(), groupNames.toArray( new String[ groupNames.size() ] ), "Select the group", "Select the group to edit..." ); String groupName = esd.open(); if ( groupName != null ) { editDataSetGroup( groupName ); } } catch ( Exception e ) { new ErrorDialog( spoon.getShell(), "Error", "Error retrieving the list of data set groups", e ); } }
Example 3
Source File: DataSetHelper.java From pentaho-pdi-dataset with Apache License 2.0 | 6 votes |
public void removeDataSetGroup() { Spoon spoon = ( (Spoon) SpoonFactory.getInstance() ); IMetaStore metaStore = spoon.getMetaStore(); MetaStoreFactory<DataSetGroup> groupFactory = new MetaStoreFactory<DataSetGroup>( DataSetGroup.class, metaStore, PentahoDefaults.NAMESPACE ); try { List<String> groupNames = groupFactory.getElementNames(); Collections.sort( groupNames ); EnterSelectionDialog esd = new EnterSelectionDialog( spoon.getShell(), groupNames.toArray( new String[ groupNames.size() ] ), "Select the group", "Select the group to edit..." ); String groupName = esd.open(); if ( groupName != null ) { // TODO: Find the unit tests for this group, if there are any, we can't remove the group // groupFactory.deleteElement( groupName ); } } catch ( Exception e ) { new ErrorDialog( spoon.getShell(), "Error", "Error retrieving the list of data set groups or deleting a group", e ); } }
Example 4
Source File: DataSetHelper.java From pentaho-pdi-dataset with Apache License 2.0 | 6 votes |
public void addDataSet() { Spoon spoon = ( (Spoon) SpoonFactory.getInstance() ); IMetaStore metaStore = spoon.getMetaStore(); try { MetaStoreFactory<DataSetGroup> groupFactory = new MetaStoreFactory<DataSetGroup>( DataSetGroup.class, metaStore, PentahoDefaults.NAMESPACE ); List<DatabaseMeta> databases = getAvailableDatabases( spoon.getRepository() ); groupFactory.addNameList( DataSetConst.DATABASE_LIST_KEY, databases ); List<DataSetGroup> groups = groupFactory.getElements(); MetaStoreFactory<DataSet> setFactory = new MetaStoreFactory<DataSet>( DataSet.class, metaStore, PentahoDefaults.NAMESPACE ); setFactory.addNameList( DataSetConst.GROUP_LIST_KEY, groups ); DataSet dataSet = new DataSet(); editDataSet( spoon, dataSet, groups, setFactory, null ); } catch ( Exception e ) { new ErrorDialog( spoon.getShell(), "Error", "Error creating a new data set", e ); } }
Example 5
Source File: DataSetHelper.java From pentaho-pdi-dataset with Apache License 2.0 | 6 votes |
public void editUnitTest( Spoon spoon, TransMeta transMeta, String unitTestName ) { IMetaStore metaStore = spoon.getMetaStore(); try { FactoriesHierarchy hierarchy = getHierarchy(); TransUnitTest unitTest = hierarchy.getTestFactory().loadElement( unitTestName ); if ( unitTest == null ) { throw new KettleException( BaseMessages.getString( PKG, "DataSetHelper.ErrorEditingUnitTest.Message", unitTestName ) ); } TransUnitTestDialog dialog = new TransUnitTestDialog( spoon.getShell(), transMeta, metaStore, unitTest ); if ( dialog.open() ) { saveUnitTest( hierarchy.getTestFactory(), unitTest, transMeta ); } } catch ( Exception exception ) { new ErrorDialog( Spoon.getInstance().getShell(), BaseMessages.getString( PKG, "DataSetHelper.ErrorEditingUnitTest.Title" ), BaseMessages.getString( PKG, "DataSetHelper.ErrorEditingUnitTest.Message", unitTestName ), exception ); } }
Example 6
Source File: LocationMouseDoubleClickExtensionPoint.java From pentaho-pdi-dataset with Apache License 2.0 | 5 votes |
private void openDataSet( String dataSetName ) { Spoon spoon = Spoon.getInstance(); List<DatabaseMeta> databases = spoon.getActiveDatabases(); IMetaStore metaStore = spoon.getMetaStore(); try { FactoriesHierarchy factoriesHierarchy = new FactoriesHierarchy( metaStore, databases ); MetaStoreFactory<DataSet> setFactory = factoriesHierarchy.getSetFactory(); MetaStoreFactory<DataSetGroup> groupFactory = factoriesHierarchy.getGroupFactory(); List<DataSetGroup> groups = groupFactory.getElements(); DataSet dataSet = factoriesHierarchy.getSetFactory().loadElement( dataSetName ); DataSetDialog dataSetDialog = new DataSetDialog( spoon.getShell(), metaStore, dataSet, groups, databases ); while ( dataSetDialog.open() ) { String message = DataSetHelper.validateDataSet( dataSet, dataSetName, setFactory.getElementNames() ); // Save the data set... // if ( message == null ) { setFactory.saveElement( dataSet ); break; } else { MessageBox box = new MessageBox( spoon.getShell(), SWT.OK ); box.setText( "Error" ); box.setMessage( message ); box.open(); } } } catch ( Exception e ) { new ErrorDialog( spoon.getShell(), "Error", "Error editing data set '" + dataSetName + "'", e ); } }
Example 7
Source File: DataSetHelper.java From pentaho-pdi-dataset with Apache License 2.0 | 5 votes |
public void editDataSetGroup( String groupName ) throws MetaStoreException, KettleException { Spoon spoon = Spoon.getInstance(); DelegatingMetaStore metaStore = spoon.getMetaStore(); List<DatabaseMeta> databases = getAvailableDatabases( spoon.getRepository() ); MetaStoreFactory<DataSetGroup> groupFactory = new MetaStoreFactory<DataSetGroup>( DataSetGroup.class, metaStore, PentahoDefaults.NAMESPACE ); groupFactory.addNameList( DataSetConst.DATABASE_LIST_KEY, databases ); DataSetGroup dataSetGroup = groupFactory.loadElement( groupName ); DataSetGroupDialog groupDialog = new DataSetGroupDialog( spoon.getShell(), dataSetGroup, databases ); while ( groupDialog.open() ) { String message = validateDataSetGroup( dataSetGroup, groupName, groupFactory.getElementNames() ); // Save the group ... // if ( message == null ) { groupFactory.saveElement( dataSetGroup ); break; } else { MessageBox box = new MessageBox( spoon.getShell(), SWT.OK ); box.setText( "Error" ); box.setMessage( message ); box.open(); } } }
Example 8
Source File: DataSetHelper.java From pentaho-pdi-dataset with Apache License 2.0 | 5 votes |
public void addDataSetGroup() { Spoon spoon = ( (Spoon) SpoonFactory.getInstance() ); IMetaStore metaStore = spoon.getMetaStore(); MetaStoreFactory<DataSetGroup> groupFactory = new MetaStoreFactory<DataSetGroup>( DataSetGroup.class, metaStore, PentahoDefaults.NAMESPACE ); try { DataSetGroup dataSetGroup = new DataSetGroup(); List<DatabaseMeta> databases = getAvailableDatabases( spoon.getRepository() ); DataSetGroupDialog groupDialog = new DataSetGroupDialog( spoon.getShell(), dataSetGroup, databases ); while ( groupDialog.open() ) { // Verify empty name, existing name... // String message = validateDataSetGroup( dataSetGroup, null, groupFactory.getElementNames() ); // Save the group again... // if ( message == null ) { groupFactory.saveElement( dataSetGroup ); break; } else { MessageBox box = new MessageBox( spoon.getShell(), SWT.OK ); box.setText( "Error" ); box.setMessage( message ); box.open(); } } } catch ( Exception e ) { new ErrorDialog( spoon.getShell(), "Error", "Error creating a new data set group", e ); } }
Example 9
Source File: DataSetHelper.java From pentaho-pdi-dataset with Apache License 2.0 | 5 votes |
public void editDataSet() { Spoon spoon = ( (Spoon) SpoonFactory.getInstance() ); IMetaStore metaStore = spoon.getMetaStore(); try { MetaStoreFactory<DataSetGroup> groupFactory = new MetaStoreFactory<DataSetGroup>( DataSetGroup.class, metaStore, PentahoDefaults.NAMESPACE ); List<DatabaseMeta> databases = getAvailableDatabases( spoon.getRepository() ); groupFactory.addNameList( DataSetConst.DATABASE_LIST_KEY, databases ); List<DataSetGroup> groups = groupFactory.getElements(); MetaStoreFactory<DataSet> setFactory = new MetaStoreFactory<DataSet>( DataSet.class, metaStore, PentahoDefaults.NAMESPACE ); setFactory.addNameList( DataSetConst.GROUP_LIST_KEY, groups ); 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 ) { DataSet dataSet = setFactory.loadElement( setName ); editDataSet( spoon, dataSet, groups, setFactory, setName ); } } catch ( Exception e ) { new ErrorDialog( spoon.getShell(), "Error", "Error retrieving the list of data set groups", e ); } }
Example 10
Source File: DataSetHelper.java From pentaho-pdi-dataset with Apache License 2.0 | 5 votes |
public void deleteDataSet() { Spoon spoon = ( (Spoon) SpoonFactory.getInstance() ); IMetaStore metaStore = spoon.getMetaStore(); try { MetaStoreFactory<DataSetGroup> groupFactory = new MetaStoreFactory<DataSetGroup>( DataSetGroup.class, metaStore, PentahoDefaults.NAMESPACE ); List<DatabaseMeta> databases = getAvailableDatabases( spoon.getRepository() ); groupFactory.addNameList( DataSetConst.DATABASE_LIST_KEY, databases ); List<DataSetGroup> groups = groupFactory.getElements(); MetaStoreFactory<DataSet> setFactory = new MetaStoreFactory<DataSet>( DataSet.class, metaStore, PentahoDefaults.NAMESPACE ); setFactory.addNameList( DataSetConst.GROUP_LIST_KEY, groups ); List<String> setNames = setFactory.getElementNames(); Collections.sort( setNames ); EnterSelectionDialog esd = new EnterSelectionDialog( spoon.getShell(), setNames.toArray( new String[ setNames.size() ] ), "Select the data set", "Select the data set to delete..." ); String setName = esd.open(); if ( setName != null ) { DataSet dataSet = setFactory.loadElement( setName ); deleteDataSet( spoon, dataSet, groups, setFactory, setName ); } } catch ( Exception e ) { new ErrorDialog( spoon.getShell(), "Error", "Error retrieving the list of data set groups", e ); } }
Example 11
Source File: DataSetHelper.java From pentaho-pdi-dataset with Apache License 2.0 | 5 votes |
public static FactoriesHierarchy getHierarchy() throws KettleException { try { Spoon spoon = Spoon.getInstance(); List<DatabaseMeta> databases = getAvailableDatabases( spoon.getRepository() ); FactoriesHierarchy hierarchy = new FactoriesHierarchy( spoon.getMetaStore(), databases ); return hierarchy; } catch ( Exception e ) { throw new KettleException( "Unable to get MetaStore factories hierarchy", e ); } }
Example 12
Source File: DataSetHelper.java From pentaho-pdi-dataset with Apache License 2.0 | 5 votes |
public void createUnitTest( Spoon spoon, TransMeta transMeta ) { try { TransUnitTest unitTest = new TransUnitTest(); unitTest.setName( transMeta.getName() + " Test" ); unitTest.setTransFilename( transMeta.getFilename() ); if ( spoon.getRepository() != null ) { unitTest.setTransObjectId( transMeta.getObjectId() == null ? null : transMeta.getObjectId().getId() ); String path = transMeta.getRepositoryDirectory().getPath(); if ( !path.endsWith( "/" ) ) { path += "/"; } path += transMeta.getName(); unitTest.setTransRepositoryPath( path ); } FactoriesHierarchy hierarchy = getHierarchy(); TransUnitTestDialog dialog = new TransUnitTestDialog( spoon.getShell(), transMeta, spoon.getMetaStore(), unitTest ); if ( dialog.open() ) { saveUnitTest( hierarchy.getTestFactory(), unitTest, transMeta ); activeTests.put( transMeta, unitTest ); spoon.refreshGraph(); } } catch ( Exception e ) { new ErrorDialog( spoon.getShell(), "Error", "Error creating a new transformation unit test", e ); } }
Example 13
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 14
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 15
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 ); } }
Example 16
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 ); } }