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