Skip to content

Commit

Permalink
PDI-15133 KTR with Filter Rows step does not save TRUE/FALSE settings…
Browse files Browse the repository at this point in the history
… when exported to XML from repository
  • Loading branch information
stanislau-strelchanka committed Aug 19, 2016
1 parent 7587ab6 commit 2fa882a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
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 Down Expand Up @@ -163,6 +163,9 @@ public boolean init( StepMetaInterface smi, StepDataInterface sdi ) {
data.trueStepname = targetStreams.get( 0 ).getStepname();
data.falseStepname = targetStreams.get( 1 ).getStepname();

meta.setTrueStepname( data.trueStepname );
meta.setFalseStepname( data.falseStepname );

data.chosesTargetSteps =
targetStreams.get( 0 ).getStepMeta() != null || targetStreams.get( 1 ).getStepMeta() != null;
return true;
Expand Down
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 Down Expand Up @@ -72,6 +72,10 @@ public class FilterRowsMeta extends BaseStepMeta implements StepMetaInterface {
*/
private Condition condition;

private String trueStepname;

private String falseStepname;

public FilterRowsMeta() {
super(); // allocate BaseStepMeta
condition = new Condition();
Expand Down Expand Up @@ -115,9 +119,9 @@ public Object clone() {
public String getXML() throws KettleException {
StringBuilder retval = new StringBuilder( 200 );

List<StreamInterface> targetStreams = getStepIOMeta().getTargetStreams();
retval.append( XMLHandler.addTagValue( "send_true_to", targetStreams.get( 0 ).getStepname() ) );
retval.append( XMLHandler.addTagValue( "send_false_to", targetStreams.get( 1 ).getStepname() ) );
retval.append( XMLHandler.addTagValue( "send_true_to", trueStepname ) );
retval.append( XMLHandler.addTagValue( "send_false_to", falseStepname ) );

retval.append( " <compare>" ).append( Const.CR );

if ( condition != null ) {
Expand All @@ -136,6 +140,9 @@ private void readData( Node stepnode ) throws KettleXMLException {
targetStreams.get( 0 ).setSubject( XMLHandler.getTagValue( stepnode, "send_true_to" ) );
targetStreams.get( 1 ).setSubject( XMLHandler.getTagValue( stepnode, "send_false_to" ) );

this.trueStepname = targetStreams.get( 0 ).getStepname();
this.falseStepname = targetStreams.get( 1 ).getStepname();

Node compare = XMLHandler.getSubNode( stepnode, "compare" );
Node condnode = XMLHandler.getSubNode( compare, "condition" );

Expand Down Expand Up @@ -203,6 +210,9 @@ public void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, Lis
targetStreams.get( 0 ).setSubject( rep.getStepAttributeString( id_step, "send_true_to" ) );
targetStreams.get( 1 ).setSubject( rep.getStepAttributeString( id_step, "send_false_to" ) );

this.trueStepname = targetStreams.get( 0 ).getStepname();
this.falseStepname = targetStreams.get( 1 ).getStepname();

condition = rep.loadConditionFromStepAttribute( id_step, "id_condition" );

} catch ( Exception e ) {
Expand All @@ -213,9 +223,13 @@ public void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, Lis

@Override
public void searchInfoAndTargetSteps( List<StepMeta> steps ) {
for ( StreamInterface stream : getStepIOMeta().getTargetStreams() ) {
List<StreamInterface> targetStreams = getStepIOMeta().getTargetStreams();
for ( StreamInterface stream : targetStreams ) {
stream.setStepMeta( StepMeta.findStep( steps, (String) stream.getSubject() ) );
}

this.trueStepname = targetStreams.get( 0 ).getStepname();
this.falseStepname = targetStreams.get( 1 ).getStepname();
}

public void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ) throws KettleException {
Expand Down Expand Up @@ -382,6 +396,7 @@ public void handleStreamSelection( StreamInterface stream ) {
StepMeta falseStep = targets.get( 1 ).getStepMeta();
if ( falseStep != null && falseStep.equals( stream.getStepMeta() ) ) {
targets.get( 1 ).setStepMeta( null );
this.falseStepname = null;
}
}
if ( index == 1 ) {
Expand All @@ -390,6 +405,7 @@ public void handleStreamSelection( StreamInterface stream ) {
StepMeta trueStep = targets.get( 0 ).getStepMeta();
if ( trueStep != null && trueStep.equals( stream.getStepMeta() ) ) {
targets.get( 0 ).setStepMeta( null );
this.trueStepname = null;
}
}
}
Expand Down Expand Up @@ -423,4 +439,19 @@ public List<String> getOrphanFields( Condition condition, RowMetaInterface prev
return orphans;
}

public String getTrueStepname() {
return trueStepname;
}

public void setTrueStepname( String trueStepname ) {
this.trueStepname = trueStepname;
}

public String getFalseStepname() {
return falseStepname;
}

public void setFalseStepname( String falseStepname ) {
this.falseStepname = falseStepname;
}
}
Expand Up @@ -28,6 +28,8 @@

import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import org.pentaho.di.core.Condition;
import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.plugins.PluginRegistry;
Expand Down Expand Up @@ -63,4 +65,20 @@ public void testSerialization() throws KettleException {
loadSaveTester.testSerialization();
}

@Test
public void testClone() {
FilterRowsMeta filterRowsMeta = new FilterRowsMeta();
filterRowsMeta.setCondition( new Condition() );
filterRowsMeta.setTrueStepname( "true" );
filterRowsMeta.setFalseStepname( "false" );

FilterRowsMeta clone = (FilterRowsMeta) filterRowsMeta.clone();
assertNotNull( clone.getCondition() );
assertNotNull( clone.getTrueStepname() );
assertTrue( "true" == clone.getTrueStepname() );
assertNotNull( clone.getFalseStepname() );
assertTrue( "false" == clone.getFalseStepname() );

}

}

0 comments on commit 2fa882a

Please sign in to comment.