use of org.pentaho.metaverse.api.IComponentDescriptor in project pentaho-metaverse by pentaho.
the class JobEntryAnalyzer method addConnectionNodes.
/**
* Adds any used database connections to the metaverse using the appropriate analyzer
*
* @throws MetaverseAnalyzerException
*/
protected void addConnectionNodes(IComponentDescriptor descriptor) throws MetaverseAnalyzerException {
if (jobEntryInterface == null) {
throw new MetaverseAnalyzerException(Messages.getString("ERROR.JobEntryInterface.IsNull"));
}
if (connectionAnalyzer != null) {
List<? extends Object> connections = connectionAnalyzer.getUsedConnections(jobEntryInterface);
for (Object connection : connections) {
String connName = null;
// see if the connection object has a getName method
try {
Method getNameMethod = connection.getClass().getMethod("getName", null);
connName = (String) getNameMethod.invoke(connection, null);
} catch (Exception e) {
// doesn't have a getName method, will try to get it from the descriptor later
}
try {
IComponentDescriptor connDescriptor = connectionAnalyzer.buildComponentDescriptor(descriptor, connection);
connName = connName == null ? descriptor.getName() : connName;
IMetaverseNode connNode = connectionAnalyzer.analyze(connDescriptor, connection);
metaverseBuilder.addLink(connNode, DictionaryConst.LINK_DEPENDENCYOF, rootNode);
} catch (Throwable t) {
// Don't throw the exception if a DB connection couldn't be analyzed, just log it and move on
LOGGER.warn(Messages.getString("WARNING.AnalyzingDatabaseConnection", connName), t);
}
}
}
}
use of org.pentaho.metaverse.api.IComponentDescriptor in project pentaho-metaverse by pentaho.
the class BaseKettleMetaverseComponentTest method testCreateFileNode.
@Test
public void testCreateFileNode() throws Exception {
component.createFileNode(null, null);
assertNull(component.createFileNode("/path/to/my/file", null));
IMetaverseBuilder metaverseBuilder = mock(IMetaverseBuilder.class);
when(metaverseBuilder.getMetaverseObjectFactory()).thenReturn(new MetaverseObjectFactory());
component.setMetaverseBuilder(metaverseBuilder);
IComponentDescriptor descriptor = mock(IComponentDescriptor.class);
INamespace ns = mock(INamespace.class);
when(descriptor.getNamespace()).thenReturn(ns);
assertNotNull(component.createFileNode("/path/to/my/file", descriptor));
}
use of org.pentaho.metaverse.api.IComponentDescriptor in project pentaho-metaverse by pentaho.
the class StepAnalyzerTest method testCreateFieldNode_virtual.
@Test
public void testCreateFieldNode_virtual() throws Exception {
IComponentDescriptor fieldDescriptor = mock(IComponentDescriptor.class);
ValueMetaInterface fieldMeta = new ValueMeta("address");
MetaverseTransientNode node = new MetaverseTransientNode("hello");
doReturn(node).when(analyzer).createNodeFromDescriptor(fieldDescriptor);
IMetaverseNode fieldNode = analyzer.createFieldNode(fieldDescriptor, fieldMeta, "nextStep", false);
assertNotNull(fieldNode);
assertNotNull(fieldNode.getProperty(DictionaryConst.PROPERTY_KETTLE_TYPE));
assertEquals("nextStep", fieldNode.getProperty(DictionaryConst.PROPERTY_TARGET_STEP));
// make sure it did not added to the graph
verify(builder, never()).addNode(node);
}
use of org.pentaho.metaverse.api.IComponentDescriptor in project pentaho-metaverse by pentaho.
the class StepAnalyzerTest method testCreateFieldNode_NoTargetStep.
@Test
public void testCreateFieldNode_NoTargetStep() throws Exception {
IComponentDescriptor fieldDescriptor = mock(IComponentDescriptor.class);
ValueMetaInterface fieldMeta = new ValueMeta("address");
MetaverseTransientNode node = new MetaverseTransientNode("hello");
doReturn(node).when(analyzer).createNodeFromDescriptor(fieldDescriptor);
IMetaverseNode fieldNode = analyzer.createFieldNode(fieldDescriptor, fieldMeta, null, true);
assertNotNull(fieldNode);
assertNotNull(fieldNode.getProperty(DictionaryConst.PROPERTY_KETTLE_TYPE));
assertNull(fieldNode.getProperty(DictionaryConst.PROPERTY_TARGET_STEP));
// make sure it did not added to the graph
verify(builder, never()).addNode(node);
}
use of org.pentaho.metaverse.api.IComponentDescriptor in project pentaho-metaverse by pentaho.
the class JobAnalyzer method analyze.
@Override
public synchronized IMetaverseNode analyze(IComponentDescriptor descriptor, IDocument document) throws MetaverseAnalyzerException {
validateState(document);
Object repoObject = document.getContent();
JobMeta jobMeta = null;
if (repoObject instanceof String) {
// hydrate the job
try {
String content = (String) repoObject;
ByteArrayInputStream xmlStream = new ByteArrayInputStream(content.getBytes());
jobMeta = new JobMeta(xmlStream, null, null);
} catch (KettleXMLException e) {
throw new MetaverseAnalyzerException(e);
}
} else if (repoObject instanceof JobMeta) {
jobMeta = (JobMeta) repoObject;
}
// construct a dummy job based on our JobMeta so we get out VariableSpace set properly
jobMeta.setFilename(document.getStringID());
IComponentDescriptor documentDescriptor = new MetaverseComponentDescriptor(document.getStringID(), DictionaryConst.NODE_TYPE_JOB, new Namespace(descriptor.getLogicalId()), descriptor.getContext());
// Create a metaverse node and start filling in details
IMetaverseNode jobNode = metaverseObjectFactory.createNodeObject(document.getNamespace(), jobMeta.getName(), DictionaryConst.NODE_TYPE_JOB);
jobNode.setLogicalIdGenerator(DictionaryConst.LOGICAL_ID_GENERATOR_DOCUMENT);
return analyze(documentDescriptor, jobMeta, jobNode, (String) document.getProperty(DictionaryConst.PROPERTY_PATH));
}
Aggregations