Skip to content

Commit

Permalink
[BACKLOG-8241] - Move the writing out of the Metadata-Injected KTR ... (
Browse files Browse the repository at this point in the history
#2582)

* [BACKLOG-8241] - Move the writing out of the Metadata-Injected KTR from before execution to after to allow for customizations to MDI to happen in a step's init() method. This allows for complex data structures to be handled in a manual fashion when traditional annotation-based MDI isn't sufficient.

* [CLEANUP] - License header date
  • Loading branch information
Rob Fellows authored and mdamour1976 committed Jun 6, 2016
1 parent 58e6928 commit 82ca9ab
Showing 1 changed file with 42 additions and 37 deletions.
79 changes: 42 additions & 37 deletions engine/src/org/pentaho/di/trans/steps/metainject/MetaInject.java
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2013 by Pentaho : http://www.pentaho.com
* Copyright (C) 2002-2016 by Pentaho : http://www.pentaho.com
*
*******************************************************************************
*
Expand All @@ -22,18 +22,6 @@

package org.pentaho.di.trans.steps.metainject;

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.pentaho.di.core.Const;
import org.pentaho.di.core.Result;
import org.pentaho.di.core.RowMetaAndData;
Expand Down Expand Up @@ -61,6 +49,18 @@
import org.pentaho.di.trans.step.StepMetaInjectionInterface;
import org.pentaho.di.trans.step.StepMetaInterface;

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

/**
* Read a simple CSV file Just output Strings found in the file...
*
Expand Down Expand Up @@ -118,30 +118,6 @@ public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws
}
}

if ( log.isDetailed() ) {
logDetailed( "XML of transformation after injection: " + data.transMeta.getXML() );
}
String targetFile = environmentSubstitute( meta.getTargetFile() );
if ( !Const.isEmpty( targetFile ) ) {
OutputStream os = null;
try {
os = KettleVFS.getOutputStream( targetFile, false );
os.write( XMLHandler.getXMLHeader().getBytes( Const.XML_ENCODING ) );
os.write( data.transMeta.getXML().getBytes( Const.XML_ENCODING ) );
} catch ( IOException e ) {
throw new KettleException( "Unable to write target file (ktr after injection) to file '" + targetFile + "'",
e );
} finally {
if ( os != null ) {
try {
os.close();
} catch ( Exception e ) {
throw new KettleException( e );
}
}
}
}

if ( !meta.isNoExecution() ) {
// Now we can execute this modified transformation metadata.
//
Expand Down Expand Up @@ -215,13 +191,42 @@ public void rowWrittenEvent( RowMetaInterface rowMeta, Object[] row ) throws Ket
copyResult( injectTrans );
}

// let the transformation complete it's execution to allow for any customizations to MDI to happen in the init methods of steps
if ( log.isDetailed() ) {
logDetailed( "XML of transformation after injection: " + data.transMeta.getXML() );
}
String targetFile = environmentSubstitute( meta.getTargetFile() );
if ( !Const.isEmpty( targetFile ) ) {
writeInjectedKtr( targetFile );
}

// All done!

setOutputDone();

return false;
}

private void writeInjectedKtr( String targetFile ) throws KettleException {
OutputStream os = null;
try {
os = KettleVFS.getOutputStream( targetFile, false );
os.write( XMLHandler.getXMLHeader().getBytes( Const.XML_ENCODING ) );
os.write( data.transMeta.getXML().getBytes( Const.XML_ENCODING ) );
} catch ( IOException e ) {
throw new KettleException( "Unable to write target file (ktr after injection) to file '" + targetFile + "'",
e );
} finally {
if ( os != null ) {
try {
os.close();
} catch ( Exception e ) {
throw new KettleException( e );
}
}
}
}

private void newInjection( String targetStep, StepMetaInterface targetStepMeta ) throws KettleException {
if ( log.isDetailed() ) {
logDetailed( "Handing step '" + targetStep + "' injection!" );
Expand Down

0 comments on commit 82ca9ab

Please sign in to comment.