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 StepAnalyzer method getPrevFieldDescriptor.
/**
* Create a new IComponentDescriptor for a field input into this step
*
* @param prevStepName
* @param fieldName
* @return
*/
protected IComponentDescriptor getPrevFieldDescriptor(String prevStepName, String fieldName) {
IComponentDescriptor prevFieldDescriptor = null;
if (StringUtils.isNotEmpty(prevStepName)) {
Object nsObj = rootNode.getProperty(DictionaryConst.PROPERTY_NAMESPACE);
INamespace ns = new Namespace(nsObj != null ? nsObj.toString() : null);
IMetaverseNode tmpOriginNode = getMetaverseObjectFactory().createNodeObject(ns, prevStepName, DictionaryConst.NODE_TYPE_TRANS_STEP);
INamespace stepFieldNamespace = new Namespace(tmpOriginNode.getLogicalId());
prevFieldDescriptor = new MetaverseComponentDescriptor(fieldName, getInputNodeType(), stepFieldNamespace, getDescriptor().getContext());
}
return prevFieldDescriptor;
}
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);
}
Aggregations