Java Code Examples for org.pentaho.di.ui.spoon.Spoon#getActiveTransformation()

The following examples show how to use org.pentaho.di.ui.spoon.Spoon#getActiveTransformation() . 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: DataSetHelper.java    From pentaho-pdi-dataset with Apache License 2.0 6 votes vote down vote up
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 2
Source File: JobEntryTransDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private boolean askToCreateNewTransformation( String prevName ) {
  MessageBox mb = new MessageBox( shell, SWT.YES | SWT.NO | SWT.ICON_QUESTION );
  mb.setMessage( BaseMessages.getString( PKG, "JobTrans.Dialog.CreateTransformationQuestion.Message" ) );
  mb.setText( BaseMessages.getString( PKG, "JobTrans.Dialog.CreateTransformationQuestion.Title" ) );
  int answer = mb.open();
  if ( answer == SWT.YES ) {
    Spoon spoon = Spoon.getInstance();
    spoon.newTransFile();
    TransMeta transMeta = spoon.getActiveTransformation();
    transMeta.initializeVariablesFrom( jobEntry );
    transMeta.setFilename( jobMeta.environmentSubstitute( prevName ) );
    wPath.setText( prevName );
    specificationMethod = ObjectLocationSpecificationMethod.FILENAME;
    spoon.saveFile();
    return true;
  }
  return false;
}
 
Example 3
Source File: DataSetHelper.java    From pentaho-pdi-dataset with Apache License 2.0 5 votes vote down vote up
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 4
Source File: DataSetHelper.java    From pentaho-pdi-dataset with Apache License 2.0 5 votes vote down vote up
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 5
Source File: DataSetHelper.java    From pentaho-pdi-dataset with Apache License 2.0 5 votes vote down vote up
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 6
Source File: DataSetHelper.java    From pentaho-pdi-dataset with Apache License 2.0 5 votes vote down vote up
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 7
Source File: DataSetHelper.java    From pentaho-pdi-dataset with Apache License 2.0 5 votes vote down vote up
public void openUnitTestTransformation() {
  try {
    Spoon spoon = Spoon.getInstance();
    FactoriesHierarchy hierarchy = getHierarchy();
    RowMetaAndData selection = selectUnitTestFromAllTests();
    if ( selection != null ) {
      String filename = selection.getString( 2, null );
      if ( StringUtils.isNotEmpty( filename ) ) {
        // Load the unit test...
        //
        String unitTestName = selection.getString( 0, null );
        TransUnitTest targetTest = hierarchy.getTestFactory().loadElement( unitTestName );

        if ( targetTest != null ) {

          String completeFilename = targetTest.calculateCompleteFilename( Variables.getADefaultVariableSpace() );
          spoon.openFile( completeFilename, false );

          TransMeta transMeta = spoon.getActiveTransformation();
          if ( transMeta != null ) {
            switchUnitTest( targetTest, transMeta );
          }
        }
      } else {
        throw new KettleException( "No filename found: repositories not supported yet for this feature" );
      }
    }
  } catch ( Exception e ) {
    new ErrorDialog( Spoon.getInstance().getShell(), "Error", "Error opening unit test transformation", e );
  }
}
 
Example 8
Source File: DataSetHelper.java    From pentaho-pdi-dataset with Apache License 2.0 4 votes vote down vote up
/**
 * 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 9
Source File: DataSetHelper.java    From pentaho-pdi-dataset with Apache License 2.0 4 votes vote down vote up
/**
 * 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 );
  }
}