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);
}
}
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());
}
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;
}
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());
}
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());
}
Aggregations