Java Code Examples for org.pentaho.di.trans.step.StepMeta#setDraw()

The following examples show how to use org.pentaho.di.trans.step.StepMeta#setDraw() . 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: StepTransform.java    From kettle-beam with Apache License 2.0 6 votes vote down vote up
private StepMeta createInjectorStep( TransMeta transMeta, String injectorStepName, RowMetaInterface injectorRowMeta, int x, int y ) {
  InjectorMeta injectorMeta = new InjectorMeta();
  injectorMeta.allocate( injectorRowMeta.size() );
  for ( int i = 0; i < injectorRowMeta.size(); i++ ) {
    ValueMetaInterface valueMeta = injectorRowMeta.getValueMeta( i );
    injectorMeta.getFieldname()[ i ] = valueMeta.getName();
    injectorMeta.getType()[ i ] = valueMeta.getType();
    injectorMeta.getLength()[ i ] = valueMeta.getLength();
    injectorMeta.getPrecision()[ i ] = valueMeta.getPrecision();
  }
  StepMeta injectorStepMeta = new StepMeta( injectorStepName, injectorMeta );
  injectorStepMeta.setLocation( x, y );
  injectorStepMeta.setDraw( true );
  transMeta.addStep( injectorStepMeta );

  return injectorStepMeta;
}
 
Example 2
Source File: StepBatchTransform.java    From kettle-beam with Apache License 2.0 6 votes vote down vote up
private StepMeta createInjectorStep( TransMeta transMeta, String injectorStepName, RowMetaInterface injectorRowMeta, int x, int y ) {
  InjectorMeta injectorMeta = new InjectorMeta();
  injectorMeta.allocate( injectorRowMeta.size() );
  for ( int i = 0; i < injectorRowMeta.size(); i++ ) {
    ValueMetaInterface valueMeta = injectorRowMeta.getValueMeta( i );
    injectorMeta.getFieldname()[ i ] = valueMeta.getName();
    injectorMeta.getType()[ i ] = valueMeta.getType();
    injectorMeta.getLength()[ i ] = valueMeta.getLength();
    injectorMeta.getPrecision()[ i ] = valueMeta.getPrecision();
  }
  StepMeta injectorStepMeta = new StepMeta( injectorStepName, injectorMeta );
  injectorStepMeta.setLocation( x, y );
  injectorStepMeta.setDraw( true );
  transMeta.addStep( injectorStepMeta );

  return injectorStepMeta;
}
 
Example 3
Source File: TransPreviewFactory.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public static final TransMeta generatePreviewTransformation( VariableSpace parent, StepMetaInterface oneMeta,
  String oneStepname ) {
  PluginRegistry registry = PluginRegistry.getInstance();

  TransMeta previewMeta = new TransMeta( parent );
  // The following operation resets the internal variables!
  //
  previewMeta.setName( parent == null ? "Preview transformation" : parent.toString() );

  // At it to the first step.
  StepMeta one = new StepMeta( registry.getPluginId( StepPluginType.class, oneMeta ), oneStepname, oneMeta );
  one.setLocation( 50, 50 );
  one.setDraw( true );
  previewMeta.addStep( one );

  DummyTransMeta twoMeta = new DummyTransMeta();
  StepMeta two = new StepMeta( registry.getPluginId( StepPluginType.class, twoMeta ), "dummy", twoMeta );
  two.setLocation( 250, 50 );
  two.setDraw( true );
  previewMeta.addStep( two );

  TransHopMeta hop = new TransHopMeta( one, two );
  previewMeta.addTransHop( hop );

  return previewMeta;
}
 
Example 4
Source File: SpoonJobDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private StepMeta getToStep( DatabaseMeta targetDbInfo, String table ) {
  String tostepname = BaseMessages.getString( PKG, "Spoon.RipDB.Monitor.ToStep.Name" ) + table + "]";
  TableOutputMeta toi = new TableOutputMeta();
  toi.setDatabaseMeta( targetDbInfo );
  toi.setTableName( table );
  toi.setCommitSize( 100 );
  toi.setTruncateTable( true );

  String tostepid = PluginRegistry.getInstance().getPluginId( StepPluginType.class, toi );
  StepMeta tostep = new StepMeta( tostepid, tostepname, toi );
  tostep.setLocation( 500, 100 );
  tostep.setDraw( true );
  tostep
    .setDescription( BaseMessages.getString( PKG, "Spoon.RipDB.Monitor.ToStep.Description1" )
      + table + BaseMessages.getString( PKG, "Spoon.RipDB.Monitor.ToStep.Description2" )
      + targetDbInfo + "]" );
  return tostep;
}
 
Example 5
Source File: BaseStreamingDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
protected TransMeta createSubTransMeta() {
  RecordsFromStreamMeta rm = new RecordsFromStreamMeta();
  String[] fieldNames = getFieldNames();
  int[] empty = new int[ fieldNames.length ];
  Arrays.fill( empty, -1 );
  rm.setFieldname( fieldNames );
  rm.setType( getFieldTypes() );
  rm.setLength( empty );
  rm.setPrecision( empty );

  StepMeta recsFromStream = new StepMeta( "RecordsFromStream", "Get records from stream", rm );
  recsFromStream.setLocation( new Point( 100, 100 ) );
  recsFromStream.setDraw( true );

  TransMeta transMeta = new TransMeta();
  transMeta.addStep( recsFromStream );
  transMeta.setFilename( "" );

  return transMeta;
}
 
Example 6
Source File: SingleThreadedExecutionGuarder.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test( expected = KettleException.class )
public void failsWhenGivenNonSingleThreadSteps() throws Exception {
  Meta metaInterface = createMeta();

  PluginRegistry plugReg = PluginRegistry.getInstance();
  String id = plugReg.getPluginId( StepPluginType.class, metaInterface );
  assertNotNull( "pluginId", id );

  StepMeta stepMeta = new StepMeta( id, "stepMetrics", metaInterface );
  stepMeta.setDraw( true );

  TransMeta transMeta = new TransMeta();
  transMeta.setName( "failsWhenGivenNonSingleThreadSteps" );
  transMeta.addStep( stepMeta );

  Trans trans = new Trans( transMeta );
  trans.prepareExecution( null );

  SingleThreadedTransExecutor executor = new SingleThreadedTransExecutor( trans );
  executor.init();
}
 
Example 7
Source File: TransTestFactory.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
static StepMeta getReadStepMeta( String name ) {
  DummyTransMeta twoMeta = new DummyTransMeta();
  StepMeta two = new StepMeta( registry.getPluginId( StepPluginType.class, twoMeta ), name, twoMeta );
  two.setLocation( 250, 50 );
  two.setDraw( true );
  return two;
}
 
Example 8
Source File: TransTestFactory.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
static StepMeta getInjectorStepMeta() {
  InjectorMeta zeroMeta = new InjectorMeta();
  StepMeta zero = new StepMeta( registry.getPluginId( StepPluginType.class, zeroMeta ), INJECTOR_STEPNAME, zeroMeta );
  zero.setLocation( 50, 50 );
  zero.setDraw( true );
  return zero;
}
 
Example 9
Source File: TransTestFactory.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static TransMeta generateTestTransformation( VariableSpace parent, StepMetaInterface oneMeta,
    String oneStepname ) {
  TransMeta previewMeta = new TransMeta( parent );

  // First the injector step...
  StepMeta zero = getInjectorStepMeta();
  previewMeta.addStep( zero );

  // Then the middle step to test...
  //
  StepMeta one = new StepMeta( registry.getPluginId( StepPluginType.class, oneMeta ), oneStepname, oneMeta );
  one.setLocation( 150, 50 );
  one.setDraw( true );
  previewMeta.addStep( one );

  // Then we add the dummy step to read the results from
  StepMeta two = getReadStepMeta();
  previewMeta.addStep( two );

  // Add the hops between the 3 steps.
  TransHopMeta zeroOne = new TransHopMeta( zero, one );
  previewMeta.addTransHop( zeroOne );
  TransHopMeta oneTwo = new TransHopMeta( one, two );
  previewMeta.addTransHop( oneTwo );

  return previewMeta;
}
 
Example 10
Source File: SpoonJobDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private StepMeta getFromStep( DatabaseMeta sourceDbInfo, String[] tables, int i, TableInputMeta tii ) {
  String fromstepname =
    BaseMessages.getString( PKG, "Spoon.RipDB.Monitor.FromStep.Name" ) + tables[i] + "]";


  String fromstepid = PluginRegistry.getInstance().getPluginId( StepPluginType.class, tii );
  StepMeta fromstep = new StepMeta( fromstepid, fromstepname, tii );
  fromstep.setLocation( 150, 100 );
  fromstep.setDraw( true );
  fromstep
    .setDescription( BaseMessages.getString( PKG, "Spoon.RipDB.Monitor.FromStep.Description" )
      + tables[i] + BaseMessages.getString( PKG, "Spoon.RipDB.Monitor.FromStep.Description2" )
      + sourceDbInfo + "]" );
  return fromstep;
}
 
Example 11
Source File: TransTestFactory.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
static StepMeta getReadStepMeta( String name ) {
  DummyTransMeta twoMeta = new DummyTransMeta();
  StepMeta two = new StepMeta( registry.getPluginId( StepPluginType.class, twoMeta ), name, twoMeta );
  two.setLocation( 250, 50 );
  two.setDraw( true );
  return two;
}
 
Example 12
Source File: TransTestFactory.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
static StepMeta getInjectorStepMeta( RowMetaInterface outputRowMeta ) {
  InjectorMeta zeroMeta = new InjectorMeta();

  // Sets output fields for cases when no rows are sent to the test step, but metadata is still needed
  if ( outputRowMeta != null && outputRowMeta.size() > 0 ) {
    String[] fieldName = new String[outputRowMeta.size()];
    int[] fieldLength = new int[outputRowMeta.size()];
    int[] fieldPrecision = new int[outputRowMeta.size()];
    int[] fieldType = new int[outputRowMeta.size()];
    for ( int i = 0; i < outputRowMeta.size(); i++ ) {
      ValueMetaInterface field = outputRowMeta.getValueMeta( i );
      fieldName[i] = field.getName();
      fieldLength[i] = field.getLength();
      fieldPrecision[i] = field.getPrecision();
      fieldType[i] = field.getType();
    }
    zeroMeta.setFieldname( fieldName );
    zeroMeta.setLength( fieldLength );
    zeroMeta.setPrecision( fieldPrecision );
    zeroMeta.setType( fieldType );
  }

  StepMeta zero = new StepMeta( registry.getPluginId( StepPluginType.class, zeroMeta ), INJECTOR_STEPNAME, zeroMeta );
  zero.setLocation( 50, 50 );
  zero.setDraw( true );

  return zero;
}
 
Example 13
Source File: TransTestFactory.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static TransMeta generateTestTransformation( VariableSpace parent, StepMetaInterface oneMeta,
    String oneStepname, RowMetaInterface injectorRowMeta ) {
  TransMeta previewMeta = new TransMeta( parent );

  // First the injector step...
  StepMeta zero = getInjectorStepMeta( injectorRowMeta );
  previewMeta.addStep( zero );

  // Then the middle step to test...
  //
  StepMeta one = new StepMeta( registry.getPluginId( StepPluginType.class, oneMeta ), oneStepname, oneMeta );
  one.setLocation( 150, 50 );
  one.setDraw( true );
  previewMeta.addStep( one );

  // Then we add the dummy step to read the results from
  StepMeta two = getReadStepMeta();
  previewMeta.addStep( two );

  // Add the hops between the 3 steps.
  TransHopMeta zeroOne = new TransHopMeta( zero, one );
  previewMeta.addTransHop( zeroOne );
  TransHopMeta oneTwo = new TransHopMeta( one, two );
  previewMeta.addTransHop( oneTwo );

  return previewMeta;
}
 
Example 14
Source File: TransGraph.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void newStep( String description ) {
  StepMeta stepMeta = spoon.newStep( transMeta, description, description, false, true );
  PropsUI.setLocation( stepMeta, currentMouseX, currentMouseY );
  stepMeta.setDraw( true );
  redraw();
}
 
Example 15
Source File: KettleDatabaseRepositoryStepDelegate.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Create a new step by loading the metadata from the specified repository.
 *
 * @param rep
 * @param stepId
 * @param databases
 * @param counters
 * @param partitionSchemas
 * @throws KettleException
 */
public StepMeta loadStepMeta( ObjectId stepId, List<DatabaseMeta> databases,
  List<PartitionSchema> partitionSchemas ) throws KettleException {
  StepMeta stepMeta = new StepMeta();
  PluginRegistry registry = PluginRegistry.getInstance();

  try {
    RowMetaAndData r = getStep( stepId );
    if ( r != null ) {
      stepMeta.setObjectId( stepId );

      stepMeta.setName( r.getString( KettleDatabaseRepository.FIELD_STEP_NAME, null ) );
      stepMeta.setDescription( r.getString( KettleDatabaseRepository.FIELD_STEP_DESCRIPTION, null ) );

      long id_step_type = r.getInteger( KettleDatabaseRepository.FIELD_STEP_ID_STEP_TYPE, -1L );
      RowMetaAndData steptyperow = getStepType( new LongObjectId( id_step_type ) );

      stepMeta.setStepID( steptyperow.getString( KettleDatabaseRepository.FIELD_STEP_TYPE_CODE, null ) );
      stepMeta.setDistributes( r.getBoolean( KettleDatabaseRepository.FIELD_STEP_DISTRIBUTE, true ) );
      int copies = (int) r.getInteger( KettleDatabaseRepository.FIELD_STEP_COPIES, 1 );
      String copiesString = r.getString( KettleDatabaseRepository.FIELD_STEP_COPIES_STRING, null );
      if ( !Utils.isEmpty( copiesString ) ) {
        stepMeta.setCopiesString( copiesString );
      } else {
        stepMeta.setCopies( copies );
      }

      int x = (int) r.getInteger( KettleDatabaseRepository.FIELD_STEP_GUI_LOCATION_X, 0 );
      int y = (int) r.getInteger( KettleDatabaseRepository.FIELD_STEP_GUI_LOCATION_Y, 0 );
      stepMeta.setLocation( new Point( x, y ) );
      stepMeta.setDraw( r.getBoolean( KettleDatabaseRepository.FIELD_STEP_GUI_DRAW, false ) );

      // Generate the appropriate class...
      PluginInterface sp = registry.findPluginWithId( StepPluginType.class, stepMeta.getStepID() );
      if ( sp == null ) {
        stepMeta.setStepMetaInterface( new MissingTrans( stepMeta.getName(), stepMeta.getStepID() ) );
      } else {
        stepMeta.setStepMetaInterface( (StepMetaInterface) registry.loadClass( sp ) );
      }
      if ( stepMeta.getStepMetaInterface() != null ) {
        // Read the step info from the repository!
        readRepCompatibleStepMeta(
          stepMeta.getStepMetaInterface(), repository, stepMeta.getObjectId(), databases );
        stepMeta.getStepMetaInterface().readRep(
          repository, repository.metaStore, stepMeta.getObjectId(), databases );
      }

      // Get the partitioning as well...
      //
      stepMeta.setStepPartitioningMeta( loadStepPartitioningMeta( stepMeta.getObjectId() ) );
      stepMeta.getStepPartitioningMeta().setPartitionSchemaAfterLoading( partitionSchemas );

      // Get the cluster schema name
      //
      stepMeta.setClusterSchemaName( repository.getStepAttributeString( stepId, "cluster_schema" ) );

      // Are we using a custom row distribution plugin?
      //
      String rowDistributionCode = repository.getStepAttributeString( stepId, 0, "row_distribution_code" );
      RowDistributionInterface rowDistribution =
        PluginRegistry.getInstance().loadClass(
          RowDistributionPluginType.class, rowDistributionCode, RowDistributionInterface.class );
      stepMeta.setRowDistribution( rowDistribution );

      // Load the attribute groups map
      //
      stepMeta.setAttributesMap( loadStepAttributesMap( stepId ) );

      // Done!
      //
      return stepMeta;
    } else {
      throw new KettleException( BaseMessages.getString(
        PKG, "StepMeta.Exception.StepInfoCouldNotBeFound", String.valueOf( stepId ) ) );
    }
  } catch ( KettleDatabaseException dbe ) {
    throw new KettleException( BaseMessages.getString( PKG, "StepMeta.Exception.StepCouldNotBeLoaded", String
      .valueOf( stepMeta.getObjectId() ) ), dbe );
  }
}
 
Example 16
Source File: CombinationLookupIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Test case for Combination lookup/update.
 */
public void testCombinationLookup() throws Exception {
  //
  // Create a new transformation...
  //
  TransMeta transMeta = new TransMeta();
  transMeta.setName( "transname" );

  // Add the database connections
  for ( int i = 0; i < databasesXML.length; i++ ) {
    DatabaseMeta databaseMeta = new DatabaseMeta( databasesXML[i] );
    transMeta.addDatabase( databaseMeta );
  }

  DatabaseMeta lookupDBInfo = transMeta.findDatabase( "lookup" );

  // Execute our setup SQLs in the database.
  Database lookupDatabase = new Database( transMeta, lookupDBInfo );
  lookupDatabase.connect();
  createTables( lookupDatabase );
  createData( lookupDatabase );

  PluginRegistry registry = PluginRegistry.getInstance();

  //
  // create the source step...
  //
  String fromstepname = "read from [" + source_table + "]";
  TableInputMeta tii = new TableInputMeta();
  tii.setDatabaseMeta( transMeta.findDatabase( "lookup" ) );
  String selectSQL = "SELECT " + Const.CR;
  selectSQL += "DLR_CD, DLR_NM, DLR_DESC ";
  selectSQL += "FROM " + source_table + " ORDER BY ORDNO;";
  tii.setSQL( selectSQL );

  String fromstepid = registry.getPluginId( StepPluginType.class, tii );
  StepMeta fromstep = new StepMeta( fromstepid, fromstepname, tii );
  fromstep.setLocation( 150, 100 );
  fromstep.setDraw( true );
  fromstep.setDescription( "Reads information from table ["
    + source_table + "] on database [" + lookupDBInfo + "]" );
  transMeta.addStep( fromstep );

  //
  // create the combination lookup/update step...
  //
  String lookupstepname = "lookup from [lookup]";
  CombinationLookupMeta clm = new CombinationLookupMeta();
  String[] lookupKey = { "DLR_CD" };
  clm.setTablename( target_table );
  clm.setKeyField( lookupKey );
  clm.setKeyLookup( lookupKey );
  clm.setTechnicalKeyField( "ID" );
  clm.setTechKeyCreation( CombinationLookupMeta.CREATION_METHOD_TABLEMAX );
  clm.setDatabaseMeta( lookupDBInfo );

  String lookupstepid = registry.getPluginId( StepPluginType.class, clm );
  StepMeta lookupstep = new StepMeta( lookupstepid, lookupstepname, clm );
  lookupstep.setDescription( "Looks up information from table [lookup] on database [" + lookupDBInfo + "]" );
  transMeta.addStep( lookupstep );

  TransHopMeta hi = new TransHopMeta( fromstep, lookupstep );
  transMeta.addTransHop( hi );

  // Now execute the transformation...
  Trans trans = new Trans( transMeta );
  trans.execute( null );

  trans.waitUntilFinished();

  checkResults( lookupDatabase );
}
 
Example 17
Source File: TransformationHasNoDisabledHopsImportRuleIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void testRule() throws Exception {

    // Create a transformation to test.
    //
    TransMeta transMeta = new TransMeta();

    // Add 3 dummy steps connected with hops.
    //
    StepMeta lastStep = null;
    for ( int i = 0; i < 3; i++ ) {
      DummyTransMeta dummyTransMeta = new DummyTransMeta();
      StepMeta stepMeta = new StepMeta( "dummy" + ( i + 1 ), dummyTransMeta );
      stepMeta.setLocation( 50 + i * 50, 50 );
      stepMeta.setDraw( true );
      transMeta.addStep( stepMeta );
      if ( lastStep != null ) {
        TransHopMeta hop = new TransHopMeta( lastStep, stepMeta );
        transMeta.addTransHop( hop );
      }
      lastStep = stepMeta;
    }

    // Load the plugin to test from the registry.
    //
    PluginRegistry registry = PluginRegistry.getInstance();
    PluginInterface plugin =
      registry.findPluginWithId( ImportRulePluginType.class, "TransformationHasNoDisabledHops" );
    assertNotNull(
      "The 'transformation has no disabled hops' rule could not be found in the plugin registry!", plugin );

    TransformationHasNoDisabledHopsImportRule rule =
      (TransformationHasNoDisabledHopsImportRule) registry.loadClass( plugin );
    assertNotNull(
      "The 'transformation has no disabled hops' class could not be loaded by the plugin registry!", plugin );

    rule.setEnabled( true );

    List<ImportValidationFeedback> feedback = rule.verifyRule( transMeta );
    assertTrue( "We didn't get any feedback from the 'transformation has no disabled hops'", !feedback.isEmpty() );
    assertTrue(
      "An approval ruling was expected",
      feedback.get( 0 ).getResultType() == ImportValidationResultType.APPROVAL );

    transMeta.getTransHop( 0 ).setEnabled( false );

    feedback = rule.verifyRule( transMeta );
    assertTrue( "We didn't get any feedback from the 'transformation has no disabled hops'", !feedback.isEmpty() );
    assertTrue(
      "An error ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR );

    rule.setEnabled( false );

    feedback = rule.verifyRule( transMeta );
    assertTrue(
      "We didn't expect any feedback from the 'transformation has no disabled hops' while disabled", feedback
        .isEmpty() );

  }