Search in sources :

Example 56 with StepMetaInterface

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

the class RowGeneratorUnitTest method setUp.

@Before
public void setUp() throws KettleException {
    // add variable to row generator step
    StepMetaInterface stepMetaInterface = spy(new RowGeneratorMeta());
    ((RowGeneratorMeta) stepMetaInterface).setRowLimit("${ROW_LIMIT}");
    String[] strings = {};
    when(((RowGeneratorMeta) stepMetaInterface).getFieldName()).thenReturn(strings);
    StepMeta stepMeta = new StepMeta();
    stepMeta.setStepMetaInterface(stepMetaInterface);
    stepMeta.setName("ROW_STEP_META");
    StepDataInterface stepDataInterface = stepMeta.getStepMetaInterface().getStepData();
    // add variable to transformation variable space
    Map<String, String> map = new HashMap<String, String>();
    map.put("ROW_LIMIT", "1440");
    TransMeta transMeta = spy(new TransMeta());
    transMeta.injectVariables(map);
    when(transMeta.findStep(anyString())).thenReturn(stepMeta);
    Trans trans = spy(new Trans(transMeta, null));
    when(trans.getSocketRepository()).thenReturn(null);
    when(trans.getLogChannelId()).thenReturn("ROW_LIMIT");
    // prepare row generator, substitutes variable by value from transformation variable space
    rowGenerator = spy(new RowGenerator(stepMeta, stepDataInterface, 0, transMeta, trans));
    rowGenerator.initializeVariablesFrom(trans);
    rowGenerator.init(stepMetaInterface, stepDataInterface);
}
Also used : HashMap(java.util.HashMap) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) TransMeta(org.pentaho.di.trans.TransMeta) Mockito.anyString(org.mockito.Mockito.anyString) StepMeta(org.pentaho.di.trans.step.StepMeta) StepDataInterface(org.pentaho.di.trans.step.StepDataInterface) Trans(org.pentaho.di.trans.Trans) Before(org.junit.Before)

Example 57 with StepMetaInterface

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

the class RunTransServletTest method setup.

@Before
public void setup() throws Exception {
    runTransServlet = new RunTransServlet();
    outData = new ByteArrayOutputStream();
    out = new PrintWriter(outData);
    stepList = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        StepMetaDataCombi stepMetaDataCombi = new StepMetaDataCombi();
        StepMetaInterface stepMeta = mock(StepMetaInterface.class);
        when(stepMeta.passDataToServletOutput()).thenReturn(false);
        stepMetaDataCombi.meta = stepMeta;
        stepList.add(stepMetaDataCombi);
    }
    when(trans.getSteps()).thenReturn(stepList);
    when(trans.getContainerObjectId()).thenReturn(transId);
}
Also used : StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PrintWriter(java.io.PrintWriter) Before(org.junit.Before)

Example 58 with StepMetaInterface

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

the class SpoonTest method testDelHop.

@Test
public void testDelHop() throws Exception {
    StepMetaInterface stepMetaInterface = Mockito.mock(StepMetaInterface.class);
    StepMeta step = new StepMeta();
    step.setStepMetaInterface(stepMetaInterface);
    TransHopMeta transHopMeta = new TransHopMeta();
    transHopMeta.setFromStep(step);
    TransMeta transMeta = Mockito.mock(TransMeta.class);
    spoon.delHop(transMeta, transHopMeta);
    Mockito.verify(stepMetaInterface, times(1)).cleanAfterHopFromRemove();
}
Also used : StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Test(org.junit.Test)

Example 59 with StepMetaInterface

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

the class SpoonStepsDelegateTest method testGetStepDialogClass.

@Test
public void testGetStepDialogClass() throws Exception {
    PluginMockInterface plugin = mock(PluginMockInterface.class);
    when(plugin.getIds()).thenReturn(new String[] { "mockPlugin" });
    when(plugin.matches("mockPlugin")).thenReturn(true);
    when(plugin.getName()).thenReturn("mockPlugin");
    StepMetaInterface meta = mock(StepMetaInterface.class);
    when(meta.getDialogClassName()).thenReturn(String.class.getName());
    when(plugin.getClassMap()).thenReturn(new HashMap<Class<?>, String>() {

        {
            put(StepMetaInterface.class, meta.getClass().getName());
            put(StepDialogInterface.class, StepDialogInterface.class.getName());
        }
    });
    PluginRegistry.getInstance().registerPlugin(StepPluginType.class, plugin);
    SpoonStepsDelegate delegate = mock(SpoonStepsDelegate.class);
    Spoon spoon = mock(Spoon.class);
    delegate.spoon = spoon;
    delegate.log = mock(LogChannelInterface.class);
    when(spoon.getShell()).thenReturn(mock(Shell.class));
    doCallRealMethod().when(delegate).getStepDialog(any(StepMetaInterface.class), any(TransMeta.class), any(String.class));
    TransMeta trans = mock(TransMeta.class);
    // verify that dialog class is requested from plugin
    try {
        // exception is expected here
        delegate.getStepDialog(meta, trans, "");
    } catch (Throwable ignore) {
        verify(meta, never()).getDialogClassName();
    }
    // verify that the deprecated way is still valid
    when(plugin.getClassMap()).thenReturn(new HashMap<Class<?>, String>() {

        {
            put(StepMetaInterface.class, meta.getClass().getName());
        }
    });
    try {
        // exception is expected here
        delegate.getStepDialog(meta, trans, "");
    } catch (Throwable ignore) {
        verify(meta, times(1)).getDialogClassName();
    }
    // cleanup
    PluginRegistry.getInstance().removePlugin(StepPluginType.class, plugin);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) StepDialogInterface(org.pentaho.di.trans.step.StepDialogInterface) Spoon(org.pentaho.di.ui.spoon.Spoon) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) TransMeta(org.pentaho.di.trans.TransMeta) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Test(org.junit.Test)

Example 60 with StepMetaInterface

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

the class Spoon method pasteXML.

public void pasteXML(TransMeta transMeta, String clipcontent, Point loc) {
    if (RepositorySecurityUI.verifyOperations(shell, rep, RepositoryOperation.MODIFY_TRANSFORMATION, RepositoryOperation.EXECUTE_TRANSFORMATION)) {
        return;
    }
    try {
        Document doc = XMLHandler.loadXMLString(clipcontent);
        Node transNode = XMLHandler.getSubNode(doc, Spoon.XML_TAG_TRANSFORMATION_STEPS);
        // De-select all, re-select pasted steps...
        transMeta.unselectAll();
        Node stepsNode = XMLHandler.getSubNode(transNode, "steps");
        int nr = XMLHandler.countNodes(stepsNode, "step");
        if (getLog().isDebug()) {
            // "I found "+nr+" steps to paste on location: "
            getLog().logDebug(BaseMessages.getString(PKG, "Spoon.Log.FoundSteps", "" + nr) + loc);
        }
        StepMeta[] steps = new StepMeta[nr];
        ArrayList<String> stepOldNames = new ArrayList<>(nr);
        // Point min = new Point(loc.x, loc.y);
        Point min = new Point(99999999, 99999999);
        // Load the steps...
        for (int i = 0; i < nr; i++) {
            Node stepNode = XMLHandler.getSubNodeByNr(stepsNode, "step", i);
            steps[i] = new StepMeta(stepNode, transMeta.getDatabases(), metaStore);
            if (loc != null) {
                Point p = steps[i].getLocation();
                if (min.x > p.x) {
                    min.x = p.x;
                }
                if (min.y > p.y) {
                    min.y = p.y;
                }
            }
        }
        // Load the hops...
        Node hopsNode = XMLHandler.getSubNode(transNode, "order");
        nr = XMLHandler.countNodes(hopsNode, "hop");
        if (getLog().isDebug()) {
            // "I found "+nr+" hops to paste."
            getLog().logDebug(BaseMessages.getString(PKG, "Spoon.Log.FoundHops", "" + nr));
        }
        TransHopMeta[] hops = new TransHopMeta[nr];
        for (int i = 0; i < nr; i++) {
            Node hopNode = XMLHandler.getSubNodeByNr(hopsNode, "hop", i);
            hops[i] = new TransHopMeta(hopNode, Arrays.asList(steps));
        }
        // This is the offset:
        Point offset = new Point(loc.x - min.x, loc.y - min.y);
        // Undo/redo object positions...
        int[] position = new int[steps.length];
        for (int i = 0; i < steps.length; i++) {
            Point p = steps[i].getLocation();
            String name = steps[i].getName();
            steps[i].setLocation(p.x + offset.x, p.y + offset.y);
            steps[i].setDraw(true);
            // Check the name, find alternative...
            stepOldNames.add(name);
            steps[i].setName(transMeta.getAlternativeStepname(name));
            transMeta.addStep(steps[i]);
            position[i] = transMeta.indexOfStep(steps[i]);
            steps[i].setSelected(true);
        }
        // Add the hops too...
        for (TransHopMeta hop : hops) {
            transMeta.addTransHop(hop);
        }
        // Load the notes...
        Node notesNode = XMLHandler.getSubNode(transNode, "notepads");
        nr = XMLHandler.countNodes(notesNode, "notepad");
        if (getLog().isDebug()) {
            // "I found "+nr+" notepads to paste."
            getLog().logDebug(BaseMessages.getString(PKG, "Spoon.Log.FoundNotepads", "" + nr));
        }
        NotePadMeta[] notes = new NotePadMeta[nr];
        for (int i = 0; i < notes.length; i++) {
            Node noteNode = XMLHandler.getSubNodeByNr(notesNode, "notepad", i);
            notes[i] = new NotePadMeta(noteNode);
            Point p = notes[i].getLocation();
            notes[i].setLocation(p.x + offset.x, p.y + offset.y);
            transMeta.addNote(notes[i]);
            notes[i].setSelected(true);
        }
        // Set the source and target steps ...
        for (StepMeta step : steps) {
            StepMetaInterface smi = step.getStepMetaInterface();
            smi.searchInfoAndTargetSteps(transMeta.getSteps());
        }
        // Set the error handling hops
        Node errorHandlingNode = XMLHandler.getSubNode(transNode, TransMeta.XML_TAG_STEP_ERROR_HANDLING);
        int nrErrorHandlers = XMLHandler.countNodes(errorHandlingNode, StepErrorMeta.XML_ERROR_TAG);
        for (int i = 0; i < nrErrorHandlers; i++) {
            Node stepErrorMetaNode = XMLHandler.getSubNodeByNr(errorHandlingNode, StepErrorMeta.XML_ERROR_TAG, i);
            StepErrorMeta stepErrorMeta = new StepErrorMeta(transMeta.getParentVariableSpace(), stepErrorMetaNode, transMeta.getSteps());
            // Handle pasting multiple times, need to update source and target step names
            int srcStepPos = stepOldNames.indexOf(stepErrorMeta.getSourceStep().getName());
            int tgtStepPos = stepOldNames.indexOf(stepErrorMeta.getTargetStep().getName());
            StepMeta sourceStep = transMeta.findStep(steps[srcStepPos].getName());
            if (sourceStep != null) {
                sourceStep.setStepErrorMeta(stepErrorMeta);
            }
            sourceStep.setStepErrorMeta(null);
            if (tgtStepPos >= 0) {
                sourceStep.setStepErrorMeta(stepErrorMeta);
                StepMeta targetStep = transMeta.findStep(steps[tgtStepPos].getName());
                stepErrorMeta.setSourceStep(sourceStep);
                stepErrorMeta.setTargetStep(targetStep);
            }
        }
        // Save undo information too...
        addUndoNew(transMeta, steps, position, false);
        int[] hopPos = new int[hops.length];
        for (int i = 0; i < hops.length; i++) {
            hopPos[i] = transMeta.indexOfTransHop(hops[i]);
        }
        addUndoNew(transMeta, hops, hopPos, true);
        int[] notePos = new int[notes.length];
        for (int i = 0; i < notes.length; i++) {
            notePos[i] = transMeta.indexOfNote(notes[i]);
        }
        addUndoNew(transMeta, notes, notePos, true);
        if (transMeta.haveStepsChanged()) {
            refreshTree();
            refreshGraph();
        }
    } catch (KettleException e) {
        // "Error pasting steps...",
        // "I was unable to paste steps to this transformation"
        new ErrorDialog(shell, BaseMessages.getString(PKG, "Spoon.Dialog.UnablePasteSteps.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.UnablePasteSteps.Message"), e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) StepErrorMeta(org.pentaho.di.trans.step.StepErrorMeta) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) Document(org.w3c.dom.Document) StepMeta(org.pentaho.di.trans.step.StepMeta) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) TransHopMeta(org.pentaho.di.trans.TransHopMeta) NotePadMeta(org.pentaho.di.core.NotePadMeta)

Aggregations

StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)77 StepMeta (org.pentaho.di.trans.step.StepMeta)40 KettleException (org.pentaho.di.core.exception.KettleException)31 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)21 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)20 TransMeta (org.pentaho.di.trans.TransMeta)16 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)16 TableItem (org.eclipse.swt.widgets.TableItem)15 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)15 SourceToTargetMapping (org.pentaho.di.core.SourceToTargetMapping)14 Trans (org.pentaho.di.trans.Trans)14 EnterMappingDialog (org.pentaho.di.ui.core.dialog.EnterMappingDialog)14 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)12 Point (org.pentaho.di.core.gui.Point)12 TransHopMeta (org.pentaho.di.trans.TransHopMeta)11 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)11 NotePadMeta (org.pentaho.di.core.NotePadMeta)8 KettleStepException (org.pentaho.di.core.exception.KettleStepException)8 JobEntryInterface (org.pentaho.di.job.entry.JobEntryInterface)8