Skip to content

Commit

Permalink
[BACKLOG-13475] Fix misspelled MDI Key with migration code (#3388)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderBuloichik authored and Ben Morrise committed Jan 19, 2017
1 parent 52eaed4 commit 346895d
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 16 deletions.
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2016 by Pentaho : http://www.pentaho.com
* Copyright (C) 2002-2017 by Pentaho : http://www.pentaho.com
*
*******************************************************************************
*
Expand Down Expand Up @@ -104,8 +104,8 @@ public class GetTableNamesMeta extends BaseStepMeta implements StepMetaInterface
@Injection( name = "DYNAMICSCHEMA", group = "FIELDS" )
private boolean dynamicSchema;

@Injection( name = "SCHENAMENAMEFIELD", group = "FIELDS" )
private String schenameNameField;
@Injection( name = "SCHEMANAMEFIELD", group = "FIELDS" )
private String schemaNameField;

private List<? extends SharedObjectInterface> databases;

Expand Down Expand Up @@ -212,15 +212,15 @@ public String isSystemObjectFieldName() {
* @return Returns the schenameNameField.
*/
public String getSchemaFieldName() {
return schenameNameField;
return schemaNameField;
}

/**
* @param schenameNameField
* teh schenameNameField to set.
* The schemaNameField to set.
*/
public void setSchemaFieldName( String schenameNameField ) {
this.schenameNameField = schenameNameField;
public void setSchemaFieldName( String schemaNameField ) {
this.schemaNameField = schemaNameField;
}

public void setIncludeTable( boolean includetable ) {
Expand Down Expand Up @@ -317,7 +317,7 @@ public void setDefault() {
objecttypefieldname = "type";
issystemobjectfieldname = "is system";
dynamicSchema = false;
schenameNameField = null;
schemaNameField = null;
}

public void getFields( RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep,
Expand Down Expand Up @@ -374,7 +374,7 @@ public String getXML() {
retval.append( " " + XMLHandler.addTagValue( "includeSynonym", includeSynonym ) );
retval.append( " " + XMLHandler.addTagValue( "addSchemaInOutput", addSchemaInOutput ) );
retval.append( " " + XMLHandler.addTagValue( "dynamicSchema", dynamicSchema ) );
retval.append( " " + XMLHandler.addTagValue( "schenameNameField", schenameNameField ) );
retval.append( " " + XMLHandler.addTagValue( "schemaNameField", schemaNameField ) );

return retval.toString();
}
Expand All @@ -398,7 +398,15 @@ private void readData( Node stepnode, List<? extends SharedObjectInterface> data
includeSynonym = "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, "includeSynonym" ) );
addSchemaInOutput = "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, "addSchemaInOutput" ) );
dynamicSchema = "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, "dynamicSchema" ) );
schenameNameField = XMLHandler.getTagValue( stepnode, "schenameNameField" );
schemaNameField = XMLHandler.getTagValue( stepnode, "schemaNameField" );

if ( XMLHandler.getTagValue( stepnode, "schenameNameField" ) != null ) {
/*
* Fix for wrong field name in the 7.0. Can be removed if we don't want to keep backward compatibility with 7.0
* tranformations.
*/
schemaNameField = XMLHandler.getTagValue( stepnode, "schenameNameField" );
}
} catch ( Exception e ) {
throw new KettleXMLException( BaseMessages.getString(
PKG, "GetTableNamesMeta.Exception.UnableToReadStepInfo" ), e );
Expand All @@ -423,7 +431,15 @@ public void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, Lis
includeSynonym = rep.getStepAttributeBoolean( id_step, "includeSynonym" );
addSchemaInOutput = rep.getStepAttributeBoolean( id_step, "addSchemaInOutput" );
dynamicSchema = rep.getStepAttributeBoolean( id_step, "dynamicSchema" );
schenameNameField = rep.getStepAttributeString( id_step, "schenameNameField" );
schemaNameField = rep.getStepAttributeString( id_step, "schemaNameField" );

if ( rep.getStepAttributeString( id_step, "schenameNameField" ) != null ) {
/*
* Fix for wrong field name in the 7.0. Can be removed if we don't want to keep backward compatibility with 7.0
* tranformations.
*/
schemaNameField = rep.getStepAttributeString( id_step, "schenameNameField" );
}
} catch ( Exception e ) {
throw new KettleException( BaseMessages.getString(
PKG, "GetTableNamesMeta.Exception.UnexpectedErrorReadingStepInfo" ), e );
Expand Down Expand Up @@ -451,7 +467,7 @@ public void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transform
rep.saveStepAttribute( id_transformation, id_step, "includeSynonym", includeSynonym );
rep.saveStepAttribute( id_transformation, id_step, "addSchemaInOutput", addSchemaInOutput );
rep.saveStepAttribute( id_transformation, id_step, "dynamicSchema", dynamicSchema );
rep.saveStepAttribute( id_transformation, id_step, "schenameNameField", schenameNameField );
rep.saveStepAttribute( id_transformation, id_step, "schemaNameField", schemaNameField );
} catch ( Exception e ) {
throw new KettleException( BaseMessages.getString( PKG, "GetTableNamesMeta.Exception.UnableToSaveStepInfo" )
+ id_step, e );
Expand Down
Expand Up @@ -82,7 +82,7 @@ GetTableNames.Injection.CONNECTIONNAME=The name of the database connection to ge
GetTableNames.Injection.FIELDS=Fields
GetTableNames.Injection.SCHEMANAME=The name of the database schema to use.
GetTableNames.Injection.DYNAMICSCHEMA=Set this option to get the schema name from a field in a previous step.
GetTableNames.Injection.SCHENAMENAMEFIELD=The name of the field to get the schema name from.
GetTableNames.Injection.SCHEMANAMEFIELD=The name of the field to get the schema name from.
GetTableNames.Injection.SETTINGS=Settings
GetTableNames.Injection.INCLUDECATALOG=Include catalogs in the output.
GetTableNames.Injection.INCLUDESCHEMA=Include schema list in the output.
Expand Down
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2016 by Pentaho : http://www.pentaho.com
* Copyright (C) 2002-2017 by Pentaho : http://www.pentaho.com
*
*******************************************************************************
*
Expand Down Expand Up @@ -98,7 +98,7 @@ public boolean get() {
return meta.isDynamicSchema();
}
} );
check( "SCHENAMENAMEFIELD", new StringGetter() {
check( "SCHEMANAMEFIELD", new StringGetter() {
public String get() {
return meta.getSchemaFieldName();
}
Expand Down
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2016 by Pentaho : http://www.pentaho.com
* Copyright (C) 2002-2017 by Pentaho : http://www.pentaho.com
*
*******************************************************************************
*
Expand Down Expand Up @@ -274,6 +274,8 @@ public void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore met
SourceStepField source = new SourceStepField( sourceStepname, sourceField );
targetSourceMapping.put( target, source );
}

MetaInjectMigration.migrateFrom70( targetSourceMapping );
} catch ( Exception e ) {
throw new KettleXMLException( "Unable to load step info from XML", e );
}
Expand Down Expand Up @@ -319,6 +321,8 @@ public void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, Lis
SourceStepField source = new SourceStepField( sourceStepname, sourceField );
targetSourceMapping.put( target, source );
}

MetaInjectMigration.migrateFrom70( targetSourceMapping );
} catch ( Exception e ) {
throw new KettleException( "Unexpected error reading step information from the repository", e );
}
Expand Down
@@ -0,0 +1,50 @@
/*! ******************************************************************************
*
* Pentaho Data Integration
*
* Copyright (C) 2017 by Pentaho : http://www.pentaho.com
*
*******************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/

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

import java.util.ArrayList;
import java.util.Map;

/**
* This class converts old mapping info into new one.
*
* @author Alexander Buloichik
*/
public class MetaInjectMigration {
/**
* Migrate mapping from 7.0 version.
*/
public static void migrateFrom70( Map<TargetStepAttribute, SourceStepField> targetSourceMapping ) {
/*
* Need to convert GetTableNamesMeta.SCHENAMENAMEFIELD to the GetTableNamesMeta.SCHEMANAMEFIELD
*/
for ( TargetStepAttribute target : new ArrayList<>( targetSourceMapping.keySet() ) ) {
if ( "SCHENAMENAMEFIELD".equals( target.getAttributeKey() ) ) {
SourceStepField so = targetSourceMapping.remove( target );
TargetStepAttribute target2 =
new TargetStepAttribute( target.getStepname(), "SCHEMANAMEFIELD", target.isDetail() );
targetSourceMapping.put( target2, so );
}
}
}
}
@@ -0,0 +1,50 @@
/*! ******************************************************************************
*
* Pentaho Data Integration
*
* Copyright (C) 2017 by Pentaho : http://www.pentaho.com
*
*******************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/

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

import static org.junit.Assert.assertEquals;

import java.util.HashMap;
import java.util.Map;

import org.junit.Test;

public class MetaInjectMigrationTest {
@Test
public void test70() {
Map<TargetStepAttribute, SourceStepField> targetSourceMapping = new HashMap<>();
TargetStepAttribute target = new TargetStepAttribute( "step", "SCHENAMENAMEFIELD", true );
SourceStepField source = new SourceStepField( "step", "field" );
targetSourceMapping.put( target, source );

MetaInjectMigration.migrateFrom70( targetSourceMapping );

assertEquals( 1, targetSourceMapping.size() );
TargetStepAttribute target2 = targetSourceMapping.keySet().iterator().next();
assertEquals( "SCHEMANAMEFIELD", target2.getAttributeKey() );
assertEquals( target.getStepname(), target2.getStepname() );
assertEquals( target.isDetail(), target2.isDetail() );

assertEquals( source, targetSourceMapping.get( target2 ) );
}
}

0 comments on commit 346895d

Please sign in to comment.