use of org.pentaho.metaverse.api.IDocumentAnalyzer in project pentaho-metaverse by pentaho.
the class MetaverseUtil method addLineageGraph.
public static void addLineageGraph(final IDocument document, Graph graph) throws MetaverseException {
if (document == null) {
throw new MetaverseException(Messages.getString("ERROR.Document.IsNull"));
}
// Find the transformation analyzer(s) and create Futures to analyze the transformation.
// Right now we expect a single transformation analyzer in the system. If we need to support more,
// the lineageGraphMap needs to map the TransMeta to a collection of Futures, etc.
IDocumentController docController = MetaverseUtil.getDocumentController();
if (docController != null) {
// Create a new builder, setting it on the DocumentController if possible
IMetaverseBuilder metaverseBuilder = new MetaverseBuilder(graph);
docController.setMetaverseBuilder(metaverseBuilder);
List<IDocumentAnalyzer> matchingAnalyzers = docController.getDocumentAnalyzers("ktr");
if (matchingAnalyzers != null) {
for (final IDocumentAnalyzer analyzer : matchingAnalyzers) {
Runnable analyzerRunner = getAnalyzerRunner(analyzer, document);
Graph g = (graph != null) ? graph : new TinkerGraph();
Future<Graph> transAnalysis = LineageGraphCompletionService.getInstance().submit(analyzerRunner, g);
// Save this Future, the client will call it when the analysis is needed
LineageGraphMap.getInstance().put(document.getContent(), transAnalysis);
}
}
}
}
use of org.pentaho.metaverse.api.IDocumentAnalyzer in project pentaho-metaverse by pentaho.
the class MetaverseUtilTest method testAddLineageGraph.
@Test
public void testAddLineageGraph() throws Exception {
IDocument document = mock(IDocument.class);
when(document.getName()).thenReturn("myDoc");
Object content = new Object();
when(document.getContent()).thenReturn(content);
IDocumentController documentController = mock(IDocumentController.class, withSettings().extraInterfaces(IRequiresMetaverseBuilder.class));
List<IDocumentAnalyzer> analyzers = new ArrayList<IDocumentAnalyzer>();
when(documentController.getDocumentAnalyzers(Mockito.anyString())).thenReturn(analyzers);
MetaverseUtil.documentController = documentController;
// Empty analyzer set
MetaverseUtil.addLineageGraph(document, null);
IDocumentAnalyzer<IMetaverseNode> documentAnalyzer = mock(IDocumentAnalyzer.class);
when(documentAnalyzer.analyze(Mockito.any(IComponentDescriptor.class), Mockito.any(IDocument.class))).thenReturn(mock(IMetaverseNode.class));
analyzers.add(documentAnalyzer);
Graph graph = new TinkerGraph();
MetaverseUtil.addLineageGraph(document, graph);
MetaverseUtil.addLineageGraph(document, null);
}
use of org.pentaho.metaverse.api.IDocumentAnalyzer in project pentaho-metaverse by pentaho.
the class JobRuntimeExtensionPointTest method testJobMetaVariablesAreCombinedWithExistingJobVariables.
@Test
public void testJobMetaVariablesAreCombinedWithExistingJobVariables() throws Exception {
JobLineageHolderMap originalHolderMap = mockBuilder();
JobRuntimeExtensionPoint extensionPoint = new JobRuntimeExtensionPoint();
IDocumentAnalyzer documentAnalyzer = Mockito.mock(IDocumentAnalyzer.class);
extensionPoint.setDocumentAnalyzer(documentAnalyzer);
final IMetaverseObjectFactory objectFactory = mock(IMetaverseObjectFactory.class);
when(mockBuilder.getMetaverseObjectFactory()).thenReturn(objectFactory);
final IDocument document = mock(IDocument.class);
when(objectFactory.createDocumentObject()).thenReturn(document);
job.setVariable("dontloseme", "okipromise");
extensionPoint.callExtensionPoint(null, job);
assertEquals("okipromise", job.getVariable("dontloseme"));
// Restore original JobLineageHolderMap for use by others
JobLineageHolderMap.setInstance(originalHolderMap);
}
Aggregations