Search in sources :

Example 1 with IStepExternalResourceConsumer

use of org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer in project pentaho-kettle by pentaho.

the class JsonInputAnalyzerPluginLifecycleListener method onStart.

@Override
public void onStart(final LifeEventHandler lifeEventHandler) throws LifecycleException {
    // instantiate a new analyzer
    final JsonInputAnalyzer analyzer = new JsonInputAnalyzer();
    // construct the external resource consumer for the files that it reads from
    final IStepExternalResourceConsumer consumer = new JsonInputExternalResourceConsumer();
    analyzer.setExternalResourceConsumer(consumer);
    // register the analyzer with PentahoSystem
    PentahoSystem.registerObject(analyzer);
    // register the consumer with PentahoSystem
    PentahoSystem.registerObject(consumer);
}
Also used : IStepExternalResourceConsumer(org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer)

Example 2 with IStepExternalResourceConsumer

use of org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer in project pentaho-metaverse by pentaho.

the class StepExternalConsumerRowListenerTest method testStepExternalConsumerRowListener.

@Test
public void testStepExternalConsumerRowListener() throws Exception {
    IStepExternalResourceConsumer consumer = mock(IStepExternalResourceConsumer.class);
    BaseStep mockStep = mock(BaseStep.class, withSettings().extraInterfaces(StepInterface.class));
    StepMeta mockStepMeta = mock(StepMeta.class);
    BaseStepMeta bsm = mock(BaseStepMeta.class, withSettings().extraInterfaces(StepMetaInterface.class));
    StepMetaInterface stepMetaInterface = (StepMetaInterface) bsm;
    when(mockStep.getStepMeta()).thenReturn(mockStepMeta);
    when(mockStepMeta.getStepMetaInterface()).thenReturn(stepMetaInterface);
    Trans mockTrans = mock(Trans.class);
    when(mockStep.getTrans()).thenReturn(mockTrans);
    IExecutionProfile executionProfile = mock(IExecutionProfile.class);
    IExecutionData executionData = mock(IExecutionData.class);
    when(executionProfile.getExecutionData()).thenReturn(executionData);
    LineageHolder holder = new LineageHolder();
    holder.setExecutionProfile(executionProfile);
    TransLineageHolderMap.getInstance().putLineageHolder(mockTrans, holder);
    StepExternalConsumerRowListener listener = new StepExternalConsumerRowListener(consumer, mockStep);
    RowMetaInterface rmi = mock(RowMetaInterface.class);
    Object[] row = new Object[0];
    listener.rowReadEvent(rmi, row);
}
Also used : BaseStep(org.pentaho.di.trans.step.BaseStep) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) IStepExternalResourceConsumer(org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer) StepInterface(org.pentaho.di.trans.step.StepInterface) IExecutionData(org.pentaho.metaverse.api.model.IExecutionData) IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) Trans(org.pentaho.di.trans.Trans) LineageHolder(org.pentaho.metaverse.api.model.LineageHolder) Test(org.junit.Test)

Example 3 with IStepExternalResourceConsumer

use of org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer in project pentaho-metaverse by pentaho.

the class StepExternalResourceConsumerListenerTest method testCallStepExtensionPoint.

@Test
public void testCallStepExtensionPoint() throws Exception {
    StepExternalResourceConsumerListener stepExtensionPoint = new StepExternalResourceConsumerListener();
    stepExtensionPoint.setStepExternalResourceConsumerProvider(MetaverseTestUtils.getStepExternalResourceConsumerProvider());
    StepMetaDataCombi stepCombi = mock(StepMetaDataCombi.class);
    BaseStepMeta bsm = mock(BaseStepMeta.class, withSettings().extraInterfaces(StepMetaInterface.class));
    stepCombi.meta = (StepMetaInterface) bsm;
    stepCombi.step = mock(StepInterface.class);
    stepCombi.stepMeta = mock(StepMeta.class);
    stepExtensionPoint.callExtensionPoint(null, stepCombi);
    Map<Class<? extends BaseStepMeta>, Set<IStepExternalResourceConsumer>> stepConsumerMap = new StepExternalResourceConsumerProvider().getStepConsumerMap();
    Set<IStepExternalResourceConsumer> consumers = new HashSet<IStepExternalResourceConsumer>();
    stepConsumerMap.put(bsm.getClass(), consumers);
    stepExtensionPoint.callExtensionPoint(null, stepCombi);
    IStepExternalResourceConsumer consumer = mock(IStepExternalResourceConsumer.class);
    when(consumer.getResourcesFromMeta(Mockito.any())).thenReturn(Collections.emptyList());
    consumers.add(consumer);
    Trans mockTrans = mock(Trans.class);
    when(stepCombi.step.getTrans()).thenReturn(mockTrans);
    stepExtensionPoint.callExtensionPoint(null, stepCombi);
    when(consumer.isDataDriven(Mockito.any())).thenReturn(Boolean.TRUE);
    stepExtensionPoint.callExtensionPoint(null, stepCombi);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) IStepExternalResourceConsumer(org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer) StepInterface(org.pentaho.di.trans.step.StepInterface) StepExternalResourceConsumerProvider(org.pentaho.metaverse.analyzer.kettle.step.StepExternalResourceConsumerProvider) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) Trans(org.pentaho.di.trans.Trans) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with IStepExternalResourceConsumer

use of org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer in project pentaho-metaverse by pentaho.

the class AbstractStepMetaJsonSerializerTest method testWriteExternalResources.

@Test
public void testWriteExternalResources() throws Exception {
    StepExternalResourceConsumerProvider mockConsumerMap = mock(StepExternalResourceConsumerProvider.class);
    List<IStepExternalResourceConsumer> consumers = new ArrayList<IStepExternalResourceConsumer>();
    Set<IExternalResourceInfo> externalResources = new HashSet<IExternalResourceInfo>();
    IExternalResourceInfo info = mock(IExternalResourceInfo.class);
    externalResources.add(info);
    IStepExternalResourceConsumer consumer = mock(IStepExternalResourceConsumer.class);
    when(consumer.getResourcesFromMeta(anyObject())).thenReturn(externalResources);
    consumers.add(consumer);
    Class<? extends BaseStepMeta> stepMetaClass = BaseStepMeta.class;
    when(mockConsumerMap.getExternalResourceConsumers(any(Collection.class))).thenReturn(consumers);
    serializer.setStepExternalResourceConsumerProvider(mockConsumerMap);
    serializer.writeExternalResources(spyMeta, json, provider);
    verify(mockConsumerMap).getExternalResourceConsumers(any(Collection.class));
    verify(json).writeArrayFieldStart(AbstractStepMetaJsonSerializer.JSON_PROPERTY_EXTERNAL_RESOURCES);
    verify(consumer).getResourcesFromMeta(anyObject());
    verify(json, times(externalResources.size())).writeObject(any(IExternalResourceInfo.class));
    verify(json).writeEndArray();
}
Also used : StepExternalResourceConsumerProvider(org.pentaho.metaverse.analyzer.kettle.step.StepExternalResourceConsumerProvider) IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) ArrayList(java.util.ArrayList) Collection(java.util.Collection) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) IStepExternalResourceConsumer(org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with IStepExternalResourceConsumer

use of org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer in project pentaho-metaverse by pentaho.

the class AbstractStepMetaJsonSerializer method writeExternalResources.

protected void writeExternalResources(T meta, JsonGenerator json, SerializerProvider serializerProvider) throws IOException, JsonGenerationException {
    Set<Class<?>> metaClassSet = new HashSet<Class<?>>(1);
    metaClassSet.add(meta.getClass());
    IStepExternalResourceConsumerProvider stepExternalResourceConsumerProvider = getStepExternalResourceConsumerProvider();
    List<IStepExternalResourceConsumer> resourceConsumers = null;
    if (stepExternalResourceConsumerProvider != null) {
        resourceConsumers = stepExternalResourceConsumerProvider.getExternalResourceConsumers(metaClassSet);
    }
    json.writeArrayFieldStart(JSON_PROPERTY_EXTERNAL_RESOURCES);
    if (resourceConsumers != null) {
        for (IStepExternalResourceConsumer resourceConsumer : resourceConsumers) {
            Collection<IExternalResourceInfo> infos = resourceConsumer.getResourcesFromMeta(meta);
            for (IExternalResourceInfo info : infos) {
                json.writeObject(info);
            }
        }
    }
    json.writeEndArray();
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) IStepExternalResourceConsumerProvider(org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumerProvider) IStepExternalResourceConsumer(org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer) HashSet(java.util.HashSet)

Aggregations

IStepExternalResourceConsumer (org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer)6 HashSet (java.util.HashSet)4 Test (org.junit.Test)3 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)3 StepInterface (org.pentaho.di.trans.step.StepInterface)3 StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)3 IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)3 Trans (org.pentaho.di.trans.Trans)2 StepMeta (org.pentaho.di.trans.step.StepMeta)2 StepMetaDataCombi (org.pentaho.di.trans.step.StepMetaDataCombi)2 StepExternalResourceConsumerProvider (org.pentaho.metaverse.analyzer.kettle.step.StepExternalResourceConsumerProvider)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Set (java.util.Set)1 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)1 BaseStep (org.pentaho.di.trans.step.BaseStep)1 IStepExternalResourceConsumerProvider (org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumerProvider)1 IExecutionData (org.pentaho.metaverse.api.model.IExecutionData)1 IExecutionProfile (org.pentaho.metaverse.api.model.IExecutionProfile)1 LineageHolder (org.pentaho.metaverse.api.model.LineageHolder)1