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