Search in sources :

Example 16 with StreamInterface

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

the class FuzzyMatchMeta 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;
    if (prev != null && prev.size() > 0) {
        cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.StepReceivingFields", prev.size() + ""), stepMeta);
        remarks.add(cr);
        // Starting from selected fields in ...
        // Check the fields from the previous stream!
        String mainField = transMeta.environmentSubstitute(getMainStreamField());
        int idx = prev.indexOfValue(mainField);
        if (idx < 0) {
            cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.MainFieldNotFound", mainField), stepMeta);
        } else {
            cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.MainFieldFound", mainField), stepMeta);
        }
        remarks.add(cr);
    } else {
        cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.CouldNotFindFieldsFromPreviousSteps"), stepMeta);
        remarks.add(cr);
    }
    if (info != null && info.size() > 0) {
        cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.StepReceivingLookupData", info.size() + ""), stepMeta);
        remarks.add(cr);
        // Check the fields from the lookup stream!
        String lookupField = transMeta.environmentSubstitute(getLookupField());
        int idx = info.indexOfValue(lookupField);
        if (idx < 0) {
            cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.FieldNotFoundInLookupStream", lookupField), stepMeta);
        } else {
            cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.FieldFoundInTheLookupStream", lookupField), stepMeta);
        }
        remarks.add(cr);
        String error_message = "";
        boolean error_found = false;
        // Check the values to retrieve from the lookup stream!
        for (int i = 0; i < value.length; i++) {
            idx = info.indexOfValue(value[i]);
            if (idx < 0) {
                error_message += "\t\t" + value[i] + Const.CR;
                error_found = true;
            }
        }
        if (error_found) {
            error_message = BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.FieldsNotFoundInLookupStream2") + Const.CR + Const.CR + error_message;
            cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepMeta);
        } else {
            cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.AllFieldsFoundInTheLookupStream2"), stepMeta);
        }
        remarks.add(cr);
    } else {
        cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.FieldsNotFoundFromInLookupSep"), stepMeta);
        remarks.add(cr);
    }
    // See if the source step is filled in!
    StreamInterface infoStream = getStepIOMeta().getInfoStreams().get(0);
    if (infoStream.getStepMeta() == null) {
        cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.SourceStepNotSelected"), stepMeta);
        remarks.add(cr);
    } else {
        cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.SourceStepIsSelected"), stepMeta);
        remarks.add(cr);
        // 
        if (info != null) {
            cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.SourceStepExist", infoStream.getStepname() + ""), stepMeta);
            remarks.add(cr);
        } else {
            cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.SourceStepDoesNotExist", infoStream.getStepname() + ""), stepMeta);
            remarks.add(cr);
        }
    }
    // See if we have input streams leading to this step!
    if (input.length >= 2) {
        cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.StepReceivingInfoFromInputSteps", input.length + ""), stepMeta);
        remarks.add(cr);
    } else {
        cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.NeedAtLeast2InputStreams", Const.CR, Const.CR), stepMeta);
        remarks.add(cr);
    }
}
Also used : CheckResult(org.pentaho.di.core.CheckResult) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Example 17 with StreamInterface

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

the class BaseStepMetaCloningTest method testCloneWithInfoSteps.

@Test
public void testCloneWithInfoSteps() throws Exception {
    final Database db1 = mock(Database.class);
    final Database db2 = mock(Database.class);
    final Repository repository = mock(Repository.class);
    final StepMeta stepMeta = mock(StepMeta.class);
    BaseStepMeta meta = new BaseStepMeta();
    meta.setChanged(true);
    meta.databases = new Database[] { db1, db2 };
    meta.ioMeta = new StepIOMeta(true, false, false, false, false, false);
    final String refStepName = "referenced step";
    final StepMeta refStepMeta = mock(StepMeta.class);
    doReturn(refStepName).when(refStepMeta).getName();
    StreamInterface stream = new Stream(StreamInterface.StreamType.INFO, refStepMeta, null, null, refStepName);
    meta.ioMeta.addStream(stream);
    meta.repository = repository;
    meta.parentStepMeta = stepMeta;
    BaseStepMeta clone = (BaseStepMeta) meta.clone();
    assertTrue(clone.hasChanged());
    // is it OK ?
    assertTrue(clone.databases == meta.databases);
    assertArrayEquals(meta.databases, clone.databases);
    assertEquals(meta.repository, clone.repository);
    assertEquals(meta.parentStepMeta, clone.parentStepMeta);
    assertNotNull(clone.ioMeta);
    assertEquals(meta.ioMeta.isInputAcceptor(), clone.ioMeta.isInputAcceptor());
    assertEquals(meta.ioMeta.isInputDynamic(), clone.ioMeta.isInputDynamic());
    assertEquals(meta.ioMeta.isInputOptional(), clone.ioMeta.isInputOptional());
    assertEquals(meta.ioMeta.isOutputDynamic(), clone.ioMeta.isOutputDynamic());
    assertEquals(meta.ioMeta.isOutputProducer(), clone.ioMeta.isOutputProducer());
    assertEquals(meta.ioMeta.isSortedDataRequired(), clone.ioMeta.isSortedDataRequired());
    final List<StreamInterface> clonedInfoStreams = clone.ioMeta.getInfoStreams();
    assertNotNull(clonedInfoStreams);
    assertEquals(1, clonedInfoStreams.size());
    final StreamInterface clonedStream = clonedInfoStreams.get(0);
    assertNotSame(stream, clonedStream);
    assertEquals(stream.getStreamType(), clonedStream.getStreamType());
    assertEquals(refStepName, clonedStream.getStepname());
    // PDI-15799
    assertSame(refStepMeta, clonedStream.getStepMeta());
}
Also used : Repository(org.pentaho.di.repository.Repository) Database(org.pentaho.di.core.database.Database) Stream(org.pentaho.di.trans.step.errorhandling.Stream) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface) Test(org.junit.Test)

Example 18 with StreamInterface

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

the class TransExecutorMetaTest method mockStepIo.

@SuppressWarnings("unchecked")
private static StepIOMetaInterface mockStepIo(StreamInterface stream, int desiredIndex) {
    List<StreamInterface> list = mock(List.class);
    when(list.indexOf(stream)).thenReturn(desiredIndex);
    when(list.get(eq(desiredIndex))).thenReturn(stream);
    StepIOMetaInterface stepIo = mock(StepIOMetaInterface.class);
    when(stepIo.getTargetStreams()).thenReturn(list);
    return stepIo;
}
Also used : StepIOMetaInterface(org.pentaho.di.trans.step.StepIOMetaInterface) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Example 19 with StreamInterface

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

the class TransExecutorMetaTest method firstStreamIsExecutionStatistics.

@Test
public void firstStreamIsExecutionStatistics() throws Exception {
    StreamInterface stream = mockStream();
    StepIOMetaInterface stepIo = mockStepIo(stream, 0);
    TransExecutorMeta meta = new TransExecutorMeta();
    meta = spy(meta);
    when(meta.getStepIOMeta()).thenReturn(stepIo);
    doCallRealMethod().when(meta).handleStreamSelection(any(StreamInterface.class));
    meta.handleStreamSelection(stream);
    assertEquals(stream.getStepMeta(), meta.getExecutionResultTargetStepMeta());
}
Also used : StepIOMetaInterface(org.pentaho.di.trans.step.StepIOMetaInterface) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface) Test(org.junit.Test)

Example 20 with StreamInterface

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

the class TransExecutorMetaTest method forthStreamIsExecutorsInput.

@Test
public void forthStreamIsExecutorsInput() throws Exception {
    StreamInterface stream = mockStream();
    StepIOMetaInterface stepIo = mockStepIo(stream, 3);
    TransExecutorMeta meta = new TransExecutorMeta();
    meta = spy(meta);
    when(meta.getStepIOMeta()).thenReturn(stepIo);
    doCallRealMethod().when(meta).handleStreamSelection(any(StreamInterface.class));
    meta.handleStreamSelection(stream);
    assertEquals(stream.getStepMeta(), meta.getExecutorsOutputStepMeta());
}
Also used : StepIOMetaInterface(org.pentaho.di.trans.step.StepIOMetaInterface) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface) Test(org.junit.Test)

Aggregations

StreamInterface (org.pentaho.di.trans.step.errorhandling.StreamInterface)84 KettleException (org.pentaho.di.core.exception.KettleException)31 KettleStepException (org.pentaho.di.core.exception.KettleStepException)26 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)19 StepIOMetaInterface (org.pentaho.di.trans.step.StepIOMetaInterface)19 StepMeta (org.pentaho.di.trans.step.StepMeta)19 Stream (org.pentaho.di.trans.step.errorhandling.Stream)10 TableItem (org.eclipse.swt.widgets.TableItem)8 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)8 Test (org.junit.Test)7 CheckResult (org.pentaho.di.core.CheckResult)7 KettleRowException (org.pentaho.di.core.exception.KettleRowException)7 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)7 ArrayList (java.util.ArrayList)6 TransHopMeta (org.pentaho.di.trans.TransHopMeta)6 StepIOMeta (org.pentaho.di.trans.step.StepIOMeta)6 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)5 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)5 Point (org.pentaho.di.core.gui.Point)5 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)5