Search in sources :

Example 1 with IDocumentAnalyzer

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);
            }
        }
    }
}
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 IDocumentAnalyzer

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);
}
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 3 with IDocumentAnalyzer

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

Aggregations

IDocumentAnalyzer (org.pentaho.metaverse.api.IDocumentAnalyzer)3 Graph (com.tinkerpop.blueprints.Graph)2 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)2 Test (org.junit.Test)2 IDocument (org.pentaho.metaverse.api.IDocument)2 IDocumentController (org.pentaho.metaverse.api.IDocumentController)2 ArrayList (java.util.ArrayList)1 IComponentDescriptor (org.pentaho.metaverse.api.IComponentDescriptor)1 IMetaverseBuilder (org.pentaho.metaverse.api.IMetaverseBuilder)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