use of org.apache.hop.pipeline.transforms.input.MappingInput in project hop by apache.
the class SimpleMapping method prepareMappingExecution.
public void prepareMappingExecution() throws HopException {
SimpleMappingData simpleMappingData = getData();
// Create the pipeline from meta-data...
simpleMappingData.mappingPipeline = new LocalPipelineEngine(simpleMappingData.mappingPipelineMeta, this, this);
// Copy the parameters over...
//
simpleMappingData.mappingPipeline.copyParametersFromDefinitions(simpleMappingData.mappingPipelineMeta);
// Set the parameters values in the mapping.
//
TransformWithMappingMeta.activateParams(simpleMappingData.mappingPipeline, simpleMappingData.mappingPipeline, this, simpleMappingData.mappingPipelineMeta.listParameters(), meta.getMappingParameters().getVariable(), meta.getMappingParameters().getInputField(), meta.getMappingParameters().isInheritingAllVariables());
// Leave a path up so that we can set variables in sub-pipelines...
//
simpleMappingData.mappingPipeline.setParentPipeline(getPipeline());
// Pass down the safe mode flag to the mapping...
//
simpleMappingData.mappingPipeline.setSafeModeEnabled(getPipeline().isSafeModeEnabled());
// Pass down the metrics gathering flag:
//
simpleMappingData.mappingPipeline.setGatheringMetrics(getPipeline().isGatheringMetrics());
//
try {
simpleMappingData.mappingPipeline.prepareExecution();
} catch (HopException e) {
throw new HopException(BaseMessages.getString(PKG, "SimpleMapping.Exception.UnableToPrepareExecutionOfMapping"), e);
}
// If there is no read/write logging transform set, we can insert the data from
// the first mapping input/output transform...
//
List<MappingInput> mappingInputs = findMappingInputs(simpleMappingData.mappingPipeline);
if (mappingInputs.isEmpty()) {
throw new HopException("The simple mapping transform needs one Mapping Input transform to write to in the sub-pipeline");
}
if (mappingInputs.size() > 1) {
throw new HopException("The simple mapping transform does not support multiple Mapping Input transforms to write to in the sub-pipeline");
}
simpleMappingData.mappingInput = mappingInputs.get(0);
List<MappingOutput> mappingOutputs = findMappingOutputs(simpleMappingData.mappingPipeline);
if (mappingOutputs.isEmpty()) {
throw new HopException("The simple mapping transform needs one Mapping Output transform to read from in the sub-pipeline");
}
if (mappingOutputs.size() > 1) {
throw new HopException("The simple mapping transform does not support multiple Mapping Output transforms to read from in the sub-pipeline");
}
simpleMappingData.mappingOutput = mappingOutputs.get(0);
// Finally, add the mapping pipeline to the active sub-pipelines
// map in the parent pipeline
//
getPipeline().addActiveSubPipeline(getTransformName(), simpleMappingData.mappingPipeline);
}
use of org.apache.hop.pipeline.transforms.input.MappingInput in project hop by apache.
the class SimpleMapping method findMappingInputs.
public static List<MappingInput> findMappingInputs(Pipeline mappingPipeline) {
List<MappingInput> list = new ArrayList<>();
List<IEngineComponent> components = mappingPipeline.getComponents();
for (IEngineComponent component : components) {
if (component instanceof MappingInput) {
list.add((MappingInput) component);
}
}
return list;
}
use of org.apache.hop.pipeline.transforms.input.MappingInput in project hop by apache.
the class SimpleMappingTest method setup.
@Before
public void setup() throws Exception {
transformMockHelper = new TransformMockHelper<>("SIMPLE_MAPPING_TEST", SimpleMappingMeta.class, SimpleMappingData.class);
when(transformMockHelper.logChannelFactory.create(any(), any(ILoggingObject.class))).thenReturn(transformMockHelper.iLogChannel);
when(transformMockHelper.pipeline.isRunning()).thenReturn(true);
// Mock for MappingInput
MappingInput mpInputMock = mock(MappingInput.class);
when(mpInputMock.getTransformName()).thenReturn(MAPPING_INPUT_TRANSFORM_NAME);
// Mock for MappingOutput
MappingOutput mpOutputMock = mock(MappingOutput.class);
when(mpOutputMock.getTransformName()).thenReturn(MAPPING_OUTPUT_TRANSFORM_NAME);
// Mock for RowDataInputMapper
RowDataInputMapper rdInputMpMock = mock(RowDataInputMapper.class);
IRowMeta rwMetaInMock = mock(RowMeta.class);
doReturn(Boolean.TRUE).when(rdInputMpMock).putRow(rwMetaInMock, new Object[] {});
// Mock for RowProducer
RowProducer rProducerMock = mock(RowProducer.class);
when(rProducerMock.putRow(any(IRowMeta.class), any(Object[].class), anyBoolean())).thenReturn(true);
// Mock for MappingIODefinition
MappingIODefinition mpIODefMock = mock(MappingIODefinition.class);
// Set up real SimpleMappingData with some mocked elements
simpleMpData.mappingInput = mpInputMock;
simpleMpData.mappingOutput = mpOutputMock;
simpleMpData.rowDataInputMapper = rdInputMpMock;
simpleMpData.mappingPipeline = transformMockHelper.pipeline;
Mockito.doReturn(mpOutputMock).when(transformMockHelper.pipeline).getTransform(MAPPING_OUTPUT_TRANSFORM_NAME, 0);
Mockito.doReturn(rProducerMock).when(transformMockHelper.pipeline).addRowProducer(MAPPING_INPUT_TRANSFORM_NAME, 0);
when(transformMockHelper.iTransformMeta.getInputMapping()).thenReturn(mpIODefMock);
}
use of org.apache.hop.pipeline.transforms.input.MappingInput in project hop by apache.
the class SimpleMappingTest method testTransformShouldStopProcessingInput_IfUnderlyingTransitionIsStopped.
@Test
public void testTransformShouldStopProcessingInput_IfUnderlyingTransitionIsStopped() throws Exception {
MappingInput mappingInput = mock(MappingInput.class);
when(mappingInput.getTransformName()).thenReturn(MAPPING_INPUT_TRANSFORM_NAME);
transformMockHelper.iTransformData.mappingInput = mappingInput;
RowProducer rowProducer = mock(RowProducer.class);
when(rowProducer.putRow(any(IRowMeta.class), any(Object[].class), anyBoolean())).thenReturn(true);
ITransform transform = mock(ITransform.class);
Pipeline mappingPipeline = mock(Pipeline.class);
when(mappingPipeline.addRowProducer(anyString(), anyInt())).thenReturn(rowProducer);
when(mappingPipeline.getTransform(anyString(), anyInt())).thenReturn(transform);
when(mappingPipeline.isFinishedOrStopped()).thenReturn(Boolean.FALSE).thenReturn(Boolean.TRUE);
transformMockHelper.iTransformData.mappingPipeline = mappingPipeline;
MappingOutput mappingOutput = mock(MappingOutput.class);
when(mappingOutput.getTransformName()).thenReturn(MAPPING_OUTPUT_TRANSFORM_NAME);
transformMockHelper.iTransformData.mappingOutput = mappingOutput;
smp = new SimpleMapping(transformMockHelper.transformMeta, transformMockHelper.iTransformMeta, transformMockHelper.iTransformData, 0, transformMockHelper.pipelineMeta, transformMockHelper.pipeline);
smp.init();
smp.addRowSetToInputRowSets(transformMockHelper.getMockInputRowSet(new Object[] {}));
smp.addRowSetToInputRowSets(transformMockHelper.getMockInputRowSet(new Object[] {}));
assertTrue(smp.processRow());
assertFalse(smp.processRow());
}
Aggregations