Java Code Examples for org.pentaho.di.trans.Trans#getTransMeta()

The following examples show how to use org.pentaho.di.trans.Trans#getTransMeta() . 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: AbstractKettleTransformationProducer.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void updateTransformationParameter( final FormulaContext formulaContext,
                                            final Trans trans )
  throws UnknownParamException, EvaluationException, ParseException {
  for ( int i = 0; i < this.parameter.length; i++ ) {
    final FormulaParameter mapping = this.parameter[ i ];
    final String sourceName = mapping.getName();
    final Object value = mapping.compute( formulaContext );
    TransMeta transMeta = trans.getTransMeta();
    if ( value != null ) {
      String paramValue = String.valueOf( value );
      trans.setParameterValue( sourceName, paramValue );
      transMeta.setParameterValue( sourceName, paramValue );
    } else {
      trans.setParameterValue( sourceName, null );
      transMeta.setParameterValue( sourceName, null );
    }
    trans.setTransMeta( transMeta );
  }
}
 
Example 2
Source File: CarteIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddTransServlet() {

  HttpTester request = new HttpTester();
  HttpTester response = new HttpTester();
  request.setMethod( "GET" );
  request.setHeader( "Host", "tester" );
  request.setURI( RegisterTransServlet.CONTEXT_PATH + "?xml=Y" );
  request.setVersion( "HTTP/1.0" );
  try {

    TransExecutionConfiguration transExecConfig = new TransExecutionConfiguration();
    Trans trans = CarteIT.generateTestTransformation();
    TransConfiguration transConfig = new TransConfiguration( trans.getTransMeta(), transExecConfig );
    request.setContent( transConfig.getXML() );
    response.parse( tester.getResponses( request.generate() ) );

    Document document = XMLHandler.loadXMLString( response.getContent() );
    NodeList nodes = document.getElementsByTagName( "result" );
    Assert.assertEquals( 1, nodes.getLength() );
    Assert.assertEquals( WebResult.STRING_OK, nodes.item( 0 ).getTextContent() );

    SlaveServerStatus status = getStatus();
    SlaveServerTransStatus transStatus = status.findTransStatus( trans.getName(), null ); // find the first one
    Assert.assertNotNull( transStatus );
    Assert.assertFalse( transStatus.isPaused() );
    Assert.assertFalse( transStatus.isRunning() );

  } catch ( Exception ex ) {
    ex.printStackTrace();
    Assert.fail( ex.getMessage() );
  }
}
 
Example 3
Source File: CarteDelegationHandler.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void transformationDelegationStarted( Trans delegatedTrans,
  TransExecutionConfiguration transExecutionConfiguration ) {
  TransConfiguration tc = new TransConfiguration( delegatedTrans.getTransMeta(), transExecutionConfiguration );
  transformationMap.registerTransformation( delegatedTrans, tc );
  delegatedTrans.addDelegationListener( this );

}
 
Example 4
Source File: ValidateTransUnitTestExtensionPoint.java    From pentaho-pdi-dataset with Apache License 2.0 4 votes vote down vote up
@Override
public void callExtensionPoint( LogChannelInterface log, Object object ) throws KettleException {
  if ( !( object instanceof Trans ) ) {
    return;
  }

  final Trans trans = (Trans) object;
  final TransMeta transMeta = trans.getTransMeta();
  boolean runUnitTest = "Y".equalsIgnoreCase( transMeta.getVariable( DataSetConst.VAR_RUN_UNIT_TEST ) );
  if ( !runUnitTest ) {
    return;
  }

  // We should always have a unit test name here...
  String unitTestName = transMeta.getVariable( DataSetConst.VAR_UNIT_TEST_NAME );
  if ( StringUtil.isEmpty( unitTestName ) ) {
    return;
  }

  try {
    IMetaStore metaStore = transMeta.getMetaStore();
    Repository repository = transMeta.getRepository();

    if ( metaStore == null ) {
      return; // Nothing to do here, we can't reference data sets.
    }

    List<DatabaseMeta> databases = DataSetConst.getAvailableDatabases( repository, transMeta.getSharedObjects() );
    FactoriesHierarchy factoriesHierarchy = new FactoriesHierarchy( metaStore, databases );

    // If the transformation has a variable set with the unit test in it, we're dealing with a unit test situation.
    //
    TransUnitTest unitTest = factoriesHierarchy.getTestFactory().loadElement( unitTestName );

    final List<UnitTestResult> results = new ArrayList<UnitTestResult>();
    trans.getExtensionDataMap().put( DataSetConst.UNIT_TEST_RESULTS, results );


    // Validate execution results with what's in the data sets...
    //
    int errors = DataSetConst.validateTransResultAgainstUnitTest( trans, unitTest, factoriesHierarchy, results );
    if ( errors == 0 ) {
      log.logBasic( "Unit test '" + unitTest.getName() + "' passed succesfully" );
    } else {
      log.logBasic( "Unit test '" + unitTest.getName() + "' failed, " + errors + " errors detected, " + results.size() + " comments to report." );

      String dontShowResults = transMeta.getVariable( DataSetConst.VAR_DO_NOT_SHOW_UNIT_TEST_ERRORS, "N" );

      final Spoon spoon = Spoon.getInstance();
      if ( spoon != null && "N".equalsIgnoreCase( dontShowResults ) ) {
        spoon.getShell().getDisplay().asyncExec( new Runnable() {
          @Override
          public void run() {
            PreviewRowsDialog dialog = new PreviewRowsDialog( spoon.getShell(), trans, SWT.NONE,
              "Unit test results",
              UnitTestResult.getRowMeta(),
              UnitTestResult.getRowData( results ) );
            dialog.setDynamic( false );
            dialog.setProposingToGetMoreRows( false );
            dialog.setProposingToStop( false );
            dialog.setTitleMessage( "Unit test results", "Here are the results of the unit test validations:" );
            dialog.open();
          }
        } );
      }
    }
    log.logBasic( "----------------------------------------------" );
    for ( UnitTestResult result : results ) {
      if ( result.getDataSetName() != null ) {
        log.logBasic( result.getStepName() + " - " + result.getDataSetName() + " : " + result.getComment() );
      } else {
        log.logBasic( result.getComment() );
      }
    }
    log.logBasic( "----------------------------------------------" );
  } catch ( Throwable e ) {
    log.logError( "Unable to validate unit test/golden rows", e );
  }

}
 
Example 5
Source File: MRUtil.java    From pentaho-hadoop-shims with Apache License 2.0 4 votes vote down vote up
/**
 * Create a copy of {@code trans}
 */
public static Trans recreateTrans( Trans trans ) {
  return new Trans( trans.getTransMeta(), trans.getParent() );
}
 
Example 6
Source File: TransGraph.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Open the transformation mentioned in the mapping...
 */
public void openMapping( StepMeta stepMeta, int index ) {
  try {
    Object referencedMeta = null;
    Trans subTrans = getActiveSubtransformation( this, stepMeta );
    if ( subTrans != null
      && ( stepMeta.getStepMetaInterface().getActiveReferencedObjectDescription() == null || index < 0 ) ) {
      TransMeta subTransMeta = subTrans.getTransMeta();
      referencedMeta = subTransMeta;
      Object[] objectArray = new Object[ 4 ];
      objectArray[ 0 ] = stepMeta;
      objectArray[ 1 ] = subTransMeta;
      ExtensionPointHandler.callExtensionPoint( log, KettleExtensionPoint.OpenMapping.id, objectArray );
    } else {
      StepMetaInterface meta = stepMeta.getStepMetaInterface();
      if ( !Utils.isEmpty( meta.getReferencedObjectDescriptions() ) ) {
        referencedMeta = meta.loadReferencedObject( index, spoon.rep, spoon.metaStore, transMeta );
      }
    }
    if ( referencedMeta == null ) {
      return;
    }

    if ( referencedMeta instanceof TransMeta ) {
      TransMeta mappingMeta = (TransMeta) referencedMeta;
      mappingMeta.clearChanged();
      spoon.addTransGraph( mappingMeta );
      TransGraph subTransGraph = spoon.getActiveTransGraph();
      attachActiveTrans( subTransGraph, this.currentStep );
    }

    if ( referencedMeta instanceof JobMeta ) {
      JobMeta jobMeta = (JobMeta) referencedMeta;
      jobMeta.clearChanged();
      spoon.addJobGraph( jobMeta );
      JobGraph jobGraph = spoon.getActiveJobGraph();
      attachActiveJob( jobGraph, this.currentStep );
    }

  } catch ( Exception e ) {
    new ErrorDialog( shell, BaseMessages.getString( PKG, "TransGraph.Exception.UnableToLoadMapping.Title" ),
      BaseMessages.getString( PKG, "TransGraph.Exception.UnableToLoadMapping.Message" ), e );
  }
}