Search in sources :

Example 1 with IDocument

use of org.pentaho.metaverse.api.IDocument in project pentaho-metaverse by pentaho.

the class TransExtensionPointUtil method addLineageGraph.

public static void addLineageGraph(final TransMeta transMeta) throws MetaverseException {
    if (transMeta == null) {
        throw new MetaverseException(Messages.getString("ERROR.Document.IsNull"));
    }
    // Get the "natural" filename (repo-based if in repository, filesystem-based otherwise)
    String filename = getFilename(transMeta);
    final Graph graph = new TinkerGraph();
    final IMetaverseBuilder metaverseBuilder = new MetaverseBuilder(graph);
    final IMetaverseObjectFactory objFactory = MetaverseUtil.getDocumentController().getMetaverseObjectFactory();
    // Add the client design node
    final String clientName = KettleClientEnvironment.getInstance().getClient().toString();
    final INamespace namespace = new Namespace(clientName);
    final IMetaverseNode designNode = objFactory.createNodeObject(clientName, clientName, DictionaryConst.NODE_TYPE_LOCATOR);
    metaverseBuilder.addNode(designNode);
    // Create a document object containing the transMeta
    final IDocument document = MetaverseUtil.createDocument(namespace, transMeta, filename, transMeta.getName(), "ktr", URLConnection.getFileNameMap().getContentTypeFor("trans.ktr"));
    MetaverseUtil.addLineageGraph(document, graph);
}
Also used : TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) INamespace(org.pentaho.metaverse.api.INamespace) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) IMetaverseObjectFactory(org.pentaho.metaverse.api.IMetaverseObjectFactory) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) MetaverseBuilder(org.pentaho.metaverse.impl.MetaverseBuilder) MetaverseException(org.pentaho.metaverse.api.MetaverseException) INamespace(org.pentaho.metaverse.api.INamespace) Namespace(org.pentaho.metaverse.api.Namespace) IDocument(org.pentaho.metaverse.api.IDocument)

Example 2 with IDocument

use of org.pentaho.metaverse.api.IDocument in project pentaho-metaverse by pentaho.

the class TransformationRuntimeExtensionPoint method startAnalyzer.

protected void startAnalyzer(Trans trans) throws KettleException {
    if (trans == null) {
        return;
    }
    // Create and populate an execution profile with what we know so far
    ExecutionProfile executionProfile = new ExecutionProfile();
    populateExecutionProfile(executionProfile, trans);
    IMetaverseBuilder builder = TransLineageHolderMap.getInstance().getMetaverseBuilder(trans);
    // Analyze the current transformation
    if (documentAnalyzer != null) {
        documentAnalyzer.setMetaverseBuilder(builder);
        // Create a document for the Trans
        final String clientName = executionProfile.getExecutionEngine().getName();
        final INamespace namespace = new Namespace(clientName);
        final IMetaverseNode designNode = builder.getMetaverseObjectFactory().createNodeObject(clientName, clientName, DictionaryConst.NODE_TYPE_LOCATOR);
        builder.addNode(designNode);
        final TransMeta transMeta = trans.getTransMeta();
        String id = TransExtensionPointUtil.getFilename(transMeta);
        IDocument metaverseDocument = builder.getMetaverseObjectFactory().createDocumentObject();
        metaverseDocument.setNamespace(namespace);
        metaverseDocument.setContent(transMeta);
        metaverseDocument.setStringID(id);
        metaverseDocument.setName(transMeta.getName());
        metaverseDocument.setExtension("ktr");
        metaverseDocument.setMimeType(URLConnection.getFileNameMap().getContentTypeFor("trans.ktr"));
        metaverseDocument.setContext(new AnalysisContext(DictionaryConst.CONTEXT_RUNTIME));
        String normalizedPath;
        try {
            normalizedPath = KettleAnalyzerUtil.normalizeFilePath(id);
        } catch (MetaverseException e) {
            normalizedPath = id;
        }
        metaverseDocument.setProperty(DictionaryConst.PROPERTY_NAME, trans.getName());
        metaverseDocument.setProperty(DictionaryConst.PROPERTY_PATH, normalizedPath);
        metaverseDocument.setProperty(DictionaryConst.PROPERTY_NAMESPACE, namespace.getNamespaceId());
        Runnable analyzerRunner = MetaverseUtil.getAnalyzerRunner(documentAnalyzer, metaverseDocument);
        MetaverseCompletionService.getInstance().submit(analyzerRunner, id);
    }
    // Save the lineage objects for later
    LineageHolder holder = TransLineageHolderMap.getInstance().getLineageHolder(trans);
    holder.setExecutionProfile(executionProfile);
    holder.setMetaverseBuilder(builder);
}
Also used : INamespace(org.pentaho.metaverse.api.INamespace) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) TransMeta(org.pentaho.di.trans.TransMeta) AnalysisContext(org.pentaho.metaverse.api.AnalysisContext) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) ExecutionProfile(org.pentaho.metaverse.impl.model.ExecutionProfile) IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) INamespace(org.pentaho.metaverse.api.INamespace) Namespace(org.pentaho.metaverse.api.Namespace) IDocument(org.pentaho.metaverse.api.IDocument) MetaverseException(org.pentaho.metaverse.api.MetaverseException) LineageHolder(org.pentaho.metaverse.api.model.LineageHolder)

Example 3 with IDocument

use of org.pentaho.metaverse.api.IDocument in project pentaho-metaverse by pentaho.

the class LocatorRunner method processFile.

/**
 * Processes the contents of a file. Creates a metaverse document, sets the main properties,
 * and calls the document listeners to parse/process the file.
 *
 * @param namespace The namespace to use for creating ids
 * @param name      The name of the file
 * @param id        The id of the file
 * @param file      The contents of the file
 */
public void processFile(INamespace namespace, String name, String id, Object file) {
    if (stopping) {
        return;
    }
    String extension = FilenameUtils.getExtension(name);
    if ("".equals(extension)) {
        return;
    }
    String mimeType;
    try {
        mimeType = fileNameMap.getContentTypeFor(name);
    } catch (Exception e) {
        mimeType = null;
    // optional attribute, continue...
    }
    try {
        IDocument metaverseDocument = MetaverseUtil.createDocument(namespace, locator.getContents(file), id, name, extension, mimeType);
        DocumentEvent event = new DocumentEvent();
        event.setEventType("add");
        event.setDocument(metaverseDocument);
        locator.notifyListeners(event);
    } catch (Exception e) {
        LOG.error(Messages.getString("ERROR.NoContentForFile", name), e);
    }
}
Also used : DocumentEvent(org.pentaho.metaverse.impl.DocumentEvent) IDocument(org.pentaho.metaverse.api.IDocument)

Example 4 with IDocument

use of org.pentaho.metaverse.api.IDocument in project pentaho-metaverse by pentaho.

the class TransformationAnalyzerTest method testAnalyzeWithMissingPlugin.

@Test(expected = MetaverseAnalyzerException.class)
public void testAnalyzeWithMissingPlugin() throws MetaverseAnalyzerException {
    IDocument newMockTransDoc = mock(IDocument.class);
    when(newMockTransDoc.getType()).thenReturn(DictionaryConst.NODE_TYPE_TRANS);
    when(newMockTransDoc.getContent()).thenReturn("<?xml version=\"1.0\" encoding=\"UTF-8\"?><transformation><step><name>Load text from file</name>" + "<type>LoadTextFromFile</type></step></transformation>");
    analyzer.analyze(descriptor, newMockTransDoc);
}
Also used : IDocument(org.pentaho.metaverse.api.IDocument) Test(org.junit.Test)

Example 5 with IDocument

use of org.pentaho.metaverse.api.IDocument 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)

Aggregations

IDocument (org.pentaho.metaverse.api.IDocument)14 Test (org.junit.Test)8 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)4 INamespace (org.pentaho.metaverse.api.INamespace)4 Namespace (org.pentaho.metaverse.api.Namespace)4 Graph (com.tinkerpop.blueprints.Graph)3 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)3 IMetaverseBuilder (org.pentaho.metaverse.api.IMetaverseBuilder)3 MetaverseException (org.pentaho.metaverse.api.MetaverseException)3 TransMeta (org.pentaho.di.trans.TransMeta)2 AnalysisContext (org.pentaho.metaverse.api.AnalysisContext)2 IDocumentAnalyzer (org.pentaho.metaverse.api.IDocumentAnalyzer)2 IMetaverseObjectFactory (org.pentaho.metaverse.api.IMetaverseObjectFactory)2 IExecutionProfile (org.pentaho.metaverse.api.model.IExecutionProfile)2 LineageHolder (org.pentaho.metaverse.api.model.LineageHolder)2 ExecutionProfile (org.pentaho.metaverse.impl.model.ExecutionProfile)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1