Search in sources :

Example 1 with IFieldLineageMetadataProvider

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

the class AbstractStepMetaJsonSerializer method getFieldLineageMetadataProvider.

protected IFieldLineageMetadataProvider getFieldLineageMetadataProvider(T meta) {
    IStepAnalyzerProvider provider = getStepAnalyzerProvider();
    if (provider == null) {
        // try to get it from PentahoSystem
        provider = PentahoSystem.get(IStepAnalyzerProvider.class);
    }
    if (provider != null) {
        Set<Class<?>> types = new HashSet<Class<?>>();
        types.add(meta.getClass());
        List<IStepAnalyzer> analyzers = provider.getAnalyzers(types);
        if (analyzers != null) {
            for (IStepAnalyzer analyzer : analyzers) {
                // try to set up the analyzer with parent step & trans meta
                if (analyzer instanceof StepAnalyzer) {
                    StepAnalyzer bsa = (StepAnalyzer) analyzer;
                    try {
                        bsa.validateState(null, meta);
                        bsa.loadInputAndOutputStreamFields(meta);
                    } catch (MetaverseAnalyzerException e) {
                    // eat it
                    }
                }
                if (analyzer instanceof IFieldLineageMetadataProvider) {
                    return (IFieldLineageMetadataProvider) analyzer;
                }
            }
        }
    }
    return new GenericStepMetaAnalyzer();
}
Also used : IStepAnalyzer(org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzer) IFieldLineageMetadataProvider(org.pentaho.metaverse.api.analyzer.kettle.step.IFieldLineageMetadataProvider) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) StepAnalyzer(org.pentaho.metaverse.api.analyzer.kettle.step.StepAnalyzer) IStepAnalyzer(org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzer) IStepAnalyzerProvider(org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzerProvider) HashSet(java.util.HashSet) GenericStepMetaAnalyzer(org.pentaho.metaverse.analyzer.kettle.step.GenericStepMetaAnalyzer)

Example 2 with IFieldLineageMetadataProvider

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

the class AbstractStepMetaJsonSerializer method writeFieldTransforms.

protected void writeFieldTransforms(T meta, JsonGenerator json, SerializerProvider serializerProvider) throws IOException, JsonGenerationException {
    json.writeArrayFieldStart(JSON_PROPERTY_TRANSFORMS);
    IFieldLineageMetadataProvider mapper = getFieldLineageMetadataProvider(meta);
    try {
        Set<ComponentDerivationRecord> changes = mapper.getChangeRecords(meta);
        if (changes != null) {
            for (ComponentDerivationRecord change : changes) {
                if (change.hasDelta()) {
                    json.writeObject(change);
                }
            }
        }
    } catch (MetaverseAnalyzerException e) {
        LOGGER.warn(Messages.getString("WARNING.Serialization.Step.WriteFieldTransforms", meta.getParentStepMeta().getName()), e);
    }
    json.writeEndArray();
}
Also used : IFieldLineageMetadataProvider(org.pentaho.metaverse.api.analyzer.kettle.step.IFieldLineageMetadataProvider) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord)

Example 3 with IFieldLineageMetadataProvider

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

the class AbstractStepMetaJsonSerializerTest method testSerializeBasic.

@Test
public void testSerializeBasic() throws Exception {
    AbstractStepMetaJsonSerializer<BaseStepMeta> spySerializer = spy(serializer);
    IFieldLineageMetadataProvider mapper = mock(IFieldLineageMetadataProvider.class);
    when(spySerializer.getFieldLineageMetadataProvider(spyMeta)).thenReturn(mapper);
    when(mapper.getInputFields(spyMeta)).thenReturn(new HashMap<String, RowMetaInterface>());
    spySerializer.serialize(spyMeta, json, provider);
    verify(json).writeStartObject();
    verify(json).writeStringField(IInfo.JSON_PROPERTY_CLASS, spyMeta.getClass().getName());
    verify(json).writeStringField(IInfo.JSON_PROPERTY_NAME, spyParent.getName());
    verify(json).writeStringField(eq(AbstractStepMetaJsonSerializer.JSON_PROPERTY_TYPE), anyString());
    // make sure the templated methods are called
    verify(spySerializer).writeRepoAttributes(spyMeta, json);
    verify(spySerializer).writeCustomProperties(spyMeta, json, provider);
    verify(spySerializer).writeInputFields(spyMeta, json);
    verify(spySerializer).writeOutputFields(spyParent, json);
    verify(json).writeArrayFieldStart(AbstractStepMetaJsonSerializer.JSON_PROPERTY_TRANSFORMS);
    verify(spySerializer).writeFieldTransforms(spyMeta, json, provider);
    verify(json).writeEndObject();
    verify(spySerializer).writeExternalResources(spyMeta, json, provider);
}
Also used : IFieldLineageMetadataProvider(org.pentaho.metaverse.api.analyzer.kettle.step.IFieldLineageMetadataProvider) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Matchers.anyString(org.mockito.Matchers.anyString) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Test(org.junit.Test)

Example 4 with IFieldLineageMetadataProvider

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

the class AbstractStepMetaJsonSerializerTest method testGetStepFieldMapper.

@Test
public void testGetStepFieldMapper() throws Exception {
    IStepAnalyzerProvider provider = mock(IStepAnalyzerProvider.class);
    IStepAnalyzer<DummyTransMeta> analyzer = mock(IStepAnalyzer.class, withSettings().extraInterfaces(IFieldLineageMetadataProvider.class));
    List<IStepAnalyzer> analyzers = new ArrayList<IStepAnalyzer>(1);
    analyzers.add(analyzer);
    when(provider.getAnalyzers(any(Set.class))).thenReturn(analyzers);
    serializer.setStepAnalyzerProvider(provider);
    IFieldLineageMetadataProvider handler = serializer.getFieldLineageMetadataProvider(spyMeta);
    assertFalse(handler instanceof GenericStepMetaAnalyzer);
}
Also used : IStepAnalyzer(org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzer) IFieldLineageMetadataProvider(org.pentaho.metaverse.api.analyzer.kettle.step.IFieldLineageMetadataProvider) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) IStepAnalyzerProvider(org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzerProvider) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) GenericStepMetaAnalyzer(org.pentaho.metaverse.analyzer.kettle.step.GenericStepMetaAnalyzer) Test(org.junit.Test)

Example 5 with IFieldLineageMetadataProvider

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

the class AbstractStepMetaJsonSerializer method writeFieldMappings.

protected void writeFieldMappings(T meta, JsonGenerator json, SerializerProvider serializerProvider) throws IOException {
    json.writeArrayFieldStart(JSON_PROPERTY_MAPPINGS);
    IFieldLineageMetadataProvider mapper = getFieldLineageMetadataProvider(meta);
    try {
        Set<IFieldMapping> fieldMappings = mapper.getFieldMappings(meta);
        if (fieldMappings != null) {
            for (IFieldMapping fieldMapping : fieldMappings) {
                json.writeObject(fieldMapping);
            }
        }
    } catch (MetaverseAnalyzerException e) {
        LOGGER.warn(Messages.getString("WARNING.Serialization.Step.WriteFieldMappings", meta.getParentStepMeta().getName()), e);
    }
    json.writeEndArray();
}
Also used : IFieldLineageMetadataProvider(org.pentaho.metaverse.api.analyzer.kettle.step.IFieldLineageMetadataProvider) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) IFieldMapping(org.pentaho.metaverse.api.model.kettle.IFieldMapping)

Aggregations

IFieldLineageMetadataProvider (org.pentaho.metaverse.api.analyzer.kettle.step.IFieldLineageMetadataProvider)10 Test (org.junit.Test)6 HashSet (java.util.HashSet)5 ArrayList (java.util.ArrayList)3 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)3 GenericStepMetaAnalyzer (org.pentaho.metaverse.analyzer.kettle.step.GenericStepMetaAnalyzer)3 MetaverseAnalyzerException (org.pentaho.metaverse.api.MetaverseAnalyzerException)3 IStepAnalyzerProvider (org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzerProvider)3 Set (java.util.Set)2 Matchers.anyString (org.mockito.Matchers.anyString)2 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)2 ComponentDerivationRecord (org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord)2 IStepAnalyzer (org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzer)2 IFieldMapping (org.pentaho.metaverse.api.model.kettle.IFieldMapping)2 HashMap (java.util.HashMap)1 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)1 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)1 StepAnalyzer (org.pentaho.metaverse.api.analyzer.kettle.step.StepAnalyzer)1 FieldMapping (org.pentaho.metaverse.api.model.kettle.FieldMapping)1 IFieldInfo (org.pentaho.metaverse.api.model.kettle.IFieldInfo)1