Search in sources :

Example 1 with IDocumentController

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);
            }
        }
    }
}
Also used : TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) IDocumentController(org.pentaho.metaverse.api.IDocumentController) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) IDocumentAnalyzer(org.pentaho.metaverse.api.IDocumentAnalyzer) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) MetaverseBuilder(org.pentaho.metaverse.impl.MetaverseBuilder) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) MetaverseException(org.pentaho.metaverse.api.MetaverseException)

Example 2 with IDocumentController

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);
}
Also used : IDocumentController(org.pentaho.metaverse.api.IDocumentController) IMetaverseObjectFactory(org.pentaho.metaverse.api.IMetaverseObjectFactory) Test(org.junit.Test)

Example 3 with IDocumentController

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;
}
Also used : IDocumentController(org.pentaho.metaverse.api.IDocumentController) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder)

Example 4 with IDocumentController

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);
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) IDocumentController(org.pentaho.metaverse.api.IDocumentController) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) IDocumentAnalyzer(org.pentaho.metaverse.api.IDocumentAnalyzer) ArrayList(java.util.ArrayList) IRequiresMetaverseBuilder(org.pentaho.metaverse.api.IRequiresMetaverseBuilder) IDocument(org.pentaho.metaverse.api.IDocument) Test(org.junit.Test)

Example 5 with IDocumentController

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());
}
Also used : BlueprintContainer(org.osgi.service.blueprint.container.BlueprintContainer) IDocumentController(org.pentaho.metaverse.api.IDocumentController) Bundle(org.osgi.framework.Bundle) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Aggregations

IDocumentController (org.pentaho.metaverse.api.IDocumentController)6 Test (org.junit.Test)3 IMetaverseBuilder (org.pentaho.metaverse.api.IMetaverseBuilder)3 Graph (com.tinkerpop.blueprints.Graph)2 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)2 IDocumentAnalyzer (org.pentaho.metaverse.api.IDocumentAnalyzer)2 ArrayList (java.util.ArrayList)1 Bundle (org.osgi.framework.Bundle)1 BundleContext (org.osgi.framework.BundleContext)1 ServiceReference (org.osgi.framework.ServiceReference)1 BlueprintContainer (org.osgi.service.blueprint.container.BlueprintContainer)1 IComponentDescriptor (org.pentaho.metaverse.api.IComponentDescriptor)1 IDocument (org.pentaho.metaverse.api.IDocument)1 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)1 IMetaverseObjectFactory (org.pentaho.metaverse.api.IMetaverseObjectFactory)1 IRequiresMetaverseBuilder (org.pentaho.metaverse.api.IRequiresMetaverseBuilder)1 MetaverseException (org.pentaho.metaverse.api.MetaverseException)1 MetaverseBuilder (org.pentaho.metaverse.impl.MetaverseBuilder)1