/** * The longer the hop, the higher the force * * @param hopMeta * @param locations * @return */ private Force getHookeAttraction( TransHopMeta hopMeta, Map<StepMeta, StepLocation> locations ) { StepLocation loc1 = locations.get( hopMeta.getFromStep() ); StepLocation loc2 = locations.get( hopMeta.getToStep() ); double springConstant = 0.01; double fx = springConstant * Math.abs( loc1.x - loc2.x ); double fy = springConstant * Math.abs( loc1.y - loc2.y ); return new Force( fx * fx, fy * fy ); }
/** * Search all hops for a hop where a certain step is at the end. * * @param tostep * The step at the end of the hop. * @return The hop or null if no hop was found. */ public TransHopMeta findTransHopTo( StepMeta tostep ) { int i; for ( i = 0; i < nrTransHops(); i++ ) { TransHopMeta hi = getTransHop( i ); if ( hi.getToStep() != null && hi.getToStep().equals( tostep ) ) { // Return the first! return hi; } } return null; }
/** * Find a certain hop in the transformation. * * @param hi * The hop information to look for. * @return The hop or null if no hop was found. */ public TransHopMeta findTransHop( TransHopMeta hi ) { return findTransHop( hi.getFromStep(), hi.getToStep() ); }
private void drawHop( TransHopMeta hi, boolean isCandidate ) { StepMeta fs = hi.getFromStep(); StepMeta ts = hi.getToStep(); if ( fs != null && ts != null ) { drawLine( fs, ts, hi, isCandidate ); } }
/** * Removes input steps having only disabled output hops so they will not be executed. * @param transMeta transMeta to process */ private static void removeDisabledInputs( TransMeta transMeta ) { List<StepMeta> unusedInputs = findHops( transMeta, hop -> !hop.isEnabled() ).stream() .map( hop -> hop.getFromStep() ) .filter( step -> isUnusedInput( transMeta, step ) ) .collect( Collectors.toList() ); for ( StepMeta unusedInput : unusedInputs ) { List<TransHopMeta> outHops = transMeta.findAllTransHopFrom( unusedInput ); List<StepMeta> subsequentSteps = outHops.stream().map( hop -> hop.getToStep() ).collect( Collectors.toList() ); outHops.forEach( transMeta::removeTransHop ); transMeta.getSteps().remove( unusedInput ); removeInactivePaths( transMeta, subsequentSteps ); } }
/** * Retrieve an array of succeeding steps for a certain originating step. * * @param stepMeta * The originating step * @return an array of succeeding steps. * @deprecated use findNextSteps instead */ @Deprecated public StepMeta[] getNextSteps( StepMeta stepMeta ) { List<StepMeta> nextSteps = new ArrayList<>(); for ( int i = 0; i < nrTransHops(); i++ ) { // Look at all the hops; TransHopMeta hi = getTransHop( i ); if ( hi.isEnabled() && hi.getFromStep().equals( stepMeta ) ) { nextSteps.add( hi.getToStep() ); } } return nextSteps.toArray( new StepMeta[nextSteps.size()] ); }
public boolean equals( Object obj ) { TransHopMeta other = (TransHopMeta) obj; if ( this.from == null || this.to == null ) { return false; } return this.from.equals( other.getFromStep() ) && this.to.equals( other.getToStep() ); }
/** * Copy information from the meta-data input to the dialog fields. */ public void getData() { if ( input.getFromStep() != null ) { wFrom.setText( input.getFromStep().getName() ); } if ( input.getToStep() != null ) { wTo.setText( input.getToStep().getName() ); } wEnabled.setSelection( input.isEnabled() ); }
private Set<StepMeta> enableDisableNextHops( StepMeta from, boolean enabled, Set<StepMeta> checkedEntries ) { checkedEntries.add( from ); transMeta.getTransHops().stream() .filter( hop -> from.equals( hop.getFromStep() ) ) .forEach( hop -> { if ( hop.isEnabled() != enabled ) { TransHopMeta before = (TransHopMeta) hop.clone(); setHopEnabled( hop, 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 static Consumer<TransHopMeta> createHop( org.pentaho.di.engine.model.Transformation transformation ) { return hop -> { try { Operation from = getOp( transformation, hop.getFromStep() ); Operation to = getOp( transformation, hop.getToStep() ); transformation.createHop( from, to, hop.isErrorHop() ? Hop.TYPE_ERROR : Hop.TYPE_NORMAL ); } catch ( KettleException e ) { Throwables.propagate( e ); } }; }
/** * Retrieve a list of succeeding steps for a certain originating step. * * @param stepMeta * The originating step * @return an array of succeeding steps. */ public List<StepMeta> findNextSteps( StepMeta stepMeta ) { List<StepMeta> nextSteps = new ArrayList<>(); for ( int i = 0; i < nrTransHops(); i++ ) { // Look at all the hops; TransHopMeta hi = getTransHop( i ); if ( hi.isEnabled() && hi.getFromStep().equals( stepMeta ) ) { nextSteps.add( hi.getToStep() ); } } return nextSteps; }
private static boolean isUnusedInput( TransMeta trans, StepMeta step ) { int nrEnabledOutHops = findHops( trans, hop -> hop.getFromStep().equals( step ) && hop.isEnabled() ).size(); int nrDisabledOutHops = findHops( trans, hop -> hop.getFromStep().equals( step ) && !hop.isEnabled() ).size(); int nrInputHops = findHops( trans, hop -> hop.getToStep().equals( step ) ).size(); return ( nrEnabledOutHops == 0 && nrDisabledOutHops > 0 && nrInputHops == 0 ); }
public void saveTransHopMeta( TransHopMeta transHopMeta, ObjectId id_transformation ) throws KettleException { try { // See if a transformation hop with the same fromstep and tostep is // already available... ObjectId id_step_from = transHopMeta.getFromStep() == null ? null : transHopMeta.getFromStep().getObjectId(); ObjectId id_step_to = transHopMeta.getToStep() == null ? null : transHopMeta.getToStep().getObjectId(); // Insert new transMeta hop in repository transHopMeta.setObjectId( insertTransHop( id_transformation, id_step_from, id_step_to, transHopMeta .isEnabled() ) ); } catch ( KettleDatabaseException dbe ) { throw new KettleException( BaseMessages.getString( PKG, "TransHopMeta.Exception.UnableToSaveTransformationHopInfo" ) + id_transformation, dbe ); } }
public void enableDisableHopsDownstream( boolean enabled ) { if ( currentHop == null ) { return; } TransHopMeta before = (TransHopMeta) currentHop.clone(); setHopEnabled( currentHop, enabled ); TransHopMeta after = (TransHopMeta) currentHop.clone(); spoon.addUndoChange( transMeta, new TransHopMeta[] { before }, new TransHopMeta[] { after }, new int[] { transMeta .indexOfTransHop( currentHop ) } ); Set<StepMeta> checkedEntries = enableDisableNextHops( currentHop.getToStep(), enabled, new HashSet<>() ); if ( checkedEntries.stream().anyMatch( entry -> transMeta.hasLoop( entry ) ) ) { modalMessageDialog( getString( "TransGraph.Dialog.HopCausesLoop.Title" ), getString( "TransGraph.Dialog.HopCausesLoop.Message" ), SWT.OK | SWT.ICON_ERROR ); } spoon.refreshGraph(); }
/** * @param transMeta transformation's meta * @param newHop hop to be checked * @return true when the hop was added, false if there was an error */ public boolean checkIfHopAlreadyExists( TransMeta transMeta, TransHopMeta newHop ) { boolean ok = true; if ( transMeta.findTransHop( newHop.getFromStep(), newHop.getToStep() ) != null ) { MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR ); mb.setMessage( BaseMessages.getString( PKG, "Spoon.Dialog.HopExists.Message" ) ); // "This hop already exists!" mb.setText( BaseMessages.getString( PKG, "Spoon.Dialog.HopExists.Title" ) ); // Error! mb.open(); ok = false; } return ok; }
private void addErrorHop() { // Automatically configure the step error handling too! // if ( candidate == null || candidate.getFromStep() == null ) { return; } StepErrorMeta errorMeta = candidate.getFromStep().getStepErrorMeta(); if ( errorMeta == null ) { errorMeta = new StepErrorMeta( transMeta, candidate.getFromStep() ); } errorMeta.setEnabled( true ); errorMeta.setTargetStep( candidate.getToStep() ); candidate.getFromStep().setStepErrorMeta( errorMeta ); }
/** * Sorts the hops in a natural way: from beginning to end. */ public void sortHopsNatural() { // Loop over the hops... for ( int j = 0; j < nrTransHops(); j++ ) { // Buble sort: we need to do this several times... for ( int i = 0; i < nrTransHops() - 1; i++ ) { TransHopMeta one = getTransHop( i ); TransHopMeta two = getTransHop( i + 1 ); StepMeta a = two.getFromStep(); StepMeta b = one.getToStep(); if ( !findPrevious( a, b ) && !a.equals( b ) ) { setTransHop( i + 1, one ); setTransHop( i, two ); } } } }
@Test public void testGetAllTransHops() throws Exception { TransMeta transMeta = new TransMeta( "transFile", "myTrans" ); StepMeta step1 = new StepMeta( "name1", null ); StepMeta step2 = new StepMeta( "name2", null ); StepMeta step3 = new StepMeta( "name3", null ); StepMeta step4 = new StepMeta( "name4", null ); TransHopMeta hopMeta1 = new TransHopMeta( step1, step2, true ); TransHopMeta hopMeta2 = new TransHopMeta( step2, step3, true ); TransHopMeta hopMeta3 = new TransHopMeta( step2, step4, true ); transMeta.addTransHop( 0, hopMeta1 ); transMeta.addTransHop( 1, hopMeta2 ); transMeta.addTransHop( 2, hopMeta3 ); List<TransHopMeta> allTransHopFrom = transMeta.findAllTransHopFrom( step2 ); assertEquals( step3, allTransHopFrom.get( 0 ).getToStep() ); assertEquals( step4, allTransHopFrom.get( 1 ).getToStep() ); }
public void flipHopDirection() { selectionRegion = null; TransHopMeta hi = getCurrentHop(); hi.flip(); if ( transMeta.hasLoop( hi.getToStep() ) ) { spoon.refreshGraph(); modalMessageDialog( getString( "TransGraph.Dialog.LoopsAreNotAllowed.Title" ), getString( "TransGraph.Dialog.LoopsAreNotAllowed.Message" ), SWT.OK | SWT.ICON_ERROR ); hi.flip(); spoon.refreshGraph(); } else { hi.setChanged(); spoon.refreshGraph(); spoon.refreshTree(); spoon.setShellText(); } }
public void enableHop() { selectionRegion = null; TransHopMeta hi = getCurrentHop(); TransHopMeta before = (TransHopMeta) hi.clone(); setHopEnabled( hi, !hi.isEnabled() ); if ( hi.isEnabled() && transMeta.hasLoop( hi.getToStep() ) ) { setHopEnabled( hi, false ); modalMessageDialog( getString( "TransGraph.Dialog.LoopAfterHopEnabled.Title" ), getString( "TransGraph.Dialog.LoopAfterHopEnabled.Message" ), SWT.OK | SWT.ICON_ERROR ); } else { TransHopMeta after = (TransHopMeta) hi.clone(); spoon.addUndoChange( transMeta, new TransHopMeta[] { before }, new TransHopMeta[] { after }, new int[] { transMeta.indexOfTransHop( hi ) } ); spoon.refreshGraph(); spoon.refreshTree(); } updateErrorMetaForHop( hi ); }