Java Code Examples for org.pentaho.di.trans.TransMeta#findStep()

The following examples show how to use org.pentaho.di.trans.TransMeta#findStep() . 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: JoinRowsMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
public void getFields( RowMetaInterface rowMeta, String origin, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  if ( space instanceof TransMeta ) {
    TransMeta transMeta = (TransMeta) space;
    StepMeta[] steps = transMeta.getPrevSteps( transMeta.findStep( origin ) );
    StepMeta mainStep = transMeta.findStep( getMainStepname() );
    rowMeta.clear();
    if ( mainStep != null ) {
      rowMeta.addRowMeta( transMeta.getStepFields( mainStep ) );
    }
    for ( StepMeta step : steps ) {
      if ( mainStep == null || !step.equals( mainStep ) ) {
        rowMeta.addRowMeta( transMeta.getStepFields( step ) );
      }
    }
  }
}
 
Example 2
Source File: BaseStepGenericXulDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public BaseStepGenericXulDialog( String xulFile, Object parent, BaseStepMeta baseStepMeta, TransMeta transMeta,
                                 String stepname ) {

  this.log = new LogChannel( baseStepMeta );
  this.transMeta = transMeta;
  this.stepname = stepname;
  if ( transMeta != null ) {
    this.stepMeta = transMeta.findStep( stepname );
  }
  this.baseStepMeta = baseStepMeta;
  this.xulFile = xulFile;
  this.parent = parent;

  try {
    initializeXul();
  } catch ( Exception e ) {
    e.printStackTrace();
    log.logError( "Error initializing (" + stepname + ") step dialog", e );
    throw new IllegalStateException( "Cannot load dialog due to error in initialization", e );
  }
}
 
Example 3
Source File: SpoonDBDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Get & show the SQL required to run the loaded transformation...
 *
 */
public void getTransSQL( TransMeta transMeta ) {
  GetSQLProgressDialog pspd = new GetSQLProgressDialog( spoon.getShell(), transMeta );
  List<SQLStatement> stats = pspd.open();
  if ( stats != null ) {
    // null means error, but we already displayed the error

    if ( stats.size() > 0 ) {
      SQLStatementsDialog ssd =
        new SQLStatementsDialog( spoon.getShell(), Variables.getADefaultVariableSpace(), SWT.NONE, stats );
      String sn = ssd.open();

      if ( sn != null ) {
        StepMeta esi = transMeta.findStep( sn );
        if ( esi != null ) {
          spoon.delegates.steps.editStep( transMeta, esi );
        }
      }
    } else {
      MessageBox mb = new MessageBox( spoon.getShell(), SWT.OK | SWT.ICON_INFORMATION );
      mb.setMessage( BaseMessages.getString( PKG, "Spoon.Dialog.NoSQLNeedEexecuted.Message" ) );
      mb.setText( BaseMessages.getString( PKG, "Spoon.Dialog.NoSQLNeedEexecuted.Title" ) ); // "SQL"
      mb.open();
    }
  }
}
 
Example 4
Source File: SpoonStepsDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public void dupeStep( TransMeta transMeta, StepMeta stepMeta ) {
  spoon.getLog().logDebug(
    toString(), BaseMessages.getString( PKG, "Spoon.Log.DuplicateStep" ) + stepMeta.getName() ); // Duplicate
  // step:

  StepMeta stMeta = (StepMeta) stepMeta.clone();
  if ( stMeta != null ) {
    String newname = transMeta.getAlternativeStepname( stepMeta.getName() );
    int nr = 2;
    while ( transMeta.findStep( newname ) != null ) {
      newname = stepMeta.getName() + " (copy " + nr + ")";
      nr++;
    }
    stMeta.setName( newname );
    // Don't select this new step!
    stMeta.setSelected( false );
    Point loc = stMeta.getLocation();
    stMeta.setLocation( loc.x + 20, loc.y + 20 );
    transMeta.addStep( stMeta );
    spoon.addUndoNew( transMeta, new StepMeta[] { (StepMeta) stMeta.clone() }, new int[] { transMeta
      .indexOfStep( stMeta ) } );
    spoon.refreshTree();
    spoon.refreshGraph();
  }
}
 
Example 5
Source File: JobGenerator.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private TransMeta generateDateTransformation(DatabaseMeta databaseMeta, LogicalTable logicalTable) throws KettleException {
  // We actually load the transformation from a template and then slightly modify it.
  //
  String filename = "/org/pentaho/di/resources/Generate date dimension.ktr";
  InputStream inputStream = getClass().getResourceAsStream(filename);
  TransMeta transMeta = new TransMeta(inputStream, Spoon.getInstance().rep, true, new Variables(), null);

  // Find the table output step and inject the target table name and database...
  //
  StepMeta stepMeta = transMeta.findStep("TARGET");
  if (stepMeta!=null) {
    TableOutputMeta meta = (TableOutputMeta) stepMeta.getStepMetaInterface();
    meta.setDatabaseMeta(databaseMeta);
    String phTable = ConceptUtil.getString(logicalTable, DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME);
    meta.setTableName(phTable);
  }

  return transMeta;
}
 
Example 6
Source File: JobGenerator.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private TransMeta generateTimeTransformation(DatabaseMeta databaseMeta, LogicalTable logicalTable) throws KettleException {
  // We actually load the transformation from a template and then slightly modify it.
  //
  String filename = "/org/pentaho/di/resources/Generate time dimension.ktr";
  InputStream inputStream = getClass().getResourceAsStream(filename);
  TransMeta transMeta = new TransMeta(inputStream, Spoon.getInstance().rep, true, new Variables(), null);

  // Find the table output step and inject the target table name and database...
  //
  StepMeta stepMeta = transMeta.findStep("TARGET");
  if (stepMeta!=null) {
    TableOutputMeta meta = (TableOutputMeta) stepMeta.getStepMetaInterface();
    meta.setDatabaseMeta(databaseMeta);
    String phTable = ConceptUtil.getString(logicalTable, DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME);
    meta.setTableName(phTable);
  }

  return transMeta;
}
 
Example 7
Source File: BaseStepDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates a new base step dialog.
 *
 * @param parent       the parent shell
 * @param baseStepMeta the associated base step metadata
 * @param transMeta    the associated transformation metadata
 * @param stepname     the step name
 */
public BaseStepDialog( Shell parent, BaseStepMeta baseStepMeta, TransMeta transMeta, String stepname ) {
  super( parent, SWT.NONE );

  this.log = new LogChannel( baseStepMeta );
  this.transMeta = transMeta;
  this.stepname = stepname;
  this.stepMeta = transMeta.findStep( stepname );
  this.baseStepMeta = (StepMetaInterface) baseStepMeta;
  this.backupChanged = baseStepMeta.hasChanged();
  this.props = PropsUI.getInstance();
}
 
Example 8
Source File: BaseStepDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates a new base step dialog.
 *
 * @param parent       the parent shell
 * @param baseStepMeta the associated base step metadata
 * @param transMeta    the associated transformation metadata
 * @param stepname     the step name
 */
public BaseStepDialog( Shell parent, StepMetaInterface baseStepMeta, TransMeta transMeta, String stepname ) {
  super( parent, SWT.NONE );

  this.log = new LogChannel( baseStepMeta );
  this.transMeta = transMeta;
  this.stepname = stepname;
  this.stepMeta = transMeta.findStep( stepname );
  this.baseStepMeta = baseStepMeta;
  this.backupChanged = baseStepMeta.hasChanged();
  this.props = PropsUI.getInstance();
}
 
Example 9
Source File: SpoonStepsDelegate.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public String editStep( TransMeta transMeta, StepMeta stepMeta ) {
  boolean refresh = false;
  String stepname = null;
  try {
    String name = stepMeta.getName();

    // Before we do anything, let's store the situation the way it
    // was...
    //
    StepMeta before = (StepMeta) stepMeta.clone();
    StepDialogInterface dialog = spoon.getStepEntryDialog( stepMeta.getStepMetaInterface(), transMeta, name );
    if ( dialog != null ) {
      dialog.setRepository( spoon.getRepository() );
      dialog.setMetaStore( spoon.getMetaStore() );
      stepname = dialog.open();
    }

    if ( !Utils.isEmpty( stepname ) ) {
      // Force the recreation of the step IO metadata object. (cached by default)
      //
      stepMeta.getStepMetaInterface().resetStepIoMeta();

      //
      // See if the new name the user enter, doesn't collide with
      // another step.
      // If so, change the stepname and warn the user!
      //
      String newname = stepname;
      StepMeta smeta = transMeta.findStep( newname, stepMeta );
      int nr = 2;
      while ( smeta != null ) {
        newname = stepname + " " + nr;
        smeta = transMeta.findStep( newname );
        nr++;
      }
      if ( nr > 2 ) {
        stepname = newname;
        MessageBox mb = new MessageBox( spoon.getShell(), SWT.OK | SWT.ICON_INFORMATION );
        mb.setMessage( BaseMessages.getString( PKG, "Spoon.Dialog.StepnameExists.Message", stepname ) );
        mb.setText( BaseMessages.getString( PKG, "Spoon.Dialog.StepnameExists.Title" ) );
        mb.open();
      }

      if ( !stepname.equals( name ) ) {
        refresh = true;
      }

      StepMeta newStepMeta = (StepMeta) stepMeta.clone();
      newStepMeta.setName( stepname );
      transMeta.clearCaches();
      transMeta.notifyAllListeners( stepMeta, newStepMeta );
      stepMeta.setName( stepname );

      //
      // OK, so the step has changed...
      // Backup the situation for undo/redo
      //
      StepMeta after = (StepMeta) stepMeta.clone();
      spoon.addUndoChange( transMeta, new StepMeta[] { before }, new StepMeta[] { after }, new int[] { transMeta
        .indexOfStep( stepMeta ) } );
    } else {
      // Scenario: change connections and click cancel...
      // Perhaps new connections were created in the step dialog?
      if ( transMeta.haveConnectionsChanged() ) {
        refresh = true;
      }
    }
    spoon.refreshGraph(); // name is displayed on the graph too.

    // TODO: verify "double pathway" steps for bug #4365
    // After the step was edited we can complain about the possible
    // deadlock here.
    //
  } catch ( Throwable e ) {
    if ( spoon.getShell().isDisposed() ) {
      return null;
    }
    new ErrorDialog(
      spoon.getShell(), BaseMessages.getString( PKG, "Spoon.Dialog.UnableOpenDialog.Title" ), BaseMessages
        .getString( PKG, "Spoon.Dialog.UnableOpenDialog.Message" ), e );
  }

  if ( refresh ) {
    spoon.refreshTree(); // Perhaps new connections were created in
    // the step
    // dialog or the step name changed.
  }

  return stepname;
}