From 8b96553757f2b546c44c53ef6c8a2e47f19e5963 Mon Sep 17 00:00:00 2001 From: Luc Boudreau Date: Wed, 24 Jan 2018 19:24:50 -0500 Subject: [PATCH] [CLEANUP] Reverts 6a5370073ab9d4b6f18f36abce89d9f0302bdefc 30fc3fc338d3f9d89a5444c802c8106e8de3216a 6cf0f2eff9fa762a51ea9bd72672cfbc2521dd0d --- .../java/org/pentaho/di/core/row/RowMeta.java | 22 +- .../java/org/pentaho/di/trans/TransMeta.java | 253 ++++++++---------- .../org/pentaho/di/trans/TransMetaTest.java | 50 +--- .../java/org/pentaho/di/ui/spoon/Spoon.java | 4 +- .../org/pentaho/di/ui/spoon/job/JobGraph.java | 60 ++--- .../pentaho/di/ui/spoon/trans/TransGraph.java | 67 ++--- .../di/ui/trans/dialog/TransHopDialog.java | 40 ++- 7 files changed, 203 insertions(+), 293 deletions(-) diff --git a/core/src/main/java/org/pentaho/di/core/row/RowMeta.java b/core/src/main/java/org/pentaho/di/core/row/RowMeta.java index 32538fb337c0..03230c74eec3 100644 --- a/core/src/main/java/org/pentaho/di/core/row/RowMeta.java +++ b/core/src/main/java/org/pentaho/di/core/row/RowMeta.java @@ -2,7 +2,7 @@ * * Pentaho Data Integration * - * Copyright (C) 2002-2018 by Hitachi Vantara : http://www.pentaho.com + * Copyright (C) 2002-2017 by Hitachi Vantara : http://www.pentaho.com * ******************************************************************************* * @@ -75,7 +75,8 @@ public RowMeta() { private RowMeta( RowMeta rowMeta, Integer targetType ) throws KettlePluginException { this( new ArrayList( rowMeta.valueMetaList.size() ), new RowMetaCache( rowMeta.cache ) ); for ( ValueMetaInterface valueMetaInterface : rowMeta.valueMetaList ) { - valueMetaList.add( ValueMetaFactory.cloneValueMeta( valueMetaInterface, targetType == null ? valueMetaInterface.getType() : targetType ) ); + valueMetaList.add( ValueMetaFactory + .cloneValueMeta( valueMetaInterface, targetType == null ? valueMetaInterface.getType() : targetType ) ); } this.needRealClone = rowMeta.needRealClone; } @@ -543,7 +544,6 @@ public int indexOfValue( String valueName ) { // but it makes no harm as they will put the same value, // because valueMetaList is defended from modifications by read lock cache.storeMapping( valueName, index ); - needRealClone = null; } } if ( index == null ) { @@ -730,7 +730,8 @@ public RowMeta( DataInputStream inputStream ) throws KettleFileException, Socket } catch ( SocketTimeoutException e ) { throw e; } catch ( EOFException e ) { - throw new KettleEOFException( "End of file while reading the number of metadata values in the row metadata", e ); + throw new KettleEOFException( + "End of file while reading the number of metadata values in the row metadata", e ); } catch ( IOException e ) { throw new KettleFileException( "Unable to read nr of metadata values: " + e.toString(), e ); } @@ -794,7 +795,8 @@ public void removeValueMeta( String valueName ) throws KettleValueException { try { int index = indexOfValue( valueName ); if ( index < 0 ) { - throw new KettleValueException( "Unable to find value metadata with name '" + valueName + "', so I can't delete it." ); + throw new KettleValueException( "Unable to find value metadata with name '" + + valueName + "', so I can't delete it." ); } removeValueMeta( index ); } finally { @@ -958,7 +960,8 @@ public boolean equals( Object[] rowData1, Object[] rowData2, int[] fieldnrs ) th * @throws KettleValueException */ @Override - public int compare( Object[] rowData1, Object[] rowData2, int[] fieldnrs1, int[] fieldnrs2 ) throws KettleValueException { + public int compare( Object[] rowData1, Object[] rowData2, int[] fieldnrs1, int[] fieldnrs2 ) + throws KettleValueException { int len = ( fieldnrs1.length < fieldnrs2.length ) ? fieldnrs1.length : fieldnrs2.length; lock.readLock().lock(); try { @@ -990,7 +993,8 @@ public int compare( Object[] rowData1, Object[] rowData2, int[] fieldnrs1, int[] * @throws KettleValueException */ @Override - public int compare( Object[] rowData1, RowMetaInterface rowMeta2, Object[] rowData2, int[] fieldnrs1, int[] fieldnrs2 ) throws KettleValueException { + public int compare( Object[] rowData1, RowMetaInterface rowMeta2, Object[] rowData2, int[] fieldnrs1, + int[] fieldnrs2 ) throws KettleValueException { int len = ( fieldnrs1.length < fieldnrs2.length ) ? fieldnrs1.length : fieldnrs2.length; lock.readLock().lock(); try { @@ -1197,7 +1201,8 @@ public RowMeta( Node node ) throws KettleException { int nrValues = XMLHandler.countNodes( node, ValueMeta.XML_META_TAG ); for ( int i = 0; i < nrValues; i++ ) { ValueMeta valueMetaSource = new ValueMeta( XMLHandler.getSubNodeByNr( node, ValueMeta.XML_META_TAG, i ) ); - ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta( valueMetaSource.getName(), valueMetaSource.getType(), valueMetaSource.getLength(), valueMetaSource.getPrecision() ); + ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta( valueMetaSource.getName(), valueMetaSource.getType(), + valueMetaSource.getLength(), valueMetaSource.getPrecision() ); ValueMetaFactory.cloneInfo( valueMetaSource, valueMeta ); addValueMeta( valueMeta ); } @@ -1310,3 +1315,4 @@ Integer findAndCompare( String name, List metas ) } } + diff --git a/engine/src/main/java/org/pentaho/di/trans/TransMeta.java b/engine/src/main/java/org/pentaho/di/trans/TransMeta.java index 1f83af6676e7..a3a8590d029f 100644 --- a/engine/src/main/java/org/pentaho/di/trans/TransMeta.java +++ b/engine/src/main/java/org/pentaho/di/trans/TransMeta.java @@ -3,7 +3,7 @@ * * Pentaho Data Integration * - * Copyright (C) 2002-2018 by Hitachi Vantara : http://www.pentaho.com + * Copyright (C) 2002-2017 by Hitachi Vantara : http://www.pentaho.com * ******************************************************************************* * @@ -23,6 +23,20 @@ package org.pentaho.di.trans; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.vfs2.FileName; import org.apache.commons.vfs2.FileObject; @@ -33,6 +47,7 @@ import org.pentaho.di.core.CheckResult; import org.pentaho.di.core.CheckResultInterface; import org.pentaho.di.core.Const; +import org.pentaho.di.core.util.Utils; import org.pentaho.di.core.Counter; import org.pentaho.di.core.DBCache; import org.pentaho.di.core.LastUsedFile; @@ -75,7 +90,6 @@ import org.pentaho.di.core.row.RowMetaInterface; import org.pentaho.di.core.row.ValueMetaInterface; import org.pentaho.di.core.util.StringUtil; -import org.pentaho.di.core.util.Utils; import org.pentaho.di.core.variables.VariableSpace; import org.pentaho.di.core.vfs.KettleVFS; import org.pentaho.di.core.xml.XMLFormatter; @@ -113,20 +127,6 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Hashtable; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - /** * This class defines information about a transformation and offers methods to save and load it from XML or a PDI * database repository, as well as methods to alter a transformation by adding/removing databases, steps, hops, etc. @@ -309,12 +309,12 @@ public enum TransformationType { /** A normal transformation. */ Normal( "Normal", BaseMessages.getString( PKG, "TransMeta.TransformationType.Normal" ) ), - /** A serial single-threaded transformation. */ - SerialSingleThreaded( "SerialSingleThreaded", BaseMessages.getString( + /** A serial single-threaded transformation. */ + SerialSingleThreaded( "SerialSingleThreaded", BaseMessages.getString( PKG, "TransMeta.TransformationType.SerialSingleThreaded" ) ), - /** A single-threaded transformation. */ - SingleThreaded( "SingleThreaded", BaseMessages + /** A single-threaded transformation. */ + SingleThreaded( "SingleThreaded", BaseMessages .getString( PKG, "TransMeta.TransformationType.SingleThreaded" ) ); /** The code corresponding to the transformation type. */ @@ -392,7 +392,8 @@ public static String[] getTransformationTypesDescriptions() { // ////////////////////////////////////////////////////////////////////////// /** A list of localized strings corresponding to string descriptions of the undo/redo actions. */ - public static final String[] desc_type_undo = { "", + public static final String[] desc_type_undo = { + "", BaseMessages.getString( PKG, "TransMeta.UndoTypeDesc.UndoChange" ), BaseMessages.getString( PKG, "TransMeta.UndoTypeDesc.UndoNew" ), BaseMessages.getString( PKG, "TransMeta.UndoTypeDesc.UndoDelete" ), @@ -839,15 +840,6 @@ public StepMeta getStep( int i ) { return steps.get( i ); } - /** - * Gets the trans hops. - * - * @return the trans hops - */ - public List getTransHops() { - return Collections.unmodifiableList( hops ); - } - /** * Retrieves a hop on a certain location (i.e. the specified index). * @@ -1116,8 +1108,8 @@ public TransHopMeta findTransHopFrom( StepMeta fromstep ) { public List findAllTransHopFrom( StepMeta fromstep ) { return hops.stream() - .filter( hop -> hop.getFromStep() != null && hop.getFromStep().equals( fromstep ) ) - .collect( Collectors.toList() ); + .filter( hop -> hop.getFromStep() != null && hop.getFromStep().equals( fromstep ) ) + .collect( Collectors.toList() ); } /** * Find a certain hop in the transformation. @@ -1760,7 +1752,6 @@ public RowMetaInterface getStepFields( StepMeta[] stepMeta ) throws KettleStepEx * the kettle step exception */ public RowMetaInterface getStepFields( StepMeta stepMeta, ProgressMonitorListener monitor ) throws KettleStepException { - clearStepFieldsCache(); setRepositoryOnMappingSteps(); return getStepFields( stepMeta, null, monitor ); } @@ -1912,17 +1903,6 @@ public RowMetaInterface getPrevStepFields( StepMeta stepMeta ) throws KettleStep */ public RowMetaInterface getPrevStepFields( StepMeta stepMeta, ProgressMonitorListener monitor ) throws KettleStepException { - // Required by current design. This cache is (or should be) a short-lived cache which gets mutated - // as the list of step fields is computed (e.g. adding the error fields when a step directs output to an error-handling - // step, and in other edge-cases). Clearing before recomputing is required, and since it's recursive, there's no elegant - // way to simply clear it after the fact. - // - // Suggest re-design. The stepFieldsCache isn't a cache at all - rather it's an intermediate result. Suggest creating the - // map when this process starts and pass it to the methods that require mutation of it. That way, there is no instance variable - // at all. This is out of scope for this fix. - // - // MB - clearStepFieldsCache(); RowMetaInterface row = new RowMeta(); if ( stepMeta == null ) { @@ -2399,8 +2379,8 @@ public String getXML( boolean includeSteps, boolean includeDatabase, boolean inc * if any errors occur during generation of the XML */ public String getXML( boolean includeSteps, boolean includeDatabase, boolean includeSlaves, boolean includeClusters, - boolean includePartitions, boolean includeNamedParameters, boolean includeLog, boolean includeDependencies, - boolean includeNotePads, boolean includeAttributeGroups ) throws KettleException { + boolean includePartitions, boolean includeNamedParameters, boolean includeLog, boolean includeDependencies, + boolean includeNotePads, boolean includeAttributeGroups ) throws KettleException { //Clear the embedded named clusters. We will be repopulating from steps that used named clusters getNamedClusterEmbedManager().clear(); @@ -2426,7 +2406,7 @@ public String getXML( boolean includeSteps, boolean includeDatabase, boolean inc retval.append( " " ).append( XMLHandler.addTagValue( "trans_status", trans_status ) ); } retval.append( " " ).append( XMLHandler.addTagValue( "directory", - directory != null ? directory.getPath() : RepositoryDirectory.DIRECTORY_SEPARATOR ) ); + directory != null ? directory.getPath() : RepositoryDirectory.DIRECTORY_SEPARATOR ) ); if ( includeNamedParameters ) { @@ -2436,9 +2416,9 @@ public String getXML( boolean includeSteps, boolean includeDatabase, boolean inc retval.append( " " ).append( XMLHandler.openTag( "parameter" ) ).append( Const.CR ); retval.append( " " ).append( XMLHandler.addTagValue( "name", parameters[idx] ) ); retval.append( " " ) - .append( XMLHandler.addTagValue( "default_value", getParameterDefault( parameters[idx] ) ) ); + .append( XMLHandler.addTagValue( "default_value", getParameterDefault( parameters[idx] ) ) ); retval.append( " " ) - .append( XMLHandler.addTagValue( "description", getParameterDescription( parameters[idx] ) ) ); + .append( XMLHandler.addTagValue( "description", getParameterDescription( parameters[idx] ) ) ); retval.append( " " ).append( XMLHandler.closeTag( "parameter" ) ).append( Const.CR ); } retval.append( " " ).append( XMLHandler.closeTag( XML_TAG_PARAMETERS ) ).append( Const.CR ); @@ -2644,7 +2624,7 @@ public TransMeta( String fname ) throws KettleXMLException, KettleMissingPlugins * in case missing plugins were found (details are in the exception in that case) */ public TransMeta( String fname, VariableSpace parentVariableSpace ) throws KettleXMLException, - KettleMissingPluginsException { + KettleMissingPluginsException { this( fname, null, true, parentVariableSpace ); } @@ -2662,7 +2642,7 @@ public TransMeta( String fname, VariableSpace parentVariableSpace ) throws Kettl * in case missing plugins were found (details are in the exception in that case) */ public TransMeta( String fname, boolean setInternalVariables ) throws KettleXMLException, - KettleMissingPluginsException { + KettleMissingPluginsException { this( fname, null, setInternalVariables ); } @@ -2697,7 +2677,7 @@ public TransMeta( String fname, Repository rep ) throws KettleXMLException, Kett * in case missing plugins were found (details are in the exception in that case) */ public TransMeta( String fname, Repository rep, boolean setInternalVariables ) throws KettleXMLException, - KettleMissingPluginsException { + KettleMissingPluginsException { this( fname, rep, setInternalVariables, null ); } @@ -2765,8 +2745,8 @@ public TransMeta( String fname, Repository rep, boolean setInternalVariables, Va * in case missing plugins were found (details are in the exception in that case) */ public TransMeta( String fname, IMetaStore metaStore, Repository rep, boolean setInternalVariables, - VariableSpace parentVariableSpace, OverwritePrompter prompter ) - throws KettleXMLException, KettleMissingPluginsException { + VariableSpace parentVariableSpace, OverwritePrompter prompter ) + throws KettleXMLException, KettleMissingPluginsException { this.metaStore = metaStore; this.repository = rep; @@ -2776,7 +2756,7 @@ public TransMeta( String fname, IMetaStore metaStore, Repository rep, boolean se doc = XMLHandler.loadXMLFile( KettleVFS.getFileObject( fname, parentVariableSpace ) ); } catch ( KettleFileException e ) { throw new KettleXMLException( BaseMessages.getString( - PKG, "TransMeta.Exception.ErrorOpeningOrValidatingTheXMLFile", fname ), e ); + PKG, "TransMeta.Exception.ErrorOpeningOrValidatingTheXMLFile", fname ), e ); } if ( doc != null ) { @@ -2785,7 +2765,7 @@ public TransMeta( String fname, IMetaStore metaStore, Repository rep, boolean se if ( transnode == null ) { throw new KettleXMLException( BaseMessages.getString( - PKG, "TransMeta.Exception.NotValidTransformationXML", fname ) ); + PKG, "TransMeta.Exception.NotValidTransformationXML", fname ) ); } // Load from this node... @@ -2793,7 +2773,7 @@ public TransMeta( String fname, IMetaStore metaStore, Repository rep, boolean se } else { throw new KettleXMLException( BaseMessages.getString( - PKG, "TransMeta.Exception.ErrorOpeningOrValidatingTheXMLFile", fname ) ); + PKG, "TransMeta.Exception.ErrorOpeningOrValidatingTheXMLFile", fname ) ); } } @@ -2816,8 +2796,8 @@ public TransMeta( String fname, IMetaStore metaStore, Repository rep, boolean se * in case missing plugins were found (details are in the exception in that case) */ public TransMeta( InputStream xmlStream, Repository rep, boolean setInternalVariables, - VariableSpace parentVariableSpace, OverwritePrompter prompter ) - throws KettleXMLException, KettleMissingPluginsException { + VariableSpace parentVariableSpace, OverwritePrompter prompter ) + throws KettleXMLException, KettleMissingPluginsException { Document doc = XMLHandler.loadXMLFile( xmlStream, null, false, false ); Node transnode = XMLHandler.getSubNode( doc, XML_TAG ); loadXML( transnode, rep, setInternalVariables, parentVariableSpace, prompter ); @@ -2855,7 +2835,7 @@ public TransMeta( Node transnode, Repository rep ) throws KettleXMLException, Ke * in case missing plugins were found (details are in the exception in that case) */ public void loadXML( Node transnode, Repository rep, boolean setInternalVariables ) throws KettleXMLException, - KettleMissingPluginsException { + KettleMissingPluginsException { loadXML( transnode, rep, setInternalVariables, null ); } @@ -2876,7 +2856,7 @@ public void loadXML( Node transnode, Repository rep, boolean setInternalVariable * in case missing plugins were found (details are in the exception in that case) */ public void loadXML( Node transnode, Repository rep, boolean setInternalVariables, VariableSpace parentVariableSpace ) - throws KettleXMLException, KettleMissingPluginsException { + throws KettleXMLException, KettleMissingPluginsException { loadXML( transnode, rep, setInternalVariables, parentVariableSpace, null ); } @@ -2924,8 +2904,8 @@ public void loadXML( Node transnode, Repository rep, boolean setInternalVariable * in case missing plugins were found (details are in the exception in that case) */ public void loadXML( Node transnode, String fname, Repository rep, boolean setInternalVariables, - VariableSpace parentVariableSpace, OverwritePrompter prompter ) - throws KettleXMLException, KettleMissingPluginsException { + VariableSpace parentVariableSpace, OverwritePrompter prompter ) + throws KettleXMLException, KettleMissingPluginsException { loadXML( transnode, fname, null, rep, setInternalVariables, parentVariableSpace, prompter ); } @@ -2950,13 +2930,13 @@ public void loadXML( Node transnode, String fname, Repository rep, boolean setIn * in case missing plugins were found (details are in the exception in that case) */ public void loadXML( Node transnode, String fname, IMetaStore metaStore, Repository rep, boolean setInternalVariables, - VariableSpace parentVariableSpace, OverwritePrompter prompter ) - throws KettleXMLException, KettleMissingPluginsException { + VariableSpace parentVariableSpace, OverwritePrompter prompter ) + throws KettleXMLException, KettleMissingPluginsException { KettleMissingPluginsException - missingPluginsException = - new KettleMissingPluginsException( - BaseMessages.getString( PKG, "TransMeta.MissingPluginsFoundWhileLoadingTransformation.Exception" ) ); + missingPluginsException = + new KettleMissingPluginsException( + BaseMessages.getString( PKG, "TransMeta.MissingPluginsFoundWhileLoadingTransformation.Exception" ) ); this.metaStore = metaStore; // Remember this as the primary meta store. @@ -2990,7 +2970,7 @@ public void loadXML( Node transnode, String fname, IMetaStore metaStore, Reposit sharedObjects = rep != null ? rep.readTransSharedObjects( this ) : readSharedObjects(); } catch ( Exception e ) { log - .logError( BaseMessages.getString( PKG, "TransMeta.ErrorReadingSharedObjects.Message", e.toString() ) ); + .logError( BaseMessages.getString( PKG, "TransMeta.ErrorReadingSharedObjects.Message", e.toString() ) ); log.logError( Const.getStackTracker( e ) ); } @@ -3276,7 +3256,7 @@ public void loadXML( Node transnode, String fname, IMetaStore metaStore, Reposit if ( !check.isShared() ) { // we don't overwrite shared objects. if ( shouldOverwrite( prompter, props, BaseMessages - .getString( PKG, "TransMeta.Message.OverwritePartitionSchemaYN", partitionSchema.getName() ), + .getString( PKG, "TransMeta.Message.OverwritePartitionSchemaYN", partitionSchema.getName() ), BaseMessages.getString( PKG, "TransMeta.Message.OverwriteConnection.DontShowAnyMoreMessage" ) ) ) { addOrReplacePartitionSchema( partitionSchema ); } @@ -3541,12 +3521,17 @@ public List getTransHopSteps( boolean all ) { public boolean isStepUsedInTransHops( StepMeta stepMeta ) { TransHopMeta fr = findTransHopFrom( stepMeta ); TransHopMeta to = findTransHopTo( stepMeta ); - return fr != null || to != null; + if ( fr != null || to != null ) { + return true; + } + return false; } /** * Checks if any selected step has been used in a hop or not. * + * @param stepMeta + * The step queried. * @return true if a step is used in a hop (active or not), false otherwise */ public boolean isAnySelectedStepUsedInTransHops() { @@ -3682,8 +3667,11 @@ public boolean hasChanged() { if ( havePartitionSchemasChanged() ) { return true; } - return haveClusterSchemasChanged(); + if ( haveClusterSchemasChanged() ) { + return true; + } + return false; } private boolean isErrorNode( Node errorHandingNode, Node checkNode ) { @@ -3730,28 +3718,7 @@ private boolean isErrorNode( Node errorHandingNode, Node checkNode ) { * @return true if a loop has been found, false if no loop is found. */ public boolean hasLoop( StepMeta stepMeta ) { - clearLoopCache(); - return hasLoop( stepMeta, null ); - } - - /** - * @deprecated use {@link #hasLoop(StepMeta, StepMeta)}} - */ - @Deprecated - public boolean hasLoop( StepMeta stepMeta, StepMeta lookup, boolean info ) { - return hasLoop( stepMeta, lookup, new HashSet() ); - } - - /** - * Checks for loop. - * - * @param stepMeta the stepmeta - * @param lookup the lookup - * @return true, if successful - */ - - public boolean hasLoop( StepMeta stepMeta, StepMeta lookup ) { - return hasLoop( stepMeta, lookup, new HashSet() ); + return hasLoop( stepMeta, null, true ) || hasLoop( stepMeta, null, false ); } /** @@ -3762,37 +3729,43 @@ public boolean hasLoop( StepMeta stepMeta, StepMeta lookup ) { * The step position to start looking * @param lookup * The original step when wandering around the transformation. - * @param checkedEntries - * Already checked entries + * @param info + * Check the informational steps or not. * * @return true if a loop has been found, false if no loop is found. */ - private boolean hasLoop( StepMeta stepMeta, StepMeta lookup, HashSet checkedEntries ) { - String cacheKey = - stepMeta.getName() + " - " + ( lookup != null ? lookup.getName() : "" ); - - Boolean hasLoop = loopCache.get( cacheKey ); - - if ( hasLoop != null ) { - return hasLoop; + private boolean hasLoop( StepMeta stepMeta, StepMeta lookup, boolean info ) { + String + cacheKey = + stepMeta.getName() + " - " + ( lookup != null ? lookup.getName() : "" ) + " - " + ( info ? "true" : "false" ); + Boolean loop = loopCache.get( cacheKey ); + if ( loop != null ) { + return loop.booleanValue(); } - hasLoop = false; - - checkedEntries.add( stepMeta ); - + boolean hasLoop = false; List prevSteps = findPreviousSteps( stepMeta, info ); int nr = prevSteps.size(); - for ( int i = 0; i < nr; i++ ) { + for ( int i = 0; i < nr && !hasLoop; i++ ) { StepMeta prevStepMeta = prevSteps.get( i ); - if ( prevStepMeta != null && ( prevStepMeta.equals( lookup ) - || ( !checkedEntries.contains( prevStepMeta ) && hasLoop( prevStepMeta, lookup == null ? stepMeta : lookup, checkedEntries ) ) ) ) { - hasLoop = true; - break; + if ( prevStepMeta != null ) { + if ( prevStepMeta.equals( stepMeta ) ) { + hasLoop = true; + break; // no need to check more but caching this one below + } else if ( prevStepMeta.equals( lookup ) ) { + hasLoop = true; + break; // no need to check more but caching this one below + } else if ( hasLoop( prevStepMeta, lookup == null ? stepMeta : lookup, info ) ) { + hasLoop = true; + break; // no need to check more but caching this one below + } } } - loopCache.put( cacheKey, hasLoop ); + // Store in the cache... + // + loopCache.put( cacheKey, Boolean.valueOf( hasLoop ) ); + return hasLoop; } @@ -4253,7 +4226,7 @@ public void sortHopsNatural() { public void analyseImpact( List impact, ProgressMonitorListener monitor ) throws KettleStepException { if ( monitor != null ) { monitor - .beginTask( BaseMessages.getString( PKG, "TransMeta.Monitor.DeterminingImpactTask.Title" ), nrSteps() ); + .beginTask( BaseMessages.getString( PKG, "TransMeta.Monitor.DeterminingImpactTask.Title" ), nrSteps() ); } boolean stop = false; for ( int i = 0; i < nrSteps() && !stop; i++ ) { @@ -4369,7 +4342,8 @@ public List getSQLStatements( ProgressMonitorListener monitor ) th if ( transLogTable.getDatabaseMeta() != null && ( !Utils.isEmpty( transLogTable.getTableName() ) || !Utils .isEmpty( performanceLogTable.getTableName() ) ) ) { try { - for ( LogTableInterface logTable : new LogTableInterface[] { transLogTable, performanceLogTable, channelLogTable, stepLogTable, } ) { + for ( LogTableInterface logTable : new LogTableInterface[] { transLogTable, performanceLogTable, + channelLogTable, stepLogTable, } ) { if ( logTable.getDatabaseMeta() != null && !Utils.isEmpty( logTable.getTableName() ) ) { Database db = null; @@ -4565,7 +4539,8 @@ public void checkSteps( List remarks, boolean only_selecte .getString( PKG, "TransMeta.Value.CheckingFieldName.FieldNameContainsSpaces.Description" ) ); } else { char[] list = - new char[] { '.', ',', '-', '/', '+', '*', '\'', '\t', '"', '|', '@', '(', ')', '{', '}', '!', '^' }; + new char[] { '.', ',', '-', '/', '+', '*', '\'', '\t', '"', '|', '@', '(', ')', '{', '}', '!', + '^' }; for ( int c = 0; c < list.length; c++ ) { if ( name.indexOf( list[c] ) >= 0 ) { values.put( v, BaseMessages.getString( PKG, @@ -5173,8 +5148,11 @@ public boolean isDatabaseConnectionUsed( DatabaseMeta databaseMeta ) { } } - return transLogTable.getDatabaseMeta() != null && transLogTable.getDatabaseMeta().equals( databaseMeta ); + if ( transLogTable.getDatabaseMeta() != null && transLogTable.getDatabaseMeta().equals( databaseMeta ) ) { + return true; + } + return false; } /** @@ -5638,8 +5616,8 @@ public void setInternalKettleVariables( VariableSpace var ) { } variables.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, - variables.getVariable( repository != null ? Const.INTERNAL_VARIABLE_TRANSFORMATION_REPOSITORY_DIRECTORY - : Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY ) ); + variables.getVariable( repository != null ? Const.INTERNAL_VARIABLE_TRANSFORMATION_REPOSITORY_DIRECTORY + : Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY ) ); } /** @@ -5689,7 +5667,7 @@ protected void setInternalFilenameKettleVariables( VariableSpace var ) { variables.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, variables.getVariable( repository != null ? Const.INTERNAL_VARIABLE_TRANSFORMATION_REPOSITORY_DIRECTORY - : Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY ) ); + : Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY ) ); } /** @@ -5706,7 +5684,7 @@ public StepMeta findMappingInputStep( String stepname ) throws KettleStepExcepti StepMeta stepMeta = findStep( stepname ); // TODO verify that it's a mapping input!! if ( stepMeta == null ) { throw new KettleStepException( BaseMessages.getString( - PKG, "TransMeta.Exception.StepNameNotFound", stepname ) ); + PKG, "TransMeta.Exception.StepNameNotFound", stepname ) ); } return stepMeta; } else { @@ -5718,13 +5696,13 @@ public StepMeta findMappingInputStep( String stepname ) throws KettleStepExcepti stepMeta = mappingStep; } else if ( stepMeta != null ) { throw new KettleStepException( BaseMessages.getString( - PKG, "TransMeta.Exception.OnlyOneMappingInputStepAllowed", "2" ) ); + PKG, "TransMeta.Exception.OnlyOneMappingInputStepAllowed", "2" ) ); } } } if ( stepMeta == null ) { throw new KettleStepException( BaseMessages.getString( - PKG, "TransMeta.Exception.OneMappingInputStepRequired" ) ); + PKG, "TransMeta.Exception.OneMappingInputStepRequired" ) ); } return stepMeta; } @@ -5744,7 +5722,7 @@ public StepMeta findMappingOutputStep( String stepname ) throws KettleStepExcept StepMeta stepMeta = findStep( stepname ); // TODO verify that it's a mapping output step. if ( stepMeta == null ) { throw new KettleStepException( BaseMessages.getString( - PKG, "TransMeta.Exception.StepNameNotFound", stepname ) ); + PKG, "TransMeta.Exception.StepNameNotFound", stepname ) ); } return stepMeta; } else { @@ -5756,13 +5734,13 @@ public StepMeta findMappingOutputStep( String stepname ) throws KettleStepExcept stepMeta = mappingStep; } else if ( stepMeta != null ) { throw new KettleStepException( BaseMessages.getString( - PKG, "TransMeta.Exception.OnlyOneMappingOutputStepAllowed", "2" ) ); + PKG, "TransMeta.Exception.OnlyOneMappingOutputStepAllowed", "2" ) ); } } } if ( stepMeta == null ) { throw new KettleStepException( BaseMessages.getString( - PKG, "TransMeta.Exception.OneMappingOutputStepRequired" ) ); + PKG, "TransMeta.Exception.OneMappingOutputStepRequired" ) ); } return stepMeta; } @@ -5775,8 +5753,8 @@ public StepMeta findMappingOutputStep( String stepname ) throws KettleStepExcept */ public List getResourceDependencies() { return steps.stream() - .flatMap( (StepMeta stepMeta) -> stepMeta.getResourceDependencies( this ).stream() ) - .collect( Collectors.toList() ); + .flatMap( (StepMeta stepMeta) -> stepMeta.getResourceDependencies( this ).stream() ) + .collect( Collectors.toList() ); } /** @@ -5812,9 +5790,9 @@ public String exportResources( VariableSpace space, Map2->3->main - TransMeta transMetaSpy = spy( transMeta ); - StepMeta stepMetaMain = createStepMeta( "mainStep" ); - StepMeta stepMeta2 = createStepMeta( "step2" ); - StepMeta stepMeta3 = createStepMeta( "step3" ); - when( transMetaSpy.findNrPrevSteps( stepMetaMain ) ).thenReturn( 1 ); - when( transMetaSpy.findPrevStep( stepMetaMain, 0 ) ).thenReturn( stepMeta2 ); - when( transMetaSpy.findNrPrevSteps( stepMeta2 ) ).thenReturn( 1 ); - when( transMetaSpy.findPrevStep( stepMeta2, 0 ) ).thenReturn( stepMeta3 ); - when( transMetaSpy.findNrPrevSteps( stepMeta3 ) ).thenReturn( 1 ); - when( transMetaSpy.findPrevStep( stepMeta3, 0 ) ).thenReturn( stepMetaMain ); - assertTrue( transMetaSpy.hasLoop( stepMetaMain ) ); - } - - @Test - public void testHasLoop_loopInPrevSteps() throws Exception { - //main->2->3->4->3 - TransMeta transMetaSpy = spy( transMeta ); - StepMeta stepMetaMain = createStepMeta( "mainStep" ); - StepMeta stepMeta2 = createStepMeta( "step2" ); - StepMeta stepMeta3 = createStepMeta( "step3" ); - StepMeta stepMeta4 = createStepMeta( "step4" ); - when( transMetaSpy.findNrPrevSteps( stepMetaMain ) ).thenReturn( 1 ); - when( transMetaSpy.findPrevStep( stepMetaMain, 0 ) ).thenReturn( stepMeta2 ); - when( transMetaSpy.findNrPrevSteps( stepMeta2 ) ).thenReturn( 1 ); - when( transMetaSpy.findPrevStep( stepMeta2, 0 ) ).thenReturn( stepMeta3 ); - when( transMetaSpy.findNrPrevSteps( stepMeta3 ) ).thenReturn( 1 ); - when( transMetaSpy.findPrevStep( stepMeta3, 0 ) ).thenReturn( stepMeta4 ); - when( transMetaSpy.findNrPrevSteps( stepMeta4 ) ).thenReturn( 1 ); - when( transMetaSpy.findPrevStep( stepMeta4, 0 ) ).thenReturn( stepMeta3 ); - //check no StackOverflow error - assertFalse( transMetaSpy.hasLoop( stepMetaMain ) ); - } - - private StepMeta createStepMeta( String name ) { - StepMeta stepMeta = mock( StepMeta.class ); - when( stepMeta.getName() ).thenReturn( name ); - return stepMeta; - } } diff --git a/ui/src/main/java/org/pentaho/di/ui/spoon/Spoon.java b/ui/src/main/java/org/pentaho/di/ui/spoon/Spoon.java index c48371bd56a3..37bd45dd69f3 100644 --- a/ui/src/main/java/org/pentaho/di/ui/spoon/Spoon.java +++ b/ui/src/main/java/org/pentaho/di/ui/spoon/Spoon.java @@ -3,7 +3,7 @@ * * Pentaho Data Integration * - * Copyright (C) 2002-2018 by Hitachi Vantara : http://www.pentaho.com + * Copyright (C) 2002-2017 by Hitachi Vantara : http://www.pentaho.com * ******************************************************************************* * @@ -3683,7 +3683,7 @@ public boolean checkIfHopAlreadyExists( TransMeta transMeta, TransHopMeta newHop public boolean performNewTransHopChecks( TransMeta transMeta, TransHopMeta newHop ) { boolean ok = true; - if ( transMeta.hasLoop( newHop.getToStep() ) ) { + if ( transMeta.hasLoop( newHop.getFromStep() ) || transMeta.hasLoop( newHop.getToStep() ) ) { MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR ); mb.setMessage( BaseMessages.getString( PKG, "TransGraph.Dialog.HopCausesLoop.Message" ) ); mb.setText( BaseMessages.getString( PKG, "TransGraph.Dialog.HopCausesLoop.Title" ) ); diff --git a/ui/src/main/java/org/pentaho/di/ui/spoon/job/JobGraph.java b/ui/src/main/java/org/pentaho/di/ui/spoon/job/JobGraph.java index ca4df1aeae14..7aa224d500a3 100644 --- a/ui/src/main/java/org/pentaho/di/ui/spoon/job/JobGraph.java +++ b/ui/src/main/java/org/pentaho/di/ui/spoon/job/JobGraph.java @@ -790,15 +790,6 @@ public void mouseDown( MouseEvent e ) { if ( hop != null ) { JobHopMeta before = (JobHopMeta) hop.clone(); hop.setEnabled( !hop.isEnabled() ); - if ( hop.isEnabled() && ( jobMeta.hasLoop( hop.getToEntry() ) ) ) { - MessageBox mb = new MessageBox( shell, SWT.CANCEL | SWT.OK | SWT.ICON_WARNING ); - mb.setMessage( BaseMessages.getString( PKG, "JobGraph.Dialog.LoopAfterHopEnabled.Message" ) ); - mb.setText( BaseMessages.getString( PKG, "JobGraph.Dialog.LoopAfterHopEnabled.Title" ) ); - int choice = mb.open(); - if ( choice == SWT.CANCEL ) { - hop.setEnabled( false ); - } - } JobHopMeta after = (JobHopMeta) hop.clone(); spoon.addUndoChange( jobMeta, new JobHopMeta[] { before }, new JobHopMeta[] { after }, new int[] { jobMeta @@ -2127,7 +2118,7 @@ public void flipHop() { currentHop.setToEntry( origFrom ); boolean cancel = false; - if ( jobMeta.hasLoop( currentHop.getToEntry() ) ) { + if ( jobMeta.hasLoop( currentHop.getFromEntry() ) || jobMeta.hasLoop( currentHop.getToEntry() ) ) { MessageBox mb = new MessageBox( shell, SWT.OK | SWT.CANCEL | SWT.ICON_WARNING ); mb.setMessage( BaseMessages.getString( PKG, "JobGraph.Dialog.HopFlipCausesLoop.Message" ) ); mb.setText( BaseMessages.getString( PKG, "JobGraph.Dialog.HopCausesLoop.Title" ) ); @@ -2151,7 +2142,7 @@ public void disableHop() { boolean orig = currentHop.isEnabled(); currentHop.setEnabled( !currentHop.isEnabled() ); - if ( !orig && ( jobMeta.hasLoop( currentHop.getToEntry() ) ) ) { + if ( !orig && ( jobMeta.hasLoop( currentHop.getFromEntry() ) || jobMeta.hasLoop( currentHop.getToEntry() ) ) ) { MessageBox mb = new MessageBox( shell, SWT.CANCEL | SWT.OK | SWT.ICON_WARNING ); mb.setMessage( BaseMessages.getString( PKG, "JobGraph.Dialog.LoopAfterHopEnabled.Message" ) ); mb.setText( BaseMessages.getString( PKG, "JobGraph.Dialog.LoopAfterHopEnabled.Title" ) ); @@ -2223,7 +2214,7 @@ public void enableHopsBetweenSelectedEntries( boolean enabled ) { JobHopMeta after = (JobHopMeta) hop.clone(); spoon.addUndoChange( jobMeta, new JobHopMeta[] { before }, new JobHopMeta[] { after }, new int[] { jobMeta .indexOfJobHop( hop ) } ); - if ( jobMeta.hasLoop( hop.getToEntry() ) ) { + if ( jobMeta.hasLoop( hop.getFromEntry() ) || jobMeta.hasLoop( hop.getToEntry() ) ) { hasLoop = true; } } @@ -2251,41 +2242,36 @@ public void enableDisableHopsDownstream( boolean enabled ) { if ( currentHop == null ) { return; } + JobHopMeta before = (JobHopMeta) currentHop.clone(); currentHop.setEnabled( enabled ); JobHopMeta after = (JobHopMeta) currentHop.clone(); spoon.addUndoChange( jobMeta, new JobHopMeta[] { before }, new JobHopMeta[] { after }, new int[] { jobMeta .indexOfJobHop( currentHop ) } ); - Set checkedEntries = enableDisableNextHops( currentHop.getToEntry(), enabled, new HashSet<>() ); - - if ( checkedEntries.stream().anyMatch( entry -> jobMeta.hasLoop( entry ) ) ) { - MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_WARNING ); - mb.setMessage( BaseMessages.getString( PKG, "JobGraph.Dialog.LoopAfterHopEnabled.Message" ) ); - mb.setText( BaseMessages.getString( PKG, "JobGraph.Dialog.LoopAfterHopEnabled.Title" ) ); - mb.open(); - } + enableDisableNextHops( currentHop.getToEntry(), enabled, 1 ); spoon.refreshGraph(); } - private Set enableDisableNextHops( JobEntryCopy from, boolean enabled, Set checkedEntries ) { - checkedEntries.add( from ); - jobMeta.getJobhops().stream() - .filter( hop -> from.equals( hop.getFromEntry() ) ) - .forEach( hop -> { - if ( hop.isEnabled() != enabled ) { - JobHopMeta before = (JobHopMeta) hop.clone(); - hop.setEnabled( enabled ); - JobHopMeta after = (JobHopMeta) hop.clone(); - spoon.addUndoChange( jobMeta, new JobHopMeta[]{ before }, new JobHopMeta[]{ after }, new int[]{ jobMeta - .indexOfJobHop( hop ) } ); - } - if ( !checkedEntries.contains( hop.getToEntry() ) ) { - enableDisableNextHops( hop.getToEntry(), enabled, checkedEntries ); - } - } ); - return checkedEntries; + private void enableDisableNextHops( JobEntryCopy from, boolean enabled, int level ) { + + if ( level > 100 ) { + return; // prevent endless running with loops in jobs + } + + for ( JobEntryCopy to : jobMeta.getJobCopies() ) { + JobHopMeta hop = jobMeta.findJobHop( from, to, true ); + if ( hop != null ) { + JobHopMeta before = (JobHopMeta) hop.clone(); + hop.setEnabled( enabled ); + JobHopMeta after = (JobHopMeta) hop.clone(); + spoon.addUndoChange( jobMeta, new JobHopMeta[] { before }, new JobHopMeta[] { after }, new int[] { jobMeta + .indexOfJobHop( hop ) } ); + + enableDisableNextHops( to, enabled, level++ ); + } + } } protected void setToolTip( int x, int y, int screenX, int screenY ) { diff --git a/ui/src/main/java/org/pentaho/di/ui/spoon/trans/TransGraph.java b/ui/src/main/java/org/pentaho/di/ui/spoon/trans/TransGraph.java index df3d10348a13..7b8f26f0dbb6 100644 --- a/ui/src/main/java/org/pentaho/di/ui/spoon/trans/TransGraph.java +++ b/ui/src/main/java/org/pentaho/di/ui/spoon/trans/TransGraph.java @@ -3,7 +3,7 @@ * * Pentaho Data Integration * - * Copyright (C) 2002-2018 by Hitachi Vantara : http://www.pentaho.com + * Copyright (C) 2002-2017 by Hitachi Vantara : http://www.pentaho.com * ******************************************************************************* * @@ -981,13 +981,6 @@ public void mouseDown( MouseEvent e ) { if ( hop != null ) { TransHopMeta before = (TransHopMeta) hop.clone(); hop.setEnabled( !hop.isEnabled() ); - if ( hop.isEnabled() && transMeta.hasLoop( hop.getToStep() ) ) { - hop.setEnabled( false ); - MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR ); - mb.setMessage( BaseMessages.getString( PKG, "TransGraph.Dialog.HopCausesLoop.Message" ) ); - mb.setText( BaseMessages.getString( PKG, "TransGraph.Dialog.HopCausesLoop.Title" ) ); - mb.open(); - } TransHopMeta after = (TransHopMeta) hop.clone(); spoon.addUndoChange( transMeta, new TransHopMeta[] { before }, new TransHopMeta[] { after }, new int[] { transMeta.indexOfTransHop( hop ) } ); @@ -2359,7 +2352,7 @@ public void flipHopDirection() { TransHopMeta hi = getCurrentHop(); hi.flip(); - if ( transMeta.hasLoop( hi.getToStep() ) ) { + if ( transMeta.hasLoop( hi.getFromStep() ) ) { spoon.refreshGraph(); MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR ); mb.setMessage( BaseMessages.getString( PKG, "TransGraph.Dialog.LoopsAreNotAllowed.Message" ) ); @@ -2381,8 +2374,8 @@ public void enableHop() { TransHopMeta hi = getCurrentHop(); TransHopMeta before = (TransHopMeta) hi.clone(); hi.setEnabled( !hi.isEnabled() ); - if ( hi.isEnabled() && transMeta.hasLoop( hi.getToStep() ) ) { - hi.setEnabled( false ); + if ( transMeta.hasLoop( hi.getToStep() ) ) { + hi.setEnabled( !hi.isEnabled() ); MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR ); mb.setMessage( BaseMessages.getString( PKG, "TransGraph.Dialog.LoopAfterHopEnabled.Message" ) ); mb.setText( BaseMessages.getString( PKG, "TransGraph.Dialog.LoopAfterHopEnabled.Title" ) ); @@ -2426,8 +2419,6 @@ public void disableHopsBetweenSelectedSteps() { public void enableHopsBetweenSelectedSteps( boolean enabled ) { List list = transMeta.getSelectedSteps(); - boolean hasLoop = false; - for ( int i = 0; i < transMeta.nrTransHops(); i++ ) { TransHopMeta hop = transMeta.getTransHop( i ); if ( list.contains( hop.getFromStep() ) && list.contains( hop.getToStep() ) ) { @@ -2437,20 +2428,9 @@ public void enableHopsBetweenSelectedSteps( boolean enabled ) { TransHopMeta after = (TransHopMeta) hop.clone(); spoon.addUndoChange( transMeta, new TransHopMeta[] { before }, new TransHopMeta[] { after }, new int[] { transMeta.indexOfTransHop( hop ) } ); - if ( transMeta.hasLoop( hop.getToStep() ) ) { - hasLoop = true; - hop.setEnabled( false ); - } } } - if ( enabled && hasLoop ) { - MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR ); - mb.setMessage( BaseMessages.getString( PKG, "TransGraph.Dialog.HopCausesLoop.Message" ) ); - mb.setText( BaseMessages.getString( PKG, "TransGraph.Dialog.HopCausesLoop.Title" ) ); - mb.open(); - } - spoon.refreshGraph(); } @@ -2473,35 +2453,24 @@ public void enableDisableHopsDownstream( boolean enabled ) { spoon.addUndoChange( transMeta, new TransHopMeta[] { before }, new TransHopMeta[] { after }, new int[] { transMeta .indexOfTransHop( currentHop ) } ); - Set checkedEntries = enableDisableNextHops( currentHop.getToStep(), enabled, new HashSet<>() ); - - if ( checkedEntries.stream().anyMatch( entry -> transMeta.hasLoop( entry ) ) ) { - MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR ); - mb.setMessage( BaseMessages.getString( PKG, "TransGraph.Dialog.HopCausesLoop.Message" ) ); - mb.setText( BaseMessages.getString( PKG, "TransGraph.Dialog.HopCausesLoop.Title" ) ); - mb.open(); - } + enableDisableNextHops( currentHop.getToStep(), enabled ); spoon.refreshGraph(); } - private Set enableDisableNextHops( StepMeta from, boolean enabled, Set checkedEntries ) { - checkedEntries.add( from ); - transMeta.getTransHops().stream() - .filter( hop -> from.equals( hop.getFromStep() ) ) - .forEach( hop -> { - if ( hop.isEnabled() != enabled ) { - TransHopMeta before = (TransHopMeta) hop.clone(); - hop.setEnabled( enabled ); - TransHopMeta after = (TransHopMeta) hop.clone(); - spoon.addUndoChange( transMeta, new TransHopMeta[]{ before }, new TransHopMeta[]{ after }, new int[]{ transMeta - .indexOfTransHop( hop ) } ); - } - if ( !checkedEntries.contains( hop.getToStep() ) ) { - enableDisableNextHops( hop.getToStep(), enabled, checkedEntries ); - } - } ); - return checkedEntries; + private void enableDisableNextHops( StepMeta from, boolean enabled ) { + for ( StepMeta to : transMeta.getSteps() ) { + TransHopMeta hop = transMeta.findTransHop( from, to, true ); + if ( hop != null ) { + TransHopMeta before = (TransHopMeta) hop.clone(); + hop.setEnabled( enabled ); + TransHopMeta after = (TransHopMeta) hop.clone(); + spoon.addUndoChange( transMeta, new TransHopMeta[] { before }, new TransHopMeta[] { after }, + new int[] { transMeta.indexOfTransHop( hop ) } ); + + enableDisableNextHops( to, enabled ); + } + } } public void editNote() { diff --git a/ui/src/main/java/org/pentaho/di/ui/trans/dialog/TransHopDialog.java b/ui/src/main/java/org/pentaho/di/ui/trans/dialog/TransHopDialog.java index 44745392fec9..32b5dee60ca1 100644 --- a/ui/src/main/java/org/pentaho/di/ui/trans/dialog/TransHopDialog.java +++ b/ui/src/main/java/org/pentaho/di/ui/trans/dialog/TransHopDialog.java @@ -2,7 +2,7 @@ * * Pentaho Data Integration * - * Copyright (C) 2002-2018 by Hitachi Vantara : http://www.pentaho.com + * Copyright (C) 2002-2017 by Hitachi Vantara : http://www.pentaho.com * ******************************************************************************* * @@ -294,18 +294,7 @@ private void ok() { input.setFromStep( transMeta.findStep( wFrom.getText() ) ); input.setToStep( transMeta.findStep( wTo.getText() ) ); - if ( input.getFromStep() == null || input.getToStep() == null ) { - MessageBox mb = new MessageBox( shell, SWT.YES | SWT.ICON_WARNING ); - mb.setMessage( BaseMessages.getString( PKG, "TransHopDialog.StepDoesNotExist.DialogMessage", input.getFromStep() == null ? wFrom - .getText() : wTo.getText() ) ); - mb.setText( BaseMessages.getString( PKG, "TransHopDialog.StepDoesNotExist.DialogTitle" ) ); - mb.open(); - } else if ( input.getFromStep().equals( input.getToStep() ) ) { - MessageBox mb = new MessageBox( shell, SWT.YES | SWT.ICON_WARNING ); - mb.setMessage( BaseMessages.getString( PKG, "TransHopDialog.CannotGoToSameStep.DialogMessage" ) ); - mb.setText( BaseMessages.getString( PKG, "TransHopDialog.CannotGoToSameStep.DialogTitle" ) ); - mb.open(); - } else if ( transMeta.hasLoop( input.getToStep() ) ) { + if ( transMeta.hasLoop( input.getFromStep() ) ) { input.setFromStep( fromBackup ); input.setToStep( toBackup ); MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR ); @@ -313,7 +302,30 @@ private void ok() { mb.setText( BaseMessages.getString( PKG, "TransHopDialog.LoopsNotAllowed.DialogTitle" ) ); mb.open(); } else { - dispose(); + if ( input.getFromStep() == null ) { + MessageBox mb = new MessageBox( shell, SWT.YES | SWT.ICON_WARNING ); + mb.setMessage( BaseMessages.getString( PKG, "TransHopDialog.StepDoesNotExist.DialogMessage", wFrom + .getText() ) ); + mb.setText( BaseMessages.getString( PKG, "TransHopDialog.StepDoesNotExist.DialogTitle" ) ); + mb.open(); + } else { + if ( input.getToStep() == null ) { + MessageBox mb = new MessageBox( shell, SWT.YES | SWT.ICON_WARNING ); + mb.setMessage( BaseMessages.getString( PKG, "TransHopDialog.StepDoesNotExist.DialogMessage", wTo + .getText() ) ); + mb.setText( BaseMessages.getString( PKG, "TransHopDialog.StepDoesNotExist.DialogTitle" ) ); + mb.open(); + } else { + if ( input.getFromStep().equals( input.getToStep() ) ) { + MessageBox mb = new MessageBox( shell, SWT.YES | SWT.ICON_WARNING ); + mb.setMessage( BaseMessages.getString( PKG, "TransHopDialog.CannotGoToSameStep.DialogMessage" ) ); + mb.setText( BaseMessages.getString( PKG, "TransHopDialog.CannotGoToSameStep.DialogTitle" ) ); + mb.open(); + } else { + dispose(); + } + } + } } }