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

The following examples show how to use org.pentaho.di.trans.TransMeta#nrTransHops() . 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: HopsFolderProvider.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
public void refresh( AbstractMeta meta, TreeNode treeNode, String filter ) {

  TransMeta transMeta = (TransMeta) meta;
  // Put the steps below it.
  for ( int i = 0; i < transMeta.nrTransHops(); i++ ) {
    TransHopMeta hopMeta = transMeta.getTransHop( i );

    if ( !filterMatch( hopMeta.toString(), filter ) ) {
      continue;
    }

    Image icon = hopMeta.isEnabled() ? guiResource.getImageHopTree() : guiResource.getImageDisabledHopTree();
    createTreeNode( treeNode, hopMeta.toString(), icon );
  }
}
 
Example 2
Source File: MetaInjectMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
public void onStepChange( TransMeta transMeta, StepMeta oldMeta, StepMeta newMeta ) {
  for ( int i = 0; i < transMeta.nrTransHops(); i++ ) {
    TransHopMeta hopMeta = transMeta.getTransHop( i );
    if ( hopMeta.getFromStep().equals( oldMeta ) ) {
      StepMeta toStepMeta = hopMeta.getToStep();
      if ( ( toStepMeta.getStepMetaInterface() instanceof MetaInjectMeta ) && ( toStepMeta.equals( this
        .getParentStepMeta() ) ) ) {
        MetaInjectMeta toMeta = (MetaInjectMeta) toStepMeta.getStepMetaInterface();
        Map<TargetStepAttribute, SourceStepField> sourceMapping = toMeta.getTargetSourceMapping();
        for ( Entry<TargetStepAttribute, SourceStepField> entry : sourceMapping.entrySet() ) {
          SourceStepField value = entry.getValue();
          if ( value.getStepname() != null && value.getStepname().equals( oldMeta.getName() ) ) {
            value.setStepname( newMeta.getName() );
          }
        }
      }
    }
  }
}
 
Example 3
Source File: TransformationHasNoDisabledHopsImportRule.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public List<ImportValidationFeedback> verifyRule( Object subject ) {

  List<ImportValidationFeedback> feedback = new ArrayList<ImportValidationFeedback>();

  if ( !isEnabled() ) {
    return feedback;
  }
  if ( !( subject instanceof TransMeta ) ) {
    return feedback;
  }

  TransMeta transMeta = (TransMeta) subject;

  for ( int i = 0; i < transMeta.nrTransHops(); i++ ) {
    TransHopMeta hop = transMeta.getTransHop( i );
    if ( !hop.isEnabled() ) {
      feedback.add( new ImportValidationFeedback(
        this, ImportValidationResultType.ERROR, "There is a disabled hop in the transformation." ) );
    }
  }

  if ( feedback.isEmpty() ) {
    feedback.add( new ImportValidationFeedback(
      this, ImportValidationResultType.APPROVAL, "All hops are enabled in this transformation." ) );
  }

  return feedback;
}
 
Example 4
Source File: SpoonRefreshHopsSubtreeTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private static TransMeta prepareMetaWithThreeHops() {
  TransMeta meta = mock( TransMeta.class );
  when( meta.nrTransHops() ).thenReturn( 3 );

  for ( int i = 0; i < meta.nrTransHops(); i++ ) {
    TransHopMeta hopMeta = mockHopMeta( i );
    when( meta.getTransHop( eq( i ) ) ).thenReturn( hopMeta );
  }
  return meta;
}
 
Example 5
Source File: SpoonStepsDelegate.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void delSteps( TransMeta transformation, StepMeta[] steps ) {
  try {
    ExtensionPointHandler.callExtensionPoint( log, KettleExtensionPoint.TransBeforeDeleteSteps.id, steps );
  } catch ( KettleException e ) {
    return;
  }

  // Hops belonging to the deleting steps are placed in a single transaction and removed.
  List<TransHopMeta> transHops = new ArrayList<>();
  int[] hopIndexes = new int[transformation.nrTransHops()];
  int hopIndex = 0;
  for ( int i = transformation.nrTransHops() - 1; i >= 0; i-- ) {
    TransHopMeta hi = transformation.getTransHop( i );
    for ( int j = 0; j < steps.length && hopIndex < hopIndexes.length; j++ ) {
      if ( hi.getFromStep().equals( steps[j] ) || hi.getToStep().equals( steps[j] ) ) {
        int idx = transformation.indexOfTransHop( hi );
        transHops.add( (TransHopMeta) hi.clone() );
        hopIndexes[hopIndex] = idx;
        transformation.removeTransHop( idx );
        spoon.refreshTree();
        hopIndex++;
        break;
      }
    }
  }
  if ( !transHops.isEmpty() ) {
    TransHopMeta[] hops = transHops.toArray( new TransHopMeta[transHops.size()] );
    spoon.addUndoDelete( transformation, hops, hopIndexes );
  }

  // Deleting steps are placed all in a single transaction and removed.
  int[] positions = new int[steps.length];
  for ( int i = 0; i < steps.length; i++ ) {
    int pos = transformation.indexOfStep( steps[i] );
    transformation.removeStep( pos );
    positions[i] = pos;
  }
  spoon.addUndoDelete( transformation, steps, positions );

  spoon.refreshTree();
  spoon.refreshGraph();
}