Search in sources :

Example 11 with StepIOMetaInterface

use of org.pentaho.di.trans.step.StepIOMetaInterface in project pentaho-kettle by pentaho.

the class SwitchCaseMeta method check.

public void check(List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository, IMetaStore metaStore) {
    CheckResult cr;
    StepIOMetaInterface ioMeta = getStepIOMeta();
    for (StreamInterface stream : ioMeta.getTargetStreams()) {
        SwitchCaseTarget target = (SwitchCaseTarget) stream.getSubject();
        if (target != null && target.caseTargetStep == null) {
            cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "SwitchCaseMeta.CheckResult.TargetStepInvalid", "false", target.caseTargetStepname), stepMeta);
            remarks.add(cr);
        }
    }
    if (Utils.isEmpty(fieldname)) {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "SwitchCaseMeta.CheckResult.NoFieldSpecified"), stepMeta);
    } else {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "SwitchCaseMeta.CheckResult.FieldSpecified"), stepMeta);
    }
    remarks.add(cr);
    // See if we have input streams leading to this step!
    if (input.length > 0) {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "SwitchCaseMeta.CheckResult.StepReceivingInfoFromOtherSteps"), stepMeta);
        remarks.add(cr);
    } else {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "SwitchCaseMeta.CheckResult.NoInputReceivedFromOtherSteps"), stepMeta);
        remarks.add(cr);
    }
}
Also used : CheckResult(org.pentaho.di.core.CheckResult) StepIOMetaInterface(org.pentaho.di.trans.step.StepIOMetaInterface) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Example 12 with StepIOMetaInterface

use of org.pentaho.di.trans.step.StepIOMetaInterface in project pentaho-kettle by pentaho.

the class TransGraph method splitHop.

private void splitHop(TransHopMeta hi) {
    int id = 0;
    if (!spoon.props.getAutoSplit()) {
        MessageDialogWithToggle md = new MessageDialogWithToggle(shell, BaseMessages.getString(PKG, "TransGraph.Dialog.SplitHop.Title"), null, BaseMessages.getString(PKG, "TransGraph.Dialog.SplitHop.Message") + Const.CR + hi.toString(), MessageDialog.QUESTION, new String[] { BaseMessages.getString(PKG, "System.Button.Yes"), BaseMessages.getString(PKG, "System.Button.No") }, 0, BaseMessages.getString(PKG, "TransGraph.Dialog.Option.SplitHop.DoNotAskAgain"), spoon.props.getAutoSplit());
        MessageDialogWithToggle.setDefaultImage(GUIResource.getInstance().getImageSpoon());
        id = md.open();
        spoon.props.setAutoSplit(md.getToggleState());
    }
    if ((id & 0xFF) == 0) {
        // Means: "Yes" button clicked!
        // Only split A-->--B by putting C in between IF...
        // C-->--A or B-->--C don't exists...
        // A ==> hi.getFromStep()
        // B ==> hi.getToStep();
        // C ==> selected_step
        // 
        boolean caExists = transMeta.findTransHop(selectedStep, hi.getFromStep()) != null;
        boolean bcExists = transMeta.findTransHop(hi.getToStep(), selectedStep) != null;
        if (!caExists && !bcExists) {
            StepMeta fromStep = hi.getFromStep();
            StepMeta toStep = hi.getToStep();
            // In case step A targets B then we now need to target C
            // 
            StepIOMetaInterface fromIo = fromStep.getStepMetaInterface().getStepIOMeta();
            for (StreamInterface stream : fromIo.getTargetStreams()) {
                if (stream.getStepMeta() != null && stream.getStepMeta().equals(toStep)) {
                    // This target stream was directed to B, now we need to direct it to C
                    stream.setStepMeta(selectedStep);
                    fromStep.getStepMetaInterface().handleStreamSelection(stream);
                }
            }
            // In case step B sources from A then we now need to source from C
            // 
            StepIOMetaInterface toIo = toStep.getStepMetaInterface().getStepIOMeta();
            for (StreamInterface stream : toIo.getInfoStreams()) {
                if (stream.getStepMeta() != null && stream.getStepMeta().equals(fromStep)) {
                    // This info stream was reading from B, now we need to direct it to C
                    stream.setStepMeta(selectedStep);
                    toStep.getStepMetaInterface().handleStreamSelection(stream);
                }
            }
            // In case there is error handling on A, we want to make it point to C now
            // 
            StepErrorMeta errorMeta = fromStep.getStepErrorMeta();
            if (fromStep.isDoingErrorHandling() && toStep.equals(errorMeta.getTargetStep())) {
                errorMeta.setTargetStep(selectedStep);
            }
            TransHopMeta newhop1 = new TransHopMeta(hi.getFromStep(), selectedStep);
            if (transMeta.findTransHop(newhop1) == null) {
                transMeta.addTransHop(newhop1);
                spoon.addUndoNew(transMeta, new TransHopMeta[] { newhop1 }, new int[] { transMeta.indexOfTransHop(newhop1) }, true);
            }
            TransHopMeta newhop2 = new TransHopMeta(selectedStep, hi.getToStep());
            if (transMeta.findTransHop(newhop2) == null) {
                transMeta.addTransHop(newhop2);
                spoon.addUndoNew(transMeta, new TransHopMeta[] { newhop2 }, new int[] { transMeta.indexOfTransHop(newhop2) }, true);
            }
            int idx = transMeta.indexOfTransHop(hi);
            spoon.addUndoDelete(transMeta, new TransHopMeta[] { hi }, new int[] { idx }, true);
            transMeta.removeTransHop(idx);
            spoon.refreshTree();
        }
    // else: Silently discard this hop-split attempt.
    }
}
Also used : StepErrorMeta(org.pentaho.di.trans.step.StepErrorMeta) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) StepIOMetaInterface(org.pentaho.di.trans.step.StepIOMetaInterface) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Example 13 with StepIOMetaInterface

use of org.pentaho.di.trans.step.StepIOMetaInterface in project pentaho-kettle by pentaho.

the class TransGraph method setToolTip.

private AreaOwner setToolTip(int x, int y, int screenX, int screenY) {
    AreaOwner subject = null;
    if (!spoon.getProperties().showToolTips()) {
        return subject;
    }
    canvas.setToolTipText(null);
    String newTip = null;
    Image tipImage = null;
    final TransHopMeta hi = findHop(x, y);
    // check the area owner list...
    // 
    StringBuilder tip = new StringBuilder();
    AreaOwner areaOwner = getVisibleAreaOwner(x, y);
    if (areaOwner != null && areaOwner.getAreaType() != null) {
        switch(areaOwner.getAreaType()) {
            case REMOTE_INPUT_STEP:
                StepMeta step = (StepMeta) areaOwner.getParent();
                tip.append("Remote input steps:").append(Const.CR).append("-----------------------").append(Const.CR);
                for (RemoteStep remoteStep : step.getRemoteInputSteps()) {
                    tip.append(remoteStep.toString()).append(Const.CR);
                }
                break;
            case REMOTE_OUTPUT_STEP:
                step = (StepMeta) areaOwner.getParent();
                tip.append("Remote output steps:").append(Const.CR).append("-----------------------").append(Const.CR);
                for (RemoteStep remoteStep : step.getRemoteOutputSteps()) {
                    tip.append(remoteStep.toString()).append(Const.CR);
                }
                break;
            case STEP_PARTITIONING:
                step = (StepMeta) areaOwner.getParent();
                tip.append("Step partitioning:").append(Const.CR).append("-----------------------").append(Const.CR);
                tip.append(step.getStepPartitioningMeta().toString()).append(Const.CR);
                if (step.getTargetStepPartitioningMeta() != null) {
                    tip.append(Const.CR).append(Const.CR).append("TARGET: " + step.getTargetStepPartitioningMeta().toString()).append(Const.CR);
                }
                break;
            case STEP_ERROR_ICON:
                String log = (String) areaOwner.getParent();
                tip.append(log);
                tipImage = GUIResource.getInstance().getImageStepError();
                break;
            case STEP_ERROR_RED_ICON:
                String redLog = (String) areaOwner.getParent();
                tip.append(redLog);
                tipImage = GUIResource.getInstance().getImageRedStepError();
                break;
            case HOP_COPY_ICON:
                step = (StepMeta) areaOwner.getParent();
                tip.append(BaseMessages.getString(PKG, "TransGraph.Hop.Tooltip.HopTypeCopy", step.getName(), Const.CR));
                tipImage = GUIResource.getInstance().getImageCopyHop();
                break;
            case ROW_DISTRIBUTION_ICON:
                step = (StepMeta) areaOwner.getParent();
                tip.append(BaseMessages.getString(PKG, "TransGraph.Hop.Tooltip.RowDistribution", step.getName(), step.getRowDistribution() == null ? "" : step.getRowDistribution().getDescription()));
                tip.append(Const.CR);
                tipImage = GUIResource.getInstance().getImageBalance();
                break;
            case HOP_INFO_ICON:
                StepMeta from = (StepMeta) areaOwner.getParent();
                StepMeta to = (StepMeta) areaOwner.getOwner();
                tip.append(BaseMessages.getString(PKG, "TransGraph.Hop.Tooltip.HopTypeInfo", to.getName(), from.getName(), Const.CR));
                tipImage = GUIResource.getInstance().getImageInfoHop();
                break;
            case HOP_ERROR_ICON:
                from = (StepMeta) areaOwner.getParent();
                to = (StepMeta) areaOwner.getOwner();
                areaOwner.getOwner();
                tip.append(BaseMessages.getString(PKG, "TransGraph.Hop.Tooltip.HopTypeError", from.getName(), to.getName(), Const.CR));
                tipImage = GUIResource.getInstance().getImageErrorHop();
                break;
            case HOP_INFO_STEP_COPIES_ERROR:
                from = (StepMeta) areaOwner.getParent();
                to = (StepMeta) areaOwner.getOwner();
                tip.append(BaseMessages.getString(PKG, "TransGraph.Hop.Tooltip.InfoStepCopies", from.getName(), to.getName(), Const.CR));
                tipImage = GUIResource.getInstance().getImageStepError();
                break;
            case STEP_INPUT_HOP_ICON:
                // StepMeta subjectStep = (StepMeta) (areaOwner.getParent());
                tip.append(BaseMessages.getString(PKG, "TransGraph.StepInputConnector.Tooltip"));
                tipImage = GUIResource.getInstance().getImageHopInput();
                break;
            case STEP_OUTPUT_HOP_ICON:
                // subjectStep = (StepMeta) (areaOwner.getParent());
                tip.append(BaseMessages.getString(PKG, "TransGraph.StepOutputConnector.Tooltip"));
                tipImage = GUIResource.getInstance().getImageHopOutput();
                break;
            case STEP_INFO_HOP_ICON:
                // subjectStep = (StepMeta) (areaOwner.getParent());
                // StreamInterface stream = (StreamInterface) areaOwner.getOwner();
                StepIOMetaInterface ioMeta = (StepIOMetaInterface) areaOwner.getOwner();
                tip.append(BaseMessages.getString(PKG, "TransGraph.StepInfoConnector.Tooltip") + Const.CR + ioMeta.toString());
                tipImage = GUIResource.getInstance().getImageHopOutput();
                break;
            case STEP_TARGET_HOP_ICON:
                StreamInterface stream = (StreamInterface) areaOwner.getOwner();
                tip.append(stream.getDescription());
                tipImage = GUIResource.getInstance().getImageHopOutput();
                break;
            case STEP_ERROR_HOP_ICON:
                StepMeta stepMeta = (StepMeta) areaOwner.getParent();
                if (stepMeta.supportsErrorHandling()) {
                    tip.append(BaseMessages.getString(PKG, "TransGraph.StepSupportsErrorHandling.Tooltip"));
                } else {
                    tip.append(BaseMessages.getString(PKG, "TransGraph.StepDoesNotSupportsErrorHandling.Tooltip"));
                }
                tipImage = GUIResource.getInstance().getImageHopOutput();
                break;
            case STEP_EDIT_ICON:
                stepMeta = (StepMeta) (areaOwner.getParent());
                tip.append(BaseMessages.getString(PKG, "TransGraph.EditStep.Tooltip"));
                tipImage = GUIResource.getInstance().getImageEdit();
                break;
            case STEP_INJECT_ICON:
                stepMeta = (StepMeta) (areaOwner.getParent());
                Object injection = areaOwner.getOwner();
                if (injection != null) {
                    tip.append(BaseMessages.getString(PKG, "TransGraph.StepInjectionSupported.Tooltip"));
                } else {
                    tip.append(BaseMessages.getString(PKG, "TransGraph.StepInjectionNotSupported.Tooltip"));
                }
                tipImage = GUIResource.getInstance().getImageInject();
                break;
            case STEP_MENU_ICON:
                tip.append(BaseMessages.getString(PKG, "TransGraph.ShowMenu.Tooltip"));
                tipImage = GUIResource.getInstance().getImageContextMenu();
                break;
            default:
                break;
        }
    }
    if (hi != null) {
        // We clicked on a HOP!
        // Set the tooltip for the hop:
        tip.append(Const.CR).append(BaseMessages.getString(PKG, "TransGraph.Dialog.HopInfo")).append(newTip = hi.toString()).append(Const.CR);
    }
    if (tip.length() == 0) {
        newTip = null;
    } else {
        newTip = tip.toString();
    }
    if (newTip == null) {
        toolTip.hide();
        if (hi != null) {
            // We clicked on a HOP!
            // Set the tooltip for the hop:
            newTip = BaseMessages.getString(PKG, "TransGraph.Dialog.HopInfo") + Const.CR + BaseMessages.getString(PKG, "TransGraph.Dialog.HopInfo.SourceStep") + " " + hi.getFromStep().getName() + Const.CR + BaseMessages.getString(PKG, "TransGraph.Dialog.HopInfo.TargetStep") + " " + hi.getToStep().getName() + Const.CR + BaseMessages.getString(PKG, "TransGraph.Dialog.HopInfo.Status") + " " + (hi.isEnabled() ? BaseMessages.getString(PKG, "TransGraph.Dialog.HopInfo.Enable") : BaseMessages.getString(PKG, "TransGraph.Dialog.HopInfo.Disable"));
            toolTip.setText(newTip);
            if (hi.isEnabled()) {
                toolTip.setImage(GUIResource.getInstance().getImageHop());
            } else {
                toolTip.setImage(GUIResource.getInstance().getImageDisabledHop());
            }
            toolTip.show(new org.eclipse.swt.graphics.Point(screenX, screenY));
        } else {
            newTip = null;
        }
    } else if (!newTip.equalsIgnoreCase(getToolTipText())) {
        Image tooltipImage = null;
        if (tipImage != null) {
            tooltipImage = tipImage;
        } else {
            tooltipImage = GUIResource.getInstance().getImageSpoonLow();
        }
        showTooltip(newTip, tooltipImage, screenX, screenY);
    }
    if (areaOwner != null && areaOwner.getExtensionAreaType() != null) {
        try {
            TransPainterFlyoutTooltipExtension extension = new TransPainterFlyoutTooltipExtension(areaOwner, this, new Point(screenX, screenY));
            ExtensionPointHandler.callExtensionPoint(LogChannel.GENERAL, KettleExtensionPoint.TransPainterFlyoutTooltip.id, extension);
        } catch (Exception e) {
            LogChannel.GENERAL.logError("Error calling extension point(s) for the transformation painter step", e);
        }
    }
    return subject;
}
Also used : StepIOMetaInterface(org.pentaho.di.trans.step.StepIOMetaInterface) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) SwtUniversalImage(org.pentaho.di.core.SwtUniversalImage) Image(org.eclipse.swt.graphics.Image) StepMeta(org.pentaho.di.trans.step.StepMeta) XulException(org.pentaho.ui.xul.XulException) InvocationTargetException(java.lang.reflect.InvocationTargetException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettleRepositoryLostException(org.pentaho.di.repository.KettleRepositoryLostException) KettleException(org.pentaho.di.core.exception.KettleException) RemoteStep(org.pentaho.di.trans.step.RemoteStep) AreaOwner(org.pentaho.di.core.gui.AreaOwner) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Example 14 with StepIOMetaInterface

use of org.pentaho.di.trans.step.StepIOMetaInterface in project pentaho-metaverse by pentaho.

the class TransformationAnalyzerTest method testAnalyzerTransformWithStepsAndHop.

@Test
public void testAnalyzerTransformWithStepsAndHop() throws MetaverseAnalyzerException {
    StepMeta mockToStepMeta = mock(StepMeta.class);
    when(mockToStepMeta.getStepMetaInterface()).thenReturn(mockSelectValuesStepMeta);
    StepIOMetaInterface stepIO = mock(StepIOMetaInterface.class);
    when(stepIO.getInfoStepnames()).thenReturn(new String[] {});
    when(mockSelectValuesStepMeta.getStepIOMeta()).thenReturn(stepIO);
    when(mockToStepMeta.getParentTransMeta()).thenReturn(mockContent);
    when(mockContent.nrSteps()).thenReturn(2);
    when(mockContent.getStep(0)).thenReturn(mockStepMeta);
    when(mockContent.getStep(1)).thenReturn(mockToStepMeta);
    when(mockContent.nrTransHops()).thenReturn(1);
    final TransHopMeta hop = new TransHopMeta(mockStepMeta, mockToStepMeta, true);
    when(mockContent.getTransHop(0)).thenReturn(hop);
    IMetaverseNode node = analyzer.analyze(descriptor, mockTransDoc);
    assertNotNull(node);
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) StepIOMetaInterface(org.pentaho.di.trans.step.StepIOMetaInterface) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Test(org.junit.Test)

Example 15 with StepIOMetaInterface

use of org.pentaho.di.trans.step.StepIOMetaInterface in project pentaho-kettle by pentaho.

the class SwitchCase method createOutputValueMapping.

/**
 * This will prepare step for execution:
 * <ol>
 * <li>will copy input row meta info, fields info, etc. step related info
 * <li>will get step IO meta info and discover target streams for target output steps
 * <li>for every target output find output rowset and expected value.
 * <li>for every discovered output rowset put it as a key-value: 'expected value'-'output rowSet'. If expected value
 * is null - put output rowset to special 'null set' (avoid usage of null as a map keys)
 * <li>Discover default row set. We expect only one default rowset, even if technically can have many. *
 * </ol>
 *
 * @throws KettleException
 *           if something goes wrong during step preparation.
 */
void createOutputValueMapping() throws KettleException {
    data.outputRowMeta = getInputRowMeta().clone();
    meta.getFields(getInputRowMeta(), getStepname(), null, null, this, repository, metaStore);
    data.fieldIndex = getInputRowMeta().indexOfValue(meta.getFieldname());
    if (data.fieldIndex < 0) {
        throw new KettleException(BaseMessages.getString(PKG, "SwitchCase.Exception.UnableToFindFieldName", meta.getFieldname()));
    }
    data.inputValueMeta = getInputRowMeta().getValueMeta(data.fieldIndex);
    try {
        StepIOMetaInterface ioMeta = meta.getStepIOMeta();
        // There is one or many case target for each target stream.
        // The ioMeta object has one more target stream for the default target though.
        // 
        List<StreamInterface> targetStreams = ioMeta.getTargetStreams();
        for (int i = 0; i < targetStreams.size(); i++) {
            SwitchCaseTarget target = (SwitchCaseTarget) targetStreams.get(i).getSubject();
            if (target == null) {
                // Skip over default option
                break;
            }
            if (target.caseTargetStep == null) {
                throw new KettleException(BaseMessages.getString(PKG, "SwitchCase.Log.NoTargetStepSpecifiedForValue", target.caseValue));
            }
            RowSet rowSet = findOutputRowSet(target.caseTargetStep.getName());
            if (rowSet == null) {
                throw new KettleException(BaseMessages.getString(PKG, "SwitchCase.Log.UnableToFindTargetRowSetForStep", target.caseTargetStep));
            }
            try {
                Object value = data.valueMeta.convertDataFromString(target.caseValue, data.stringValueMeta, null, null, ValueMetaInterface.TRIM_TYPE_NONE);
                // 
                if (data.valueMeta.isNull(value)) {
                    data.nullRowSetSet.add(rowSet);
                } else {
                    data.outputMap.put(value, rowSet);
                }
            } catch (Exception e) {
                throw new KettleException(BaseMessages.getString(PKG, "SwitchCase.Log.UnableToConvertValue", target.caseValue), e);
            }
        }
        if (meta.getDefaultTargetStep() != null) {
            RowSet rowSet = findOutputRowSet(meta.getDefaultTargetStep().getName());
            if (rowSet != null) {
                data.defaultRowSetSet.add(rowSet);
                if (data.nullRowSetSet.isEmpty()) {
                    data.nullRowSetSet.add(rowSet);
                }
            }
        }
    } catch (Exception e) {
        throw new KettleException(e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RowSet(org.pentaho.di.core.RowSet) StepIOMetaInterface(org.pentaho.di.trans.step.StepIOMetaInterface) KettleException(org.pentaho.di.core.exception.KettleException) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Aggregations

StepIOMetaInterface (org.pentaho.di.trans.step.StepIOMetaInterface)23 StreamInterface (org.pentaho.di.trans.step.errorhandling.StreamInterface)19 StepMeta (org.pentaho.di.trans.step.StepMeta)10 KettleException (org.pentaho.di.core.exception.KettleException)7 TransHopMeta (org.pentaho.di.trans.TransHopMeta)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)6 Point (org.pentaho.di.core.gui.Point)6 KettleStepException (org.pentaho.di.core.exception.KettleStepException)4 AreaOwner (org.pentaho.di.core.gui.AreaOwner)4 StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)4 RowSet (org.pentaho.di.core.RowSet)3 EImage (org.pentaho.di.core.gui.PrimitiveGCInterface.EImage)3 TransMeta (org.pentaho.di.trans.TransMeta)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 NotePadMeta (org.pentaho.di.core.NotePadMeta)2 KettleValueException (org.pentaho.di.core.exception.KettleValueException)2 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)2 KettleRepositoryLostException (org.pentaho.di.repository.KettleRepositoryLostException)2