use of org.pentaho.metaverse.api.IDocumentController 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.IDocumentController in project pentaho-metaverse by pentaho.
the class TransExtensionPointUtilTest method testAddLineageGraphNullFilename.
@Test
public void testAddLineageGraphNullFilename() throws Exception {
IDocumentController mockDoc = mock(IDocumentController.class);
IMetaverseObjectFactory factory = MetaverseTestUtils.getMetaverseObjectFactory();
when(mockDoc.getMetaverseObjectFactory()).thenReturn(factory);
MetaverseUtil.setDocumentController(mockDoc);
when(transMeta.getFilename()).thenReturn(null);
when(transMeta.getPathAndName()).thenReturn("/Transformation 1");
TransExtensionPointUtil.addLineageGraph(transMeta);
}
use of org.pentaho.metaverse.api.IDocumentController in project pentaho-metaverse by pentaho.
the class MetaverseTestUtils method getDocumentController.
public static IDocumentController getDocumentController() {
IDocumentController documentController = mock(IDocumentController.class);
IMetaverseBuilder metaverseBuilder = mock(IMetaverseBuilder.class);
when(metaverseBuilder.getMetaverseObjectFactory()).thenReturn(getMetaverseObjectFactory());
when(documentController.getMetaverseObjectFactory()).thenReturn(getMetaverseObjectFactory());
when(documentController.getMetaverseBuilder()).thenReturn(metaverseBuilder);
return documentController;
}
use of org.pentaho.metaverse.api.IDocumentController 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.IDocumentController in project pentaho-metaverse by pentaho.
the class MetaverseUtilTest method testGetDocumentController.
@Test
public void testGetDocumentController() throws Exception {
IDocumentController documentController = MetaverseUtil.getDocumentController();
assertNotNull(documentController);
MetaverseUtil.documentController = null;
assertNull(MetaverseUtil.getDocumentController());
// Generate an exception
MetaverseBeanUtil instance = MetaverseBeanUtil.getInstance();
BundleContext bundleContext = mock(BundleContext.class);
Bundle bundle = mock(Bundle.class);
when(bundleContext.getBundle()).thenReturn(bundle);
instance.setBundleContext(bundleContext);
ServiceReference serviceReference = mock(ServiceReference.class);
BlueprintContainer service = mock(BlueprintContainer.class);
when(bundleContext.getService(Mockito.any(ServiceReference.class))).thenReturn(service);
when(service.getComponentInstance("IDocumentController")).thenReturn(documentController);
assertNull(MetaverseUtil.getDocumentController());
}
Aggregations