public List<TransHopMeta> findAllTransHopFrom( StepMeta fromstep ) { return hops.stream() .filter( hop -> hop.getFromStep() != null && hop.getFromStep().equals( fromstep ) ) .collect( Collectors.toList() ); } /**
/** * 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 ); }
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 ); }
/** * Search all hops for a hop where a certain step is at the start. * * @param fromstep * The step at the start of the hop. * @return The hop or null if no hop was found. */ public TransHopMeta findTransHopFrom( StepMeta fromstep ) { int i; for ( i = 0; i < nrTransHops(); i++ ) { TransHopMeta hi = getTransHop( i ); if ( hi.getFromStep() != null && hi.getFromStep().equals( fromstep ) ) { // 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 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 ); }
/** * Retrieve an array of preceding steps for a certain destination step. This includes the info steps. * * @param stepMeta * The destination step * @return An array containing the preceding steps. */ public StepMeta[] getPrevSteps( StepMeta stepMeta ) { List<StepMeta> prevSteps = previousStepCache.get( getStepMetaCacheKey( stepMeta, true ) ); if ( prevSteps == null ) { prevSteps = new ArrayList<>(); for ( int i = 0; i < nrTransHops(); i++ ) { // Look at all the hops; TransHopMeta hopMeta = getTransHop( i ); if ( hopMeta.isEnabled() && hopMeta.getToStep().equals( stepMeta ) ) { prevSteps.add( hopMeta.getFromStep() ); } } } return prevSteps.toArray( new StepMeta[prevSteps.size()] ); }
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; }
/** * Find the number of succeeding steps for a certain originating step. * * @param stepMeta * The originating step * @return The number of succeeding steps. * @deprecated use {@link #getNextSteps(StepMeta)} */ @Deprecated public int findNrNextSteps( StepMeta stepMeta ) { int count = 0; int i; for ( i = 0; i < nrTransHops(); i++ ) { // Look at all the hops; TransHopMeta hi = getTransHop( i ); if ( hi.isEnabled() && hi.getFromStep().equals( stepMeta ) ) { count++; } } return count; }
private void updateErrorMetaForHop( TransHopMeta hop ) { if ( hop != null && hop.isErrorHop() ) { StepErrorMeta errorMeta = hop.getFromStep().getStepErrorMeta(); if ( errorMeta != null ) { errorMeta.setEnabled( hop.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; }
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 ); } }
/** * @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; }
/** * 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 ); } } } }